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