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.
8 # Usage: USES=python or USES=python:args
9 # Valid ARGS: <version>, build, run, test
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:
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
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
29 # test Indicates that Python is needed at test time and adds
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
36 # Variables, which can be set by a user:
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.
44 # Variables, which can be set by the port:
46 # USE_PYTHON - A list of additional features and functionality to
47 # enable. Supported features are:
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}.
57 # The values for the uniquefiles USES are set as
60 # UNIQUE_PREFIX= ${PYTHON_PKGNAMEPREFIX}
61 # UNIQUE_SUFFIX= -${PYTHON_VER}
63 # If the port is installed for the current default
64 # python version, scripts and binaries in
70 # are linked from the prefixed version to the
71 # prefix-less original name, e.g.
72 # bin/foo-2.7 --> bin/foo.
74 # distutils - Use distutils as do-configure, do-build and
77 # autoplist - Automatically generates the packaging list for a
78 # port that uses distutils when defined.
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.
88 # pythonprefix - Says that the port installs in ${PYTHONBASE} instead
91 # noegginfo - Skip an egg-info entry from plist, if defined.
93 # PYTHON_CMD - Python's command line file name, including the
94 # version number (used for dependencies).
95 # default: ${PYTHONBASE}/bin/${PYTHON_VERSION}
97 # PYSETUP - Name of the setup script used by the distutils
101 # PYDISTUTILS_PKGNAME
102 # - Internal name in the distutils for egg-info.
103 # default: ${PORTNAME}
105 # PYDISTUTILS_PKGVERSION
106 # - Internal version in the distutils for egg-info.
107 # default: ${PORTVERSION}
109 # PYDISTUTILS_CONFIGURE_TARGET
110 # - Pass this command to distutils on configure stage.
113 # PYDISTUTILS_BUILD_TARGET
114 # - Pass this command to distutils on build stage.
117 # PYDISTUTILS_INSTALL_TARGET
118 # - Pass this command to distutils on install stage.
121 # PYDISTUTILS_CONFIGUREARGS
122 # - Arguments to config with distutils.
125 # PYDISTUTILS_BUILDARGS
126 # - Arguments to build with distutils.
129 # PYDISTUTILS_INSTALLARGS
130 # - Arguments to install with distutils.
131 # default: -c -O1 --prefix=${PREFIX} --single-version-externally-managed --root=${STAGEDIR}
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
137 # The following variables can be read by ports and must not be modified:
139 # PYTHONBASE - The installation prefix of the chosen Python
140 # interpreter, e.g. /usr/local
143 # - Version number suitable for ${PORTVERSION}.
145 # PYTHON_PORTSDIR - The port directory of the chosen Python interpreter
147 # PYTHON_REL - The release number of the chosen Python interpreter
148 # without dots, e.g. 2706, 3401, ...
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.
154 # PYTHON_MAJOR_VER - The major release version of the chosen Python
155 # interpreter, e.g. 2, 3, ...
157 # PYTHON_VER - The major-minor release version of the chosen Python
158 # interpreter, e.g. 2.7, 3.4, ...
160 # PYTHON_ABIVER - Additional ABI flags set by the chosen Python
161 # interpreter, e.g. md
163 # PYTHON_INCLUDEDIR - Location of the Python include files.
164 # default: ${PYTHONBASE}/include/${PYTHON_VERSION}
166 # PYTHON_LIBDIR - Base of the python library tree
167 # default: ${PYTHONBASE}/lib/${PYTHON_VERSION}
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
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).
177 # PYTHONPREFIX_INCLUDEDIR default: ${PREFIX}/include/${PYTHON_VERSION}
178 # PYTHONPREFIX_LIBDIR default: ${PREFIX}/lib/${PYTHON_VERSION}
179 # PYTHONPREFIX_SITELIBDIR default: ${PYTHONPREFIX_LIBDIR}/site-packages
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.
186 # PYTHON_PKGNAMEPREFIX
187 # - Use this as a ${PKGNAMEPREFIX} to distinguish
188 # packages for different Python versions.
189 # default: py${PYTHON_SUFFIX}-
191 # Using USES=python.mk also will add some useful entries to PLIST_SUB:
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}
201 # Deprecated variables, which exist for compatibility and will be removed
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
210 # PYTHON_PKGNAMESUFFIX
211 # - Deprecated, use PYTHON_PKGNAMEPREFIX instead
212 # default: -py${PYTHON_SUFFIX}
214 # PYDISTUTILS_INSTALLNOSINGLE
215 # - Deprecated without replacement
217 # MAINTAINER: python@FreeBSD.org
219 .if !defined(_INCLUDE_USES_PYTHON_MK)
220 _INCLUDE_USES_PYTHON_MK= yes
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
230 # Make each individual feature available as _PYTHON_FEATURE_<FEATURENAME>
231 .for var in ${USE_PYTHON}
232 _PYTHON_FEATURE_${var:tu}= yes
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}
245 .if ${_PYTHON_ARGS:Mrun}
247 _PYTHON_ARGS:= ${_PYTHON_ARGS:Nrun}
249 .if ${_PYTHON_ARGS:Mtest}
250 _PYTHON_TEST_DEP= yes
251 _PYTHON_ARGS:= ${_PYTHON_ARGS:Ntest}
254 # The port does not specify a build, run or test dependency, assume all are
256 .if !defined(_PYTHON_BUILD_DEP) && !defined(_PYTHON_RUN_DEP) && \
257 !defined(_PYTHON_TEST_DEP) && !defined(PYTHON_NO_DEPENDS)
258 _PYTHON_BUILD_DEP= yes
260 _PYTHON_TEST_DEP= yes
263 .if defined(PYTHON_DEFAULT_VERSION)
264 WARNING+= "PYTHON_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python=${PYTHON_DEFAULT_VERSION:S/^python//} instead"
266 .if defined(PYTHON2_DEFAULT_VERSION)
267 WARNING+= "PYTHON2_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python2=${PYTHON2_DEFAULT_VERSION:S/^python//} instead"
269 .if defined(PYTHON3_DEFAULT_VERSION)
270 WARNING+= "PYTHON3_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python3=${PYTHON3_DEFAULT_VERSION:S/^python//} instead"
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
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}"
283 PYTHON_DEFAULT_VERSION= python${_PYTHON_DEFAULT_VERSION}
285 PYTHON_DEFAULT_VERSION= python${PYTHON_DEFAULT}
286 .endif # exists(${LOCALBASE}/bin/python)
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}
294 PYTHON2_DEFAULT_VERSION?= python${PYTHON2_DEFAULT}
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}
301 PYTHON3_DEFAULT_VERSION?= python${PYTHON3_DEFAULT}
304 .if ${_PYTHON_ARGS} == "2"
305 _PYTHON_ARGS= ${PYTHON2_DEFAULT_VERSION:S/^python//}
307 .elif ${_PYTHON_ARGS} == "3"
308 _PYTHON_ARGS= ${PYTHON3_DEFAULT_VERSION:S/^python//}
310 .endif # ${_PYTHON_ARGS} == "2"
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
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//}
330 _PYTHON_VERSION:= ${PYTHON_DEFAULT_VERSION:S/^python//}
331 .endif # defined(PYTHON_VERSION)
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]}
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
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}
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}
364 .if !defined(_PYTHON_VERSION)
365 IGNORE= needs an unsupported version of Python
367 .endif # defined(_PYTHON_VERSION_NONSUPPORTED)
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}
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
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}
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"
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}
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
411 # Default ABI flags for lang/python3x ports
416 .if !defined(PYTHONBASE)
417 PYTHONBASE!= (${PYTHON_CMD} -c 'import sys; print(sys.prefix)' \
418 2> /dev/null || ${ECHO_CMD} ${LOCALBASE}) | ${TAIL} -1
420 _EXPORTED_VARS+= PYTHONBASE
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}
429 PYTHONPREFIX_INCLUDEDIR= ${PYTHON_INCLUDEDIR:S;${PYTHONBASE};${PREFIX};}
430 PYTHONPREFIX_LIBDIR= ${PYTHON_LIBDIR:S;${PYTHONBASE};${PREFIX};}
431 PYTHONPREFIX_SITELIBDIR= ${PYTHON_SITELIBDIR:S;${PYTHONBASE};${PREFIX};}
433 # Used for recording the installed files.
434 _PYTHONPKGLIST= ${WRKDIR}/.PLIST.pymodtmp
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).
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
449 .if defined(_PYTHON_FEATURE_CONCURRENT)
450 _USES_POST+= uniquefiles:dirs
451 .if ${PYTHON_VERSION} == ${PYTHON_DEFAULT_VERSION}
452 UNIQUE_DEFAULT_LINKS= yes
454 UNIQUE_DEFAULT_LINKS= no
456 UNIQUE_PREFIX= ${PYTHON_PKGNAMEPREFIX}
457 UNIQUE_SUFFIX= -${PYTHON_VER}
459 .if defined(_PYTHON_FEATURE_AUTOPLIST)
460 UNIQUE_FIND_SUFFIX_FILES= \
461 ${SED} -e 's|^${PREFIX}/||' ${_PYTHONPKGLIST} ${TMPPLIST} | \
462 ${GREP} -e '^bin/.*$$\|^sbin/.*$$\|^libexec/.*$$'
464 UNIQUE_FIND_SUFFIX_FILES= \
465 ${GREP} -he '^bin/.*$$\|^sbin/.*$$\|^libexec/.*$$' ${TMPPLIST} 2>/dev/null
467 .endif # defined(_PYTHON_FEATURE_CONCURRENT)
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}
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
489 PYDISTUTILS_INSTALLARGS+= --root=${STAGEDIR}
491 PYDISTUTILS_INSTALLARGS:= --record ${_PYTHONPKGLIST} \
492 ${PYDISTUTILS_INSTALLARGS}
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}
499 .if !defined(_PYTHON_FEATURE_NOEGGINFO) && \
500 !defined(_PYTHON_FEATURE_AUTOPLIST) && \
501 defined(_PYTHON_FEATURE_DISTUTILS) && \
503 _USES_stage+= 933: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}; \
514 .if defined(_PYTHON_FEATURE_AUTOPLIST) && defined(_PYTHON_FEATURE_DISTUTILS)
515 _RELSITELIBDIR= ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;}
516 _RELLIBDIR= ${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;}
518 _USES_stage+= 934: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}
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
535 PYOEXTENSION= opt-1.pyc
537 _USES_stage+= 935:add-plist-python
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} \
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)
551 # Fix for programs that build python from a GNU auto* environment
552 CONFIGURE_ENV+= PYTHON="${PYTHON_CMD}"
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}
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
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}
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}
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}
583 # set $PREFIX as Python's one
584 .if defined(_PYTHON_FEATURE_PYTHONPREFIX)
585 PREFIX= ${PYTHONBASE}
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}
599 .endif # _INCLUDE_USES_PYTHON_MK
601 .if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_PYTHON_POST_MK)
602 _INCLUDE_USES_PYTHON_POST_MK= yes
604 # py-distutils support
605 PYDISTUTILS_CONFIGURE_TARGET?= config
606 PYDISTUTILS_BUILD_TARGET?= build
607 PYDISTUTILS_INSTALL_TARGET?= install
609 .if defined(_PYTHON_FEATURE_DISTUTILS)
610 LDSHARED?= ${CC} -shared
611 MAKE_ENV+= LDSHARED="${LDSHARED}" PYTHONDONTWRITEBYTECODE= PYTHONOPTIMIZE=
613 .if !target(do-configure) && !defined(HAS_CONFIGURE) && !defined(GNU_CONFIGURE)
615 @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_CONFIGURE_TARGET} ${PYDISTUTILS_CONFIGUREARGS})
618 .if !target(do-build)
620 @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_BUILD_TARGET} ${PYDISTUTILS_BUILDARGS})
623 .if !target(do-install)
625 @(cd ${INSTALL_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_INSTALL_TARGET} ${PYDISTUTILS_INSTALLARGS})
627 .endif # defined(_PYTHON_FEATURE_DISTUTILS)
628 .endif # defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_PYTHON_POST_MK)