public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-python] [PATCH python-utils-r1] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS.
@ 2013-03-20 19:30 Michał Górny
  2013-03-28 12:23 ` Michał Górny
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Górny @ 2013-03-20 19:30 UTC (permalink / raw
  To: gentoo-python; +Cc: python, Michał Górny

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: [<impl>]
+# @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: [<impl>]
+# @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: [<EPYTHON>] <path>...
-- 
1.8.1.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-python] [PATCH python-utils-r1] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS.
  2013-03-20 19:30 [gentoo-python] [PATCH python-utils-r1] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS Michał Górny
@ 2013-03-28 12:23 ` Michał Górny
  0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2013-03-28 12:23 UTC (permalink / raw
  To: Michał Górny; +Cc: gentoo-python, python

[-- Attachment #1: Type: text/plain, Size: 295 bytes --]

On Wed, 20 Mar 2013 20:30:21 +0100
Michał Górny <mgorny@gentoo.org> wrote:

> 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

Committed.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-28 12:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20 19:30 [gentoo-python] [PATCH python-utils-r1] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS Michał Górny
2013-03-28 12:23 ` Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox