1 | # @configure_input@ |
---|
2 | # $Id: common_defs.sh.in 2458 2011-04-03 15:14:46Z peter $ |
---|
3 | |
---|
4 | # Copyright (C) 2009, 2010, 2011 Peter Johansson |
---|
5 | # |
---|
6 | # This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | # |
---|
8 | # The yat library is free software; you can redistribute it |
---|
9 | # and/or modify it under the terms of the GNU General Public License as |
---|
10 | # published by the Free Software Foundation; either version 3 of the |
---|
11 | # License, or (at your option) any later version. |
---|
12 | # |
---|
13 | # The yat library is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | # General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU General Public License |
---|
19 | # along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | |
---|
21 | |
---|
22 | # function copied from GNU Automake 1.10.2 |
---|
23 | # |
---|
24 | # is_newest FILE FILES |
---|
25 | # -------------------- |
---|
26 | # Return false if any file in FILES is newer than FILE. |
---|
27 | # Resolve ties in favor of FILE. |
---|
28 | is_newest () |
---|
29 | { |
---|
30 | test x`find "$@" -newer "$1"` = x |
---|
31 | } |
---|
32 | |
---|
33 | # |
---|
34 | # |
---|
35 | bootstrap () |
---|
36 | { |
---|
37 | @MKDIR_P@ m4 |
---|
38 | autoreconf -siv && true |
---|
39 | res=$? |
---|
40 | case $res in |
---|
41 | 0) |
---|
42 | :;; |
---|
43 | 63) |
---|
44 | exit 77;; |
---|
45 | *) |
---|
46 | exit $res;; |
---|
47 | esac |
---|
48 | } |
---|
49 | |
---|
50 | # Usage: run PROG EXPECTED_EXITCODE [OPTION]... |
---|
51 | run () |
---|
52 | { |
---|
53 | test $# -ge 2 || exit 1 |
---|
54 | foo_prog=$1 |
---|
55 | shift |
---|
56 | expected_exitcode=$1 |
---|
57 | shift |
---|
58 | exitcode=0 |
---|
59 | $foo_prog ${1+"$@"} > stdout 2>stderr || exitcode=$? |
---|
60 | cat stderr >&2 |
---|
61 | cat stdout |
---|
62 | test $exitcode = $expected_exitcode || exit 1 |
---|
63 | } |
---|
64 | |
---|
65 | me=$0 |
---|
66 | |
---|
67 | echo "=== Running $me ===" |
---|
68 | |
---|
69 | # if required tool is not available, exit 77 to skip test |
---|
70 | if test -n "$required"; then |
---|
71 | for tool in $required; do |
---|
72 | case $tool in |
---|
73 | automake) |
---|
74 | echo "$me: running $tool --version" |
---|
75 | ($tool --version) || exit 77; |
---|
76 | # skip test if automake older than v1.10 |
---|
77 | version_am=`$tool --version | head -n 1 | cut -f 2 -d ')'` |
---|
78 | ver_major=`echo ${version_am} | cut -f 1 -d '.'` |
---|
79 | test ${ver_major} -ge 1 || exit 77 |
---|
80 | ver_minor=`echo ${version_am} | cut -f 2 -d '.'` |
---|
81 | test ${ver_major} -gt 1 || test ${ver_minor} -ge 10 || exit 77 |
---|
82 | ;; |
---|
83 | libtool) |
---|
84 | # GNU libtool comes as glibtool on Mac OS |
---|
85 | (echo "$me: running libtool --version" && libtool --version) || \ |
---|
86 | (echo "$me: running glibtool --version" && glibtool --version) || exit 77 |
---|
87 | ;; |
---|
88 | static) |
---|
89 | if (test "x@enable_static@" = "xno"); then |
---|
90 | echo static libyat disabled; |
---|
91 | exit 77; |
---|
92 | fi |
---|
93 | ;; |
---|
94 | *) |
---|
95 | echo "$me: running $tool --version" |
---|
96 | ($tool --version) || exit 77 |
---|
97 | esac |
---|
98 | done |
---|
99 | fi |
---|
100 | |
---|
101 | # some defs we need in tests |
---|
102 | test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'` |
---|
103 | test_dir="testSubDir/$test_dir" |
---|
104 | abs_top_builddir=@abs_top_builddir@ |
---|
105 | abs_top_srcdir=@abs_top_srcdir@ |
---|
106 | move_if_change=@abs_top_srcdir@/build_support/move-if-change |
---|
107 | |
---|
108 | rm -rf $test_dir |
---|
109 | @MKDIR_P@ --verbose $test_dir |
---|
110 | |
---|
111 | cd $test_dir |
---|
112 | |
---|
113 | if (echo "$required" | grep autoconf > /dev/null); then |
---|
114 | echo "creating configure.ac" |
---|
115 | cat > configure.ac <<EOF |
---|
116 | AC_INIT([hello],[1.0]) |
---|
117 | AC_CONFIG_SRCDIR([hello.cc]) |
---|
118 | AM_INIT_AUTOMAKE([foreign]) |
---|
119 | AC_CONFIG_MACRO_DIR([m4]) |
---|
120 | AC_LANG(C++) |
---|
121 | AC_PROG_CXXCPP |
---|
122 | AC_PROG_CXX |
---|
123 | EOF |
---|
124 | if (echo "$required" | grep libtool > /dev/null); then |
---|
125 | echo AC_PROG_LIBTOOL >> configure.ac |
---|
126 | fi |
---|
127 | |
---|
128 | |
---|
129 | echo "creating Makefile.am" |
---|
130 | cat > Makefile.am <<EOF |
---|
131 | ACLOCAL_AMFLAGS = -I m4 -I ${abs_top_srcdir}/m4 --install |
---|
132 | AM_CPPFLAGS = \$(YAT_CPPFLAGS) |
---|
133 | AM_CXXFLAGS = \$(YAT_CXXFLAGS) |
---|
134 | LDADD = \$(YAT_LDADD) |
---|
135 | bin_PROGRAMS = hello |
---|
136 | TESTS = hello |
---|
137 | hello_SOURCES = hello.cc |
---|
138 | EOF |
---|
139 | |
---|
140 | echo "creating hello.cc" |
---|
141 | cat > hello.cc <<EOF |
---|
142 | #include <yat/utility/Vector.h> |
---|
143 | #include <yat/utility/version.h> |
---|
144 | #include <algorithm> |
---|
145 | #include <iostream> |
---|
146 | #include <string> |
---|
147 | int main(void) |
---|
148 | { |
---|
149 | using namespace theplu::yat; |
---|
150 | if (utility::version()!="@VERSION@") { |
---|
151 | std::cerr << "Incorrect version of linked libyat\n"; |
---|
152 | return 1; |
---|
153 | } |
---|
154 | // testing something with gsl |
---|
155 | utility::Vector v(10); |
---|
156 | v.resize(120); |
---|
157 | // testing something with boost |
---|
158 | std::copy(v.begin(), v.begin()+10, v.begin()+10); |
---|
159 | return 0; |
---|
160 | } |
---|
161 | EOF |
---|
162 | fi #end of creation of autotool files |
---|
163 | |
---|
164 | # turn on shell traces |
---|
165 | set -x |
---|