]> arthur.barton.de Git - bup.git/blob - config/configure
configure: check for <readline.h> vs <readline/readline.h>
[bup.git] / config / configure
1 #!/usr/bin/env bash
2
3 bup_find_prog()
4 {
5     # Prints prog path to stdout or nothing.
6     local name="$1" result="$2"
7     TLOGN "checking for $name"
8     if ! [ "$result" ]; then
9         result=`acLookFor "$name"`
10     fi
11     TLOG " ($result)"
12     echo "$result"
13 }
14
15 bup_try_c_code()
16 {
17     local code="$1" tmpdir rc cflags=''
18     if test -z "$code"; then
19         AC_FAIL "No code provided to test compile"
20     fi
21     case "$#" in
22         1) ;;
23         2) cflags="$2" ;;
24         *)
25             AC_FAIL "Invald call to bup_try_c_code" "$@"
26             ;;
27     esac
28     tmpdir="$(mktemp -d "bup-try-c-compile-XXXXXXX")" || exit $?
29     echo "$code" > "$tmpdir/test.c" || exit $?
30     $AC_CC -Wall -Werror $cflags -c -o "$tmpdir/test" "$tmpdir/test.c"
31     rc=$?
32     rm -r "$tmpdir" || exit $?
33     return $rc
34 }
35
36 TARGET=bup
37
38 . ./configure.inc
39
40 AC_INIT $TARGET
41
42 if ! AC_PROG_CC; then
43     LOG " You need to have a functional C compiler to build $TARGET"
44     exit 1
45 fi
46
47 MAKE="$(bup_find_prog make "$MAKE")"
48 if test -z "$MAKE"; then
49     MAKE="$(bup_find_prog gmake "$GMAKE")"
50 fi
51
52 if test -z "$MAKE"; then
53     AC_FAIL "ERROR: unable to find make"
54 fi
55
56 if ! ($MAKE --version | grep "GNU Make"); then
57     AC_FAIL "ERROR: $MAKE is not GNU Make"
58 fi
59
60 MAKE_VERSION=`$MAKE --version | grep "GNU Make" | awk '{print $3}'`
61 if [ -z "$MAKE_VERSION" ]; then
62     AC_FAIL "ERROR: $MAKE --version does not return sensible output?"
63 fi
64 expr "$MAKE_VERSION" '>=' '3.81' || AC_FAIL "ERROR: $MAKE must be >= version 3.81"
65
66 AC_SUB bup_make "$MAKE"
67
68 bup_python="$(type -p "$PYTHON")"
69 test -z "$bup_python" && bup_python="$(bup_find_prog python2.7 '')"
70 test -z "$bup_python" && bup_python="$(bup_find_prog python2.6 '')"
71 test -z "$bup_python" && bup_python="$(bup_find_prog python2 '')"
72 test -z "$bup_python" && bup_python="$(bup_find_prog python '')"
73 if test -z "$bup_python"; then
74     AC_FAIL "ERROR: unable to find python"
75 else
76     AC_SUB bup_python "$bup_python"
77     AC_SUB bup_python_majver \
78            "$("$bup_python" -c 'import sys; print(sys.version_info[0])')"
79 fi
80
81 bup_git="$(bup_find_prog git '')"
82 if test -z "$bup_git"; then
83     AC_FAIL "ERROR: unable to find git"
84 fi
85
86 # For stat.
87 AC_CHECK_HEADERS sys/stat.h
88 AC_CHECK_HEADERS sys/types.h
89
90 # For stat and mincore.
91 AC_CHECK_HEADERS unistd.h
92
93 # For mincore.
94 AC_CHECK_HEADERS sys/mman.h
95
96 # For FS_IOC_GETFLAGS and FS_IOC_SETFLAGS.
97 AC_CHECK_HEADERS linux/fs.h
98 AC_CHECK_HEADERS sys/ioctl.h
99
100 # On GNU/kFreeBSD utimensat is defined in GNU libc, but won't work.
101 if [ -z "$OS_GNU_KFREEBSD" ]; then
102     AC_CHECK_FUNCS utimensat
103 fi
104 AC_CHECK_FUNCS utimes
105 AC_CHECK_FUNCS lutimes
106
107
108 builtin_mul_overflow_code="
109 #include <stddef.h>
110 int main(int argc, char **argv)
111 {
112     size_t n = 0, size = 0, total;
113     __builtin_mul_overflow(n, size, &total);
114     return 0;
115 }
116 "
117
118 TLOGN "checking for __builtin_mul_overflow"
119 if bup_try_c_code "$builtin_mul_overflow_code"; then
120     AC_DEFINE BUP_HAVE_BUILTIN_MUL_OVERFLOW 1
121     TLOG ' (found)'
122 else
123     TLOG ' (not found)'
124 fi
125
126
127 AC_CHECK_FUNCS mincore
128
129 mincore_incore_code="
130 #if 0$ac_defined_HAVE_UNISTD_H
131 #include <unistd.h>
132 #endif
133 #if 0$ac_defined_HAVE_SYS_MMAN_H
134 #include <sys/mman.h>
135 #endif
136 int main(int argc, char **argv)
137 {
138     if (MINCORE_INCORE)
139       return 0;
140 }
141 "
142
143 mincore_buf_type_code()
144 {
145     local vec_type="$1"
146     echo "
147 #include <sys/mman.h>
148 int main(int argc, char **argv)
149 {
150     void *x = 0;
151     $vec_type *buf = 0;
152     return mincore(x, 0, buf);
153 }" || exit $?
154 }
155
156 if test "$ac_defined_HAVE_MINCORE"; then
157     TLOGN "checking for MINCORE_INCORE"
158     if bup_try_c_code "$mincore_incore_code"; then
159         AC_DEFINE BUP_HAVE_MINCORE_INCORE 1
160         TLOG ' (found)'
161     else
162         TLOG ' (not found)'
163     fi
164
165     TLOGN "checking mincore buf type"
166     if bup_try_c_code "$(mincore_buf_type_code char)"; then
167         AC_DEFINE BUP_MINCORE_BUF_TYPE 'char'
168         TLOG ' (char)'
169     elif bup_try_c_code "$(mincore_buf_type_code 'unsigned char')"; then
170         AC_DEFINE BUP_MINCORE_BUF_TYPE 'unsigned char'
171         TLOG ' (unsigned char)'
172     else
173         AC_FAIL "ERROR: unexpected mincore definition; please notify bup-list@googlegroups.com"
174     fi
175 fi
176
177
178 TLOGN "checking for readline"
179 bup_have_readline=''
180 bup_readline_includes_in_subdir=''
181 bup_readline_via_pkg_config=''
182 if pkg-config readline; then
183     bup_readline_cflags="$(pkg-config readline --cflags)" || exit $?
184     bup_readline_ldflags="$(pkg-config readline --libs)" || exit $?
185     # It looks like it's not uncommon for pkg-config to provide a -I
186     # that doesn't support the documentation's specified #include
187     # <readline/readline.h>.  See what's really going on.
188     if bup_try_c_code '#include <readline/readline.h>' "$bup_readline_cflags"
189     then
190         bup_have_readline=1
191         bup_readline_includes_in_subdir=1
192     elif bup_try_c_code '#include <readline.h>' "$bup_readline_cflags"
193     then
194         bup_have_readline=1
195     fi
196     if test "$bup_have_readline"; then
197         bup_readline_via_pkg_config=1
198     else
199         bup_readline_cflags=''
200         bup_readline_ldflags=''
201     fi
202 fi
203 if ! test "$bup_have_readline"; then
204     if bup_try_c_code '#include <readline/readline.h>'; then
205         bup_readline_ldflags=-lreadline
206         bup_have_readline=1
207         bup_readline_includes_in_subdir=1
208     elif bup_try_c_code '#include <readline.h>'; then
209         bup_readline_ldflags=-lreadline
210         bup_have_readline=1
211     fi
212 fi
213 if test "$bup_have_readline"; then
214     AC_DEFINE BUP_HAVE_READLINE 1
215     if test "$bup_readline_includes_in_subdir"; then
216         AC_DEFINE BUP_READLINE_INCLUDES_IN_SUBDIR 1
217     fi
218     if test "$bup_readline_via_pkg_config"; then
219         TLOG ' (yes, pkg-config)'
220     else
221         TLOG ' (yes)'
222     fi
223 fi
224
225
226 AC_SUB bup_readline_cflags "$bup_readline_cflags"
227 AC_SUB bup_readline_ldflags "$bup_readline_ldflags"
228 AC_SUB bup_have_readline "$bup_have_readline"
229
230
231 AC_CHECK_FIELD stat st_atim sys/types.h sys/stat.h unistd.h
232 AC_CHECK_FIELD stat st_mtim sys/types.h sys/stat.h unistd.h
233 AC_CHECK_FIELD stat st_ctim sys/types.h sys/stat.h unistd.h
234
235 AC_CHECK_FIELD stat st_atimensec sys/types.h sys/stat.h unistd.h
236 AC_CHECK_FIELD stat st_mtimensec sys/types.h sys/stat.h unistd.h
237 AC_CHECK_FIELD stat st_ctimensec sys/types.h sys/stat.h unistd.h
238
239 AC_CHECK_FIELD tm tm_gmtoff time.h
240
241
242 orig_ac_cc="$AC_CC"
243 orig_libs="$LIBS"
244 TLOGN "checking for libacl"
245 if pkg-config libacl; then
246     bup_libacl_cflags="$(pkg-config libacl --cflags)"
247     bup_libacl_ldflags="$(pkg-config libacl --libs)"
248     TLOG ' (yes, pkg-config)'
249 else
250     bup_libacl_cflags=
251     bup_libacl_ldflags='-lacl'
252     TLOG ' (yes)'
253 fi
254 AC_CC="$AC_CC${bup_libacl_cflags:+ $bup_libacl_cflags}"
255 LIBS="$bup_libacl_ldflags"
256 AC_CHECK_HEADERS sys/acl.h
257 AC_CHECK_HEADERS acl/libacl.h
258 AC_CHECK_FUNCS acl_get_file
259 AC_CHECK_FUNCS acl_from_text
260 AC_CHECK_FUNCS acl_set_file
261 # Note: These are linux specific, but we need them (for now?)
262 AC_CHECK_FUNCS acl_extended_file
263 AC_CHECK_FUNCS acl_to_any_text
264 TLOGN "checking for complete acl support"
265 if test "$ac_defined_HAVE_ACL_EXTENDED_FILE"; then
266     bup_have_libacl=1
267     AC_SUB bup_libacl_cflags "$bup_libacl_cflags"
268     AC_SUB bup_libacl_ldflags "$bup_libacl_ldflags"
269     TLOG ' (yes)'
270 else
271     bup_have_libacl=
272     AC_SUB bup_have_libacl ''
273     TLOG ' (no)'
274 fi
275 AC_SUB bup_have_libacl "$bup_have_libacl"
276 AC_CC="$orig_ac_cc"
277 LIBS="$orig_libs"
278
279
280 AC_OUTPUT config.vars
281
282 if test -e config.var; then rm -r config.var; fi
283 mkdir -p config.var
284 echo -n "$MAKE" > config.var/bup-make
285 echo -n "$bup_python" > config.var/bup-python
286
287 if test -e bin; then rm -r bin; fi
288 mkdir -p bin
289 cd bin && ln -s "$bup_python" python
290
291 printf "
292 found: python (%q, $("$bup_python" --version 2>&1))
293 found: git (%q, ($("$bup_git" --version))
294 " \
295        "$bup_python" \
296        "$bup_git" \
297        1>&5
298
299 summarize()
300 {
301     local found="$1"
302     shift
303     if test "$found"; then
304         TLOG found: "$@"
305     else
306         TLOG not found: "$@"
307     fi
308 }
309 summarize "$bup_have_readline" 'readline support (e.g. bup ftp)'
310 summarize "$bup_have_libacl" 'POSIX ACL support'
311 TLOG