]> arthur.barton.de Git - bup.git/blob - config/configure
d8f6b4b8ec430bf631d9dbc150332da01085ddba
[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 # FIXME: real tmpdir
41 rm -rf finished config/bin config.var config.var.tmp config.vars
42
43 AC_INIT $TARGET
44
45 if ! AC_PROG_CC; then
46     LOG " You need to have a functional C compiler to build $TARGET"
47     exit 1
48 fi
49
50 for make_candidate in make gmake; do
51     found_make="$(bup_find_prog "$make_candidate" "$MAKE")"
52     if test "$found_make" \
53             && ("$found_make" --version | grep "GNU Make"); then
54         MAKE="$found_make"
55         break;
56     fi
57 done
58
59 if ! test "$MAKE"; then
60     AC_FAIL "ERROR: unable to find GNU make as make or gmake"
61 fi
62
63 MAKE_VERSION=`$MAKE --version | grep "GNU Make" | awk '{print $3}'`
64 if [ -z "$MAKE_VERSION" ]; then
65     AC_FAIL "ERROR: $MAKE --version does not return sensible output?"
66 fi
67 expr "$MAKE_VERSION" '>=' '3.81' || AC_FAIL "ERROR: $MAKE must be >= version 3.81"
68
69 AC_SUB bup_make "$MAKE"
70
71
72 # Haven't seen a documented way to determine the python version via
73 # python-config right now, so we'll defer version checking until
74 # later.
75
76 if test "$BUP_PYTHON_CONFIG"; then
77     bup_python_config="$(type -p "$BUP_PYTHON_CONFIG")"
78     if test -z "$bup_python_config"; then
79         AC_FAIL $(printf "ERROR: BUP_PYTHON_CONFIG value %q appears invalid" \
80                          "$BUP_PYTHON_CONFIG")
81     fi
82 else
83     for py_maj_ver in 9 8 7 6; do
84         bup_python_config="$(bup_find_prog "python3.$py_maj_ver-config" '')"
85         test -z "$bup_python_config" || break
86     done
87     test -z "$bup_python_config" \
88         && bup_python_config="$(bup_find_prog python3-config '')"
89     test -z "$bup_python_config" \
90         && bup_python_config="$(bup_find_prog python2.7-config '')"
91     if test -z "$bup_python_config"; then
92         AC_FAIL "ERROR: unable to find a suitable python-config"
93     fi
94 fi
95
96
97 bup_python_cflags=$("$bup_python_config" --cflags) || exit $?
98 bup_python_ldflags=$("$bup_python_config" --ldflags) || exit $?
99 bup_python_cflags_embed=$("$bup_python_config" --cflags --embed)
100 if test $? -eq 0; then
101     bup_python_ldflags_embed=$("$bup_python_config" --ldflags --embed) || exit $?
102 else  # Earlier versions didn't support --embed
103     bup_python_cflags_embed=$("$bup_python_config" --cflags) || exit $?
104     bup_python_ldflags_embed=$("$bup_python_config" --ldflags) || exit $?
105 fi
106
107 bup_python_cflags="$bup_python_cflags -fPIC"
108
109 case "$OSTYPE" in
110     darwin*)
111         # For at least 10.3+ (2003+)
112         bup_python_ldflags="$bup_python_ldflags -bundle -undefined dynamic_lookup"
113         ;;
114     *)
115         bup_python_ldflags="$bup_python_ldflags -shared"
116         ;;
117 esac
118
119 AC_SUB bup_python_config "$bup_python_config"
120 AC_SUB bup_python_cflags "$bup_python_cflags"
121 AC_SUB bup_python_ldflags "$bup_python_ldflags"
122 AC_SUB bup_python_cflags_embed "$bup_python_cflags_embed"
123 AC_SUB bup_python_ldflags_embed "$bup_python_ldflags_embed"
124
125
126 bup_git="$(bup_find_prog git '')"
127 if test -z "$bup_git"; then
128     AC_FAIL "ERROR: unable to find git"
129 fi
130
131 # For stat.
132 AC_CHECK_HEADERS sys/stat.h
133 AC_CHECK_HEADERS sys/types.h
134
135 # For stat and mincore.
136 AC_CHECK_HEADERS unistd.h
137
138 # For mincore.
139 AC_CHECK_HEADERS sys/mman.h
140
141 # For FS_IOC_GETFLAGS and FS_IOC_SETFLAGS.
142 AC_CHECK_HEADERS linux/fs.h
143 AC_CHECK_HEADERS sys/ioctl.h
144
145 # On GNU/kFreeBSD utimensat is defined in GNU libc, but won't work.
146 if [ -z "$OS_GNU_KFREEBSD" ]; then
147     AC_CHECK_FUNCS utimensat
148 fi
149 AC_CHECK_FUNCS utimes
150 AC_CHECK_FUNCS lutimes
151
152 builtin_mul_overflow_code="
153 #include <stddef.h>
154 int main(int argc, char **argv)
155 {
156     size_t n = 0, size = 0, total;
157     __builtin_mul_overflow(n, size, &total);
158     return 0;
159 }
160 "
161
162 TLOGN "checking for __builtin_mul_overflow"
163 if bup_try_c_code "$builtin_mul_overflow_code"; then
164     AC_DEFINE BUP_HAVE_BUILTIN_MUL_OVERFLOW 1
165     TLOG ' (found)'
166 else
167     TLOG ' (not found)'
168 fi
169
170
171 AC_CHECK_FUNCS mincore
172
173 mincore_incore_code="
174 #if 0$ac_defined_HAVE_UNISTD_H
175 #include <unistd.h>
176 #endif
177 #if 0$ac_defined_HAVE_SYS_MMAN_H
178 #include <sys/mman.h>
179 #endif
180 int main(int argc, char **argv)
181 {
182     if (MINCORE_INCORE)
183       return 0;
184 }
185 "
186
187 mincore_buf_type_code()
188 {
189     local vec_type="$1"
190     echo "
191 #include <sys/mman.h>
192 int main(int argc, char **argv)
193 {
194     void *x = 0;
195     $vec_type *buf = 0;
196     return mincore(x, 0, buf);
197 }" || exit $?
198 }
199
200 if test "$ac_defined_HAVE_MINCORE"; then
201     TLOGN "checking for MINCORE_INCORE"
202     if bup_try_c_code "$mincore_incore_code"; then
203         AC_DEFINE BUP_HAVE_MINCORE_INCORE 1
204         TLOG ' (found)'
205     else
206         TLOG ' (not found)'
207     fi
208
209     TLOGN "checking mincore buf type"
210     if bup_try_c_code "$(mincore_buf_type_code char)"; then
211         AC_DEFINE BUP_MINCORE_BUF_TYPE 'char'
212         TLOG ' (char)'
213     elif bup_try_c_code "$(mincore_buf_type_code 'unsigned char')"; then
214         AC_DEFINE BUP_MINCORE_BUF_TYPE 'unsigned char'
215         TLOG ' (unsigned char)'
216     else
217         AC_FAIL "ERROR: unexpected mincore definition; please notify bup-list@googlegroups.com"
218     fi
219 fi
220
221
222 TLOGN "checking for readline"
223 bup_have_readline=''
224 bup_readline_includes_in_subdir=''
225 bup_readline_via_pkg_config=''
226 # We test this specific thing because it should work everywhere and it was
227 # a particulary problem on macos (we'd get the wrong includes if we just
228 # tested that the includes work).
229 readline_test_code='
230   static char *on_completion_entry(const char *text, int state) { return NULL; }
231   void bup_test(void) { rl_completion_entry_function = on_completion_entry; }
232 '
233 if pkg-config readline; then
234     bup_readline_cflags="$(pkg-config readline --cflags)" || exit $?
235     bup_readline_ldflags="$(pkg-config readline --libs)" || exit $?
236     # It looks like it's not uncommon for pkg-config to provide a -I
237     # that doesn't support the documentation's specified #include
238     # <readline/readline.h>.  See what's really going on.
239     if bup_try_c_code "#include <readline/readline.h> $readline_test_code" \
240                       "$bup_readline_cflags"
241     then
242         bup_have_readline=1
243         bup_readline_includes_in_subdir=1
244     elif bup_try_c_code "#include <readline.h> $readline_test_code" \
245                         "$bup_readline_cflags"
246     then
247         bup_have_readline=1
248     fi
249     if test "$bup_have_readline"; then
250         bup_readline_via_pkg_config=1
251     else
252         bup_readline_cflags=''
253         bup_readline_ldflags=''
254     fi
255 fi
256 if ! test "$bup_have_readline"; then
257     if bup_try_c_code "#include <readline/readline.h> $readline_test_code"; then
258         bup_readline_ldflags=-lreadline
259         bup_have_readline=1
260         bup_readline_includes_in_subdir=1
261     elif bup_try_c_code "#include <readline.h> $readline_test_code"; then
262         bup_readline_ldflags=-lreadline
263         bup_have_readline=1
264     fi
265 fi
266 if test "$bup_have_readline"; then
267     AC_DEFINE BUP_HAVE_READLINE 1
268     if test "$bup_readline_includes_in_subdir"; then
269         AC_DEFINE BUP_READLINE_INCLUDES_IN_SUBDIR 1
270     fi
271     if test "$bup_readline_via_pkg_config"; then
272         TLOG ' (yes, pkg-config)'
273     else
274         TLOG ' (yes)'
275     fi
276 fi
277
278
279 AC_SUB bup_readline_cflags "$bup_readline_cflags"
280 AC_SUB bup_readline_ldflags "$bup_readline_ldflags"
281 AC_SUB bup_have_readline "$bup_have_readline"
282
283
284 AC_CHECK_FIELD stat st_atim sys/types.h sys/stat.h unistd.h
285 AC_CHECK_FIELD stat st_mtim sys/types.h sys/stat.h unistd.h
286 AC_CHECK_FIELD stat st_ctim sys/types.h sys/stat.h unistd.h
287
288 AC_CHECK_FIELD stat st_atimensec sys/types.h sys/stat.h unistd.h
289 AC_CHECK_FIELD stat st_mtimensec sys/types.h sys/stat.h unistd.h
290 AC_CHECK_FIELD stat st_ctimensec sys/types.h sys/stat.h unistd.h
291
292 AC_CHECK_FIELD tm tm_gmtoff time.h
293
294
295 orig_ac_cc="$AC_CC"
296 orig_libs="$LIBS"
297 TLOGN "checking for libacl"
298 if pkg-config libacl; then
299     bup_libacl_cflags="$(pkg-config libacl --cflags)"
300     bup_libacl_ldflags="$(pkg-config libacl --libs)"
301     TLOG ' (yes, pkg-config)'
302 else
303     bup_libacl_cflags=
304     bup_libacl_ldflags='-lacl'
305     TLOG ' (yes)'
306 fi
307 AC_CC="$AC_CC${bup_libacl_cflags:+ $bup_libacl_cflags}"
308 LIBS="$bup_libacl_ldflags"
309 AC_CHECK_HEADERS sys/acl.h
310 AC_CHECK_HEADERS acl/libacl.h
311 AC_CHECK_FUNCS acl_get_file
312 AC_CHECK_FUNCS acl_from_text
313 AC_CHECK_FUNCS acl_set_file
314 # Note: These are linux specific, but we need them (for now?)
315 AC_CHECK_FUNCS acl_extended_file
316 AC_CHECK_FUNCS acl_to_any_text
317 TLOGN "checking for complete acl support"
318 if test "$ac_defined_HAVE_ACL_EXTENDED_FILE"; then
319     bup_have_libacl=1
320     AC_SUB bup_libacl_cflags "$bup_libacl_cflags"
321     AC_SUB bup_libacl_ldflags "$bup_libacl_ldflags"
322     TLOG ' (yes)'
323 else
324     bup_have_libacl=
325     AC_SUB bup_have_libacl ''
326     TLOG ' (no)'
327 fi
328 AC_SUB bup_have_libacl "$bup_have_libacl"
329 AC_CC="$orig_ac_cc"
330 LIBS="$orig_libs"
331
332 AC_OUTPUT config.vars
333
334 set -euo pipefail
335
336 # FIXME: real tmpdir
337 mkdir -p config.var.tmp
338 echo -n "$MAKE" > config.var.tmp/bup-make
339 echo -n "$bup_python_config" > config.var.tmp/bup-python-config
340 mv config.var.tmp config.var
341
342 if test -e bin; then rm -r bin; fi
343 mkdir -p bin
344 (cd bin && ln -s "$MAKE" make)
345
346 touch finished
347
348 printf "
349 found: python-config (%q)
350 found: git (%q, ($("$bup_git" --version))
351 " \
352        "$bup_python_config" \
353        "$bup_git" \
354        1>&5
355
356 summarize()
357 {
358     local found="$1"
359     shift
360     if test "$found"; then
361         TLOG found: "$@"
362     else
363         TLOG not found: "$@"
364     fi
365 }
366 summarize "$bup_have_readline" 'readline support (e.g. bup ftp)'
367 summarize "$bup_have_libacl" 'POSIX ACL support'
368 TLOG