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