1 # -*- tab-width: 4; -*-
7 .if !defined(_POSTMKINCLUDED) && !defined(Python_Pre_Include)
9 Python_Pre_Include= bsd.python.mk
10 Python_Include_MAINTAINER= python@FreeBSD.org
12 # This file contains some variable definitions that are supposed to
13 # make your life easier when dealing with ports related to the Python
14 # language. It's automatically included when USE_PYTHON is defined in
15 # the ports' makefile. If your port requires only some set of Python
16 # versions, you can define USE_PYTHON as [min]-[max] or min+ or -max
17 # or as an explicit version or as a meta port version (eg. 3.1-3.2
18 # for [min]-[max], 2.7+ or -3.2 for min+ and -max, 2.7 for an
19 # explicit version or 3 for a meta port version).
23 # PYTHONBASE - Python port's installation prefix.
24 # default: ${LOCALBASE}
26 # PYTHON_CMD - Python's command line file name, including the version
27 # number (used for dependencies).
28 # default: ${PYTHONBASE}/bin/${PYTHON_VERSION}
30 # PYTHON_DISTNAME - The ${DISTNAME} for your python version. Needed for
31 # extensions like bsddb, gdbm, sqlite3 and tkinter, which
32 # are built from sources contained in the Python
36 # - The ${MASTER_SITES} for your python version. (You must
37 # use this instead of ${MASTER_SITE_PYTHON} to support
40 # PYTHON_MASTER_SITE_SUBDIR
41 # - The ${MASTER_SITE_SUBDIR} for your python version.
43 # PYTHON_INCLUDEDIR - Location of the Python include files.
44 # default: ${PYTHONBASE}/include/${PYTHON_VERSION}
46 # PYTHON_LIBDIR - Base of the python library tree
47 # default: ${PYTHONBASE}/lib/${PYTHON_VERSION}
49 # PYTHON_PKGNAMEPREFIX
50 # - Use this as a ${PKGNAMEPREFIX} to distinguish
51 # packages for different Python versions.
52 # default: py${PYTHON_SUFFIX}-
54 # PYTHON_PKGNAMESUFFIX
55 # - If your port's name is more popular without `py-'
56 # prefix, use this as a ${PKGNAMESUFFIX} alternatively.
57 # default: -py${PYTHON_SUFFIX}
59 # PYTHON_PLATFORM - Python's idea of the OS release.
60 # XXX This is faked with ${OPSYS} and ${OSREL} until I
61 # find out how to delay defining a variable until after
62 # a certain target has been built.
64 # PYTHON_PORTSDIR - The source of your binary's port. Needed for the
68 # - Version number suitable for ${PORTVERSION}.
70 # PYTHON_REL - Version number in numerical format, to ease
71 # comparison in makefiles
73 # PYTHON_SITELIBDIR - Location of the site-packages tree. Don't change,
74 # unless you know what you do.
75 # default: ${PYTHON_LIBDIR}/site-packages
77 # PYTHON_SUFFIX - Yet another short version number, primarily intended
78 # for ${PYTHON_PKGNAMEPREFIX}.
80 # PYTHON_VERSION - Version of the python binary in your ${PATH}, in the
81 # format "python2.0". Set this in your makefile in case you
82 # want to build extensions with an older binary.
83 # default: depends on the version of your python binary
85 # PYTHON_VER - Version of the python binary in your ${PATH}, in the
88 # PYTHON_DEFAULT_VERSION
89 # - Version of the default python binary in your ${PATH}, in
90 # the format "python2.7".
92 # PYTHON2_DEFAULT_VERSION
93 # - Version of the default python2 binary in your ${PATH}, in
94 # the format "python2.7".
96 # PYTHON3_DEFAULT_VERSION
97 # - Version of the default python3 binary in your ${PATH}, in
98 # the format "python3.2".
100 # PYTHON_MAJOR_VER - Python version major number. 2 for python-2.x,
101 # 3 for python-3.x and so on.
103 # PYTHON_WRKSRC - The ${WRKSRC} for your python version. Needed for
104 # extensions like Tkinter, py-gdbm and py-expat, which
105 # are built from sources contained in the Python
108 # There are PREFIX-clean variants of the PYTHON_*DIR variables above.
109 # They are meant to be used in the installation targets.
111 # PYTHONPREFIX_INCLUDEDIR default: ${PREFIX}/include/${PYTHON_VERSION}
112 # PYTHONPREFIX_LIBDIR default: ${PREFIX}/lib/${PYTHON_VERSION}
113 # PYTHONPREFIX_SITELIBDIR default: ${PYTHONPREFIX_LIBDIR}/site-packages
115 # PYGAME - Dependency line for the Pygame library.
117 # PYNUMERIC - Dependency line for the numeric extension.
119 # PYNUMPY - Dependency line for the new numeric extension.
120 # py-numpy, Py-Numeric is deprecated.
122 # PYXML - Dependency line for the XML extension. As of Python-2.0,
123 # this extension is in the base distribution.
125 # USE_PYTHON_PREFIX - Says that the port installs in ${PYTHONBASE}.
127 # USE_PYDISTUTILS - Use distutils as do-configure, do-build and do-install
130 # PYSETUP - Name of the setup script used by the distutils package.
133 # PYDISTUTILS_AUTOPLIST
134 # - Automatically generates the packaging list for a port that uses
135 # distutils or setuptools (easy_install) when defined.
136 # requires: USE_PYDISTUTILS
138 # PYTHON_PY3K_PLIST_HACK
139 # - Automatically generates Python 3.x compatible __pycache__ entries
140 # from a Python 2.x packaging list when defined. Use this for ports that
141 # do *not* use standard Python packaging mechanisms such as distutils
142 # or setuptools, and support *both* Python 2.x and 3.x. Not needed when
143 # PYDISTUTILS_AUTOPLIST is defined.
145 # PYDISTUTILS_PKGNAME
146 # - Internal name in the distutils for egg-info.
147 # default: ${PORTNAME}
149 # PYDISTUTILS_PKGVERSION
150 # - Internal version in the distutils for egg-info.
151 # default: ${PORTVERSION}
153 # PYDISTUTILS_CONFIGURE_TARGET
154 # - Pass this command to distutils on configure stage.
157 # PYDISTUTILS_BUILD_TARGET
158 # - Pass this command to distutils on build stage.
161 # PYDISTUTILS_INSTALL_TARGET
162 # - Pass this command to distutils on install stage.
165 # PYDISTUTILS_CONFIGUREARGS
166 # - Arguments to config with distutils.
169 # PYDISTUTILS_BUILDARGS
170 # - Arguments to build with distutils.
173 # PYDISTUTILS_INSTALLARGS
174 # - Arguments to install with distutils.
175 # default: -c -O1 --prefix=${PREFIX}
177 # PYDISTUTILS_EGGINFO
178 # - Canonical name for egg-info.
179 # default: ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info
181 # PYDISTUTILS_NOEGGINFO
182 # - Skip an egg-info entry from plist when defined.
185 # - Canonical directory name for easy_install egg packages.
186 # default: ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}${PYEASYINSTALL_OSARCH}.egg
188 # PYEASYINSTALL_OSARCH
189 # - Platform identifier for easy_install.
190 # default: -${OPSYS:tl}-${OSVERSION:C/([0-9]*)[0-9]{5}/\1/}-${ARCH}
191 # if PYEASYINSTALL_ARCHDEP is defined.
193 # PYEASYINSTALL_CMD - Full file path to easy_install command.
194 # default: ${LOCALBASE}/bin/easy_install-${PYTHON_VER}
196 _PYTHON_PORTBRANCH= 2.7
197 _PYTHON_ALLBRANCHES= 2.7 3.4 3.3 3.2 3.1 # preferred first
199 # Determine version number of Python to use
200 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
202 .if defined(PYTHON_DEFAULT_VERSION)
203 WARNING+= "PYTHON_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python=${PYTHON_DEFAULT_VERSION:S/^python//} instead"
205 .if defined(PYTHON2_DEFAULT_VERSION)
206 WARNING+= "PYTHON2_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python2=${PYTHON2_DEFAULT_VERSION:S/^python//} instead"
208 .if defined(PYTHON3_DEFAULT_VERSION)
209 WARNING+= "PYTHON3_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python3=${PYTHON3_DEFAULT_VERSION:S/^python//} instead"
212 .if exists(${LOCALBASE}/bin/python)
213 _PYTHON_DEFAULT_VERSION!= (${LOCALBASE}/bin/python -c \
214 'import sys; print(sys.version[:3])' 2> /dev/null \
215 || ${ECHO_CMD} ${_PYTHON_PORTBRANCH}) | ${TAIL} -1
216 .if defined(PYTHON_DEFAULT) && (${PYTHON_DEFAULT} != ${_PYTHON_DEFAULT_VERSION})
217 WARNING+= "Your requested default python version ${PYTHON_DEFAULT} is different from the installed default python interpreter version ${_PYTHON_DEFAULT_VERSION}"
219 PYTHON_DEFAULT_VERSION= python${_PYTHON_DEFAULT_VERSION}
221 PYTHON_DEFAULT_VERSION= python${PYTHON_DEFAULT}
222 .endif # exists(${LOCALBASE}/bin/python)
224 # Is only a meta-port version defined?
225 .if ${PYTHON_DEFAULT_VERSION} == "python2"
226 PYTHON2_DEFAULT_VERSION?= python${PYTHON2_DEFAULT}
227 .elif ${PYTHON_DEFAULT_VERSION:R} == "python2"
228 PYTHON2_DEFAULT_VERSION= ${PYTHON_DEFAULT_VERSION}
230 PYTHON2_DEFAULT_VERSION?= python${PYTHON2_DEFAULT}
233 .if ${PYTHON_DEFAULT_VERSION} == "python3"
234 PYTHON3_DEFAULT_VERSION?= python${PYTHON3_DEFAULT}
235 .elif ${PYTHON_DEFAULT_VERSION:R} == "python3"
236 PYTHON3_DEFAULT_VERSION= ${PYTHON_DEFAULT_VERSION}
238 PYTHON3_DEFAULT_VERSION?= python${PYTHON3_DEFAULT}
241 .if defined(PYTHON_VERSION)
242 _PYTHON_VERSION:= ${PYTHON_VERSION:S/^python//}
243 _PYTHON_CMD= ${LOCALBASE}/bin/${PYTHON_VERSION}
245 _PYTHON_VERSION:= ${PYTHON_DEFAULT_VERSION:S/^python//}
246 _PYTHON_CMD= ${LOCALBASE}/bin/${PYTHON_DEFAULT_VERSION}
249 .if !defined(USE_PYTHON)
250 .if defined(USE_PYTHON_BUILD)
251 USE_PYTHON= ${USE_PYTHON_BUILD}
252 .elif defined(USE_PYTHON_RUN)
253 USE_PYTHON= ${USE_PYTHON_RUN}
256 .endif # defined(USE_PYTHON_BUILD)
258 USE_PYTHON_BUILD= yes
260 .endif # !defined(USE_PYTHON)
262 .if ${USE_PYTHON} == "2"
263 USE_PYTHON= ${PYTHON2_DEFAULT_VERSION:S/^python//}
265 .elif ${USE_PYTHON} == "3"
266 USE_PYTHON= ${PYTHON3_DEFAULT_VERSION:S/^python//}
268 .endif # ${USE_PYTHON} == "2"
270 # Validate Python version whether it meets USE_PYTHON version restriction.
271 _PYTHON_VERSION_CHECK:= ${USE_PYTHON:C/^([1-9]\.[0-9])$/\1-\1/}
272 _PYTHON_VERSION_MINIMUM_TMP:= ${_PYTHON_VERSION_CHECK:C/([1-9]\.[0-9])[-+].*/\1/}
273 _PYTHON_VERSION_MINIMUM:= ${_PYTHON_VERSION_MINIMUM_TMP:M[1-9].[0-9]}
274 _PYTHON_VERSION_MAXIMUM_TMP:= ${_PYTHON_VERSION_CHECK:C/.*-([1-9]\.[0-9])/\1/}
275 _PYTHON_VERSION_MAXIMUM:= ${_PYTHON_VERSION_MAXIMUM_TMP:M[1-9].[0-9]}
277 .if !empty(_PYTHON_VERSION_MINIMUM) && ( \
278 ${_PYTHON_VERSION} < ${_PYTHON_VERSION_MINIMUM})
279 _PYTHON_VERSION_NONSUPPORTED= ${_PYTHON_VERSION_MINIMUM} at least
280 .elif !empty(_PYTHON_VERSION_MAXIMUM) && ( \
281 ${_PYTHON_VERSION} > ${_PYTHON_VERSION_MAXIMUM})
282 _PYTHON_VERSION_NONSUPPORTED= ${_PYTHON_VERSION_MAXIMUM} at most
285 # If we have an unsupported version of Python, try another.
286 .if defined(_PYTHON_VERSION_NONSUPPORTED)
287 .if defined(PYTHON_VERSION) || defined(PYTHON_CMD)
288 IGNORE= needs Python ${_PYTHON_VERSION_NONSUPPORTED}.\
289 But you specified ${_PYTHON_VERSION}
291 .undef _PYTHON_VERSION
292 .for ver in ${_PYTHON_ALLBRANCHES}
294 .if !defined(_PYTHON_VERSION) && \
295 !(!empty(_PYTHON_VERSION_MINIMUM) && ( \
296 ${__VER} < ${_PYTHON_VERSION_MINIMUM})) && \
297 !(!empty(_PYTHON_VERSION_MAXIMUM) && ( \
298 ${__VER} > ${_PYTHON_VERSION_MAXIMUM}))
299 _PYTHON_VERSION= ${ver}
300 _PYTHON_CMD= ${LOCALBASE}/bin/python${ver}
303 .if !defined(_PYTHON_VERSION)
304 IGNORE= needs an unsupported version of Python
305 _PYTHON_VERSION= ${_PYTHON_PORTBRANCH} # just to avoid version sanity checking.
307 .endif # defined(PYTHON_VERSION) || defined(PYTHON_CMD)
308 .endif # defined(_PYTHON_VERSION_NONSUPPORTED)
310 PYTHON_VERSION?= python${_PYTHON_VERSION}
311 PYTHON_CMD?= ${_PYTHON_CMD}
312 .if !defined(PYTHONBASE)
313 PYTHONBASE!= (${PYTHON_CMD} -c 'import sys; print(sys.prefix)' \
314 2> /dev/null || ${ECHO_CMD} ${LOCALBASE}) | ${TAIL} -1
316 DEPENDS_ARGS+= PYTHON_VERSION=${PYTHON_VERSION}
318 # We can only use the cached version if we are using the default python version. Otherwise it
319 # should point to some other version we have installed, according to the port USE_PYTHON
321 .if !defined(PYTHON_DEFAULT_PORTVERSION) || (${PYTHON_VERSION} != ${PYTHON_DEFAULT_VERSION})
322 .if exists(${PYTHON_CMD})
323 _PYTHON_PORTVERSION!= (${PYTHON_CMD} -c 'import sys; \
324 print(sys.version.split()[0].replace("b",".b"))' 2> /dev/null) | ${TAIL} -1
326 .if !defined(PYTHON_NO_DEPENDS) && !empty(_PYTHON_PORTVERSION)
327 PYTHON_PORTVERSION= ${_PYTHON_PORTVERSION}
329 .elif defined(PYTHON_DEFAULT_PORTVERSION)
330 PYTHON_PORTVERSION= ${PYTHON_DEFAULT_PORTVERSION}
333 # Propagate the chosen python version to submakes.
334 .MAKEFLAGS: PYTHON_VERSION=python${_PYTHON_VERSION}
337 .if ${PYTHON_VERSION} == "python3.4"
338 PYTHON_PORTVERSION?= 3.4.0
339 PYTHON_PORTSDIR= ${PORTSDIR}/lang/python34
343 .if exists(${PYTHON_CMD}-config) && ${PORTNAME} != python34
344 PYTHON_ABIVER!= ${PYTHON_CMD}-config --abiflags
348 .elif ${PYTHON_VERSION} == "python3.3"
349 PYTHON_PORTVERSION?= 3.3.5
350 PYTHON_PORTSDIR= ${PORTSDIR}/lang/python33
354 .if exists(${PYTHON_CMD}-config) && defined(PORTNAME) && ${PORTNAME} != python33
355 PYTHON_ABIVER!= ${PYTHON_CMD}-config --abiflags
359 .elif ${PYTHON_VERSION} == "python3.2"
360 PYTHON_PORTVERSION?= 3.2.5
361 PYTHON_PORTSDIR= ${PORTSDIR}/lang/python32
365 .if exists(${PYTHON_CMD}-config) && defined(PORTNAME) && ${PORTNAME} != python32
366 PYTHON_ABIVER!= ${PYTHON_CMD}-config --abiflags
370 .elif ${PYTHON_VERSION} == "python3.1"
371 PYTHON_PORTVERSION?= 3.1.5
372 PYTHON_PORTSDIR= ${PORTSDIR}/lang/python31
378 .elif ${PYTHON_VERSION} == "python2.7"
379 PYTHON_PORTVERSION?= 2.7.6
380 PYTHON_PORTSDIR= ${PORTSDIR}/lang/python27
385 # Python versions in development
386 .elif defined(FORCE_PYTHON_VERSION)
387 PYTHON_PORTSDIR= # empty
388 PYTHON_NO_DEPENDS= YES
389 PYTHON_REL!= ${PYTHON_CMD} -c 'import sys; h = "%x" % sys.hexversion; \
390 print(h[0]+h[2]+h[4])'
391 PYTHON_SUFFIX!= ${PYTHON_CMD} -c 'import sys; h = "%x" % sys.hexversion; \
393 PYTHON_VER!= ${PYTHON_CMD} -c 'import sys; print(sys.version[:3])'
397 @${ECHO} "Makefile error: bad value for PYTHON_VERSION: ${PYTHON_VERSION}."
398 @${ECHO} "Legal values are:"
399 @${ECHO} " python2.7 (default)"
400 @${ECHO} " python3.1"
401 @${ECHO} " python3.2"
402 @${ECHO} " python3.3"
403 @${ECHO} " python3.4"
407 PYTHON_MAJOR_VER= ${PYTHON_VER:R}
409 PYTHON_MASTER_SITES= ${MASTER_SITE_PYTHON}
410 PYTHON_MASTER_SITE_SUBDIR= ftp/python/${PYTHON_PORTVERSION:C/rc[0-9]//}
411 PYTHON_DISTNAME= Python-${PYTHON_PORTVERSION:S/.rc/rc/}
412 PYTHON_WRKSRC= ${WRKDIR}/Python-${PYTHON_PORTVERSION:S/.rc/rc/}
414 PYTHON_ABIVER?= # empty
415 PYTHON_INCLUDEDIR= ${PYTHONBASE}/include/${PYTHON_VERSION}${PYTHON_ABIVER}
416 PYTHON_LIBDIR= ${PYTHONBASE}/lib/${PYTHON_VERSION}
417 PYTHON_PKGNAMEPREFIX= py${PYTHON_SUFFIX}-
418 PYTHON_PKGNAMESUFFIX= -py${PYTHON_SUFFIX}
419 PYTHON_PLATFORM= ${OPSYS:tl}${OSREL:C/\.[0-9.]*//}
420 PYTHON_SITELIBDIR= ${PYTHON_LIBDIR}/site-packages
422 PYTHONPREFIX_INCLUDEDIR= ${PYTHON_INCLUDEDIR:S;${PYTHONBASE};${PREFIX};}
423 PYTHONPREFIX_LIBDIR= ${PYTHON_LIBDIR:S;${PYTHONBASE};${PREFIX};}
424 PYTHONPREFIX_SITELIBDIR= ${PYTHON_SITELIBDIR:S;${PYTHONBASE};${PREFIX};}
426 _CURRENTPORT:= ${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
427 .if defined(USE_PYDISTUTILS) && ${_CURRENTPORT:S/${PYTHON_SUFFIX}$//} != ${PYTHON_PKGNAMEPREFIX}setuptools
428 BUILD_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}setuptools${PYTHON_SUFFIX}>0:${PORTSDIR}/devel/py-setuptools${PYTHON_SUFFIX}
429 RUN_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}setuptools${PYTHON_SUFFIX}>0:${PORTSDIR}/devel/py-setuptools${PYTHON_SUFFIX}
433 .if defined(USE_PYDISTUTILS) && ${USE_PYDISTUTILS} == "easy_install"
435 PYDISTUTILS_BUILD_TARGET?= bdist_egg
436 PYDISTUTILS_INSTALL_TARGET?= easy_install
437 PYDISTUTILS_INSTALLARGS?= -O 1 -N -S ${PYTHON_SITELIBDIR} \
438 -d ${PYEASYINSTALL_SITELIBDIR} \
439 -s ${PYEASYINSTALL_BINDIR} \
440 ${WRKSRC}/dist/${PYEASYINSTALL_EGG}
441 .if !defined(NO_STAGE)
442 MAKE_ENV+= PYTHONUSERBASE=${STAGEDIR}${PYTHONBASE}
443 PYDISTUTILS_INSTALLARGS:= -m -q --user ${PYDISTUTILS_INSTALLARGS}
446 .if ${PREFIX} != ${LOCALBASE} || !defined(NO_STAGE)
447 MAKE_ENV+= PYTHONPATH=${PYEASYINSTALL_SITELIBDIR}
450 .if defined(PYEASYINSTALL_ARCHDEP)
451 PYEASYINSTALL_OSARCH?= -${OPSYS:tl}-${OSVERSION:C/([0-9]*)[0-9]{5}/\1/}-${ARCH}
452 MAKE_ENV+= _PYTHON_HOST_PLATFORM=${PYEASYINSTALL_OSARCH}
454 PYEASYINSTALL_EGG?= ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}${PYEASYINSTALL_OSARCH}.egg
455 PYEASYINSTALL_CMD?= ${LOCALBASE}/bin/easy_install-${PYTHON_VER}
456 PYEASYINSTALL_BINDIR?= ${PREFIX}/bin
457 PYEASYINSTALL_SITELIBDIR?= ${PYTHONPREFIX_SITELIBDIR}
459 PLIST_SUB+= PYEASYINSTALL_EGG=${PYEASYINSTALL_EGG}
461 pre-install: pre-install-easyinstall
462 pre-install-easyinstall:
463 .if defined(NO_STAGE)
464 @${MKDIR} ${PYEASYINSTALL_SITELIBDIR}
466 @${MKDIR} ${STAGEDIR}${PYEASYINSTALL_SITELIBDIR}
469 add-plist-post: add-plist-easyinstall
470 add-plist-easyinstall:
471 @# Easiest to fake pyeasyinstall, or it complains about paths
472 @${ECHO_CMD} "@unexec ${REINPLACE_CMD} -i '' \
473 -e '\,^\./${PYEASYINSTALL_EGG}$$,d' \
474 ${PYEASYINSTALL_SITELIBDIR}/easy-install.pth" \
476 @${ECHO_CMD} "@exec ${PRINTF} '1a\n./${PYEASYINSTALL_EGG}\n.\nw\nq\n' | \
477 /bin/ed ${PYEASYINSTALL_SITELIBDIR}/easy-install.pth" \
480 .if !defined(NO_STAGE)
481 .if !target(stage-python-compileall)
482 stage-python-compileall:
483 (cd ${STAGEDIR}${PREFIX} && \
484 ${PYTHON_CMD} ${PYTHON_LIBDIR}/compileall.py \
485 -d ${PYTHONPREFIX_SITELIBDIR} -f ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;} && \
486 ${PYTHON_CMD} -O ${PYTHON_LIBDIR}/compileall.py \
487 -d ${PYTHONPREFIX_SITELIBDIR} -f ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;})
490 post-install: stage-python-compileall
493 .endif # defined(USE_PYDISTUTILS) && ${USE_PYDISTUTILS} == "easy_install"
497 PYDISTUTILS_SETUP?= -c "import setuptools; __file__='${PYSETUP}'; exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))"
498 PYDISTUTILS_CONFIGUREARGS?=
499 PYDISTUTILS_BUILDARGS?=
500 PYDISTUTILS_INSTALLARGS?= -c -O1 --prefix=${PREFIX}
501 .if defined(USE_PYDISTUTILS) && ${USE_PYDISTUTILS} != "easy_install"
502 . if !defined(PYDISTUTILS_INSTALLNOSINGLE)
503 PYDISTUTILS_INSTALLARGS+= --single-version-externally-managed
505 . if !defined(NO_STAGE)
506 PYDISTUTILS_INSTALLARGS+= --root=${STAGEDIR}
509 _PYTHONPKGLIST= ${WRKDIR}/.PLIST.pymodtmp
510 PYDISTUTILS_INSTALLARGS:= --record ${_PYTHONPKGLIST} \
511 ${PYDISTUTILS_INSTALLARGS}
513 PYDISTUTILS_PKGNAME?= ${PORTNAME}
514 PYDISTUTILS_PKGVERSION?=${PORTVERSION}
515 PYDISTUTILS_EGGINFO?= ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info
516 PYDISTUTILS_EGGINFODIR?=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
519 .if !defined(PYDISTUTILS_NOEGGINFO) && \
520 !defined(PYDISTUTILS_AUTOPLIST) && \
521 (defined(INSTALLS_EGGINFO) || \
522 (defined(USE_PYDISTUTILS) && \
523 ${USE_PYDISTUTILS} != "easy_install")) && \
525 . for egginfo in ${PYDISTUTILS_EGGINFO}
526 if [ -d "${PYDISTUTILS_EGGINFODIR}/${egginfo}" ]; then \
527 ${LS} ${PYDISTUTILS_EGGINFODIR}/${egginfo} | while read f; do \
528 ${ECHO_CMD} ${PYDISTUTILS_EGGINFODIR:S;^${STAGEDIR}${PYTHONBASE}/;;}/${egginfo}/$${f} >> ${TMPPLIST}; \
530 ${ECHO_CMD} "@unexec rmdir \"%D/${PYDISTUTILS_EGGINFODIR:S;${STAGEDIR}${PYTHONBASE}/;;}/${egginfo}\" 2>/dev/null || true" >> ${TMPPLIST}; \
537 .if defined(PYDISTUTILS_AUTOPLIST) && defined(USE_PYDISTUTILS)
538 _RELSITELIBDIR= ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;}
539 _RELLIBDIR= ${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;}
541 add-plist-post: add-plist-pymod
543 @{ ${ECHO_CMD} "#mtree"; ${CAT} ${MTREE_FILE}; } | ${TAR} tf - | \
544 ${SED} '/^\.$$/d' > ${WRKDIR}/.localmtree
545 @${ECHO_CMD} "${_RELSITELIBDIR}" >> ${WRKDIR}/.localmtree
546 @${ECHO_CMD} "${_RELLIBDIR}" >> ${WRKDIR}/.localmtree
547 @${SED} -e 's|^${STAGEDIR}${PREFIX}/||' \
548 -e 's|^${PREFIX}/||' \
549 -e 's|^\(man/man[0-9]\)/\(.*\.[0-9]\)$$|\1/\2${MANEXT}|' \
550 ${_PYTHONPKGLIST} | ${SORT} >> ${TMPPLIST}
551 @${SED} -e 's|^${STAGEDIR}${PREFIX}/\(.*\)/\(.*\)|\1|' \
552 -e 's|^${PREFIX}/\(.*\)/\(.*\)|\1|' ${_PYTHONPKGLIST} | \
553 ${AWK} '{ num = split($$0, a, "/"); res=""; \
554 for(i = 1; i <= num; ++i) { \
555 if (i == 1) res = a[i]; \
556 else res = res "/" a[i]; \
560 while read line; do \
561 ${GREP} -qw "^$${line}$$" ${WRKDIR}/.localmtree || { \
562 [ -n "$${line}" ] && \
563 ${ECHO_CMD} "@unexec rmdir \"%D/$${line}\" 2>/dev/null || true"; \
565 done | ${SORT} | uniq | ${SORT} -r >> ${TMPPLIST}
566 @${ECHO_CMD} "@unexec rmdir \"%D/${PYTHON_SITELIBDIR:S;${PYTHONBASE}/;;}\" 2>/dev/null || true" >> ${TMPPLIST}
567 @${ECHO_CMD} "@unexec rmdir \"%D/${PYTHON_LIBDIR:S;${PYTHONBASE}/;;}\" 2>/dev/null || true" >> ${TMPPLIST}
570 .if ${PYTHON_REL} >= 320 && defined(PYTHON_PY3K_PLIST_HACK)
571 # When Python version is 3.2+ we rewrite all the filenames
572 # of TMPPLIST that end with .py[co], so that they conform
573 # to PEP 3147 (see http://www.python.org/dev/peps/pep-3147/)
574 PYMAGICTAG= ${PYTHON_CMD} -c 'import imp; print(imp.get_tag())'
577 /\.py[co]$$/ && !($$0 ~ "/" pc "/") {id = match($$0, /\/[^\/]+\.py[co]$$/); if (id != 0) {d = substr($$0, 1, RSTART - 1); dirs[d] = 1}; sub(/\.py[co]$$/, "." mt "&"); sub(/[^\/]+\.py[co]$$/, pc "/&"); print; next} \
578 /^@dirrm / {d = substr($$0, 8); if (d in dirs) {print $$0 "/" pc}; print $$0; next} \
580 END {if (sp in dirs) {print "@dirrm " sp "/" pc}} \
582 pc="__pycache__" mt="$$(${PYMAGICTAG})" sp="${PYTHON_SITELIBDIR:S,${PYTHONBASE}/,,g}" \
583 ${TMPPLIST} > ${TMPPLIST}.pyc_tmp
584 @${MV} ${TMPPLIST}.pyc_tmp ${TMPPLIST}
585 .endif # ${PYTHON_REL} >= 320 && defined(PYTHON_PY3K_PLIST_HACK)
586 .endif # defined(PYDISTUTILS_AUTOPLIST) && defined(USE_PYDISTUTILS)
588 # Fix for programs that build python from a GNU auto* environment
589 CONFIGURE_ENV+= PYTHON="${PYTHON_CMD}"
591 # Python 3rd-party modules
592 PYGAME= ${PYTHON_PKGNAMEPREFIX}game>0:${PORTSDIR}/devel/py-game
593 PYNUMERIC= ${PYTHON_SITELIBDIR}/Numeric/Numeric.py:${PORTSDIR}/math/py-numeric
594 PYNUMPY= ${PYTHON_SITELIBDIR}/numpy/core/numeric.py:${PORTSDIR}/math/py-numpy
595 PYXML= ${PYTHON_SITELIBDIR}/_xmlplus/__init__.py:${PORTSDIR}/textproc/py-xml
598 PYTHON_NO_DEPENDS?= NO
600 .if ${PYTHON_NO_DEPENDS} == "NO"
601 .if defined(USE_PYTHON_BUILD)
602 BUILD_DEPENDS+= ${PYTHON_CMD}:${PYTHON_PORTSDIR}
603 .if defined(_WANTS_META_PORT)
604 BUILD_DEPENDS+= python${_WANTS_META_PORT}:${PORTSDIR}/lang/python${_WANTS_META_PORT}
607 .if defined(USE_PYTHON_RUN)
608 RUN_DEPENDS+= ${PYTHON_CMD}:${PYTHON_PORTSDIR}
609 .if defined(_WANTS_META_PORT)
610 RUN_DEPENDS+= python${_WANTS_META_PORT}:${PORTSDIR}/lang/python${_WANTS_META_PORT}
613 .endif # ${PYTHON_NO_DEPENDS} == "NO"
615 # set $PREFIX as Python's one
616 .if defined(USE_PYTHON_PREFIX)
617 PREFIX= ${PYTHONBASE}
620 # Substitutions for pkg-plist
621 # Use a short form of the PYTHONPREFIX_*DIR variables; we don't need the
622 # base directory in the plist file.
623 PLIST_SUB+= PYTHON_INCLUDEDIR=${PYTHONPREFIX_INCLUDEDIR:S;${PREFIX}/;;} \
624 PYTHON_LIBDIR=${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;} \
625 PYTHON_PLATFORM=${PYTHON_PLATFORM} \
626 PYTHON_SITELIBDIR=${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;} \
627 PYTHON_VERSION=${PYTHON_VERSION}
629 # XXX Hm, should I export some of the variables above to *_ENV?
632 # If multiple Python versions are installed and cmake is used, it might
633 # happen that a cmake-enabled port using find_package(PythonLibs) and
634 # find_package(PythonInterp) detects different Python versions.
635 # This in turn might cause it to link against version X while using the
636 # includes of version Y, leading to a broken port.
637 # Enforce a certain Python version by using PYTHON_VER for cmake.
639 CMAKE_ARGS+= -DPythonLibs_FIND_VERSION:STRING="${PYTHON_VER}" \
640 -DPythonInterp_FIND_VERSION:STRING="${PYTHON_VER}"
642 .endif # !defined(_POSTMKINCLUDED) && !defined(Python_Pre_Include)
644 .if defined(_POSTMKINCLUDED) && !defined(Python_Post_Include)
646 Python_Post_Include= bsd.python.mk
648 # py-distutils support
649 PYDISTUTILS_CONFIGURE_TARGET?= config
650 PYDISTUTILS_BUILD_TARGET?= build
651 PYDISTUTILS_INSTALL_TARGET?= install
653 .if defined(USE_PYDISTUTILS)
654 LDSHARED?= ${CC} -shared
655 MAKE_ENV+= LDSHARED="${LDSHARED}" PYTHONDONTWRITEBYTECODE= PYTHONOPTIMIZE=
657 .if !target(do-configure) && !defined(HAS_CONFIGURE) && !defined(GNU_CONFIGURE)
659 @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_CONFIGURE_TARGET} ${PYDISTUTILS_CONFIGUREARGS})
662 .if !target(do-build)
664 @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_BUILD_TARGET} ${PYDISTUTILS_BUILDARGS})
667 .if !target(do-install)
669 @(cd ${INSTALL_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_INSTALL_TARGET} ${PYDISTUTILS_INSTALLARGS})
672 add-plist-post: add-plist-egginfo
674 .if defined(PYEASYINSTALL_ARCHDEP)
675 .if !target(easyinstall-setopt)
677 @(cd ${BUILD_WRKSRC}; \
678 ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYSETUP} setopt -c build -o build-platlib -s lib.${PYEASYINSTALL_OSARCH:S/^-//}; \
679 ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYSETUP} setopt -c build -o build-temp -s temp.${PYEASYINSTALL_OSARCH:S/^-//}-${PYTHON_VER}; \
680 ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYSETUP} setopt -c bdist_egg -o plat-name -s ${PYEASYINSTALL_OSARCH:S/^-//}; \
681 ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYSETUP} setopt -c bdist -o plat-name -s ${PYEASYINSTALL_OSARCH:S/^-//})
682 .endif # !target(eayinstall-setopt)
684 pre-build: easyinstall-setopt
685 .endif # defined(PYEASYINSTALL_ARCHDEP)
686 .endif # defined(USE_PYDISTUTILS)
688 .endif # defined(_POSTMKINCLUDED) && !defined(Python_Post_Include)