From 91bf576a43ca013a66a55f679102046a9d95e716 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Mar 2021 10:47:58 +0100 Subject: [PATCH] build: fix detection of python for autotools The goal of this code is to detect python, but prefer python3 while also allowing the user to override the path. That did not work in all cases, due to what seems like a bug in AM_PATH_PYTHON(). AM_PATH_PYTHON() is documented to ignore failure if [action-if-not-found] is given. So one might assume that: AM_PATH_PYTHON([3], [], [PYTHON=]) if test -z "$PYTHON"; then AM_PATH_PYTHON([], [], [PYTHON=python]) fi first tries to look for v3, and if that fails search for any python interpreter. That did not work however with: $ ./configure PYTHON=/usr/bin/python2 ... checking pkg-config is at least version 0.9.0... yes checking whether /usr/bin/python2 version is >= 3... no configure: error: Python interpreter is too old because the first AM_PATH_PYTHON() is fatal. Work around that. Fixes: 54a1cfa97321 ('build: prefer python3 over python2 in autotools's configure script') --- configure.ac | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 9f74007796..de6e272360 100644 --- a/configure.ac +++ b/configure.ac @@ -1229,9 +1229,13 @@ else fi AC_SUBST(NM_LOG_COMPILER, 'LOG_COMPILER = "$(top_srcdir)/tools/run-nm-test.sh" --called-from-make "$(abs_top_builddir)" "$(LIBTOOL)" "$(with_valgrind)" "'"$with_valgrind_suppressions"'" --launch-dbus=auto') -AM_PATH_PYTHON([3], [], [PYTHON=]) -if test -z "$PYTHON"; then - AM_PATH_PYTHON([], [], [PYTHON=python]) +if test -n "$PYTHON" ; then + AM_PATH_PYTHON([], [], []) +else + AM_PATH_PYTHON([3], [], [PYTHON=]) + if test -z "$PYTHON"; then + AM_PATH_PYTHON([], [], []) + fi fi AC_SUBST(PYTHON, [$PYTHON]) AC_DEFINE_UNQUOTED(TEST_NM_PYTHON, "$PYTHON", [Define python path for test binary])