From 6a25a6238f4bee2cd3ab6a9ca246d0f7548f9121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 19 Mar 2013 20:02:27 +0100 Subject: [PATCH] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS. As in wrapping pkg-config or python-config, whichever is appropriate for given Python version. Fixes: https://bugs.gentoo.org/show_bug.cgi?id=461706 --- gx86/eclass/python-utils-r1.eclass | 106 ++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass index feb6e3d..a966062 100644 --- a/gx86/eclass/python-utils-r1.eclass +++ b/gx86/eclass/python-utils-r1.eclass @@ -34,7 +34,7 @@ fi if [[ ! ${_PYTHON_UTILS_R1} ]]; then -inherit multilib +inherit multilib toolchain-funcs # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS # @INTERNAL @@ -136,6 +136,34 @@ _python_impl_supported() { # /usr/lib64/libpython2.6.so # @CODE +# @ECLASS-VARIABLE: PYTHON_CFLAGS +# @DESCRIPTION: +# Proper C compiler flags for building against Python. Obtained from +# pkg-config or python-config. +# +# 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 +# -I/usr/include/python2.7 +# @CODE + +# @ECLASS-VARIABLE: PYTHON_LIBS +# @DESCRIPTION: +# Proper C compiler flags for linking against Python. Obtained from +# pkg-config or python-config. +# +# 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 +# -lpython2.7 +# @CODE + # @ECLASS-VARIABLE: PYTHON_PKG_DEP # @DESCRIPTION: # The complete dependency on a particular Python package as a string. @@ -238,7 +266,7 @@ python_export() { libname=lib${impl} ;; *) - die "${EPYTHON} lacks a dynamic library" + die "${impl} lacks a dynamic library" ;; esac @@ -247,6 +275,46 @@ python_export() { export PYTHON_LIBPATH=${path}/${libname}$(get_libname) debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}" ;; + PYTHON_CFLAGS) + local val + + case "${impl}" in + python2.5|python2.6) + # old versions support python-config only + val=$("${impl}-config" --includes) + ;; + python*) + # python-2.7, python-3.2, etc. + val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-}) + ;; + *) + die "${impl}: obtaining ${var} not supported" + ;; + esac + + export PYTHON_CFLAGS=${val} + debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}" + ;; + PYTHON_LIBS) + local val + + case "${impl}" in + python2.5|python2.6) + # old versions support python-config only + val=$("${impl}-config" --libs) + ;; + python*) + # python-2.7, python-3.2, etc. + val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-}) + ;; + *) + die "${impl}: obtaining ${var} not supported" + ;; + esac + + export PYTHON_LIBS=${val} + debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}" + ;; PYTHON_PKG_DEP) local d case ${impl} in @@ -353,6 +421,40 @@ python_get_library_path() { echo "${PYTHON_LIBPATH}" } +# @FUNCTION: python_get_CFLAGS +# @USAGE: [] +# @DESCRIPTION: +# Obtain and print the compiler flags for building against Python, +# 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 and pkg-config installed, and therefore proper +# build-time dependencies need be added to the ebuild. +python_get_CFLAGS() { + debug-print-function ${FUNCNAME} "${@}" + + python_export "${@}" PYTHON_CFLAGS + echo "${PYTHON_CFLAGS}" +} + +# @FUNCTION: python_get_LIBS +# @USAGE: [] +# @DESCRIPTION: +# Obtain and print the compiler flags for linking against Python, +# 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 and pkg-config installed, and therefore proper +# build-time dependencies need be added to the ebuild. +python_get_LIBS() { + debug-print-function ${FUNCNAME} "${@}" + + python_export "${@}" PYTHON_LIBS + echo "${PYTHON_LIBS}" +} + # @FUNCTION: _python_rewrite_shebang # @INTERNAL # @USAGE: [] ... -- 1.8.1.5