#!/usr/bin/env bash
+ac_help="--with-pylint[=yes|no|maybe] require and run pylint (maybe)"
+
bup_find_prog()
{
# Prints prog path to stdout or nothing.
return $rc
}
+bup_config_cflags=()
+
+bup-add-cflag-if-supported()
+{
+ local opt="$1"
+ if test -z "$opt"; then
+ AC_FAIL 'No option to check'
+ fi
+ TLOGN "checking for $AC_CC $opt support"
+ if bup_try_c_code \
+ "int main(int argc, char**argv) { return 0; }" \
+ "$opt";
+ then
+ bup_config_cflags+="$opt"
+ TLOG ' (found)'
+ else
+ TLOG ' (not found)'
+ fi
+}
+
+
TARGET=bup
+argv=()
+with_pylint=maybe
+while test $# -gt 0; do
+ case "$1" in
+ --with-pylint=yes) with_pylint=yes; shift;;
+ --with-pylint=maybe) with_pylint=maybe; shift;;
+ --with-pylint=no) with_pylint=no; shift;;
+ *) argv+=("$1"); shift;;
+ esac
+done
+
+# Set $@ to the adjusted args
+set - "${argv[@]}"
+
. ./configure.inc
+# FIXME: real tmpdir
+rm -rf finished config/bin config.var config.var.tmp config.vars
+
AC_INIT $TARGET
if ! AC_PROG_CC; then
exit 1
fi
-MAKE="$(bup_find_prog make "$MAKE")"
-if test -z "$MAKE"; then
- MAKE="$(bup_find_prog gmake "$GMAKE")"
-fi
+bup-add-cflag-if-supported -Wno-unused-command-line-argument
-if test -z "$MAKE"; then
- AC_FAIL "ERROR: unable to find make"
-fi
+for make_candidate in make gmake; do
+ found_make="$(bup_find_prog "$make_candidate" "$MAKE")"
+ if test "$found_make" \
+ && ("$found_make" --version | grep "GNU Make"); then
+ MAKE="$found_make"
+ break;
+ fi
+done
-if ! ($MAKE --version | grep "GNU Make"); then
- AC_FAIL "ERROR: $MAKE is not GNU Make"
+if ! test "$MAKE"; then
+ AC_FAIL "ERROR: unable to find GNU make as make or gmake"
fi
MAKE_VERSION=`$MAKE --version | grep "GNU Make" | awk '{print $3}'`
AC_SUB bup_make "$MAKE"
-bup_python="$(type -p "$PYTHON")"
-test -z "$bup_python" && bup_python="$(bup_find_prog python2.7 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python2.6 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python2 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python3.8 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python3.7 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python3.6 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python3 '')"
-test -z "$bup_python" && bup_python="$(bup_find_prog python '')"
-if test -z "$bup_python"; then
- AC_FAIL "ERROR: unable to find python"
+
+# Haven't seen a documented way to determine the python version via
+# python-config right now, so we'll defer version checking until
+# later.
+
+if test "$BUP_PYTHON_CONFIG"; then
+ bup_python_config="$(type -p "$BUP_PYTHON_CONFIG")"
+ if test -z "$bup_python_config"; then
+ AC_FAIL $(printf "ERROR: BUP_PYTHON_CONFIG value %q appears invalid" \
+ "$BUP_PYTHON_CONFIG")
+ fi
else
- AC_SUB bup_python "$bup_python"
- AC_SUB bup_python_majver \
- "$("$bup_python" -c 'import sys; print(sys.version_info[0])')"
+ for py_maj_ver in 9 8 7 6; do
+ bup_python_config="$(bup_find_prog "python3.$py_maj_ver-config" '')"
+ test -z "$bup_python_config" || break
+ done
+ test -z "$bup_python_config" \
+ && bup_python_config="$(bup_find_prog python3-config '')"
+ test -z "$bup_python_config" \
+ && bup_python_config="$(bup_find_prog python2.7-config '')"
+ if test -z "$bup_python_config"; then
+ AC_FAIL "ERROR: unable to find a suitable python-config"
+ fi
+fi
+
+
+bup_python_cflags=$("$bup_python_config" --cflags) || exit $?
+bup_python_ldflags=$("$bup_python_config" --ldflags) || exit $?
+bup_python_cflags_embed=$("$bup_python_config" --cflags --embed)
+if test $? -eq 0; then
+ bup_python_ldflags_embed=$("$bup_python_config" --ldflags --embed) || exit $?
+else # Earlier versions didn't support --embed
+ bup_python_cflags_embed=$("$bup_python_config" --cflags) || exit $?
+ bup_python_ldflags_embed=$("$bup_python_config" --ldflags) || exit $?
fi
+bup_python_cflags="$bup_python_cflags -fPIC"
+
+case "$OSTYPE" in
+ darwin*)
+ # For at least 10.3+ (2003+)
+ bup_python_ldflags="$bup_python_ldflags -bundle -undefined dynamic_lookup"
+ ;;
+ *)
+ bup_python_ldflags="$bup_python_ldflags -shared"
+ ;;
+esac
+
+AC_SUB bup_python_config "$bup_python_config"
+AC_SUB bup_python_cflags "$bup_python_cflags"
+AC_SUB bup_python_ldflags "$bup_python_ldflags"
+AC_SUB bup_python_cflags_embed "$bup_python_cflags_embed"
+AC_SUB bup_python_ldflags_embed "$bup_python_ldflags_embed"
+
+
bup_git="$(bup_find_prog git '')"
if test -z "$bup_git"; then
AC_FAIL "ERROR: unable to find git"
AC_CHECK_FUNCS lutimes
-builtin_mul_overflow_code="
-#include <stddef.h>
-int main(int argc, char **argv)
-{
- size_t n = 0, size = 0, total;
- __builtin_mul_overflow(n, size, &total);
- return 0;
-}
-"
-
-TLOGN "checking for __builtin_mul_overflow"
-if bup_try_c_code "$builtin_mul_overflow_code"; then
- AC_DEFINE BUP_HAVE_BUILTIN_MUL_OVERFLOW 1
- TLOG ' (found)'
-else
- TLOG ' (not found)'
-fi
-
-
AC_CHECK_FUNCS mincore
mincore_incore_code="
# It looks like it's not uncommon for pkg-config to provide a -I
# that doesn't support the documentation's specified #include
# <readline/readline.h>. See what's really going on.
- if bup_try_c_code "#include <readline/readline.h> $readline_test_code" \
+ if bup_try_c_code "#include <stdio.h> // required by unpatched readline
+#include <readline/readline.h>
+$readline_test_code" \
"$bup_readline_cflags"
then
bup_have_readline=1
bup_readline_includes_in_subdir=1
- elif bup_try_c_code "#include <readline.h> $readline_test_code" \
+ elif bup_try_c_code "#include <stdio.h> // required by unpatched readline
+#include <readline.h>
+$readline_test_code" \
"$bup_readline_cflags"
then
bup_have_readline=1
AC_CC="$orig_ac_cc"
LIBS="$orig_libs"
+AC_SUB bup_config_cflags "$bup_config_cflags"
AC_OUTPUT config.vars
-if test -e config.var; then rm -r config.var; fi
-mkdir -p config.var
-echo -n "$MAKE" > config.var/bup-make
-echo -n "$bup_python" > config.var/bup-python
+set -euo pipefail
+
+# FIXME: real tmpdir
+mkdir -p config.var.tmp
+echo -n "$MAKE" > config.var.tmp/bup-make
+echo -n "$bup_python_config" > config.var.tmp/bup-python-config
+echo -n "$with_pylint" > config.var.tmp/with-pylint
+mv config.var.tmp config.var
if test -e bin; then rm -r bin; fi
mkdir -p bin
-(cd bin && ln -s "$bup_python" python)
+(cd bin && ln -s "$MAKE" make)
+
+touch finished
printf "
-found: python (%q, $("$bup_python" --version 2>&1))
+found: python-config (%q)
found: git (%q, ($("$bup_git" --version))
" \
- "$bup_python" \
+ "$bup_python_config" \
"$bup_git" \
1>&5