Skip to content

Commit

Permalink
plugins/python: support Python 3.8
Browse files Browse the repository at this point in the history
With Python 3.8, modules are no longer link with libpython by default. Therefore
codes that are meant for embedding Python must pass --embed to python-configure
in order to get the complete set of flags to do so.
  • Loading branch information
paumard committed Oct 25, 2019
1 parent d9fe749 commit ea20fb5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
21 changes: 13 additions & 8 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -16087,14 +16087,19 @@ $as_echo "no" >&6; }
fi


if test "x" = "xyes" && $PYTHON_CONFIGURE --embed; then :
PYTHON_EMBED_FLAG="--embed"
else
PYTHON_EMBED_FLAG=""
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python includes" >&5
$as_echo_n "checking for Python includes... " >&6; }
if ${pc_cv_python_includes+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_includes=`$PYTHON_CONFIG --includes 2>&5`
pc_cv_python_includes=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --includes 2>&5`
else
pc_cv_python_includes="-I$includedir/$_PYTHON_BASENAME"
fi
Expand All @@ -16112,7 +16117,7 @@ if ${pc_cv_python_prefix+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_prefix=`$PYTHON_CONFIG --prefix 2>&5`
pc_cv_python_prefix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --prefix 2>&5`
else
ac_ext=py
ac_compile='chmod +x conftest.$ac_ext >&5'
Expand Down Expand Up @@ -16158,7 +16163,7 @@ if ${pc_cv_python_exec_prefix+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_exec_prefix=`$PYTHON_CONFIG --exec-prefix 2>&5`
pc_cv_python_exec_prefix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --exec-prefix 2>&5`
else
ac_ext=py
ac_compile='chmod +x conftest.$ac_ext >&5'
Expand Down Expand Up @@ -16210,7 +16215,7 @@ if ${pc_cv_python_includes+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_includes=`$PYTHON_CONFIG --includes 2>&5`
pc_cv_python_includes=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --includes 2>&5`
else
pc_cv_python_includes="-I$includedir/$_PYTHON_BASENAME"
fi
Expand All @@ -16226,7 +16231,7 @@ if ${pc_cv_python_cflags+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_cflags=`$PYTHON_CONFIG --cflags 2>&5`
pc_cv_python_cflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --cflags 2>&5`
else
pc_cv_python_cflags=
fi
Expand All @@ -16242,7 +16247,7 @@ if ${pc_cv_python_ldflags+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_ldflags=`$PYTHON_CONFIG --ldflags 2>&5`
pc_cv_python_ldflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --ldflags 2>&5`
else
pc_cv_python_ldflags=
fi
Expand All @@ -16258,7 +16263,7 @@ if ${pc_cv_python_libs+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_libs=`$PYTHON_CONFIG --libs 2>&5`
pc_cv_python_libs=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --libs 2>&5`
else
pc_cv_python_libs="-l$_PYTHON_BASENAME"
fi
Expand Down Expand Up @@ -16424,7 +16429,7 @@ if ${pc_cv_python_extension_suffix+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_extension_suffix=`$PYTHON_CONFIG --extension-suffix 2>&5`
pc_cv_python_extension_suffix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --extension-suffix 2>&5`
else
pc_cv_python_extension_suffix=
fi
Expand Down
24 changes: 15 additions & 9 deletions m4/python.m4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
# Copyright 2019 Thibaut Paumard <thibaut.paumard@obspm.fr>
#
# This file is part of pyconfigure. This program is free
# software; you can redistribute it and/or modify it under the
Expand Down Expand Up @@ -43,6 +44,7 @@
#
# 4. Looking for specific libs & functionality

# 2019-10-25 Thibaut Paumard add support for --embed in Python >= 3.8

## ----------------------- ##
## 1. Language selection. ##
Expand Down Expand Up @@ -160,9 +162,10 @@ m4_ifval([$1],
])# PC_PROG_PYTHON


# PC_PYTHON_PROG_PYTHON_CONFIG(PROG-TO-CHECK-FOR)
# PC_PYTHON_PROG_PYTHON_CONFIG(PROG-TO-CHECK-FOR,EMBED)
# ----------------------------------------------
# Find the python-config program
# Set EMBED to 'yes' if embedding Python.
AC_DEFUN([PC_PYTHON_PROG_PYTHON_CONFIG],
[AC_REQUIRE([PC_PROG_PYTHON])[]dnl
AC_ARG_VAR([PYTHON_CONFIG], [the Python-config program])
Expand All @@ -172,6 +175,9 @@ m4_define([_PYTHON_BASENAME], [`basename $PYTHON`])
m4_ifval([$1],
[AC_PATH_PROGS(PYTHON_CONFIG, [$1 _PYTHON_BASENAME-config])],
[AC_PATH_PROG(PYTHON_CONFIG, _PYTHON_BASENAME-config)])
AS_IF([test "x$2" = "xyes" && $PYTHON_CONFIGURE --embed],
[PYTHON_EMBED_FLAG="--embed"],
[PYTHON_EMBED_FLAG=""])
]) # PC_PYTHON_PROG_PYTHON_CONFIG


Expand Down Expand Up @@ -252,7 +258,7 @@ AC_DEFUN([PC_PYTHON_CHECK_PREFIX],
dnl Try to get it with python-config otherwise do it from within Python
AC_CACHE_CHECK([for Python prefix], [pc_cv_python_prefix],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_prefix=`$PYTHON_CONFIG --prefix 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_prefix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --prefix 2>&AS_MESSAGE_LOG_FD`
else
AC_LANG_PUSH(Python)[]dnl
AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
Expand All @@ -277,7 +283,7 @@ AC_DEFUN([PC_PYTHON_CHECK_EXEC_PREFIX],
dnl Try to get it with python-config otherwise do it from within Python
AC_CACHE_CHECK([for Python exec-prefix], [pc_cv_python_exec_prefix],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_exec_prefix=`$PYTHON_CONFIG --exec-prefix 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_exec_prefix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --exec-prefix 2>&AS_MESSAGE_LOG_FD`
else
AC_LANG_PUSH(Python)[]dnl
AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
Expand Down Expand Up @@ -305,7 +311,7 @@ AC_DEFUN([PC_PYTHON_CHECK_INCLUDES],
dnl Try to find the headers location with python-config otherwise guess
AC_CACHE_CHECK([for Python includes], [pc_cv_python_includes],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_includes=`$PYTHON_CONFIG --includes 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_includes=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --includes 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_includes="[-I$includedir/$_PYTHON_BASENAME]m4_ifdef(PYTHON_ABI_FLAGS,
PYTHON_ABI_FLAGS,)"
Expand Down Expand Up @@ -334,7 +340,7 @@ AC_DEFUN([PC_PYTHON_CHECK_LIBS],
dnl Try to find the lib flags with python-config otherwise guess
AC_CACHE_CHECK([for Python libs], [pc_cv_python_libs],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_libs=`$PYTHON_CONFIG --libs 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_libs=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --libs 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_libs="[-l$_PYTHON_BASENAME]m4_ifdef(PYTHON_ABI_FLAGS, PYTHON_ABI_FLAGS,)"
fi
Expand Down Expand Up @@ -368,7 +374,7 @@ AC_DEFUN([PC_PYTHON_CHECK_CFLAGS],
dnl Try to find the CFLAGS with python-config otherwise give up
AC_CACHE_CHECK([for Python CFLAGS], [pc_cv_python_cflags],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_cflags=`$PYTHON_CONFIG --cflags 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_cflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --cflags 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_cflags=
fi
Expand All @@ -384,7 +390,7 @@ AC_DEFUN([PC_PYTHON_CHECK_LDFLAGS],
dnl Try to find the LDFLAGS with python-config otherwise give up
AC_CACHE_CHECK([for Python LDFLAGS], [pc_cv_python_ldflags],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_ldflags=`$PYTHON_CONFIG --ldflags 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_ldflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --ldflags 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_ldflags=
fi
Expand All @@ -400,7 +406,7 @@ AC_DEFUN([PC_PYTHON_CHECK_EXTENSION_SUFFIX],
dnl Try to find the suffix with python-config otherwise give up
AC_CACHE_CHECK([for Python extension suffix], [pc_cv_python_extension_suffix],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_extension_suffix=`$PYTHON_CONFIG --extension-suffix 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_extension_suffix=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --extension-suffix 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_extension_suffix=
fi
Expand All @@ -416,7 +422,7 @@ AC_DEFUN([PC_PYTHON_CHECK_ABI_FLAGS],
dnl Try to find the ABI flags with python-config otherwise give up
AC_CACHE_CHECK([for Python ABI flags], [pc_cv_python_abi_flags],
[if test -x "$PYTHON_CONFIG"; then
pc_cv_python_abi_flags=`$PYTHON_CONFIG --abiflags 2>&AS_MESSAGE_LOG_FD`
pc_cv_python_abi_flags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --abiflags 2>&AS_MESSAGE_LOG_FD`
else
pc_cv_python_abi_flags=
fi
Expand Down
13 changes: 9 additions & 4 deletions plugins/python/configure
Original file line number Diff line number Diff line change
Expand Up @@ -17008,14 +17008,19 @@ $as_echo "no" >&6; }
fi


if test "xyes" = "xyes" && $PYTHON_CONFIGURE --embed; then :
PYTHON_EMBED_FLAG="--embed"
else
PYTHON_EMBED_FLAG=""
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python includes" >&5
$as_echo_n "checking for Python includes... " >&6; }
if ${pc_cv_python_includes+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_includes=`$PYTHON_CONFIG --includes 2>&5`
pc_cv_python_includes=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --includes 2>&5`
else
pc_cv_python_includes="-I$includedir/$_PYTHON_BASENAME"
fi
Expand All @@ -17041,7 +17046,7 @@ if ${pc_cv_python_cflags+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_cflags=`$PYTHON_CONFIG --cflags 2>&5`
pc_cv_python_cflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --cflags 2>&5`
else
pc_cv_python_cflags=
fi
Expand All @@ -17057,7 +17062,7 @@ if ${pc_cv_python_ldflags+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_ldflags=`$PYTHON_CONFIG --ldflags 2>&5`
pc_cv_python_ldflags=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --ldflags 2>&5`
else
pc_cv_python_ldflags=
fi
Expand All @@ -17073,7 +17078,7 @@ if ${pc_cv_python_libs+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -x "$PYTHON_CONFIG"; then
pc_cv_python_libs=`$PYTHON_CONFIG --libs 2>&5`
pc_cv_python_libs=`$PYTHON_CONFIG $PYTHON_EMBED_FLAG --libs 2>&5`
else
pc_cv_python_libs="-l$_PYTHON_BASENAME"
fi
Expand Down
2 changes: 1 addition & 1 deletion plugins/python/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ AC_ARG_WITH([python],
[])

PC_PROG_PYTHON([python3], [2.7], [4.0])
PC_PYTHON_PROG_PYTHON_CONFIG
PC_PYTHON_PROG_PYTHON_CONFIG([],[yes])
PC_PYTHON_CHECK_INCLUDES
PC_PYTHON_CHECK_HEADERS
PC_PYTHON_CHECK_CFLAGS
Expand Down

0 comments on commit ea20fb5

Please sign in to comment.