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