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