Skip to content

Commit

Permalink
Switch to PKG_CHECK_MODULES
Browse files Browse the repository at this point in the history
drop  --with-python-config and --with-python-dir option
also use EXTRAS_CXXFLAGS instead of changing CXXFLAGS
  • Loading branch information
remicollet committed Aug 21, 2024
1 parent 2a542af commit 13a1d9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 57 deletions.
70 changes: 14 additions & 56 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,81 +1,39 @@
dnl $Id$
dnl config.m4 for extension phpy

PHP_ARG_WITH([python_dir],
[dir of python],
[AS_HELP_STRING([[--with-python-dir[=DIR]]],
[Specify python installation dir, default is /opt/anaconda3])], [no], [no])


PHP_ARG_WITH([python_version],
[version of python],
[AS_HELP_STRING([[--with-python-version[=VERSION]]],
[Specify version of python, default is 3.11])], [no], [no])

PHP_ARG_WITH([python_config],
[path of python_config],
[AS_HELP_STRING([[--with-python-config[=PATH]]],
[Specify path of python_config])], [no], [no])
[Specify version of python, or use default (ex: 3.12)])], [no], [no])

PHP_ARG_ENABLE([phpy],
[whether to enable phpy support],
[AS_HELP_STRING([--enable-phpy],
[Enable phpy support])],
[no])

AC_DEFUN([GET_PYTHON_LDFLAGS], [
TMP_RESULT="$($PHP_PYTHON_CONFIG --embed --ldflags)"
if test $? -eq 0; then
PYTHON_LDFLAGS="$TMP_RESULT"
elif test $? -eq 1; then
PYTHON_LDFLAGS="$LDFLAGS $($PHP_PYTHON_CONFIG --ldflags)"
else
AC_MSG_ERROR([failed to execute `$PHP_PYTHON_CONFIG --ldflags`])
fi
LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS"
])

AC_DEFUN([GET_PYTHON_INCLUDES], [
TMP_RESULT="$INCLUDES $($PHP_PYTHON_CONFIG --includes)"
if test $? -eq 0; then
INCLUDES="$INCLUDES $TMP_RESULT"
else
AC_MSG_ERROR([failed to execute `$PHP_PYTHON_CONFIG --includes`])
fi
])

if test "$PHP_PHPY" != "no"; then
if test "$PHP_PYTHON_CONFIG" != "no"; then
GET_PYTHON_INCLUDES()
GET_PYTHON_LDFLAGS()
dnl modern version use python3-embed, old (<= 3.6) use python3
if test "$PHP_PYTHON_VERSION" = "no"; then
PKG_CHECK_MODULES([PYTHON], [python3-embed],,
[PKG_CHECK_MODULES([PYTHON], [python3])]
)
else
if test "$PHP_PYTHON_DIR" = "no"; then
PHP_PYTHON_DIR="/opt/anaconda3"
fi
if test "$PHP_PYTHON_VERSION" = "no"; then
if test -f "${PHP_PYTHON_DIR}/bin/python"; then
PHP_PYTHON_VERSION=$("${PHP_PYTHON_DIR}/bin/python" -c "import sys; print('%d.%d'%(sys.version_info.major, sys.version_info.minor))")
elif test -f "${PHP_PYTHON_DIR}/python"; then
PHP_PYTHON_VERSION=$("${PHP_PYTHON_DIR}/python" -c "import sys; print('%d.%d'%(sys.version_info.major, sys.version_info.minor))")
else
PHP_PYTHON_VERSION="3.11"
fi
fi
AC_MSG_RESULT([PYTHON_DIR=${PHP_PYTHON_DIR}])
AC_MSG_RESULT([PYTHON_VERSION=${PHP_PYTHON_VERSION}])

PHP_ADD_INCLUDE("${PHP_PYTHON_DIR}/include/python${PHP_PYTHON_VERSION}")
PHP_ADD_LIBRARY_WITH_PATH("python${PHP_PYTHON_VERSION}", "${PHP_PYTHON_DIR}/lib", PHPY_SHARED_LIBADD)
PKG_CHECK_MODULES([PYTHON], [python-${PHP_PYTHON_VERSION}-embed],,
[PKG_CHECK_MODULES([PYTHON], [python-${PHP_PYTHON_VERSION}])]
)
fi
PHP_EVAL_LIBLINE($PYTHON_LIBS, PHPY_SHARED_LIBADD)
PHP_EVAL_INCLINE($PYTHON_CFLAGS)

PHP_REQUIRE_CXX()

PHP_SUBST(PHPY_SHARED_LIBADD)

AC_DEFINE(HAVE_PHPY, 1, [ Have phpy support ])

CXXFLAGS="$CXXFLAGS -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -z now"
CXXFLAGS="$CXXFLAGS -std=c++14"
EXTRAS_CXXFLAGS="-Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -z now"
EXTRAS_CXXFLAGS="$EXTRAS_CXXFLAGS -std=c++14"

if test -f "$abs_srcdir/phpy.cc"; then
phpy_source_dir=$abs_srcdir
Expand All @@ -90,7 +48,7 @@ if test "$PHP_PHPY" != "no"; then
phpy_source_files=$(cd $phpy_source_dir && find src -type f -name "*.cc")
phpy_source_files="phpy.cc $phpy_source_files"

PHP_NEW_EXTENSION(phpy, $phpy_source_files , $ext_shared,,, cxx)
PHP_NEW_EXTENSION(phpy, $phpy_source_files , $ext_shared,, $EXTRAS_CXXFLAGS, cxx)

dnl AC_MSG_RESULT([$ext_builddir])

Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
</dependencies>
<providesextension>phpy</providesextension>
<extsrcrelease>
<configureoption name="with-python-config" prompt="Specify the path of python-config" default="/usr/bin/python3-config"/>
<configureoption name="with-python-version" prompt="Specify the version of python (ex: 3.12)" default="no"/>
</extsrcrelease>
</package>

0 comments on commit 13a1d9d

Please sign in to comment.