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