From 0fca9cee3641a1e75f9d56a8ad8f5ce8bc824d93 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 22 Aug 2018 06:04:32 +0200 Subject: [PATCH] build: improve python search pattern - try pythonN.N-config after pythonN-config - use "python-config --ldflags" instead of --libs - add Python 3.6 to explicitly searched versions - if linking fails, try with "-lz" added Signed-off-by: David Lamparter --- configure.ac | 90 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/configure.ac b/configure.ac index 12c1857758..aadf8a9303 100755 --- a/configure.ac +++ b/configure.ac @@ -531,25 +531,10 @@ AM_CONDITIONAL([FPM], [test "x$enable_fpm" = "xyes"]) # # Python for clippy # -AS_IF([test "$host" = "$build"], [ - PYTHONCONFIG="" - - # ordering: - # 1. try python3, but respect the user's preference on which minor ver - # 2. try python, which might be py3 or py2 again on the user's preference - # 3. try python2 (can really only be 2.7 but eh) - # 4. try 3.5 > 3.4 > 3.3 > 3.2 > 2.7 through pkg-config (no user pref) - # - # (AX_PYTHON_DEVEL has no clue about py3 vs py2) - # (AX_PYTHON does not do what we need) - - AC_CHECK_TOOLS([PYTHONCONFIG], [python3-config python-config python2-config]) - if test -n "$PYTHONCONFIG"; then - PYTHON_CFLAGS="`\"${PYTHONCONFIG}\" --includes`" - PYTHON_LIBS="`\"${PYTHONCONFIG}\" --libs`" - AC_MSG_CHECKING([whether we found a working Python version]) - AC_LINK_IFELSE_FLAGS([$PYTHON_CFLAGS], [$PYTHON_LIBS], [AC_LANG_PROGRAM([ +AC_DEFUN([FRR_PYTHON_CHECK_WORKING], [ + AC_MSG_CHECKING([whether we found a working Python version]) + AC_LINK_IFELSE_FLAGS([$PYTHON_CFLAGS], [$PYTHON_LIBS], [AC_LANG_PROGRAM([ #include #if PY_VERSION_HEX < 0x02070000 #error python too old @@ -562,23 +547,8 @@ int main(void); return 0; } ])], [ - PYTHONCONFIG="" - unset PYTHON_LIBS - unset PYTHON_CFLAGS - ]) - fi - - if test -z "$PYTHONCONFIG"; then - PKG_CHECK_MODULES([PYTHON], python-3.5, [], [ - PKG_CHECK_MODULES([PYTHON], python-3.4, [], [ - PKG_CHECK_MODULES([PYTHON], python-3.3, [], [ - PKG_CHECK_MODULES([PYTHON], python-3.2, [], [ - PKG_CHECK_MODULES([PYTHON], python-2.7, [], [ - AC_MSG_FAILURE([could not find python-config or pkg-config python, please install Python development files from libpython-dev or similar]) - ])])])])]) - - - AC_MSG_CHECKING([whether we found a working Python version]) + # some python installs are missing the zlib dependency... + PYTHON_LIBS="${PYTHON_LIBS} -lz" AC_LINK_IFELSE_FLAGS([$PYTHON_CFLAGS], [$PYTHON_LIBS], [AC_LANG_PROGRAM([ #include #if PY_VERSION_HEX < 0x02070000 @@ -592,6 +562,56 @@ int main(void); return 0; } ])], [ + m4_if([$1], [], [ + PYTHONCONFIG="" + unset PYTHON_LIBS + unset PYTHON_CFLAGS + ], [$1]) + ]) + ]) +]) + +AS_IF([test "$host" = "$build"], [ + PYTHONCONFIG="" + + # ordering: + # 1. try python3, but respect the user's preference on which minor ver + # 2. try python, which might be py3 or py2 again on the user's preference + # 3. try python2 (can really only be 2.7 but eh) + # 4. try 3.6 > 3.5 > 3.4 > 3.3 > 3.2 > 2.7 through pkg-config (no user pref) + # + # (AX_PYTHON_DEVEL has no clue about py3 vs py2) + # (AX_PYTHON does not do what we need) + + AC_CHECK_TOOLS([PYTHONCONFIG], [ \ + python3-config \ + python-config \ + python2-config \ + python3.6-config \ + python3.5-config \ + python3.4-config \ + python3.3-config \ + python3.2-config \ + python2.7-config ]) + if test -n "$PYTHONCONFIG"; then + PYTHON_CFLAGS="`\"${PYTHONCONFIG}\" --includes`" + PYTHON_LIBS="`\"${PYTHONCONFIG}\" --ldflags`" + + FRR_PYTHON_CHECK_WORKING([]) + fi + + if test -z "$PYTHONCONFIG"; then + PKG_CHECK_MODULES([PYTHON], python-3.6, [], [ + PKG_CHECK_MODULES([PYTHON], python-3.5, [], [ + PKG_CHECK_MODULES([PYTHON], python-3.4, [], [ + PKG_CHECK_MODULES([PYTHON], python-3.3, [], [ + PKG_CHECK_MODULES([PYTHON], python-3.2, [], [ + PKG_CHECK_MODULES([PYTHON], python-2.7, [], [ + AC_MSG_FAILURE([could not find python-config or pkg-config python, please install Python development files from libpython-dev or similar]) + ])])])])])]) + + + FRR_PYTHON_CHECK_WORKING([ AC_MSG_FAILURE([could not find python-config or pkg-config python, please install Python development files from libpython-dev or similar]) ]) fi -- 2.39.5