Sync Mk with ports
[dports.git] / Mk / Uses / python.mk
1 # $FreeBSD$
2 #
3 # Provide support for Python related ports. This includes detecting Python
4 # interpreters, ports providing package and modules for python as well as
5 # consumer ports requiring Python at build or run time.
6 #
7 # Feature:      python
8 # Usage:        USES=python or USES=python:args
9 # Valid ARGS:   <version>, build, run, test
10 #
11 # version       If your port requires only some set of Python versions, you
12 #               can set this to [min]-[max] or min+ or -max or as an
13 #               explicit version or as a meta port version (eg. 3.3-3.4 for
14 #               [min]-[max], 2.7+ or -3.3 for min+ and -max, 2.7 for an
15 #               explicit version or 3 for a meta port version). Example:
16 #
17 #                       USES=python:2.7         # Only use Python 2.7
18 #                       USES=python:3.3+        # Use Python 3.3 or newer
19 #                       USES=python:3.3-3.4     # Use Python 3.3 or 3.4
20 #                       USES=python:-3.3        # Use any Python up to 3.3
21 #                       USES=python:2           # Use the Python 2 meta port
22 #                       USES=python             # Use the set default Python
23 #                                               # version
24 #
25 # build         Indicates that Python is needed at build time and adds
26 #               it to BUILD_DEPENDS.
27 # run           Indicates that Python is needed at run time and adds
28 #               it to RUN_DEPENDS.
29 # test          Indicates that Python is needed at test time and adds
30 #               it to TEST_DEPENDS.
31 #
32 # If build, run and test are omitted, Python will be added as BUILD_DEPENDS,
33 # RUN_DEPENDS and TEST_DEPENDS. PYTHON_NO_DEPENDS can be set to not add any
34 # dependencies.
35 #
36 # Variables, which can be set by a user:
37 #
38 # PYTHON_VERSION        - The chosen Python interpreter including the version,
39 #                         e.g. python2.7, python3.3, etc. This allows the user
40 #                         to override the currently chosen default version and
41 #                         to install the port for a specific Python version.
42 #                         It must not be set by a port.
43 #
44 # Variables, which can be set by the port:
45 #
46 # USE_PYTHON            - A list of additional features and functionality to
47 #                         enable. Supported features are:
48 #
49 #       concurrent      - Indicates that the port can be installed for
50 #                         different python versions at the same time. The port
51 #                         is supposed to use a unique prefix for certain
52 #                         directories using USES=uniquefiles:dirs (see the
53 #                         uniquefiles.mk Uses for details about the
54 #                         directories), if set to yes. Binaries receive an
55 #                         additional suffix, based on ${PYTHON_VER}.
56 #
57 #                         The values for the uniquefiles USES are set as
58 #                         follows:
59 #
60 #                               UNIQUE_PREFIX=  ${PYTHON_PKGNAMEPREFIX}
61 #                               UNIQUE_SUFFIX=  -${PYTHON_VER}
62 #
63 #                         If the port is installed for the current default
64 #                         python version, scripts and binaries in
65 #
66 #                               ${PREFIX}/bin
67 #                               ${PREFIX}/sbin
68 #                               ${PREFIX}/libexec
69 #
70 #                         are linked from the prefixed version to the
71 #                         prefix-less original name, e.g.
72 #                         bin/foo-2.7 --> bin/foo.
73 #
74 #       distutils       - Use distutils as do-configure, do-build and
75 #                         do-install targets.
76 #
77 #       autoplist       - Automatically generates the packaging list for a
78 #                         port that uses distutils when defined.
79 #                         requires: distutils
80 #
81 #       py3kplist       - Automatically generates Python 3.x compatible
82 #                         __pycache__ entries from a Python 2.x packaging list
83 #                         when defined. Use this for ports that do *not* use
84 #                         standard Python packaging mechanisms such as
85 #                         distutils, and support *both* Python 2.x and 3.x.
86 #                         Not needed, if USE_PYTHON=autoplist is set.
87 #
88 #       pythonprefix    - Says that the port installs in ${PYTHONBASE} instead
89 #                         of ${PREFIX}.
90 #
91 #       noegginfo       - Skip an egg-info entry from plist, if defined.
92 #
93 # PYTHON_CMD            - Python's command line file name, including the
94 #                         version number (used for dependencies).
95 #                         default: ${PYTHONBASE}/bin/${PYTHON_VERSION}
96 #
97 # PYSETUP               - Name of the setup script used by the distutils
98 #                         package.
99 #                         default: setup.py
100 #
101 # PYDISTUTILS_PKGNAME
102 #                       - Internal name in the distutils for egg-info.
103 #                         default: ${PORTNAME}
104 #
105 # PYDISTUTILS_PKGVERSION
106 #                       - Internal version in the distutils for egg-info.
107 #                         default: ${PORTVERSION}
108 #
109 # PYDISTUTILS_CONFIGURE_TARGET
110 #                       - Pass this command to distutils on configure stage.
111 #                         default: config
112 #
113 # PYDISTUTILS_BUILD_TARGET
114 #                       - Pass this command to distutils on build stage.
115 #                         default: build
116 #
117 # PYDISTUTILS_INSTALL_TARGET
118 #                       - Pass this command to distutils on install stage.
119 #                         default: install
120 #
121 # PYDISTUTILS_CONFIGUREARGS
122 #                       - Arguments to config with distutils.
123 #                         default: <empty>
124 #
125 # PYDISTUTILS_BUILDARGS
126 #                       - Arguments to build with distutils.
127 #                         default: <empty>
128 #
129 # PYDISTUTILS_INSTALLARGS
130 #                       - Arguments to install with distutils.
131 #                         default: -c -O1 --prefix=${PREFIX} --single-version-externally-managed --root=${STAGEDIR}
132 #
133 # PYDISTUTILS_EGGINFO
134 #                       - Canonical name for egg-info.
135 #                         default: ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info
136 #
137 # The following variables can be read by ports and must not be modified:
138 #
139 # PYTHONBASE            - The installation prefix of the chosen Python
140 #                         interpreter, e.g. /usr/local
141 #
142 # PYTHON_PORTVERSION
143 #                       - Version number suitable for ${PORTVERSION}.
144 #
145 # PYTHON_PORTSDIR       - The port directory of the chosen Python interpreter
146 #
147 # PYTHON_REL            - The release number of the chosen Python interpreter
148 #                         without dots, e.g. 2706, 3401, ...
149 #
150 # PYTHON_SUFFIX         - The major-minor release number of the chosen Python
151 #                         interpreter without dots, e.g. 27, 34, ...
152 #                         Used for prefixes and suffixes.
153 #
154 # PYTHON_MAJOR_VER      - The major release version of the chosen Python
155 #                         interpreter, e.g. 2, 3, ...
156 #
157 # PYTHON_VER            - The major-minor release version of the chosen Python
158 #                         interpreter, e.g. 2.7, 3.4, ...
159 #
160 # PYTHON_ABIVER         - Additional ABI flags set by the chosen Python
161 #                         interpreter, e.g. md
162 #
163 # PYTHON_INCLUDEDIR     - Location of the Python include files.
164 #                         default: ${PYTHONBASE}/include/${PYTHON_VERSION}
165 #
166 # PYTHON_LIBDIR         - Base of the python library tree
167 #                         default: ${PYTHONBASE}/lib/${PYTHON_VERSION}
168 #
169 # PYTHON_SITELIBDIR     - Location of the site-packages tree. Don't change,
170 #                         unless you know what you do.
171 #                         default: ${PYTHON_LIBDIR}/site-packages
172 #
173 # There are PREFIX-clean variants of the PYTHON_*DIR variables above.
174 # They are meant to be used by ports instead of the above variables, so the
175 # ports respect ${PREFIX} (unless USE_PYTHON=pythonprefix is specified).
176 #
177 # PYTHONPREFIX_INCLUDEDIR       default: ${PREFIX}/include/${PYTHON_VERSION}
178 # PYTHONPREFIX_LIBDIR           default: ${PREFIX}/lib/${PYTHON_VERSION}
179 # PYTHONPREFIX_SITELIBDIR       default: ${PYTHONPREFIX_LIBDIR}/site-packages
180 #
181 # PYTHON_PLATFORM       - Python's idea of the OS release.
182 #                         This is faked with ${OPSYS} and ${OSREL} until we
183 #                         find out how to delay defining a variable until
184 #                         after a certain target has been built.
185 #
186 # PYTHON_PKGNAMEPREFIX
187 #                       - Use this as a ${PKGNAMEPREFIX} to distinguish
188 #                         packages for different Python versions.
189 #                         default: py${PYTHON_SUFFIX}-
190 #
191 # Using USES=python.mk also will add some useful entries to PLIST_SUB:
192 #
193 #       PYTHON_INCLUDEDIR=${PYTHONPREFIX_INCLUDEDIR:S;${PREFIX}/;;}
194 #       PYTHON_LIBDIR=${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;}
195 #       PYTHON_PLATFORM=${PYTHON_PLATFORM}
196 #       PYTHON_SITELIBDIR=${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;}
197 #       PYTHON_VER=${PYTHON_VER}
198 #       PYTHON_VERSION=${PYTHON_VERSION}
199 #
200 #
201 # Deprecated variables, which exist for compatibility and will be removed
202 # soon:
203 #
204 # PYTHON_DEFAULT_VERSION
205 # PYTHON2_DEFAULT_VERSION
206 # PYTHON3_DEFAULT_VERSION
207 #                       - Deprecated, use PYTHON[2,3]_DEFAULT instead,
208 #                         see bsd.default-versions.mk
209 #
210 # PYTHON_PKGNAMESUFFIX
211 #                       - Deprecated, use PYTHON_PKGNAMEPREFIX instead
212 #                         default: -py${PYTHON_SUFFIX}
213 #
214 # PYDISTUTILS_INSTALLNOSINGLE
215 #                       - Deprecated without replacement
216 #
217 # MAINTAINER: python@FreeBSD.org
218
219 .if !defined(_INCLUDE_USES_PYTHON_MK)
220 _INCLUDE_USES_PYTHON_MK=        yes
221
222 # What Python version and what Python interpreters are currently supported?
223 # When adding a version, please keep the comment in
224 # Mk/bsd.default-versions.mk in sync.
225 _PYTHON_VERSIONS=               2.7 3.4 3.5 3.3 # preferred first
226 _PYTHON_PORTBRANCH=             2.7             # ${_PYTHON_VERSIONS:[1]}
227 _PYTHON_BASECMD=                ${LOCALBASE}/bin/python
228 _PYTHON_RELPORTDIR=             lang/python
229
230 # Make each individual feature available as _PYTHON_FEATURE_<FEATURENAME>
231 .for var in ${USE_PYTHON}
232 _PYTHON_FEATURE_${var:tu}=      yes
233 .endfor
234
235 # Make sure that no dependency or some other environment variable
236 # pollutes the build/run dependency detection
237 .undef _PYTHON_BUILD_DEP
238 .undef _PYTHON_RUN_DEP
239 .undef _PYTHON_TEST_DEP
240 _PYTHON_ARGS=           ${python_ARGS:S/,/ /g}
241 .if ${_PYTHON_ARGS:Mbuild}
242 _PYTHON_BUILD_DEP=      yes
243 _PYTHON_ARGS:=          ${_PYTHON_ARGS:Nbuild}
244 .endif
245 .if ${_PYTHON_ARGS:Mrun}
246 _PYTHON_RUN_DEP=        yes
247 _PYTHON_ARGS:=          ${_PYTHON_ARGS:Nrun}
248 .endif
249 .if ${_PYTHON_ARGS:Mtest}
250 _PYTHON_TEST_DEP=       yes
251 _PYTHON_ARGS:=          ${_PYTHON_ARGS:Ntest}
252 .endif
253
254 # The port does not specify a build, run or test dependency, assume all are
255 # required.
256 .if !defined(_PYTHON_BUILD_DEP) && !defined(_PYTHON_RUN_DEP) && \
257     !defined(_PYTHON_TEST_DEP) && !defined(PYTHON_NO_DEPENDS)
258 _PYTHON_BUILD_DEP=      yes
259 _PYTHON_RUN_DEP=        yes
260 _PYTHON_TEST_DEP=       yes
261 .endif
262
263 .if defined(PYTHON_DEFAULT_VERSION)
264 WARNING+=       "PYTHON_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python=${PYTHON_DEFAULT_VERSION:S/^python//} instead"
265 .endif
266 .if defined(PYTHON2_DEFAULT_VERSION)
267 WARNING+=       "PYTHON2_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python2=${PYTHON2_DEFAULT_VERSION:S/^python//} instead"
268 .endif
269 .if defined(PYTHON3_DEFAULT_VERSION)
270 WARNING+=       "PYTHON3_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python3=${PYTHON3_DEFAULT_VERSION:S/^python//} instead"
271 .endif
272
273 .if exists(${LOCALBASE}/bin/python)
274 .if !defined(_PYTHON_DEFAULT_VERSION)
275 _PYTHON_DEFAULT_VERSION!=       (${LOCALBASE}/bin/python -c \
276                 'import sys; print("%d.%d" % sys.version_info[:2])' 2> /dev/null \
277                 || ${ECHO_CMD} ${_PYTHON_PORTBRANCH}) | ${TAIL} -1
278 .endif
279 _EXPORTED_VARS+=        _PYTHON_DEFAULT_VERSION
280 .if defined(PYTHON_DEFAULT) && (${PYTHON_DEFAULT} != ${_PYTHON_DEFAULT_VERSION})
281 WARNING+=       "Your requested default python version ${PYTHON_DEFAULT} is different from the installed default python interpreter version ${_PYTHON_DEFAULT_VERSION}"
282 .endif
283 PYTHON_DEFAULT_VERSION=         python${_PYTHON_DEFAULT_VERSION}
284 .else
285 PYTHON_DEFAULT_VERSION=         python${PYTHON_DEFAULT}
286 .endif # exists(${LOCALBASE}/bin/python)
287
288 # Is only a meta-port version defined?
289 .if ${PYTHON_DEFAULT_VERSION} == "python2"
290 PYTHON2_DEFAULT_VERSION?=       python${PYTHON2_DEFAULT}
291 .elif ${PYTHON_DEFAULT_VERSION:R} == "python2"
292 PYTHON2_DEFAULT_VERSION=        ${PYTHON_DEFAULT_VERSION}
293 .else
294 PYTHON2_DEFAULT_VERSION?=       python${PYTHON2_DEFAULT}
295 .endif
296 .if ${PYTHON_DEFAULT_VERSION} == "python3"
297 PYTHON3_DEFAULT_VERSION?=       python${PYTHON3_DEFAULT}
298 .elif ${PYTHON_DEFAULT_VERSION:R} == "python3"
299  PYTHON3_DEFAULT_VERSION=       ${PYTHON_DEFAULT_VERSION}
300 .else
301 PYTHON3_DEFAULT_VERSION?=       python${PYTHON3_DEFAULT}
302 .endif
303
304 .if ${_PYTHON_ARGS} == "2"
305 _PYTHON_ARGS=           ${PYTHON2_DEFAULT_VERSION:S/^python//}
306 _WANTS_META_PORT=       2
307 .elif ${_PYTHON_ARGS} == "3"
308 _PYTHON_ARGS=           ${PYTHON3_DEFAULT_VERSION:S/^python//}
309 _WANTS_META_PORT=       3
310 .endif  # ${_PYTHON_ARGS} == "2"
311
312 .if defined(PYTHON_VERSION)
313 # A port/user requests a specific python version for its dependencies via
314 # DEPENDS_ARGS, since it requires the specific python version itself.
315 # Several things can happen now:
316 #       a) the dependency supports the requested version -> everything's fine
317 #       b) the dependency does not support the requested version
318 #               1) the dependency works in a way that the different python
319 #                  versions do not matter -> everything's fine
320 #               2) the dependency is likely to break due to the conflict
321 #                  nothing's fine
322 #
323 # b.2) needs to be resolved. Due to the complexity of how different pieces of
324 # software are built, we can't solve this automatically. Instead, let's assume
325 # that maintainers know what they are doing and assume PYTHON_VERSION to be a
326 # hint. Just warn maintainers, if the versions do not match
327 # (_PYTHON_VERSION_NONSUPPORTED).
328 _PYTHON_VERSION:=       ${PYTHON_VERSION:S/^python//}
329 .else
330 _PYTHON_VERSION:=       ${PYTHON_DEFAULT_VERSION:S/^python//}
331 .endif # defined(PYTHON_VERSION)
332
333 # Validate Python version whether it meets the version restriction.
334 _PYTHON_VERSION_CHECK:=         ${_PYTHON_ARGS:C/^([1-9]\.[0-9])$/\1-\1/}
335 _PYTHON_VERSION_MINIMUM_TMP:=   ${_PYTHON_VERSION_CHECK:C/([1-9]\.[0-9])[-+].*/\1/}
336 _PYTHON_VERSION_MINIMUM:=       ${_PYTHON_VERSION_MINIMUM_TMP:M[1-9].[0-9]}
337 _PYTHON_VERSION_MAXIMUM_TMP:=   ${_PYTHON_VERSION_CHECK:C/.*-([1-9]\.[0-9])/\1/}
338 _PYTHON_VERSION_MAXIMUM:=       ${_PYTHON_VERSION_MAXIMUM_TMP:M[1-9].[0-9]}
339
340 .undef _PYTHON_VERSION_NONSUPPORTED
341 .if !empty(_PYTHON_VERSION_MINIMUM) && (${_PYTHON_VERSION} < ${_PYTHON_VERSION_MINIMUM})
342 _PYTHON_VERSION_NONSUPPORTED=   ${_PYTHON_VERSION_MINIMUM} at least
343 .elif !empty(_PYTHON_VERSION_MAXIMUM) && (${_PYTHON_VERSION} > ${_PYTHON_VERSION_MAXIMUM})
344 _PYTHON_VERSION_NONSUPPORTED=   ${_PYTHON_VERSION_MAXIMUM} at most
345 .endif
346
347 # If we have an unsupported version of Python, try another.
348 .if defined(_PYTHON_VERSION_NONSUPPORTED)
349 .if defined(PYTHON_VERSION) || defined(PYTHON_CMD)
350 _PV:=           ${_PYTHON_VERSION}      # preserve the specified python version
351 WARNING+=       "needs Python ${_PYTHON_VERSION_NONSUPPORTED}. But a port depending on this one specified ${_PV}"
352 .endif # defined(PYTHON_VERSION) || defined(PYTHON_CMD)
353 .undef _PYTHON_VERSION
354 .for ver in ${PYTHON2_DEFAULT} ${PYTHON3_DEFAULT} ${_PYTHON_VERSIONS}
355 __VER=          ${ver}
356 .if !defined(_PYTHON_VERSION) && \
357         !(!empty(_PYTHON_VERSION_MINIMUM) && ( \
358                 ${__VER} < ${_PYTHON_VERSION_MINIMUM})) && \
359         !(!empty(_PYTHON_VERSION_MAXIMUM) && ( \
360                 ${__VER} > ${_PYTHON_VERSION_MAXIMUM}))
361 _PYTHON_VERSION=        ${ver}
362 .endif
363 .endfor
364 .if !defined(_PYTHON_VERSION)
365 IGNORE=         needs an unsupported version of Python
366 .endif
367 .endif  # defined(_PYTHON_VERSION_NONSUPPORTED)
368
369 # Pass PYTHON_VERSION down the dependency chain. This ensures that
370 # port A -> B -> C all will use the same python version and do not
371 # try to find a different one, if the passed version fits into
372 # the supported version range.
373 PYTHON_VERSION?=        python${_PYTHON_VERSION}
374 .if !defined(PYTHON_NO_DEPENDS)
375 DEPENDS_ARGS+=          PYTHON_VERSION=${PYTHON_VERSION}
376 .endif
377
378 # NOTE:
379 #
380 #  PYTHON_VERSION will hold whatever is passed down the dependency chain.
381 #  If a user runs `make PYTHON_VERSION=python3.3, PYTHON_VERSION will be
382 #  set to 'python3.3'. A port however may require a different version,
383 #  which is stored (above) in _PYTHON_VERSION.
384 #  Every python bit below hence should use python${_PYTHON_VERSION}, since
385 #  this is the value, the _port_ requires
386 #
387
388 # Got the correct python version, set some publicly accessible variables
389 PYTHON_VER=             ${_PYTHON_VERSION}
390 PYTHON_SUFFIX=          ${_PYTHON_VERSION:S/.//g}
391 PYTHON_MAJOR_VER=       ${PYTHON_VER:R}
392 PYTHON_REL=             # empty
393 PYTHON_ABIVER=          # empty
394 PYTHON_PORTSDIR=        ${_PYTHON_RELPORTDIR}${PYTHON_SUFFIX}
395 # Protect partial checkouts from Mk/Scripts/functions.sh:export_ports_env().
396 .if !defined(_PORTS_ENV_CHECK) || exists(${PORTSDIR}/${PYTHON_PORTSDIR})
397 .include "${PORTSDIR}/${PYTHON_PORTSDIR}/Makefile.version"
398 .endif
399 # Create a 4 integer version string, prefixing 0 to the last token if
400 # it's a single character. Only use the the first 3 tokens of
401 # PORTVERSION to support pre-release versions (rc3, alpha4, etc) of
402 # any Python port (lang/pythonXY)
403 PYTHON_REL=     ${PYTHON_PORTVERSION:C/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/:C/\.([0-9]+)$/.0\1/:C/\.0?([0-9][0-9])$/.\1/:S/.//g}
404
405 # Might be overridden by calling ports
406 PYTHON_CMD?=            ${_PYTHON_BASECMD}${_PYTHON_VERSION}
407 .if ${PYTHON_VER} != 2.7
408 .if exists(${PYTHON_CMD}-config)
409 PYTHON_ABIVER!=         ${PYTHON_CMD}-config --abiflags
410 .else
411 # Default ABI flags for lang/python3x ports
412 PYTHON_ABIVER=          m
413 .endif
414 .endif
415
416 .if !defined(PYTHONBASE)
417 PYTHONBASE!=    (${PYTHON_CMD} -c 'import sys; print(sys.prefix)' \
418                         2> /dev/null || ${ECHO_CMD} ${LOCALBASE}) | ${TAIL} -1
419 .endif
420 _EXPORTED_VARS+=        PYTHONBASE
421
422 PYTHON_INCLUDEDIR=      ${PYTHONBASE}/include/python${_PYTHON_VERSION}${PYTHON_ABIVER}
423 PYTHON_LIBDIR=          ${PYTHONBASE}/lib/python${_PYTHON_VERSION}
424 PYTHON_PLATFORM=        ${OPSYS:tl}${OSREL:C/\.[0-9.]*//}
425 PYTHON_SITELIBDIR=      ${PYTHON_LIBDIR}/site-packages
426 PYTHON_PKGNAMEPREFIX=   py${PYTHON_SUFFIX}-
427 PYTHON_PKGNAMESUFFIX=   -py${PYTHON_SUFFIX}
428
429 PYTHONPREFIX_INCLUDEDIR=        ${PYTHON_INCLUDEDIR:S;${PYTHONBASE};${PREFIX};}
430 PYTHONPREFIX_LIBDIR=            ${PYTHON_LIBDIR:S;${PYTHONBASE};${PREFIX};}
431 PYTHONPREFIX_SITELIBDIR=        ${PYTHON_SITELIBDIR:S;${PYTHONBASE};${PREFIX};}
432
433 # Used for recording the installed files.
434 _PYTHONPKGLIST= ${WRKDIR}/.PLIST.pymodtmp
435
436 # Ports bound to a certain python version SHOULD
437 # - use the PYTHON_PKGNAMEPREFIX
438 # - use directories using the PYTHON_PKGNAMEPREFIX
439 # - install binaries using the required PYTHON_VER, with
440 #   the default python version creating a symlink to the original binary
441 #   name (for staging-aware ports).
442 #
443 # What makes a port 'bound' to a certain python version?
444 # - it installs data into PYTHON_SITELIBDIR, PYTHON_INCLUDEDIR, ...
445 # - it links against libpython*.so
446 # - it uses USE_PYTHON=distutils
447 #
448
449 .if defined(_PYTHON_FEATURE_CONCURRENT)
450 _USES_POST+=            uniquefiles:dirs
451 .if ${PYTHON_VERSION} == ${PYTHON_DEFAULT_VERSION}
452 UNIQUE_DEFAULT_LINKS=   yes
453 .else
454 UNIQUE_DEFAULT_LINKS=   no
455 .endif
456 UNIQUE_PREFIX=          ${PYTHON_PKGNAMEPREFIX}
457 UNIQUE_SUFFIX=          -${PYTHON_VER}
458
459 .if defined(_PYTHON_FEATURE_AUTOPLIST)
460 UNIQUE_FIND_SUFFIX_FILES=       \
461         ${SED} -e 's|^${PREFIX}/||' ${_PYTHONPKGLIST} ${TMPPLIST} | \
462         ${GREP} -e '^bin/.*$$\|^sbin/.*$$\|^libexec/.*$$'
463 .else
464 UNIQUE_FIND_SUFFIX_FILES=       \
465         ${GREP} -he '^bin/.*$$\|^sbin/.*$$\|^libexec/.*$$' ${TMPPLIST} 2>/dev/null
466 .endif
467 .endif # defined(_PYTHON_FEATURE_CONCURRENT)
468
469 _CURRENTPORT:=  ${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
470 .if defined(_PYTHON_FEATURE_DISTUTILS) && \
471         ${_CURRENTPORT:S/${PYTHON_SUFFIX}$//} != ${PYTHON_PKGNAMEPREFIX}setuptools
472 BUILD_DEPENDS+=         ${PYTHON_PKGNAMEPREFIX}setuptools${PYTHON_SUFFIX}>0:devel/py-setuptools${PYTHON_SUFFIX}
473 RUN_DEPENDS+=           ${PYTHON_PKGNAMEPREFIX}setuptools${PYTHON_SUFFIX}>0:devel/py-setuptools${PYTHON_SUFFIX}
474 .endif
475
476 # distutils support
477 PYSETUP?=               setup.py
478 PYDISTUTILS_SETUP?=     -c \
479         "import sys; import setuptools; \
480         __file__='${PYSETUP}'; sys.argv[0]='${PYSETUP}'; \
481         exec(compile(open(__file__, 'rb').read().replace(b'\\r\\n', b'\\n'), __file__, 'exec'))"
482 PYDISTUTILS_CONFIGUREARGS?=     # empty
483 PYDISTUTILS_BUILDARGS?=         # empty
484 PYDISTUTILS_INSTALLARGS?=       -c -O1 --prefix=${PREFIX}
485 .if defined(_PYTHON_FEATURE_DISTUTILS)
486 . if !defined(PYDISTUTILS_INSTALLNOSINGLE)
487 PYDISTUTILS_INSTALLARGS+=       --single-version-externally-managed
488 . endif
489 PYDISTUTILS_INSTALLARGS+=       --root=${STAGEDIR}
490 .endif
491 PYDISTUTILS_INSTALLARGS:=       --record ${_PYTHONPKGLIST} \
492                 ${PYDISTUTILS_INSTALLARGS}
493
494 PYDISTUTILS_PKGNAME?=   ${PORTNAME}
495 PYDISTUTILS_PKGVERSION?=${PORTVERSION}
496 PYDISTUTILS_EGGINFO?=   ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info
497 PYDISTUTILS_EGGINFODIR?=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
498
499 .if !defined(_PYTHON_FEATURE_NOEGGINFO) && \
500         !defined(_PYTHON_FEATURE_AUTOPLIST) && \
501         defined(_PYTHON_FEATURE_DISTUTILS) && \
502         defined(PYTHON_REL)
503 _USES_stage+=   933:add-plist-egginfo
504 add-plist-egginfo:
505 . for egginfo in ${PYDISTUTILS_EGGINFO}
506         if [ -d "${PYDISTUTILS_EGGINFODIR}/${egginfo}" ]; then \
507                 ${LS} ${PYDISTUTILS_EGGINFODIR}/${egginfo} | while read f; do \
508                         ${ECHO_CMD} ${PYDISTUTILS_EGGINFODIR:S;^${STAGEDIR}${PREFIX}/;;}/${egginfo}/$${f} >> ${TMPPLIST}; \
509                 done; \
510         fi;
511 . endfor
512 .endif
513
514 .if defined(_PYTHON_FEATURE_AUTOPLIST) && defined(_PYTHON_FEATURE_DISTUTILS)
515 _RELSITELIBDIR= ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;}
516 _RELLIBDIR=             ${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;}
517
518 _USES_stage+=   934:add-plist-pymod
519 add-plist-pymod:
520         @${SED} -e 's|^${STAGEDIR}${PREFIX}/||' \
521                 -e 's|^${PREFIX}/||' \
522                 -e 's|^\(man/.*man[0-9]\)/\(.*\.[0-9]\)$$|\1/\2.gz|' \
523                 -e 's|[[:alnum:]|[:space:]]*/\.\./*||g; s|/\./|/|g' \
524                 ${_PYTHONPKGLIST} | ${SORT} >> ${TMPPLIST}
525
526 .else
527 .if ${PYTHON_REL} >= 3200 && defined(_PYTHON_FEATURE_PY3KPLIST)
528 # When Python version is 3.2+ we rewrite all the filenames
529 # of TMPPLIST that end with .py[co], so that they conform
530 # to PEP 3147 (see http://www.python.org/dev/peps/pep-3147/)
531 PYMAGICTAG=             ${PYTHON_CMD} -c 'import imp; print(imp.get_tag())'
532 .if ${PYTHON_REL} < 3500
533 PYOEXTENSION=   pyo
534 .else
535 PYOEXTENSION=   opt-1.pyc
536 .endif
537 _USES_stage+=   935:add-plist-python
538 add-plist-python:
539         @${AWK} '\
540                 /\.py[co]$$/ && !($$0 ~ "/" pc "/") {id = match($$0, /\/[^\/]+\.py[co]$$/); if (id != 0) {d = substr($$0, 1, RSTART - 1); dirs[d] = 1}; sub(/\.pyc$$/,  "." mt "&"); sub(/\.pyo$$/, "." mt "." pyo); sub(/[^\/]+\.py[co]$$/, pc "/&"); print; next} \
541                 /^@dirrm / {d = substr($$0, 8); if (d in dirs) {print $$0 "/" pc}; print $$0; next} \
542                 /^@dirrmtry / {d = substr($$0, 11); if (d in dirs) {print $$0 "/" pc}; print $$0; next} \
543                 {print} \
544                 ' \
545                 pc="__pycache__" mt="$$(${PYMAGICTAG})" pyo="${PYOEXTENSION}" \
546                 ${TMPPLIST} > ${TMPPLIST}.pyc_tmp
547         @${MV} ${TMPPLIST}.pyc_tmp ${TMPPLIST}
548 .endif # ${PYTHON_REL} >= 3200 && defined(_PYTHON_FEATURE_PY3KPLIST)
549 .endif # defined(_PYTHON_FEATURE_AUTOPLIST) && defined(_PYTHON_FEATURE_DISTUTILS)
550
551 # Fix for programs that build python from a GNU auto* environment
552 CONFIGURE_ENV+= PYTHON="${PYTHON_CMD}"
553
554 # By default CMake picks up the highest available version of Python package.
555 # Enforce the version required by the port or the default.
556 CMAKE_ARGS+=    -DPython_ADDITIONAL_VERSIONS=${PYTHON_VER}
557
558 # Python 3rd-party modules
559 PYGAME=         ${PYTHON_PKGNAMEPREFIX}game>0:devel/py-game
560 PYNUMERIC=      ${PYTHON_SITELIBDIR}/Numeric/Numeric.py:math/py-numeric
561 PYNUMPY=        ${PYTHON_SITELIBDIR}/numpy/core/numeric.py:math/py-numpy
562
563 # dependencies
564 .if defined(_PYTHON_BUILD_DEP)
565 BUILD_DEPENDS+= ${PYTHON_CMD}:${PYTHON_PORTSDIR}
566 .if defined(_WANTS_META_PORT)
567 BUILD_DEPENDS+= python${_WANTS_META_PORT}:${_PYTHON_RELPORTDIR}${_WANTS_META_PORT}
568 .endif
569 .endif
570 .if defined(_PYTHON_RUN_DEP)
571 RUN_DEPENDS+=   ${PYTHON_CMD}:${PYTHON_PORTSDIR}
572 .if defined(_WANTS_META_PORT)
573 RUN_DEPENDS+=   python${_WANTS_META_PORT}:${_PYTHON_RELPORTDIR}${_WANTS_META_PORT}
574 .endif
575 .endif
576 .if defined(_PYTHON_TEST_DEP)
577 TEST_DEPENDS+=  ${PYTHON_CMD}:${PYTHON_PORTSDIR}
578 .if defined(_WANTS_META_PORT)
579 TEST_DEPENDS+=  python${_WANTS_META_PORT}:${_PYTHON_RELPORTDIR}${_WANTS_META_PORT}
580 .endif
581 .endif
582
583 # set $PREFIX as Python's one
584 .if defined(_PYTHON_FEATURE_PYTHONPREFIX)
585 PREFIX=         ${PYTHONBASE}
586 .endif
587
588 # Substitutions for pkg-plist
589 # Use a short form of the PYTHONPREFIX_*DIR variables; we don't need the
590 # base directory in the plist file.
591 PLIST_SUB+=     PYTHON_INCLUDEDIR=${PYTHONPREFIX_INCLUDEDIR:S;${PREFIX}/;;} \
592                 PYTHON_LIBDIR=${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;} \
593                 PYTHON_PLATFORM=${PYTHON_PLATFORM} \
594                 PYTHON_SITELIBDIR=${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;} \
595                 PYTHON_VER=${PYTHON_VER} \
596                 PYTHON_VERSION=python${_PYTHON_VERSION}
597
598 _USES_POST+=    python
599 .endif # _INCLUDE_USES_PYTHON_MK
600
601 .if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_PYTHON_POST_MK)
602 _INCLUDE_USES_PYTHON_POST_MK=   yes
603
604 # py-distutils support
605 PYDISTUTILS_CONFIGURE_TARGET?=  config
606 PYDISTUTILS_BUILD_TARGET?=      build
607 PYDISTUTILS_INSTALL_TARGET?=    install
608
609 .if defined(_PYTHON_FEATURE_DISTUTILS)
610 LDSHARED?=      ${CC} -shared
611 MAKE_ENV+=      LDSHARED="${LDSHARED}" PYTHONDONTWRITEBYTECODE= PYTHONOPTIMIZE=
612
613 .if !target(do-configure) && !defined(HAS_CONFIGURE) && !defined(GNU_CONFIGURE)
614 do-configure:
615         @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_CONFIGURE_TARGET} ${PYDISTUTILS_CONFIGUREARGS})
616 .endif
617
618 .if !target(do-build)
619 do-build:
620         @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_BUILD_TARGET} ${PYDISTUTILS_BUILDARGS})
621 .endif
622
623 .if !target(do-install)
624 do-install:
625         @(cd ${INSTALL_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_INSTALL_TARGET} ${PYDISTUTILS_INSTALLARGS})
626 .endif
627 .endif # defined(_PYTHON_FEATURE_DISTUTILS)
628 .endif # defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_PYTHON_POST_MK)