| 1 |
dnl Functions for Python bindings |
| 2 |
dnl |
| 3 |
dnl Version: 20240418 |
| 4 |
|
| 5 |
dnl Function to check if the python binary is available |
| 6 |
dnl "python${PYTHON_VERSION} python python# python#.#" |
| 7 |
AC_DEFUN([AX_PROG_PYTHON], |
| 8 |
[AS_IF( |
| 9 |
[test "x${PYTHON_VERSION}" != x], |
| 10 |
[ax_python_progs="python${PYTHON_VERSION}"], |
| 11 |
[ax_python_progs="python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python2 python2.7 python2.6 python2.5"]) |
| 12 |
AC_CHECK_PROGS( |
| 13 |
[PYTHON], |
| 14 |
[$ax_python_progs]) |
| 15 |
AS_IF( |
| 16 |
[test "x${PYTHON}" != x], |
| 17 |
[ax_prog_python_version=`${PYTHON} -c "import sys; sys.stdout.write('%d.%d' % (sys.version_info[[0]], sys.version_info[[1]]))" 2>/dev/null`; |
| 18 |
ax_prog_python_platform=`${PYTHON} -c "import sys; sys.stdout.write(sys.platform)" 2>/dev/null`; |
| 19 |
AC_SUBST( |
| 20 |
[PYTHON_PLATFORM], |
| 21 |
[$ax_prog_python_platform]) |
| 22 |
], |
| 23 |
[AC_MSG_ERROR( |
| 24 |
[Unable to find python]) |
| 25 |
]) |
| 26 |
AC_SUBST( |
| 27 |
[PYTHON], |
| 28 |
[$PYTHON]) |
| 29 |
]) |
| 30 |
|
| 31 |
dnl Function to check if the python-config binary is available |
| 32 |
dnl "python${PYTHON_VERSION}-config python-config" |
| 33 |
AC_DEFUN([AX_PROG_PYTHON_CONFIG], |
| 34 |
[AS_IF( |
| 35 |
[test "x${PYTHON_CONFIG}" = x && test "x${PYTHON_VERSION}" != x], |
| 36 |
[AC_CHECK_PROGS( |
| 37 |
[PYTHON_CONFIG], |
| 38 |
[python${PYTHON_VERSION}-config]) |
| 39 |
]) |
| 40 |
AS_IF( |
| 41 |
[test "x${PYTHON_CONFIG}" = x], |
| 42 |
[AC_CHECK_PROGS( |
| 43 |
[PYTHON_CONFIG], |
| 44 |
[python-config python3-config python3.12-config python3.11-config python3.10-config python3.9-config python3.8-config python3.7-config python3.6-config python3.5-config python3.4-config python3.3-config python3.2-config python3.1-config python3.0-config python2-config python2.7-config python2.6-config python2.5-config]) |
| 45 |
]) |
| 46 |
AS_IF( |
| 47 |
[test "x${PYTHON_CONFIG}" = x], |
| 48 |
[AC_MSG_ERROR( |
| 49 |
[Unable to find python-config]) |
| 50 |
]) |
| 51 |
AC_SUBST( |
| 52 |
[PYTHON_CONFIG], |
| 53 |
[$PYTHON_CONFIG]) |
| 54 |
]) |
| 55 |
|
| 56 |
dnl Function to detect if a Python build environment is available |
| 57 |
AC_DEFUN([AX_PYTHON_CHECK], |
| 58 |
[AX_PROG_PYTHON |
| 59 |
AX_PROG_PYTHON_CONFIG |
| 60 |
|
| 61 |
AS_IF( |
| 62 |
[test "x${PYTHON_CONFIG}" != x], |
| 63 |
[dnl Check for Python includes |
| 64 |
PYTHON_INCLUDES=`${PYTHON_CONFIG} --includes 2>/dev/null`; |
| 65 |
|
| 66 |
AC_MSG_CHECKING( |
| 67 |
[for Python includes]) |
| 68 |
AC_MSG_RESULT( |
| 69 |
[$PYTHON_INCLUDES]) |
| 70 |
|
| 71 |
dnl Check for Python libraries |
| 72 |
PYTHON_LDFLAGS=`${PYTHON_CONFIG} --ldflags 2>/dev/null`; |
| 73 |
|
| 74 |
AC_MSG_CHECKING( |
| 75 |
[for Python libraries]) |
| 76 |
AC_MSG_RESULT( |
| 77 |
[$PYTHON_LDFLAGS]) |
| 78 |
|
| 79 |
dnl For CygWin and MinGW add the -no-undefined linker flag |
| 80 |
AS_CASE( |
| 81 |
[$build], |
| 82 |
[*-*-cygwin*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], |
| 83 |
[*-*-mingw*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], |
| 84 |
[*-*-msys*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], |
| 85 |
[*],[]) |
| 86 |
|
| 87 |
dnl Check for the existence of Python.h |
| 88 |
BACKUP_CPPFLAGS="${CPPFLAGS}" |
| 89 |
CPPFLAGS="${CPPFLAGS} ${PYTHON_INCLUDES}" |
| 90 |
|
| 91 |
AC_CHECK_HEADERS( |
| 92 |
[Python.h], |
| 93 |
[ac_cv_header_python_h=yes], |
| 94 |
[ac_cv_header_python_h=no]) |
| 95 |
|
| 96 |
CPPFLAGS="${BACKUP_CPPFLAGS}" |
| 97 |
]) |
| 98 |
|
| 99 |
AS_IF( |
| 100 |
[test "x${ac_cv_header_python_h}" != xyes], |
| 101 |
[ac_cv_enable_python=no], |
| 102 |
[ac_cv_enable_python=${ax_prog_python_version} |
| 103 |
AC_SUBST( |
| 104 |
[PYTHON_CPPFLAGS], |
| 105 |
[$PYTHON_INCLUDES]) |
| 106 |
|
| 107 |
AC_SUBST( |
| 108 |
[PYTHON_LDFLAGS], |
| 109 |
[$PYTHON_LDFLAGS]) |
| 110 |
|
| 111 |
dnl Check for Python prefix |
| 112 |
AS_IF( |
| 113 |
[test "x${ac_cv_with_pyprefix}" = x || test "x${ac_cv_with_pyprefix}" = xno], |
| 114 |
[ax_python_prefix="\${prefix}"], |
| 115 |
[ax_python_prefix=`${PYTHON_CONFIG} --prefix 2>/dev/null`]) |
| 116 |
|
| 117 |
AC_SUBST( |
| 118 |
[PYTHON_PREFIX], |
| 119 |
[$ax_python_prefix]) |
| 120 |
|
| 121 |
dnl Check for Python exec-prefix |
| 122 |
AS_IF( |
| 123 |
[test "x${ac_cv_with_pyprefix}" = x || test "x${ac_cv_with_pyprefix}" = xno], |
| 124 |
[ax_python_exec_prefix="\${exec_prefix}"], |
| 125 |
[ax_python_exec_prefix=`${PYTHON_CONFIG} --exec-prefix 2>/dev/null`]) |
| 126 |
|
| 127 |
AC_SUBST( |
| 128 |
[PYTHON_EXEC_PREFIX], |
| 129 |
[$ax_python_exec_prefix]) |
| 130 |
|
| 131 |
dnl Check for Python library directory |
| 132 |
ax_python_pythondir_suffix=`${PYTHON} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib(0, 0, prefix=''))" 2>/dev/null`; |
| 133 |
|
| 134 |
AS_IF( |
| 135 |
[test "x${ac_cv_with_pythondir}" = x || test "x${ac_cv_with_pythondir}" = xno], |
| 136 |
[AS_IF( |
| 137 |
[test "x${ac_cv_with_pyprefix}" = x || test "x${ac_cv_with_pyprefix}" = xno], |
| 138 |
[ax_python_pythondir="${ax_python_prefix}/${ax_python_pythondir_suffix}"], |
| 139 |
[ax_python_pythondir=`${PYTHON} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib()) " 2>/dev/null`])], |
| 140 |
[ax_python_pythondir=$ac_cv_with_pythondir]) |
| 141 |
|
| 142 |
AC_SUBST( |
| 143 |
[pythondir], |
| 144 |
[$ax_python_pythondir]) |
| 145 |
|
| 146 |
dnl Check for Python platform specific library directory |
| 147 |
ax_python_pyexecdir_suffix=`${PYTHON} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib(1, 0, prefix=''))" 2>/dev/null`; |
| 148 |
ax_python_library_dir=`${PYTHON} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_lib(True)) " 2>/dev/null`; |
| 149 |
|
| 150 |
AS_IF( |
| 151 |
[test "x${ac_cv_with_pyprefix}" = x || test "x${ac_cv_with_pyprefix}" = xno], |
| 152 |
[ax_python_pyexecdir="${ax_python_exec_prefix}/${ax_python_pyexecdir_suffix}"], |
| 153 |
[ax_python_pyexecdir=$ax_python_library_dir]) |
| 154 |
|
| 155 |
AC_SUBST( |
| 156 |
[pyexecdir], |
| 157 |
[$ax_python_pyexecdir]) |
| 158 |
|
| 159 |
AC_SUBST( |
| 160 |
[PYTHON_LIBRARY_DIR], |
| 161 |
[$ax_python_pyexecdir_suffix]) |
| 162 |
|
| 163 |
AC_SUBST( |
| 164 |
[PYTHON_PACKAGE_DIR], |
| 165 |
[$ax_python_library_dir]) |
| 166 |
]) |
| 167 |
]) |
| 168 |
|
| 169 |
dnl Function to determine the prefix of pythondir |
| 170 |
AC_DEFUN([AX_PYTHON_CHECK_PYPREFIX], |
| 171 |
[AX_COMMON_ARG_WITH( |
| 172 |
[pyprefix], |
| 173 |
[pyprefix], |
| 174 |
[use `python-config --prefix' to determine the prefix of pythondir instead of --prefix], |
| 175 |
[no], |
| 176 |
[no]) |
| 177 |
]) |
| 178 |
|
| 179 |
dnl Function to detect if to enable Python |
| 180 |
AC_DEFUN([AX_PYTHON_CHECK_ENABLE], |
| 181 |
[AX_PYTHON_CHECK_PYPREFIX |
| 182 |
|
| 183 |
AX_COMMON_ARG_ENABLE( |
| 184 |
[python], |
| 185 |
[python], |
| 186 |
[build Python bindings], |
| 187 |
[no]) |
| 188 |
AX_COMMON_ARG_WITH( |
| 189 |
[pythondir], |
| 190 |
[pythondir], |
| 191 |
[use to specify the Python directory (pythondir)], |
| 192 |
[no], |
| 193 |
[no]) |
| 194 |
|
| 195 |
AS_IF( |
| 196 |
[test "x${ac_cv_enable_python}" != xno], |
| 197 |
[AX_PYTHON_CHECK]) |
| 198 |
|
| 199 |
AM_CONDITIONAL( |
| 200 |
HAVE_PYTHON, |
| 201 |
[test "x${ac_cv_enable_python}" != xno]) |
| 202 |
|
| 203 |
AM_CONDITIONAL( |
| 204 |
HAVE_PYTHON_TESTS, |
| 205 |
[test "x${ac_cv_enable_python}" != xno]) |
| 206 |
]) |
| 207 |
]) |
| 208 |
|