Use openjdk 7 over openjdk 6
[dports.git] / Mk / bsd.python.mk
1 # -*- tab-width: 4; -*-
2 # ex: ts=4
3 #
4 # $FreeBSD$
5 #
6
7 .if !defined(_POSTMKINCLUDED) && !defined(Python_Pre_Include)
8
9 Python_Pre_Include=             bsd.python.mk
10 Python_Include_MAINTAINER=      python@FreeBSD.org
11
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).
20 #
21 # The variables:
22 #
23 # PYTHONBASE            - Python port's installation prefix.
24 #                                         default: ${LOCALBASE}
25 #
26 # PYTHON_CMD            - Python's command line file name, including the version
27 #                                         number (used for dependencies).
28 #                                         default: ${PYTHONBASE}/bin/${PYTHON_VERSION}
29 #
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
33 #                                         distribution.
34 #
35 # PYTHON_MASTER_SITES
36 #                                       - The ${MASTER_SITES} for your python version. (You must
37 #                                         use this instead of ${MASTER_SITE_PYTHON} to support
38 #                                         python-devel port.)
39 #
40 # PYTHON_MASTER_SITE_SUBDIR
41 #                                       - The ${MASTER_SITE_SUBDIR} for your python version.
42 #
43 # PYTHON_INCLUDEDIR     - Location of the Python include files.
44 #                                         default: ${PYTHONBASE}/include/${PYTHON_VERSION}
45 #
46 # PYTHON_LIBDIR         - Base of the python library tree
47 #                                         default: ${PYTHONBASE}/lib/${PYTHON_VERSION}
48 #
49 # PYTHON_PKGNAMEPREFIX
50 #                                       - Use this as a ${PKGNAMEPREFIX} to distinguish
51 #                                         packages for different Python versions.
52 #                                         default: py${PYTHON_SUFFIX}-
53 #
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}
58 #
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.
63 #
64 # PYTHON_PORTSDIR       - The source of your binary's port. Needed for the
65 #                                         RUN_DEPENDS.
66 #
67 # PYTHON_PORTVERSION
68 #                                       - Version number suitable for ${PORTVERSION}.
69 #
70 # PYTHON_REL            - Version number in numerical format, to ease
71 #                                         comparison in makefiles
72 #
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
76 #
77 # PYTHON_SUFFIX         - Yet another short version number, primarily intended
78 #                                         for ${PYTHON_PKGNAMEPREFIX}.
79 #
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
84 #
85 # PYTHON_VER            - Version of the python binary in your ${PATH}, in the
86 #                                         format "2.7".
87 #
88 # PYTHON_DEFAULT_VERSION
89 #                                       - Version of the default python binary in your ${PATH}, in
90 #                                         the format "python2.7".
91 #
92 # PYTHON2_DEFAULT_VERSION
93 #                                       - Version of the default python2 binary in your ${PATH}, in
94 #                                         the format "python2.7".
95 #
96 # PYTHON3_DEFAULT_VERSION
97 #                                       - Version of the default python3 binary in your ${PATH}, in
98 #                                         the format "python3.2".
99 #
100 # PYTHON_MAJOR_VER      - Python version major number. 2 for python-2.x,
101 #                                         3 for python-3.x and so on.
102 #
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
106 #                                         distribution.
107 #
108 # There are PREFIX-clean variants of the PYTHON_*DIR variables above.
109 # They are meant to be used in the installation targets.
110 #
111 # PYTHONPREFIX_INCLUDEDIR       default: ${PREFIX}/include/${PYTHON_VERSION}
112 # PYTHONPREFIX_LIBDIR           default: ${PREFIX}/lib/${PYTHON_VERSION}
113 # PYTHONPREFIX_SITELIBDIR       default: ${PYTHONPREFIX_LIBDIR}/site-packages
114 #
115 # PYGAME                        - Dependency line for the Pygame library.
116 #
117 # PYNUMERIC                     - Dependency line for the numeric extension.
118 #
119 # PYNUMPY                       - Dependency line for the new numeric extension.
120 #                     py-numpy, Py-Numeric is deprecated.
121 #
122 # PYXML                         - Dependency line for the XML extension. As of Python-2.0,
123 #                                         this extension is in the base distribution.
124 #
125 # USE_PYTHON_PREFIX     - Says that the port installs in ${PYTHONBASE}.
126 #
127 # USE_PYDISTUTILS       - Use distutils as do-configure, do-build and do-install
128 #                                         targets.
129 #
130 # PYSETUP                       - Name of the setup script used by the distutils package.
131 #                                         default: setup.py
132 #
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
137 #
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.
144 #
145 # PYDISTUTILS_PKGNAME
146 #                                       - Internal name in the distutils for egg-info.
147 #                                         default: ${PORTNAME}
148 #
149 # PYDISTUTILS_PKGVERSION
150 #                                       - Internal version in the distutils for egg-info.
151 #                                         default: ${PORTVERSION}
152 #
153 # PYDISTUTILS_CONFIGURE_TARGET
154 #                                       - Pass this command to distutils on configure stage.
155 #                                         default: config
156 #
157 # PYDISTUTILS_BUILD_TARGET
158 #                                       - Pass this command to distutils on build stage.
159 #                                         default: build
160 #
161 # PYDISTUTILS_INSTALL_TARGET
162 #                                       - Pass this command to distutils on install stage.
163 #                                         default: install
164 #
165 # PYDISTUTILS_CONFIGUREARGS
166 #                                       - Arguments to config with distutils.
167 #                                         default: <empty>
168 #
169 # PYDISTUTILS_BUILDARGS
170 #                                       - Arguments to build with distutils.
171 #                                         default: <empty>
172 #
173 # PYDISTUTILS_INSTALLARGS
174 #                                       - Arguments to install with distutils.
175 #                                         default: -c -O1 --prefix=${PREFIX}
176 #
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
180 #
181 # PYDISTUTILS_NOEGGINFO
182 #                                       - Skip an egg-info entry from plist when defined.
183 #
184 # PYEASYINSTALL_EGG
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
187 #
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.
192 #
193 # PYEASYINSTALL_CMD - Full file path to easy_install command.
194 #                                         default: ${LOCALBASE}/bin/easy_install-${PYTHON_VER}
195
196 _PYTHON_PORTBRANCH=             2.7
197 _PYTHON_ALLBRANCHES=    2.7 3.4 3.3 3.2 3.1     # preferred first
198
199 # Determine version number of Python to use
200 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
201
202 .if defined(PYTHON_DEFAULT_VERSION)
203 WARNING+=       "PYTHON_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python=${PYTHON_DEFAULT_VERSION:S/^python//} instead"
204 .endif
205 .if defined(PYTHON2_DEFAULT_VERSION)
206 WARNING+=       "PYTHON2_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python2=${PYTHON2_DEFAULT_VERSION:S/^python//} instead"
207 .endif
208 .if defined(PYTHON3_DEFAULT_VERSION)
209 WARNING+=       "PYTHON3_DEFAULT_VERSION is defined, consider using DEFAULT_VERSIONS=python3=${PYTHON3_DEFAULT_VERSION:S/^python//} instead"
210 .endif
211
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}"
218 .endif
219 PYTHON_DEFAULT_VERSION=         python${_PYTHON_DEFAULT_VERSION}
220 .else
221 PYTHON_DEFAULT_VERSION=         python${PYTHON_DEFAULT}
222 .endif # exists(${LOCALBASE}/bin/python)
223
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}
229 .else
230 PYTHON2_DEFAULT_VERSION?=       python${PYTHON2_DEFAULT}
231 .endif
232
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}
237 .else
238 PYTHON3_DEFAULT_VERSION?=       python${PYTHON3_DEFAULT}
239 .endif
240
241 .if defined(PYTHON_VERSION)
242 _PYTHON_VERSION:=       ${PYTHON_VERSION:S/^python//}
243 _PYTHON_CMD=            ${LOCALBASE}/bin/${PYTHON_VERSION}
244 .else
245 _PYTHON_VERSION:=       ${PYTHON_DEFAULT_VERSION:S/^python//}
246 _PYTHON_CMD=            ${LOCALBASE}/bin/${PYTHON_DEFAULT_VERSION}
247 .endif
248
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}
254 .else
255 USE_PYTHON=             yes
256 .endif  # defined(USE_PYTHON_BUILD)
257 .else
258 USE_PYTHON_BUILD=       yes
259 USE_PYTHON_RUN=         yes
260 .endif  # !defined(USE_PYTHON)
261
262 .if ${USE_PYTHON} == "2"
263 USE_PYTHON=                     ${PYTHON2_DEFAULT_VERSION:S/^python//}
264 _WANTS_META_PORT=       2
265 .elif ${USE_PYTHON} == "3"
266 USE_PYTHON=                     ${PYTHON3_DEFAULT_VERSION:S/^python//}
267 _WANTS_META_PORT=       3
268 .endif  # ${USE_PYTHON} == "2"
269
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]}
276
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
283 .endif
284
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}
290 .else
291 .undef _PYTHON_VERSION
292 .for ver in ${PYTHON2_DEFAULT} ${PYTHON3_DEFAULT} ${_PYTHON_ALLBRANCHES}
293 __VER=          ${ver}
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}
301 .endif
302 .endfor
303 .if !defined(_PYTHON_VERSION)
304 IGNORE=                         needs an unsupported version of Python
305 _PYTHON_VERSION=        ${_PYTHON_PORTBRANCH} # just to avoid version sanity checking.
306 .endif
307 .endif  # defined(PYTHON_VERSION) || defined(PYTHON_CMD)
308 .endif  # defined(_PYTHON_VERSION_NONSUPPORTED)
309
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
315 .endif
316 DEPENDS_ARGS+=          PYTHON_VERSION=${PYTHON_VERSION}
317
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
320 # specification
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
325 .endif
326 .if !defined(PYTHON_NO_DEPENDS) && !empty(_PYTHON_PORTVERSION)
327 PYTHON_PORTVERSION=     ${_PYTHON_PORTVERSION}
328 .endif
329 .elif defined(PYTHON_DEFAULT_PORTVERSION)
330 PYTHON_PORTVERSION=     ${PYTHON_DEFAULT_PORTVERSION}
331 .endif
332
333 # Propagate the chosen python version to submakes.
334 .MAKEFLAGS:     PYTHON_VERSION=python${_PYTHON_VERSION}
335
336 # Python-3.4
337 .if ${PYTHON_VERSION} == "python3.4"
338 PYTHON_PORTVERSION?=    3.4.0
339 PYTHON_PORTSDIR=        ${PORTSDIR}/lang/python34
340 PYTHON_REL=             340
341 PYTHON_SUFFIX=          34
342 PYTHON_VER=             3.4
343 .if exists(${PYTHON_CMD}-config) && ${PORTNAME} != python34
344 PYTHON_ABIVER!=         ${PYTHON_CMD}-config --abiflags
345 .endif
346
347 # Python-3.3
348 .elif ${PYTHON_VERSION} == "python3.3"
349 PYTHON_PORTVERSION?=    3.3.5
350 PYTHON_PORTSDIR=        ${PORTSDIR}/lang/python33
351 PYTHON_REL=             335
352 PYTHON_SUFFIX=          33
353 PYTHON_VER=             3.3
354 .if exists(${PYTHON_CMD}-config) && defined(PORTNAME) && ${PORTNAME} != python33
355 PYTHON_ABIVER!=         ${PYTHON_CMD}-config --abiflags
356 .endif
357
358 # Python-3.2
359 .elif ${PYTHON_VERSION} == "python3.2"
360 PYTHON_PORTVERSION?=    3.2.5
361 PYTHON_PORTSDIR=        ${PORTSDIR}/lang/python32
362 PYTHON_REL=             325
363 PYTHON_SUFFIX=          32
364 PYTHON_VER=             3.2
365 .if exists(${PYTHON_CMD}-config) && defined(PORTNAME) && ${PORTNAME} != python32
366 PYTHON_ABIVER!=         ${PYTHON_CMD}-config --abiflags
367 .endif
368
369 # Python-3.1
370 .elif ${PYTHON_VERSION} == "python3.1"
371 PYTHON_PORTVERSION?=    3.1.5
372 PYTHON_PORTSDIR=        ${PORTSDIR}/lang/python31
373 PYTHON_REL=             315
374 PYTHON_SUFFIX=          31
375 PYTHON_VER=             3.1
376
377 # Python-2.7
378 .elif ${PYTHON_VERSION} == "python2.7"
379 PYTHON_PORTVERSION?=    2.7.6
380 PYTHON_PORTSDIR=        ${PORTSDIR}/lang/python27
381 PYTHON_REL=             276
382 PYTHON_SUFFIX=          27
383 PYTHON_VER=             2.7
384
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; \
392                                                 print(h[0]+h[2])'
393 PYTHON_VER!=            ${PYTHON_CMD} -c 'import sys; print(sys.version[:3])'
394
395 .else
396 check-makevars::
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"
404         @${FALSE}
405 .endif
406
407 PYTHON_MAJOR_VER=       ${PYTHON_VER:R}
408
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/}
413
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
421
422 PYTHONPREFIX_INCLUDEDIR=        ${PYTHON_INCLUDEDIR:S;${PYTHONBASE};${PREFIX};}
423 PYTHONPREFIX_LIBDIR=            ${PYTHON_LIBDIR:S;${PYTHONBASE};${PREFIX};}
424 PYTHONPREFIX_SITELIBDIR=        ${PYTHON_SITELIBDIR:S;${PYTHONBASE};${PREFIX};}
425
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}
430 .endif
431
432 # setuptools support
433 .if defined(USE_PYDISTUTILS) && ${USE_PYDISTUTILS} == "easy_install"
434
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}
444 .endif
445
446 .if ${PREFIX} != ${LOCALBASE} || !defined(NO_STAGE)
447 MAKE_ENV+=                                              PYTHONPATH=${PYEASYINSTALL_SITELIBDIR}
448 .endif
449
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}
453 .endif
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}
458
459 PLIST_SUB+=             PYEASYINSTALL_EGG=${PYEASYINSTALL_EGG}
460
461 pre-install: pre-install-easyinstall
462 pre-install-easyinstall:
463 .if defined(NO_STAGE)
464         @${MKDIR} ${PYEASYINSTALL_SITELIBDIR}
465 .else
466         @${MKDIR} ${STAGEDIR}${PYEASYINSTALL_SITELIBDIR}
467 .endif
468
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" \
475                 >> ${TMPPLIST}
476         @${ECHO_CMD} "@exec ${PRINTF} '1a\n./${PYEASYINSTALL_EGG}\n.\nw\nq\n' | \
477                         /bin/ed ${PYEASYINSTALL_SITELIBDIR}/easy-install.pth" \
478                 >> ${TMPPLIST}
479
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}/;;})
488 .endif
489
490 post-install: stage-python-compileall
491 .endif
492
493 .endif          # defined(USE_PYDISTUTILS) && ${USE_PYDISTUTILS} == "easy_install"
494
495 # distutils support
496 PYSETUP?=                               setup.py
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
504 . endif
505 . if !defined(NO_STAGE)
506 PYDISTUTILS_INSTALLARGS+=       --root=${STAGEDIR}
507 . endif
508 .endif
509 _PYTHONPKGLIST=                         ${WRKDIR}/.PLIST.pymodtmp
510 PYDISTUTILS_INSTALLARGS:=       --record ${_PYTHONPKGLIST} \
511                 ${PYDISTUTILS_INSTALLARGS}
512
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}
517
518 add-plist-egginfo:
519 .if !defined(PYDISTUTILS_NOEGGINFO) && \
520         !defined(PYDISTUTILS_AUTOPLIST) && \
521         (defined(INSTALLS_EGGINFO) ||   \
522                 (defined(USE_PYDISTUTILS) && \
523                  ${USE_PYDISTUTILS} != "easy_install")) && \
524          defined(PYTHON_REL)
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}; \
529                 done; \
530                 ${ECHO_CMD} "@unexec rmdir \"%D/${PYDISTUTILS_EGGINFODIR:S;${STAGEDIR}${PYTHONBASE}/;;}/${egginfo}\" 2>/dev/null || true" >> ${TMPPLIST}; \
531         fi;
532 . endfor
533 .else
534         @${DO_NADA}
535 .endif
536
537 .if defined(PYDISTUTILS_AUTOPLIST) && defined(USE_PYDISTUTILS)
538 _RELSITELIBDIR= ${PYTHONPREFIX_SITELIBDIR:S;${PREFIX}/;;}
539 _RELLIBDIR=             ${PYTHONPREFIX_LIBDIR:S;${PREFIX}/;;}
540
541 add-plist-post: add-plist-pymod
542 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]; \
557                                                 print res; \
558                                         } \
559                                 }' | \
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"; \
564                         }; \
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}
568
569 .else
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())'
575 add-plist-post:
576         @${AWK} '\
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} \
579                 {print} \
580                 END {if (sp in dirs) {print "@dirrm " sp "/" pc}} \
581                 ' \
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)
587
588 # Fix for programs that build python from a GNU auto* environment
589 CONFIGURE_ENV+= PYTHON="${PYTHON_CMD}"
590
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
596
597 # dependencies
598 PYTHON_NO_DEPENDS?=             NO
599
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}
605 .endif
606 .endif
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}
611 .endif
612 .endif
613 .endif          # ${PYTHON_NO_DEPENDS} == "NO"
614
615 # set $PREFIX as Python's one
616 .if defined(USE_PYTHON_PREFIX)
617 PREFIX=                 ${PYTHONBASE}
618 .endif
619
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}
628
629 # XXX Hm, should I export some of the variables above to *_ENV?
630
631
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.
638
639 CMAKE_ARGS+=    -DPythonLibs_FIND_VERSION:STRING="${PYTHON_VER}" \
640                 -DPythonInterp_FIND_VERSION:STRING="${PYTHON_VER}"
641
642 .endif          # !defined(_POSTMKINCLUDED) && !defined(Python_Pre_Include)
643
644 .if defined(_POSTMKINCLUDED) && !defined(Python_Post_Include)
645
646 Python_Post_Include=                    bsd.python.mk
647
648 # py-distutils support
649 PYDISTUTILS_CONFIGURE_TARGET?=  config
650 PYDISTUTILS_BUILD_TARGET?=              build
651 PYDISTUTILS_INSTALL_TARGET?=    install
652
653 .if defined(USE_PYDISTUTILS)
654 LDSHARED?=      ${CC} -shared
655 MAKE_ENV+=      LDSHARED="${LDSHARED}" PYTHONDONTWRITEBYTECODE= PYTHONOPTIMIZE=
656
657 .if !target(do-configure) && !defined(HAS_CONFIGURE) && !defined(GNU_CONFIGURE)
658 do-configure:
659         @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_CONFIGURE_TARGET} ${PYDISTUTILS_CONFIGUREARGS})
660 .endif
661
662 .if !target(do-build)
663 do-build:
664         @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_BUILD_TARGET} ${PYDISTUTILS_BUILDARGS})
665 .endif
666
667 .if !target(do-install)
668 do-install:
669         @(cd ${INSTALL_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_INSTALL_TARGET} ${PYDISTUTILS_INSTALLARGS})
670 .endif
671
672 add-plist-post: add-plist-egginfo
673
674 .if defined(PYEASYINSTALL_ARCHDEP)
675 .if !target(easyinstall-setopt)
676 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)
683
684 pre-build: easyinstall-setopt
685 .endif          # defined(PYEASYINSTALL_ARCHDEP)
686 .endif          # defined(USE_PYDISTUTILS)
687
688 .endif          # defined(_POSTMKINCLUDED) && !defined(Python_Post_Include)