python-utils-r1.eclass: Support getting PYTHON_CONFIG path
authorMichał Górny <mgorny@gentoo.org>
Sun, 8 Nov 2015 08:27:50 +0000 (09:27 +0100)
committerMichał Górny <mgorny@gentoo.org>
Wed, 11 Nov 2015 10:21:33 +0000 (11:21 +0100)
eclass/python-utils-r1.eclass
eclass/tests/python-utils-r1.sh

index e8de6b9fd1e89e38170ed514dca9eaa5a96d26ac..68926abe9da7d1ae110138824c327b9414db109e 100644 (file)
@@ -190,6 +190,20 @@ _python_impl_supported() {
 # -lpython2.7
 # @CODE
 
+# @ECLASS-VARIABLE: PYTHON_CONFIG
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Path to the python-config executable.
+#
+# Set and exported on request using python_export().
+# Valid only for CPython. Requires a proper build-time dependency
+# on the Python implementation and on pkg-config.
+#
+# Example value:
+# @CODE
+# /usr/bin/python2.7-config
+# @CODE
+
 # @ECLASS-VARIABLE: PYTHON_PKG_DEP
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -323,6 +337,22 @@ python_export() {
                                export PYTHON_LIBS=${val}
                                debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
                                ;;
+                       PYTHON_CONFIG)
+                               local flags val
+
+                               case "${impl}" in
+                                       python*)
+                                               flags=$("${PYTHON}" -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS") or "")')
+                                               val=${PYTHON}${flags}-config
+                                               ;;
+                                       *)
+                                               die "${impl}: obtaining ${var} not supported"
+                                               ;;
+                               esac
+
+                               export PYTHON_CONFIG=${val}
+                               debug-print "${FUNCNAME}: PYTHON_CONFIG = ${PYTHON_CONFIG}"
+                               ;;
                        PYTHON_PKG_DEP)
                                local d
                                case ${impl} in
@@ -443,6 +473,23 @@ python_get_LIBS() {
        echo "${PYTHON_LIBS}"
 }
 
+# @FUNCTION: python_get_PYTHON_CONFIG
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the PYTHON_CONFIG location for the given
+# implementation. If no implementation is provided, ${EPYTHON} will be
+# used.
+#
+# Please note that this function can be used with CPython only.
+# It requires Python installed, and therefore proper build-time
+# dependencies need be added to the ebuild.
+python_get_PYTHON_CONFIG() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       python_export "${@}" PYTHON_CONFIG
+       echo "${PYTHON_CONFIG}"
+}
+
 # @FUNCTION: python_get_scriptdir
 # @USAGE: [<impl>]
 # @DESCRIPTION:
index 457756de3e42c973dc52bdb7d0da8f1e5075d243..b683c51830a924181bf46b660724ed3a433dcea7 100755 (executable)
@@ -67,6 +67,7 @@ if [[ -x /usr/bin/python2.7 ]]; then
        test_var PYTHON_SITEDIR python2_7 "/usr/lib*/python2.7/site-packages"
        test_var PYTHON_INCLUDEDIR python2_7 /usr/include/python2.7
        test_var PYTHON_LIBPATH python2_7 "/usr/lib*/libpython2.7$(get_libname)"
+       test_var PYTHON_CONFIG python2_7 /usr/bin/python2.7-config
 fi
 test_var PYTHON_PKG_DEP python2_7 '*dev-lang/python*:2.7'
 test_var PYTHON_SCRIPTDIR python2_7 /usr/lib/python-exec/python2.7
@@ -78,6 +79,7 @@ if [[ -x /usr/bin/python3.4 ]]; then
        test_var PYTHON_SITEDIR python3_4 "/usr/lib*/python3.4/site-packages"
        test_var PYTHON_INCLUDEDIR python3_4 "/usr/include/python3.4${abiflags}"
        test_var PYTHON_LIBPATH python3_4 "/usr/lib*/libpython3.4${abiflags}$(get_libname)"
+       test_var PYTHON_CONFIG python3_4 "/usr/bin/python3.4${abiflags}-config"
 fi
 test_var PYTHON_PKG_DEP python3_4 '*dev-lang/python*:3.4'
 test_var PYTHON_SCRIPTDIR python3_4 /usr/lib/python-exec/python3.4