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