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