]> arthur.barton.de Git - bup.git/blob - config/configure
c7ab50c3819b2b7446b887101afe3bb278e104b2
[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
18     if test -z "$code"; then
19         AC_FAIL "No code provided to test compile"
20     fi
21     tmpdir="$(mktemp -d "bup-try-c-compile-XXXXXXX")" || exit $?
22     echo "$code" > "$tmpdir/test.c" || exit $?
23     $AC_CC -Wall -Werror -c -o "$tmpdir/test" "$tmpdir/test.c"
24     rc=$?
25     rm -r "$tmpdir" || exit $?
26     return $rc
27 }
28
29 TARGET=bup
30
31 . ./configure.inc
32
33 AC_INIT $TARGET
34
35 if ! AC_PROG_CC; then
36     LOG " You need to have a functional C compiler to build $TARGET"
37     exit 1
38 fi
39
40 MAKE="$(bup_find_prog make "$MAKE")"
41 if test -z "$MAKE"; then
42     MAKE="$(bup_find_prog gmake "$GMAKE")"
43 fi
44
45 if test -z "$MAKE"; then
46     AC_FAIL "ERROR: unable to find make"
47 fi
48
49 if ! ($MAKE --version | grep "GNU Make"); then
50     AC_FAIL "ERROR: $MAKE is not GNU Make"
51 fi
52
53 MAKE_VERSION=`$MAKE --version | grep "GNU Make" | awk '{print $3}'`
54 if [ -z "$MAKE_VERSION" ]; then
55     AC_FAIL "ERROR: $MAKE --version does not return sensible output?"
56 fi
57 expr "$MAKE_VERSION" '>=' '3.81' || AC_FAIL "ERROR: $MAKE must be >= version 3.81"
58
59 AC_SUB bup_make "$MAKE"
60
61 bup_python="$(type -p "$PYTHON")"
62 test -z "$bup_python" && bup_python="$(bup_find_prog python2.7 '')"
63 test -z "$bup_python" && bup_python="$(bup_find_prog python2.6 '')"
64 test -z "$bup_python" && bup_python="$(bup_find_prog python2 '')"
65 test -z "$bup_python" && bup_python="$(bup_find_prog python '')"
66 if test -z "$bup_python"; then
67     AC_FAIL "ERROR: unable to find python"
68 else
69     AC_SUB bup_python "$bup_python"
70     AC_SUB bup_python_majver \
71            "$("$bup_python" -c 'import sys; print(sys.version_info[0])')"
72 fi
73
74 bup_git="$(bup_find_prog git '')"
75 if test -z "$bup_git"; then
76     AC_FAIL "ERROR: unable to find git"
77 fi
78
79 # For stat.
80 AC_CHECK_HEADERS sys/stat.h
81 AC_CHECK_HEADERS sys/types.h
82
83 # For stat and mincore.
84 AC_CHECK_HEADERS unistd.h
85
86 # For mincore.
87 AC_CHECK_HEADERS sys/mman.h
88
89 # For FS_IOC_GETFLAGS and FS_IOC_SETFLAGS.
90 AC_CHECK_HEADERS linux/fs.h
91 AC_CHECK_HEADERS sys/ioctl.h
92
93 # On GNU/kFreeBSD utimensat is defined in GNU libc, but won't work.
94 if [ -z "$OS_GNU_KFREEBSD" ]; then
95     AC_CHECK_FUNCS utimensat
96 fi
97 AC_CHECK_FUNCS utimes
98 AC_CHECK_FUNCS lutimes
99
100
101 builtin_mul_overflow_code="
102 #include <stddef.h>
103 int main(int argc, char **argv)
104 {
105     size_t n = 0, size = 0, total;
106     __builtin_mul_overflow(n, size, &total);
107     return 0;
108 }
109 "
110
111 TLOGN "checking for __builtin_mul_overflow"
112 if bup_try_c_code "$builtin_mul_overflow_code"; then
113     AC_DEFINE BUP_HAVE_BUILTIN_MUL_OVERFLOW 1
114     TLOG ' (found)'
115 else
116     TLOG ' (not found)'
117 fi
118
119
120 AC_CHECK_FUNCS mincore
121
122 mincore_incore_code="
123 #if 0$ac_defined_HAVE_UNISTD_H
124 #include <unistd.h>
125 #endif
126 #if 0$ac_defined_HAVE_SYS_MMAN_H
127 #include <sys/mman.h>
128 #endif
129 int main(int argc, char **argv)
130 {
131     if (MINCORE_INCORE)
132       return 0;
133 }
134 "
135
136 mincore_buf_type_code()
137 {
138     local vec_type="$1"
139     echo "
140 #include <sys/mman.h>
141 int main(int argc, char **argv)
142 {
143     void *x = 0;
144     $vec_type *buf = 0;
145     return mincore(x, 0, buf);
146 }" || exit $?
147 }
148
149 if test "$ac_defined_HAVE_MINCORE"; then
150     TLOGN "checking for MINCORE_INCORE"
151     if bup_try_c_code "$mincore_incore_code"; then
152         AC_DEFINE BUP_HAVE_MINCORE_INCORE 1
153         TLOG ' (found)'
154     else
155         TLOG ' (not found)'
156     fi
157
158     TLOGN "checking mincore buf type"
159     if bup_try_c_code "$(mincore_buf_type_code char)"; then
160         AC_DEFINE BUP_MINCORE_BUF_TYPE 'char'
161         TLOG ' (char)'
162     elif bup_try_c_code "$(mincore_buf_type_code 'unsigned char')"; then
163         AC_DEFINE BUP_MINCORE_BUF_TYPE 'unsigned char'
164         TLOG ' (unsigned char)'
165     else
166         AC_FAIL "ERROR: unexpected mincore definition; please notify bup-list@googlegroups.com"
167     fi
168 fi
169
170 TLOGN "checking for readline"
171 if pkg-config readline; then
172     bup_readline_cflags="$(pkg-config readline --cflags)" || exit $?
173     bup_readline_ldflags="$(pkg-config readline --libs)" || exit $?
174     bup_have_readline=1
175     AC_DEFINE BUP_HAVE_READLINE 1
176     TLOG ' (yes, pkg-config)'
177 elif bup_try_c_code '#include <readline/readline.h>'; then
178     bup_readline_cflags=''
179     bup_readline_ldflags=-lreadline
180     bup_have_readline=1
181     AC_DEFINE BUP_HAVE_READLINE 1
182     TLOG ' (yes)'
183 else
184     bup_readline_cflags=''
185     bup_readline_ldflags=''
186     bup_have_readline=''
187     TLOG ' (no)'
188 fi
189 AC_SUB bup_readline_cflags "$bup_readline_cflags"
190 AC_SUB bup_readline_ldflags "$bup_readline_ldflags"
191 AC_SUB bup_have_readline "$bup_have_readline"
192
193 AC_CHECK_FIELD stat st_atim sys/types.h sys/stat.h unistd.h
194 AC_CHECK_FIELD stat st_mtim sys/types.h sys/stat.h unistd.h
195 AC_CHECK_FIELD stat st_ctim sys/types.h sys/stat.h unistd.h
196
197 AC_CHECK_FIELD stat st_atimensec sys/types.h sys/stat.h unistd.h
198 AC_CHECK_FIELD stat st_mtimensec sys/types.h sys/stat.h unistd.h
199 AC_CHECK_FIELD stat st_ctimensec sys/types.h sys/stat.h unistd.h
200
201 AC_CHECK_FIELD tm tm_gmtoff time.h
202
203
204 orig_ac_cc="$AC_CC"
205 orig_libs="$LIBS"
206 TLOGN "checking for libacl"
207 if pkg-config libacl; then
208     bup_libacl_cflags="$(pkg-config libacl --cflags)"
209     bup_libacl_ldflags="$(pkg-config libacl --libs)"
210     TLOG ' (yes, pkg-config)'
211 else
212     bup_libacl_cflags=
213     bup_libacl_ldflags='-lacl'
214     TLOG ' (yes)'
215 fi
216 AC_CC="$AC_CC${bup_libacl_cflags:+ $bup_libacl_cflags}"
217 LIBS="$bup_libacl_ldflags"
218 AC_CHECK_HEADERS sys/acl.h
219 AC_CHECK_HEADERS acl/libacl.h
220 AC_CHECK_FUNCS acl_get_file
221 AC_CHECK_FUNCS acl_from_text
222 AC_CHECK_FUNCS acl_set_file
223 # Note: These are linux specific, but we need them (for now?)
224 AC_CHECK_FUNCS acl_extended_file
225 AC_CHECK_FUNCS acl_to_any_text
226 TLOGN "checking for complete acl support"
227 if test "$ac_defined_HAVE_ACL_EXTENDED_FILE"; then
228     bup_have_libacl=1
229     AC_SUB bup_libacl_cflags "$bup_libacl_cflags"
230     AC_SUB bup_libacl_ldflags "$bup_libacl_ldflags"
231     TLOG ' (yes)'
232 else
233     bup_have_libacl=
234     AC_SUB bup_have_libacl ''
235     TLOG ' (no)'
236 fi
237 AC_SUB bup_have_libacl "$bup_have_libacl"
238 AC_CC="$orig_ac_cc"
239 LIBS="$orig_libs"
240
241
242 AC_OUTPUT config.vars
243
244 if test -e config.var; then rm -r config.var; fi
245 mkdir -p config.var
246 echo -n "$MAKE" > config.var/bup-make
247 echo -n "$bup_python" > config.var/bup-python
248
249 if test -e bin; then rm -r bin; fi
250 mkdir -p bin
251 cd bin && ln -s "$bup_python" python
252
253 printf "
254 found: python (%q, $("$bup_python" --version 2>&1))
255 found: git (%q, ($("$bup_git" --version))
256 " \
257        "$bup_python" \
258        "$bup_git" \
259        1>&5
260
261 summarize()
262 {
263     local found="$1"
264     shift
265     if test "$found"; then
266         TLOG found: "$@"
267     else
268         TLOG not found: "$@"
269     fi
270 }
271 summarize "$bup_have_readline" 'readline support (e.g. bup ftp)'
272 summarize "$bup_have_libacl" 'POSIX ACL support'
273 TLOG