Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH python-utils-r1] Support obtaining PYTHON_CFLAGS and PYTHON_LIBS.
Date: Wed, 20 Mar 2013 19:29:42
Message-Id: 1363807821-2093-1-git-send-email-mgorny@gentoo.org
1 As in wrapping pkg-config or python-config, whichever is appropriate for
2 given Python version.
3
4 Fixes: https://bugs.gentoo.org/show_bug.cgi?id=461706
5 ---
6 gx86/eclass/python-utils-r1.eclass | 106 ++++++++++++++++++++++++++++++++++++-
7 1 file changed, 104 insertions(+), 2 deletions(-)
8
9 diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
10 index feb6e3d..a966062 100644
11 --- a/gx86/eclass/python-utils-r1.eclass
12 +++ b/gx86/eclass/python-utils-r1.eclass
13 @@ -34,7 +34,7 @@ fi
14
15 if [[ ! ${_PYTHON_UTILS_R1} ]]; then
16
17 -inherit multilib
18 +inherit multilib toolchain-funcs
19
20 # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
21 # @INTERNAL
22 @@ -136,6 +136,34 @@ _python_impl_supported() {
23 # /usr/lib64/libpython2.6.so
24 # @CODE
25
26 +# @ECLASS-VARIABLE: PYTHON_CFLAGS
27 +# @DESCRIPTION:
28 +# Proper C compiler flags for building against Python. Obtained from
29 +# pkg-config or python-config.
30 +#
31 +# Set and exported on request using python_export().
32 +# Valid only for CPython. Requires a proper build-time dependency
33 +# on the Python implementation and on pkg-config.
34 +#
35 +# Example value:
36 +# @CODE
37 +# -I/usr/include/python2.7
38 +# @CODE
39 +
40 +# @ECLASS-VARIABLE: PYTHON_LIBS
41 +# @DESCRIPTION:
42 +# Proper C compiler flags for linking against Python. Obtained from
43 +# pkg-config or python-config.
44 +#
45 +# Set and exported on request using python_export().
46 +# Valid only for CPython. Requires a proper build-time dependency
47 +# on the Python implementation and on pkg-config.
48 +#
49 +# Example value:
50 +# @CODE
51 +# -lpython2.7
52 +# @CODE
53 +
54 # @ECLASS-VARIABLE: PYTHON_PKG_DEP
55 # @DESCRIPTION:
56 # The complete dependency on a particular Python package as a string.
57 @@ -238,7 +266,7 @@ python_export() {
58 libname=lib${impl}
59 ;;
60 *)
61 - die "${EPYTHON} lacks a dynamic library"
62 + die "${impl} lacks a dynamic library"
63 ;;
64 esac
65
66 @@ -247,6 +275,46 @@ python_export() {
67 export PYTHON_LIBPATH=${path}/${libname}$(get_libname)
68 debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}"
69 ;;
70 + PYTHON_CFLAGS)
71 + local val
72 +
73 + case "${impl}" in
74 + python2.5|python2.6)
75 + # old versions support python-config only
76 + val=$("${impl}-config" --includes)
77 + ;;
78 + python*)
79 + # python-2.7, python-3.2, etc.
80 + val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-})
81 + ;;
82 + *)
83 + die "${impl}: obtaining ${var} not supported"
84 + ;;
85 + esac
86 +
87 + export PYTHON_CFLAGS=${val}
88 + debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}"
89 + ;;
90 + PYTHON_LIBS)
91 + local val
92 +
93 + case "${impl}" in
94 + python2.5|python2.6)
95 + # old versions support python-config only
96 + val=$("${impl}-config" --libs)
97 + ;;
98 + python*)
99 + # python-2.7, python-3.2, etc.
100 + val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-})
101 + ;;
102 + *)
103 + die "${impl}: obtaining ${var} not supported"
104 + ;;
105 + esac
106 +
107 + export PYTHON_LIBS=${val}
108 + debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
109 + ;;
110 PYTHON_PKG_DEP)
111 local d
112 case ${impl} in
113 @@ -353,6 +421,40 @@ python_get_library_path() {
114 echo "${PYTHON_LIBPATH}"
115 }
116
117 +# @FUNCTION: python_get_CFLAGS
118 +# @USAGE: [<impl>]
119 +# @DESCRIPTION:
120 +# Obtain and print the compiler flags for building against Python,
121 +# for the given implementation. If no implementation is provided,
122 +# ${EPYTHON} will be used.
123 +#
124 +# Please note that this function can be used with CPython only.
125 +# It requires Python and pkg-config installed, and therefore proper
126 +# build-time dependencies need be added to the ebuild.
127 +python_get_CFLAGS() {
128 + debug-print-function ${FUNCNAME} "${@}"
129 +
130 + python_export "${@}" PYTHON_CFLAGS
131 + echo "${PYTHON_CFLAGS}"
132 +}
133 +
134 +# @FUNCTION: python_get_LIBS
135 +# @USAGE: [<impl>]
136 +# @DESCRIPTION:
137 +# Obtain and print the compiler flags for linking against Python,
138 +# for the given implementation. If no implementation is provided,
139 +# ${EPYTHON} will be used.
140 +#
141 +# Please note that this function can be used with CPython only.
142 +# It requires Python and pkg-config installed, and therefore proper
143 +# build-time dependencies need be added to the ebuild.
144 +python_get_LIBS() {
145 + debug-print-function ${FUNCNAME} "${@}"
146 +
147 + python_export "${@}" PYTHON_LIBS
148 + echo "${PYTHON_LIBS}"
149 +}
150 +
151 # @FUNCTION: _python_rewrite_shebang
152 # @INTERNAL
153 # @USAGE: [<EPYTHON>] <path>...
154 --
155 1.8.1.5

Replies