From 419fff0b17e4e304f5a831115cfbcdb85ec34056 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 29 Jul 2019 15:32:08 -0400 Subject: [PATCH] configure.ac: refine Python 3 interpreter and dev. libraries detection This patch refines how the `configure` script detects the Python 3 interpreter and development libraries. The goal is to clean up this part of `configure.ac` and to make the Python 3 interpreter available as a general tool for testing, even without building the Python bindings or the Python plugin provider. Before this patch, `configure` ensures that the Python interpreter and the development libraries exist and are valid if you use the `--enable-python-bindings` or `--enable-python-plugins` option. With this patch, `configure` always tries to find the Python interpreter. If it finds it, it sets the local `have_python` shell variable and defines the `HAVE_PYTHON` Automake definition. If `configure` finds the Python interpreter, it always tries to find `python-config`. It if finds it, it sets the local `have_python_dev` shell variable and defines the `HAVE_PYTHON_DEV` Automake definition. You can still override the include directories and linker flags with the `PYTHON_INCLUDE` and `PYTHON_LDFLAGS` environment variables. Now, if you specify the `--enable-python-bindings` or `--enable-python-plugins` option, `$have_python_dev` must be `yes`. What used to be `HAVE_PYTHON` (Automake definition) is renamed to `ENABLE_PYTHON_COMMON_DEPS`: this is defined if we need to build any common Python dependency. As of this patch, the only one is the internal `py-common` convenience library. In the final `configure` report, I added: * Whether or not the Python interpreter was found and its path. * Whether or not the `python-config` program (called "development libraries") was found and its path. This patch was only tested manually, locally removing the Python interpreter, the `python-config` program, and passing the `--enable-python-bindings` or `--enable-python-plugins` option to test the different `configure` paths. Signed-off-by: Philippe Proulx Change-Id: Id0ac60ebc97a9ce2951aee713eccdc24c19d3791 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1799 Tested-by: jenkins Reviewed-by: Michael Jeanson --- configure.ac | 75 ++++++++++++++++++++++++--------------- src/py-common/Makefile.am | 4 +-- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index 3649cb45..8b6960b2 100644 --- a/configure.ac +++ b/configure.ac @@ -444,7 +444,7 @@ AM_CONDITIONAL([ENABLE_API_DOC], [test "x$enable_api_doc" = xyes]) AM_CONDITIONAL([ENABLE_BUILT_IN_PLUGINS], [test "x$enable_built_in_plugins" = xyes]) AM_CONDITIONAL([ENABLE_BUILT_IN_PYTHON_PLUGIN_SUPPORT], [test "x$enable_built_in_python_plugin_support" = xyes]) AM_CONDITIONAL([ENABLE_MAN_PAGES], [test "x$enable_man_pages" = xyes]) -AM_CONDITIONAL([HAVE_PYTHON], [test "x$enable_python_bindings" = xyes || test "x$enable_python_plugins" = xyes]) +AM_CONDITIONAL([ENABLE_PYTHON_COMMON_DEPS], [test "x$enable_python_bindings" = xyes || test "x$enable_python_plugins" = xyes]) # Set defines for optionnal features conditionnals in the source code @@ -505,41 +505,48 @@ AS_IF([test "x$enable_python_bindings" = xyes], [AX_PKG_SWIG(2.0.0, [], [AC_MSG_ERROR([SWIG 2.0.0 or newer is required to build the python bindings])])] ) -AS_IF([test "x$enable_python_bindings" = xyes || test "x$enable_python_plugins" = xyes], - [ - AM_PATH_PYTHON([3.0], [], [AC_MSG_ERROR(Python 3 is not available or is not the default Python interpreter on your system. See the README file to learn how to override your distribution's default Python interpreter.)]) - +AM_PATH_PYTHON([3.0], [ AM_PATH_PYTHON_MODULES([PYTHON]) + # pythondir is the path where extra modules are to be installed pythondir=$PYTHON_PREFIX/$PYTHON_MODULES_PATH + # pyexecdir is the path that contains shared objects used by the extra modules pyexecdir=$PYTHON_EXEC_PREFIX/$PYTHON_MODULES_PATH - AS_IF([test -z "$PYTHON_INCLUDE"], [ - AS_IF([test -z "$PYTHON_CONFIG"], [ - AC_PATH_PROGS([PYTHON_CONFIG], - [python$PYTHON_VERSION-config python-config], - [no], - [`dirname $PYTHON`]) - AS_IF([test "$PYTHON_CONFIG" = no], [AC_MSG_ERROR([cannot find python-config for $PYTHON. Is python-dev installed?])]) - ]) - AC_MSG_CHECKING([Python include flags]) - PYTHON_INCLUDE=`$PYTHON_CONFIG --includes` - AC_MSG_RESULT([$PYTHON_INCLUDE]) + + AS_IF([test -z "$PYTHON_CONFIG"], [ + AC_PATH_PROGS([PYTHON_CONFIG], + [python$PYTHON_VERSION-config python-config], + [], + [`dirname $PYTHON`]) ]) - AS_IF([test -z "$PYTHON_LDFLAGS"], [ - AS_IF([test -z "$PYTHON_CONFIG"], [ - AC_PATH_PROGS([PYTHON_CONFIG], - [python$PYTHON_VERSION-config python-config], - [no], - [`dirname $PYTHON`]) - AS_IF([test "$PYTHON_CONFIG" = no], [AC_MSG_ERROR([cannot find python-config for $PYTHON. Is python-dev installed?])]) + + AS_IF([test -n "$PYTHON_CONFIG"], [ + AS_IF([test -z "$PYTHON_INCLUDE"], [ + AC_MSG_CHECKING([Python include flags]) + PYTHON_INCLUDE=`$PYTHON_CONFIG --includes` + AC_MSG_RESULT([$PYTHON_INCLUDE]) + ]) + + AS_IF([test -z "$PYTHON_LDFLAGS"], [ + AC_MSG_CHECKING([Python library flags]) + PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags` + AC_MSG_RESULT([$PYTHON_LDFLAGS]) ]) - AC_MSG_CHECKING([Python library flags]) - PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags` - AC_MSG_RESULT([$PYTHON_LDFLAGS]) ]) - ] -) +], [:]) + +AS_IF([test "$PYTHON" != :], [have_python=yes], [have_python=no]) +AS_IF([test -n "$PYTHON_CONFIG"], [have_python_dev=yes], [have_python_dev=no]) + +AM_CONDITIONAL([HAVE_PYTHON], [test "x$have_python" = xyes]) +AM_CONDITIONAL([HAVE_PYTHON_DEV], [test "x$have_python_dev" = xyes]) + +AS_IF([test "x$enable_python_bindings" = xyes || test "x$enable_python_plugins" = xyes], [ + AS_IF([test "x$have_python_dev" = xno], [ + AC_MSG_ERROR([Cannot find a suitable python-config. You can override the python-config path with the PYTHON_CONFIG environment variable.]) + ]) +]) AS_IF([test "x$enable_python_bindings_doc" = xyes], [ @@ -777,13 +784,23 @@ PPRINT_PROP_STRING([Target architecture], $target_arch) AS_ECHO PPRINT_SUBTITLE([Python 3 language support]) +test "x$have_python" = "xyes" && value=1 || value=0 +PPRINT_PROP_BOOL([Have Python interpreter], $value) +test "x$have_python_dev" = "xyes" && value=1 || value=0 +PPRINT_PROP_BOOL([Have Python development libraries], $value) test "x$enable_python_bindings" = "xyes" && value=1 || value=0 PPRINT_PROP_BOOL([Python bindings], $value) test "x$enable_python_plugins" = "xyes" && value=1 || value=0 PPRINT_PROP_BOOL([Python plugin support], $value) -AS_IF([test "x$enable_python_bindings" = "xyes" || test "x$enable_python_plugins" = "xyes"], [ +AS_IF([test "x$have_python" = "xyes"], [ + PPRINT_PROP_STRING([Python interpreter path], [$PYTHON]) +]) +AS_IF([test "x$have_python_dev" = "xyes"], [ + PPRINT_PROP_STRING([python-config path], [$PYTHON_CONFIG]) PPRINT_PROP_STRING([Python include paths], [$PYTHON_INCLUDE]) PPRINT_PROP_STRING([Python linker flags], [$PYTHON_LDFLAGS]) +]) +AS_IF([test "x$enable_python_bindings" = "xyes"], [ PPRINT_PROP_STRING([SWIG executable], [$SWIG]) PPRINT_PROP_STRING([SWIG library], [$SWIG_LIB]) ]) diff --git a/src/py-common/Makefile.am b/src/py-common/Makefile.am index bc52700b..941124a9 100644 --- a/src/py-common/Makefile.am +++ b/src/py-common/Makefile.am @@ -1,4 +1,4 @@ -if HAVE_PYTHON +if ENABLE_PYTHON_COMMON_DEPS AM_CPPFLAGS += $(PYTHON_INCLUDE) noinst_LTLIBRARIES = libbabeltrace2-py-common.la @@ -6,4 +6,4 @@ noinst_LTLIBRARIES = libbabeltrace2-py-common.la libbabeltrace2_py_common_la_SOURCES = \ py-common.c \ py-common.h -endif # HAVE_PYTHON +endif # ENABLE_PYTHON_COMMON_DEPS -- 2.34.1