Annotation of pkgsrc/lang/python/pyversion.mk, revision 1.173
1.173 ! gdt 1: # $NetBSD: pyversion.mk,v 1.172 2025/07/22 12:24:28 gdt Exp $
1.44 rillig 2:
1.171 gdt 3: # This file provides an interface to decide which version of python
4: # should be used in building a package. It should be directly
5: # included by packages as a way to depend on python when none of the
6: # other methods are appropriate, e.g. a package that produces a binary
7: # that embeds python. It is indirectly included by the other methods.
8: #
9: # There are three kinds of python versions:
1.173 ! gdt 10: # - 2.7: Very old, and only usable if explicitly marked as supported.
! 11: # - old 3.x: Usable if explicitly marked as supported and requested,
1.171 gdt 12: # but globally disabled by default because too many packages fail,
13: # and it's painful for no gain to have to explicitly exclude it.
14: # Bulk builds do not build these versions.
1.173 ! gdt 15: # - current 3.x: Usable unless marked as not accepted. Includes the
1.171 gdt 16: # default version, older versions not yet too troublesome, and
17: # often a version newer than default.
18: #
1.172 gdt 19: # The value of "current 3.x" is defined by the default value of
20: # PYTHON_VERSIONS_ACCEPTED. pbulk uses this set to determine which
21: # python versions are built during a bulk build.
22: #
1.173 ! gdt 23: # For any given package, there are a set of python3 versions that one
! 24: # can use with the upstream code, and perhaps a reduced version that
! 25: # pkgsrc chooses to use, often due to dependencies in pkgsrc not
! 26: # supporting an older version. The set of versions is expressed in
! 27: # one of several ways, but not a mixture:
! 28: # - No variables set, meaning that the supported versions are exactly
! 29: # those in the default value of PYTHON_VERSIONS_ACCEPTED.
! 30: # - PYTHON_VERSIONS_ACCEPTED set, meaning that is the set of
! 31: # buildable versions. This can include values not in the default,
! 32: # and it can omit values in the default.
! 33: # - PYTHON_VERSIONS_INCOMPATIBLE set, meaning that the set of
! 34: # buildable versions is the default value of
! 35: # PYTHON_VERSIONS_ACCEPTED, minus the INCOMPATIBLE versions. This
! 36: # is preferred when omitting a specific old version, so that when a
! 37: # new version is added, it is included.
! 38: # NB: If a version is in the ACCEPTED set, that version must also be
! 39: # in the ACCEPTED set of every (recursive) dependency.
1.172 gdt 40: #
1.171 gdt 41: # The general plan for version selection (ignoring 2.7) is:
42: # - If PYTHON_VERSION_REQD is set, choose it (and fail if not in
43: # PYTHON_VERSIONS_ACCEPTED).
44: # - If PYTHON_VERSION_DEFAULT is in PYTHON_VERSIONS_ACCEPTED, choose
45: # it.
46: # - Otherwise, choose the first version in PYTHON_VERSIONS_ACCEPTED.
47: #
48: # With 2.7, 27 is considered included in PYTHON_VERSIONS_ACCEPTED if
49: # PYTHON_27_ACCEPTED is defined. If so, then:
50: # - If PYTHON_VERSION_REQD is 27, 27 is used.
51: # - If PYTHON_VERSION_DEFAULT is not in PYTHON_VERSIONS_ACCEPTED,
52: # then the highest version in ACCEPTED is chosen. (For a package
53: # that supports only 27, this will be 27.)
1.44 rillig 54: #
1.48 rillig 55: # === User-settable variables ===
1.44 rillig 56: #
57: # PYTHON_VERSION_DEFAULT
1.172 gdt 58: # The preferred Python version to use. Typical use is to move
59: # to a newer version before pkgsrc moves. Another possible use
60: # is to stay on an older version when pkgsrc advances.
1.171 gdt 61: #
1.172 gdt 62: # Reasonable values: Default value of PYTHON_VERSIONS_ACCEPTED.
1.171 gdt 63: # Possible values: Reasonable values and "old 3.x".
1.163 wiz 64: # Default: 312
1.44 rillig 65: #
1.104 cheusov 66: # === Infrastructure variables ===
67: #
1.101 cheusov 68: # PYTHON_VERSION_REQD
1.171 gdt 69: # Python version to use. This variable should not be set by the
70: # user or in packages. Normally it is used by bulk build tools,
71: # or e.g. as "make PYTHON_VERSION_REQD=311 replace".
1.101 cheusov 72: #
73: # Possible: ${PYTHON_VERSIONS_ACCEPTED}
74: # Default: ${PYTHON_VERSION_DEFAULT}
75: #
1.48 rillig 76: # === Package-settable variables ===
1.44 rillig 77: #
78: # PYTHON_VERSIONS_ACCEPTED
1.171 gdt 79: # The Python versions that can be used to build the package.
80: # Order is significant, with the first feasible value chosen;
81: # normal practice is to list all feasible versions in decreasing
82: # order.
1.44 rillig 83: #
1.171 gdt 84: # Possible values: 313 312 311
1.170 wiz 85: # Default: 313 312 311
1.92 joerg 86: #
1.171 gdt 87: # PYTHON_27_ACCEPTED
88: # Set if the package can build with 2.7. (27 should not be
89: # placed in PYTHON_VERSIONS_ACCEPTED.)
90: #
1.44 rillig 91: # PYTHON_VERSIONS_INCOMPATIBLE
1.171 gdt 92: # The Python versions that cannot be used to build the package.
93: # Any "current 3.x" version that fails to build and work must be
94: # listed. "Old 3.x" versions may be listed, and if present
95: # should not be pruned (as long as the old lang/pythonNN version
96: # is in pkgsrc). However it is not a consequential error if it
97: # is missing, as those are not built by default in bulk builds.
98: # (27 should not be listed as incompatible, as that's true
99: # unless PYTHON_27_ACCEPTED is set.)
1.44 rillig 100: #
1.171 gdt 101: # Possible values: 39 310 311 312 313
1.113 wiz 102: # Default: (empty)
1.44 rillig 103: #
104: # PYTHON_FOR_BUILD_ONLY
105: # Whether Python is needed only at build time or at run time.
106: #
1.125 ryoon 107: # Possible values: yes no test tool
1.108 riastrad 108: # Default: no
1.44 rillig 109: #
1.103 cheusov 110: # PYTHON_SELF_CONFLICT
111: # If set to "yes", additional CONFLICTS entries are added for
1.153 gdt 112: # registering a conflict between pyNN-<modulename> packages,
113: # covering all versions. (Expressing CONFLICTS that are limited
114: # to some versions must be done with a hand-written CONFLICTS
115: # entry.)
1.103 cheusov 116: #
117: # Possible values: yes no
118: # Default: no
119: #
1.52 rillig 120: # === Defined variables ===
121: #
1.148 wiz 122: # PYTHON_VERSION
123: # Version of python that will be used in this build, as
124: # a three-digit number of major_version * 100 + minor_version.
125: #
1.166 adam 126: # Examples: 207, 309, 310, 311, 312, 313
1.148 wiz 127: #
1.52 rillig 128: # PYPKGPREFIX
129: # The prefix to use in PKGNAME for extensions which are meant
130: # to be installed for multiple Python versions.
131: #
1.163 wiz 132: # Example: py312
1.52 rillig 133: #
134: # PYVERSSUFFIX
135: # The suffix to executables and in the library path, equal to
136: # sys.version[0:3].
137: #
1.163 wiz 138: # Example: 3.12
1.52 rillig 139: #
1.46 rillig 140: # Keywords: python
141: #
1.2 drochner 142:
143: .if !defined(PYTHON_PYVERSION_MK)
144: PYTHON_PYVERSION_MK= defined
1.1 drochner 145:
1.66 joerg 146: # derive a python version from the package name if possible
147: # optionally handled quoted package names
148: .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
149: defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9]-*)
1.121 rillig 150: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
1.146 markd 151: .elif defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9][0-9]-*) || \
152: defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9][0-9]-*)
153: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9][0-9])-.*/\2/}
1.66 joerg 154: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
155: defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9]-*)
1.121 rillig 156: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
1.146 markd 157: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9][0-9]-*) || \
158: defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9][0-9]-*)
159: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9][0-9])-.*/\2/}
1.66 joerg 160: .endif
161:
1.168 tnn 162: .include "../../mk/bsd.fast.prefs.mk"
1.1 drochner 163:
1.46 rillig 164: BUILD_DEFS+= PYTHON_VERSION_DEFAULT
165: BUILD_DEFS_EFFECTS+= PYPACKAGE
166:
1.163 wiz 167: PYTHON_VERSION_DEFAULT?= 312
1.170 wiz 168: PYTHON_VERSIONS_ACCEPTED?= 313 312 311
1.160 wiz 169: .if defined(PYTHON_27_ACCEPTED)
170: PYTHON_VERSIONS_ACCEPTED+= 27
171: .endif
1.56 joerg 172: PYTHON_VERSIONS_INCOMPATIBLE?= # empty by default
173:
1.1 drochner 174: # transform the list into individual variables
175: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.121 rillig 176: . if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
1.1 drochner 177: _PYTHON_VERSION_${pv}_OK= yes
1.56 joerg 178: _PYTHON_VERSIONS_ACCEPTED+= ${pv}
1.121 rillig 179: . endif
1.1 drochner 180: .endfor
181:
182: #
183: # choose a python version where to add,
184: # try to be intelligent
185: #
1.136 gutterid 186: # if a version is explicitly required, take it
1.2 drochner 187: .if defined(PYTHON_VERSION_REQD)
1.40 joerg 188: # but check if it is acceptable first, error out otherwise
1.121 rillig 189: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2 drochner 190: _PYTHON_VERSION= ${PYTHON_VERSION_REQD}
1.121 rillig 191: . endif
1.40 joerg 192: .else
193: # if the default is accepted, it is first choice
1.121 rillig 194: . if !defined(_PYTHON_VERSION)
195: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1 drochner 196: _PYTHON_VERSION= ${PYTHON_VERSION_DEFAULT}
1.121 rillig 197: . endif
198: . endif
1.1 drochner 199: # prefer an already installed version, in order of "accepted"
1.121 rillig 200: . if !defined(_PYTHON_VERSION)
201: . for pv in ${PYTHON_VERSIONS_ACCEPTED}
202: . if defined(_PYTHON_VERSION_${pv}_OK)
1.1 drochner 203: _PYTHON_VERSION?= ${pv}
1.121 rillig 204: . endif
205: . endfor
206: . endif
1.1 drochner 207: .endif
1.40 joerg 208:
1.87 wiz 209: #
210: # Variable assignment for multi-python packages
211: MULTI+= PYTHON_VERSION_REQD=${_PYTHON_VERSION}
212:
1.40 joerg 213: # No supported version found, annotate to simplify statements below.
1.1 drochner 214: .if !defined(_PYTHON_VERSION)
1.40 joerg 215: _PYTHON_VERSION= none
1.148 wiz 216: # since no supported version is found and no build will happen,
217: # choose a numeric default
218: PYTHON_VERSION= 0
1.115 obache 219: PKG_FAIL_REASON+= "No valid Python version"
1.142 gdt 220: PYPKGPREFIX= none
221: PYVERSSUFFIX= none
1.148 wiz 222: .else
223: PYTHON_VERSION= ${_PYTHON_VERSION:C/^(.)(.)$/\10\2/}
1.1 drochner 224: .endif
225:
1.103 cheusov 226: # Additional CONFLICTS
227: .if ${PYTHON_SELF_CONFLICT:U:tl} == "yes"
1.121 rillig 228: . for i in ${PYTHON_VERSIONS_ACCEPTED:N${_PYTHON_VERSION}}
1.134 nia 229: . if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${i})
1.121 rillig 230: CONFLICTS+= ${PKGNAME:S/py${_PYTHON_VERSION}/py${i}/:C/-[0-9].*$/-[0-9]*/}
1.134 nia 231: . endif
1.121 rillig 232: . endfor
1.103 cheusov 233: .endif # PYCONFLICTS
234:
235: #
1.100 drochner 236: PLIST_VARS+= py2x py3x
237:
1.115 obache 238: .if empty(_PYTHON_VERSION:Mnone)
1.121 rillig 239: PYPACKAGE= python${_PYTHON_VERSION}
240: PYVERSSUFFIX= ${_PYTHON_VERSION:C/^([0-9])/\1./1}
241: BUILDLINK_API_DEPENDS.${PYPACKAGE}?= ${PYPACKAGE}>=${PYVERSSUFFIX}
242: PYPKGSRCDIR= ../../lang/${PYPACKAGE}
1.149 riastrad 243: PYDEPENDENCY= ${BUILDLINK_API_DEPENDS.${PYPACKAGE}:=:${PYPKGSRCDIR}}
1.121 rillig 244: PYPKGPREFIX= py${_PYTHON_VERSION}
1.115 obache 245: .endif
1.114 obache 246: .if !empty(_PYTHON_VERSION:M3*)
1.121 rillig 247: PLIST.py3x= yes
1.114 obache 248: .endif
249: .if !empty(_PYTHON_VERSION:M2*)
1.121 rillig 250: PLIST.py2x= yes
1.1 drochner 251: .endif
1.5 drochner 252:
1.38 rillig 253: PTHREAD_OPTS+= require
1.33 jlam 254: .include "../../mk/pthread.buildlink3.mk"
1.38 rillig 255:
1.109 riastrad 256: PYTHON_FOR_BUILD_ONLY?= no
1.37 kristerw 257: .if defined(PYPKGSRCDIR)
1.108 riastrad 258: . if !empty(PYTHON_FOR_BUILD_ONLY:M[tT][oO][oO][lL])
259: TOOL_DEPENDS+= ${PYDEPENDENCY}
1.125 ryoon 260: . elif !empty(PYTHON_FOR_BUILD_ONLY:M[tT][eE][sS][tT])
261: TEST_DEPENDS+= ${PYDEPENDENCY}
1.107 riastrad 262: . else
1.108 riastrad 263: . if !empty(PYTHON_FOR_BUILD_ONLY:M[yY][eE][sS])
264: BUILDLINK_DEPMETHOD.python?= build
1.169 jperkin 265: . else
266: BUILDLINK_DEPMETHOD.python?= full
1.108 riastrad 267: . endif
1.107 riastrad 268: . include "${PYPKGSRCDIR}/buildlink3.mk"
1.167 riastrad 269: . if ${USE_CROSS_COMPILE:tl} == "yes"
1.150 riastrad 270: TOOL_DEPENDS+= ${PYDEPENDENCY}
271: MAKE_ENV+= PYTHONPATH=${WRKDIR:Q}/.pysite:${_CROSS_DESTDIR:Q}${LOCALBASE:Q}/${PYLIB:Q}
272: pre-configure: ${WRKDIR}/.pysite/sitecustomize.py
1.151 riastrad 273: .include "${PYPKGSRCDIR}/platname.mk"
1.150 riastrad 274: ${WRKDIR}/.pysite/sitecustomize.py:
275: @${STEP_MSG} "Creating Python sitecustomize.py for cross-compiling"
276: ${RUN} ${MKDIR} ${.TARGET:H}
277: ${RUN} ( \
278: ${ECHO} "import sys" && \
1.151 riastrad 279: ${PRINTF} "sys.platform = '%s'\\n" ${PY_PLATNAME:Q} && \
1.150 riastrad 280: for v in \
281: sys.base_exec_prefix \
282: sys.base_prefix \
283: sys.exec_prefix \
284: sys.prefix \
285: ; do \
286: ${PRINTF} "%s = '%s'\\n" "$$v" ${LOCALBASE:Q}; \
287: done; \
288: ) >${.TARGET}.tmp
289: ${RUN} ${MV} -f ${.TARGET}.tmp ${.TARGET}
290: . endif
1.107 riastrad 291: . endif
1.37 kristerw 292: .endif
1.11 jlam 293:
294: PYTHONBIN= ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.150 riastrad 295: TOOL_PYTHONBIN= ${TOOLBASE}/bin/python${PYVERSSUFFIX}
296: .if exists(${TOOL_PYTHONBIN}m)
297: PYTHONCONFIG= ${TOOLBASE}/bin/python${PYVERSSUFFIX}m-config
1.127 markd 298: .else
1.150 riastrad 299: PYTHONCONFIG= ${TOOLBASE}/bin/python${PYVERSSUFFIX}-config
1.127 markd 300: .endif
1.73 joerg 301: PY_COMPILE_ALL= \
1.150 riastrad 302: ${TOOL_PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.73 joerg 303: PY_COMPILE_O_ALL= \
1.150 riastrad 304: ${TOOL_PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11 jlam 305:
1.139 adam 306: PYINC= include/python${PYVERSSUFFIX}
307: PYLIB= lib/python${PYVERSSUFFIX}
308: PYSITELIB= ${PYLIB}/site-packages
1.72 joerg 309:
1.161 hauke 310: # Expect paths directly under PREFIX, but allow for ${PLIST.*} prefix(es)
311: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYINC:S|/|\\/|g}/ \
1.82 obache 312: { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.161 hauke 313: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYSITELIB:S|/|\\/|g}/ \
1.82 obache 314: { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.161 hauke 315: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYLIB:S|/|\\/|g}/ \
1.82 obache 316: { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.2 drochner 317:
1.150 riastrad 318: ALL_ENV+= PYTHON=${TOOL_PYTHONBIN}
1.147 gdt 319: .if defined(USE_CMAKE) || defined(BUILD_USES_CMAKE)
1.135 nia 320: # used by FindPython
1.164 wiz 321: CMAKE_CONFIGURE_ARGS+= -DPython_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
322: CMAKE_CONFIGURE_ARGS+= -DPython_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 323: # used by FindPython2
324: . if !empty(_PYTHON_VERSION:M2*)
1.164 wiz 325: CMAKE_CONFIGURE_ARGS+= -DPython2_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
326: CMAKE_CONFIGURE_ARGS+= -DPython2_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 327: . endif
328: # used by FindPython3
329: . if !empty(_PYTHON_VERSION:M3*)
1.164 wiz 330: CMAKE_CONFIGURE_ARGS+= -DPython3_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
331: CMAKE_CONFIGURE_ARGS+= -DPython3_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 332: . endif
1.80 drochner 333: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
1.164 wiz 334: CMAKE_CONFIGURE_ARGS+= -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
1.116 dbj 335: # set this explicitly, as by default it will prefer the built in framework
1.126 bsiegert 336: # on Darwin
1.164 wiz 337: CMAKE_CONFIGURE_ARGS+= -DPYTHON_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
338: CMAKE_CONFIGURE_ARGS+= -DPYTHON_INCLUDE_PATH:PATH=${BUILDLINK_DIR}/${PYINC}
339: CMAKE_CONFIGURE_ARGS+= -DPYTHON_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
1.80 drochner 340: .endif
1.47 rillig 341:
1.131 rillig 342: _VARGROUPS+= pyversion
343: _USER_VARS.pyversion= PYTHON_VERSION_DEFAULT
344: _PKG_VARS.pyversion= \
345: PYTHON_VERSIONS_ACCEPTED PYTHON_VERSIONS_INCOMPATIBLE \
1.147 gdt 346: PYTHON_SELF_CONFLICT PYTHON_FOR_BUILD_ONLY USE_CMAKE BUILD_USES_CMAKE
1.131 rillig 347: _SYS_VARS.pyversion= \
1.161 hauke 348: PYTHON_VERSION PYTHON_VERSION_REQD PYPACKAGE PYVERSSUFFIX \
349: PYPKGSRCDIR PYPKGPREFIX PYTHONBIN PYTHONCONFIG PY_COMPILE_ALL \
1.164 wiz 350: PY_COMPILE_O_ALL PYINC PYLIB PYSITELIB CMAKE_CONFIGURE_ARGS \
1.150 riastrad 351: TOOL_PYTHONBIN
1.131 rillig 352: _USE_VARS.pyversion= \
353: PKGNAME_REQD PKGNAME_OLD LOCALBASE PREFIX BUILDLINK_DIR PKGNAME
354: _DEF_VARS.pyversion= \
355: CONFLICTS MULTI PLIST_VARS BUILDLINK_API_DEPENDS.${PYPACKAGE} \
356: PYDEPENDENCY PLIST.py2x PLIST.py3x PTHREAD_OPTS TOOL_DEPENDS \
357: TEST_DEPENDS BUILDLINK_DEPMETHOD.python PRINT_PLIST_AWK ALL_ENV \
358: _PYTHON_VERSIONS_ACCEPTED _PYTHON_VERSION
359: _IGN_VARS.pyversion= _PYTHON_*
360: _LISTED_VARS.pyversion= *_ARGS
361: _SORTED_VARS.pyversion= *_DEPENDS *_ENV
362:
1.2 drochner 363: .endif # PYTHON_PYVERSION_MK
CVSweb <webmaster@jp.NetBSD.org>