This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add configure check for python program


Add a configure check that looks for python3 and python in that order
since we had agreed in the past to prefer python3 over python in all
our code.  The patch also adjusts invocations through the various
Makefiles to use the set variable and disables targets if we don't find
a python installation.

Tested on x86_64 with:

    make bench
    make subdirs=nptl check

with and without some python3 modules installed (PExpect for example) to
verify that the pretty printer tests return UNSUPPORTED as expected.

I have not touched localedata/unicode-gen since that makefile does not
run as part of glibc build.

	* configure.ac: Check for python3 or python.
	* configure: Regenerated.
	* config.make.in (PYTHON): New variable.
	* benchtests/Makefile: Don't define PYTHON.
	(bench): Define target only if PYTHON was defined.
	* Rules: Don't define PYTHON.
	Define pretty printer targets only if PYTHON was defined.
	(python-flags, python-invoke): Remove.
	(tests-printers-out): Use PYTHON instead of python-invoke.
---
 Rules               | 13 +++---------
 benchtests/Makefile |  6 ++++--
 config.make.in      |  1 +
 configure           | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 configure.ac        | 16 +++++++++++++-
 5 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/Rules b/Rules
index fe18ce5..c85d4da 100644
--- a/Rules
+++ b/Rules
@@ -255,16 +255,8 @@ endif
 
 endif	# tests
 
+ifdef PYTHON
 ifneq "$(strip $(tests-printers))" ""
-# We're defining this here for now; later it'll be defined at configure time
-# inside Makeconfig.
-PYTHON := python
-
-# Invoke Python using -B to avoid generating .pyc files on the source dir,
-# so that we can keep it read-only.
-python-flags := -B
-
-python-invoke := $(PYTHON) $(python-flags)
 
 # Static pattern rule for building the test programs for the pretty printers.
 $(tests-printers-programs): %: %.o $(tests-printers-libs) \
@@ -283,9 +275,10 @@ py-env := PYTHONPATH=$(py-const-dir):$(..)scripts:$${PYTHONPATH}
 $(tests-printers-out): $(objpfx)%.out: $(objpfx)% %.py %.c $(pretty-printers) \
 		       $(..)scripts/test_printers_common.py
 	$(test-wrapper-env) $(py-env) \
-	    $(python-invoke) $*.py $*.c $(objpfx)$* $(pretty-printers) > $@; \
+	    $(PYTHON) $*.py $*.c $(objpfx)$* $(pretty-printers) > $@; \
 	$(evaluate-test)
 endif
+endif
 
 
 .PHONY: distclean realclean subdir_distclean subdir_realclean \
diff --git a/benchtests/Makefile b/benchtests/Makefile
index ba4d068..c1d2781 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -18,8 +18,6 @@
 # Makefile for benchmark tests.  The only useful target here is `bench`.
 # Add benchmark functions in alphabetical order.
 
-PYTHON := python
-
 subdir := benchtests
 
 include ../Makeconfig
@@ -141,7 +139,11 @@ bench-clean:
 	rm -f $(timing-type) $(addsuffix .o,$(timing-type))
 	rm -f $(addprefix $(objpfx),$(bench-extra-objs))
 
+# Define the bench target only if the target has a usable python installation.
+ifdef PYTHON
 bench: bench-build bench-set bench-func bench-malloc
+endif
+
 # Target to only build the benchmark without running it.  We generate locales
 # only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/config.make.in b/config.make.in
index d2d9b8a..35e7e59 100644
--- a/config.make.in
+++ b/config.make.in
@@ -126,6 +126,7 @@ MSGFMT = @MSGFMT@
 BASH = @BASH_SHELL@
 AWK = @AWK@
 PERL = @PERL@
+PYTHON = @PYTHON@
 
 # Additional libraries.
 LIBGD = @LIBGD@
diff --git a/configure b/configure
index 5cf3230..de5d9cd 100755
--- a/configure
+++ b/configure
@@ -639,6 +639,7 @@ CXX_CMATH_HEADER
 CXX_CSTDLIB_HEADER
 CXX_SYSINCLUDES
 SYSINCLUDES
+PYTHON
 AUTOCONF
 NM
 AWK
@@ -5086,17 +5087,72 @@ else
   AUTOCONF=no
 fi
 
+# Check for python3 if available, or else python.
+for ac_prog in python3 python
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_PYTHON+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$PYTHON"; then
+  ac_cv_prog_PYTHON="$PYTHON" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_PYTHON="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+PYTHON=$ac_cv_prog_PYTHON
+if test -n "$PYTHON"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
+$as_echo "$PYTHON" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$PYTHON" && break
+done
+test -n "$PYTHON" || PYTHON="no"
+
+case "x$PYTHON" in
+xno|x|x:) PYTHON=no ;;
+*) ;;
+esac
+
+if test "x$PYTHON" = xno; then
+  aux_missing="$aux_missing python"
+else
+  PYTHON="$PYTHON -B"
+fi
+
 test -n "$critic_missing" && as_fn_error $? "
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions." "$LINENO" 5
 
 test -n "$aux_missing" && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions." >&5
 $as_echo "$as_me: WARNING:
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions." >&2;}
 
 # if using special system headers, find out the compiler's sekrit
diff --git a/configure.ac b/configure.ac
index d719fad..5b08ba9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1050,13 +1050,27 @@ else
   AUTOCONF=no
 fi
 
+# Check for python3 if available, or else python.
+AC_CHECK_PROGS(PYTHON_PROG, python3 python, no)
+case "x$PYTHON_PROG" in
+xno|x|x:) PYTHON_PROG=no ;;
+*) ;;
+esac
+
+if test "x$PYTHON_PROG" = xno; then
+  aux_missing="$aux_missing python"
+else
+  PYTHON="$PYTHON_PROG -B"
+  AC_SUBST(PYTHON)
+fi
+
 test -n "$critic_missing" && AC_MSG_ERROR([
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions.])
 
 test -n "$aux_missing" && AC_MSG_WARN([
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions.])
 
 # if using special system headers, find out the compiler's sekrit
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]