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