Fixup fromcvs/togit conversion
[pkgsrcv2.git] / lang / python / pyversion.mk
1 # $NetBSD: pyversion.mk,v 1.100 2012/08/01 19:07:20 drochner Exp $
2
3 # This file determines which Python version is used as a dependency for
4 # a package.
5 #
6 # === User-settable variables ===
7 #
8 # PYTHON_VERSION_DEFAULT
9 #       The preferred Python version to use.
10 #
11 #       Possible values: 25 26 27 31 32
12 #       Default: 27
13 #
14 # PYTHON_VERSION_REQD
15 #       Python version to use. This is a user variable and
16 #       should not be set in packages.
17 #       Normally it is used by bulk build tools.
18 #
19 #       Possible: ${PYTHON_VERSIONS_ACCEPTED}
20 #       Default:  ${PYTHON_VERSION_DEFAULT}
21 #
22 # === Package-settable variables ===
23 #
24 # PYTHON_VERSIONS_ACCEPTED
25 #       The Python versions that are acceptable for the package. The
26 #       order of the entries matters, since earlier entries are
27 #       preferred over later ones.
28 #
29 #       Possible values: 32 31 27 26 25
30 #       Default: (32 31) 27 26 25
31 #
32 # PYTHON_VERSIONS_INCLUDE_3X
33 #       Wether the default PYTHON_VERSIONS_ACCEPTED should include
34 #       3.x versions for for this package or not.
35 #       This variable must be set before including bsd.prefs.mk.
36 #
37 #       Possible values: yes no
38 #       Default: no
39 #
40 # PYTHON_VERSIONS_INCOMPATIBLE
41 #       The Python versions that are NOT acceptable for the package.
42 #
43 #       Possible values: 25 26 27 31 32
44 #       Default: (depends on the platform)
45 #
46 # PYTHON_FOR_BUILD_ONLY
47 #       Whether Python is needed only at build time or at run time.
48 #
49 #       Possible values: (defined) (undefined)
50 #       Default: (undefined)
51 #
52 # === Defined variables ===
53 #
54 # PYPKGPREFIX
55 #       The prefix to use in PKGNAME for extensions which are meant
56 #       to be installed for multiple Python versions.
57 #
58 #       Example: py27
59 #
60 # PYVERSSUFFIX
61 #       The suffix to executables and in the library path, equal to
62 #       sys.version[0:3].
63 #
64 #       Example: 2.7
65 #
66 # Keywords: python
67 #
68
69 .if !defined(PYTHON_PYVERSION_MK)
70 PYTHON_PYVERSION_MK=    defined
71
72 # derive a python version from the package name if possible
73 # optionally handled quoted package names
74 .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
75     defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9]-*)
76 PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
77 .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
78       defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9]-*)
79 PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
80 .endif
81
82 .include "../../mk/bsd.prefs.mk"
83
84 BUILD_DEFS+=            PYTHON_VERSION_DEFAULT
85 BUILD_DEFS_EFFECTS+=    PYPACKAGE
86
87 PYTHON_VERSION_DEFAULT?=                27
88 .if ${PYTHON_VERSIONS_INCLUDE_3X:U:tl} == "yes"
89 PYTHON_VERSIONS_ACCEPTED?=              32 31 27 26 25
90 .else
91 PYTHON_VERSIONS_ACCEPTED?=              27 26 25
92 .endif
93 PYTHON_VERSIONS_INCOMPATIBLE?=          # empty by default
94
95 BUILDLINK_API_DEPENDS.python25?=                python25>=2.5.1
96 BUILDLINK_API_DEPENDS.python26?=                python26>=2.6
97 BUILDLINK_API_DEPENDS.python27?=                python27>=2.7
98 BUILDLINK_API_DEPENDS.python31?=                python31>=3.1
99 BUILDLINK_API_DEPENDS.python32?=                python32>=3.2
100
101 # transform the list into individual variables
102 .for pv in ${PYTHON_VERSIONS_ACCEPTED}
103 .if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
104 _PYTHON_VERSION_${pv}_OK=       yes
105 _PYTHON_VERSIONS_ACCEPTED+=     ${pv}
106 .endif
107 .endfor
108
109 #
110 # choose a python version where to add,
111 # try to be intelligent
112 #
113 # if a version is explicitely required, take it
114 .if defined(PYTHON_VERSION_REQD)
115 # but check if it is acceptable first, error out otherwise
116 . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
117 _PYTHON_VERSION=        ${PYTHON_VERSION_REQD}
118 . endif
119 .else
120 # if the default is accepted, it is first choice
121 . if !defined(_PYTHON_VERSION)
122 . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
123 _PYTHON_VERSION=        ${PYTHON_VERSION_DEFAULT}
124 . endif
125 . endif
126 # prefer an already installed version, in order of "accepted"
127 . if !defined(_PYTHON_VERSION)
128 . for pv in ${PYTHON_VERSIONS_ACCEPTED}
129 . if defined(_PYTHON_VERSION_${pv}_OK)
130 _PYTHON_VERSION?=       ${pv}
131 . endif
132 . endfor
133 . endif
134 .endif
135
136 #
137 # Variable assignment for multi-python packages
138 MULTI+= PYTHON_VERSION_REQD=${_PYTHON_VERSION}
139
140 # No supported version found, annotate to simplify statements below.
141 .if !defined(_PYTHON_VERSION)
142 _PYTHON_VERSION=        none
143 .endif
144
145 PLIST_VARS+=    py2x py3x
146
147 .if ${_PYTHON_VERSION} == "32"
148 PYPKGSRCDIR=    ../../lang/python32
149 PYDEPENDENCY=   ${BUILDLINK_API_DEPENDS.python32}:${PYPKGSRCDIR}
150 PYPACKAGE=      python32
151 PYVERSSUFFIX=   3.2
152 PYPKGPREFIX=    py32
153 PLIST.py3x=     yes
154 .elif ${_PYTHON_VERSION} == "31"
155 PYPKGSRCDIR=    ../../lang/python31
156 PYDEPENDENCY=   ${BUILDLINK_API_DEPENDS.python31}:${PYPKGSRCDIR}
157 PYPACKAGE=      python31
158 PYVERSSUFFIX=   3.1
159 PYPKGPREFIX=    py31
160 PLIST.py3x=     yes
161 .elif ${_PYTHON_VERSION} == "27"
162 PYPKGSRCDIR=    ../../lang/python27
163 PYDEPENDENCY=   ${BUILDLINK_API_DEPENDS.python27}:${PYPKGSRCDIR}
164 PYPACKAGE=      python27
165 PYVERSSUFFIX=   2.7
166 PYPKGPREFIX=    py27
167 PLIST.py2x=     yes
168 .elif ${_PYTHON_VERSION} == "26"
169 PYPKGSRCDIR=    ../../lang/python26
170 PYDEPENDENCY=   ${BUILDLINK_API_DEPENDS.python26}:${PYPKGSRCDIR}
171 PYPACKAGE=      python26
172 PYVERSSUFFIX=   2.6
173 PYPKGPREFIX=    py26
174 PLIST.py2x=     yes
175 .elif ${_PYTHON_VERSION} == "25"
176 PYPKGSRCDIR=    ../../lang/python25
177 PYDEPENDENCY=   ${BUILDLINK_API_DEPENDS.python25}:${PYPKGSRCDIR}
178 PYPACKAGE=      python25
179 PYVERSSUFFIX=   2.5
180 PYPKGPREFIX=    py25
181 PLIST.py2x=     yes
182 .else
183 PKG_FAIL_REASON+=   "No valid Python version"
184 PYPKGPREFIX=
185 .endif
186
187 PTHREAD_OPTS+=  require
188 .include "../../mk/pthread.buildlink3.mk"
189
190 .if defined(PYTHON_FOR_BUILD_ONLY)
191 BUILDLINK_DEPMETHOD.python?=    build
192 .endif
193 .if defined(PYPKGSRCDIR)
194 .include "${PYPKGSRCDIR}/buildlink3.mk"
195 .endif
196
197 PYTHONBIN=      ${LOCALBASE}/bin/python${PYVERSSUFFIX}
198 PYTHONCONFIG=   ${LOCALBASE}/bin/python${PYVERSSUFFIX}-config
199 PY_COMPILE_ALL= \
200         ${PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
201 PY_COMPILE_O_ALL= \
202         ${PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
203
204 .if exists(${PYTHONBIN})
205 PYINC!= ${PYTHONBIN} -c "import distutils.sysconfig; \
206         print (distutils.sysconfig.get_python_inc(0, \"\"))" || ${ECHO} ""
207 PYLIB!= ${PYTHONBIN} -c "import distutils.sysconfig; \
208         print (distutils.sysconfig.get_python_lib(0, 1, \"\"))" || ${ECHO} ""
209 PYSITELIB!=     ${PYTHONBIN} -c "import distutils.sysconfig; \
210         print (distutils.sysconfig.get_python_lib(0, 0, \"\"))" || ${ECHO} ""
211
212 PRINT_PLIST_AWK+=       /^${PYINC:S|/|\\/|g}/ \
213                         { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
214 PRINT_PLIST_AWK+=       /^${PYSITELIB:S|/|\\/|g}/ \
215                         { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
216 PRINT_PLIST_AWK+=       /^${PYLIB:S|/|\\/|g}/ \
217                         { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
218 .endif
219
220 ALL_ENV+=       PYTHON=${PYTHONBIN}
221 .if defined(USE_CMAKE)
222 # used by FindPythonInterp.cmake and FindPythonLibs.cmake
223 CMAKE_ARGS+=    -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
224 .endif
225
226 .endif  # PYTHON_PYVERSION_MK