From 7cb48c4608b5d8f7e605108bbebf96147be248cf 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') (cherry picked from commit 91bf576a43ca013a66a55f679102046a9d95e716) (cherry picked from commit 58a24f4f66b7e1c0042dd598a10af1753bfa1e3b) --- configure.ac | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 0e9340cda0..5631d1f4b3 100644 --- a/configure.ac +++ b/configure.ac @@ -1216,9 +1216,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])