Annotation of pkgsrc/lang/python/pyversion.mk, revision 1.176
1.176 ! adam 1: # $NetBSD: pyversion.mk,v 1.175 2025/10/05 22:43:14 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.171 gdt 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.175 wiz 62: # Default: 313
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.176 ! adam 82: # Possible values: 314 313 312 311
! 83: # Default: 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.176 ! adam 99: # Possible values: 310 311 312 313 314
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.176 ! adam 124: # Examples: 207, 310, 311, 312, 313, 314
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.175 wiz 130: # Example: py313
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
146: .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
147: defined(PKGNAME_REQD) && !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.146 markd 149: .elif defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9][0-9]-*) || \
150: defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9][0-9]-*)
151: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9][0-9])-.*/\2/}
1.66 joerg 152: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
153: defined(PKGNAME_OLD) && !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.146 markd 155: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9][0-9]-*) || \
156: defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9][0-9]-*)
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.175 wiz 165: PYTHON_VERSION_DEFAULT?= 313
1.176 ! adam 166: PYTHON_VERSIONS_ACCEPTED?= 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.115 obache 243: .endif
1.114 obache 244: .if !empty(_PYTHON_VERSION:M3*)
1.121 rillig 245: PLIST.py3x= yes
1.114 obache 246: .endif
247: .if !empty(_PYTHON_VERSION:M2*)
1.121 rillig 248: PLIST.py2x= yes
1.1 drochner 249: .endif
1.5 drochner 250:
1.38 rillig 251: PTHREAD_OPTS+= require
1.33 jlam 252: .include "../../mk/pthread.buildlink3.mk"
1.38 rillig 253:
1.109 riastrad 254: PYTHON_FOR_BUILD_ONLY?= no
1.37 kristerw 255: .if defined(PYPKGSRCDIR)
1.108 riastrad 256: . if !empty(PYTHON_FOR_BUILD_ONLY:M[tT][oO][oO][lL])
257: TOOL_DEPENDS+= ${PYDEPENDENCY}
1.125 ryoon 258: . elif !empty(PYTHON_FOR_BUILD_ONLY:M[tT][eE][sS][tT])
259: TEST_DEPENDS+= ${PYDEPENDENCY}
1.107 riastrad 260: . else
1.108 riastrad 261: . if !empty(PYTHON_FOR_BUILD_ONLY:M[yY][eE][sS])
262: BUILDLINK_DEPMETHOD.python?= build
1.169 jperkin 263: . else
264: BUILDLINK_DEPMETHOD.python?= full
1.108 riastrad 265: . endif
1.107 riastrad 266: . include "${PYPKGSRCDIR}/buildlink3.mk"
1.167 riastrad 267: . if ${USE_CROSS_COMPILE:tl} == "yes"
1.150 riastrad 268: TOOL_DEPENDS+= ${PYDEPENDENCY}
269: MAKE_ENV+= PYTHONPATH=${WRKDIR:Q}/.pysite:${_CROSS_DESTDIR:Q}${LOCALBASE:Q}/${PYLIB:Q}
270: pre-configure: ${WRKDIR}/.pysite/sitecustomize.py
1.151 riastrad 271: .include "${PYPKGSRCDIR}/platname.mk"
1.150 riastrad 272: ${WRKDIR}/.pysite/sitecustomize.py:
273: @${STEP_MSG} "Creating Python sitecustomize.py for cross-compiling"
274: ${RUN} ${MKDIR} ${.TARGET:H}
275: ${RUN} ( \
276: ${ECHO} "import sys" && \
1.151 riastrad 277: ${PRINTF} "sys.platform = '%s'\\n" ${PY_PLATNAME:Q} && \
1.150 riastrad 278: for v in \
279: sys.base_exec_prefix \
280: sys.base_prefix \
281: sys.exec_prefix \
282: sys.prefix \
283: ; do \
284: ${PRINTF} "%s = '%s'\\n" "$$v" ${LOCALBASE:Q}; \
285: done; \
286: ) >${.TARGET}.tmp
287: ${RUN} ${MV} -f ${.TARGET}.tmp ${.TARGET}
288: . endif
1.107 riastrad 289: . endif
1.37 kristerw 290: .endif
1.11 jlam 291:
292: PYTHONBIN= ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.150 riastrad 293: TOOL_PYTHONBIN= ${TOOLBASE}/bin/python${PYVERSSUFFIX}
294: .if exists(${TOOL_PYTHONBIN}m)
295: PYTHONCONFIG= ${TOOLBASE}/bin/python${PYVERSSUFFIX}m-config
1.127 markd 296: .else
1.150 riastrad 297: PYTHONCONFIG= ${TOOLBASE}/bin/python${PYVERSSUFFIX}-config
1.127 markd 298: .endif
1.73 joerg 299: PY_COMPILE_ALL= \
1.150 riastrad 300: ${TOOL_PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.73 joerg 301: PY_COMPILE_O_ALL= \
1.150 riastrad 302: ${TOOL_PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11 jlam 303:
1.139 adam 304: PYINC= include/python${PYVERSSUFFIX}
305: PYLIB= lib/python${PYVERSSUFFIX}
306: PYSITELIB= ${PYLIB}/site-packages
1.72 joerg 307:
1.161 hauke 308: # Expect paths directly under PREFIX, but allow for ${PLIST.*} prefix(es)
309: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYINC:S|/|\\/|g}/ \
1.82 obache 310: { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.161 hauke 311: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYSITELIB:S|/|\\/|g}/ \
1.82 obache 312: { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.161 hauke 313: PRINT_PLIST_AWK+= /(^|^\$$.+\})${PYLIB:S|/|\\/|g}/ \
1.82 obache 314: { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.2 drochner 315:
1.150 riastrad 316: ALL_ENV+= PYTHON=${TOOL_PYTHONBIN}
1.147 gdt 317: .if defined(USE_CMAKE) || defined(BUILD_USES_CMAKE)
1.135 nia 318: # used by FindPython
1.164 wiz 319: CMAKE_CONFIGURE_ARGS+= -DPython_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
320: CMAKE_CONFIGURE_ARGS+= -DPython_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 321: # used by FindPython2
322: . if !empty(_PYTHON_VERSION:M2*)
1.164 wiz 323: CMAKE_CONFIGURE_ARGS+= -DPython2_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
324: CMAKE_CONFIGURE_ARGS+= -DPython2_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 325: . endif
326: # used by FindPython3
327: . if !empty(_PYTHON_VERSION:M3*)
1.164 wiz 328: CMAKE_CONFIGURE_ARGS+= -DPython3_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
329: CMAKE_CONFIGURE_ARGS+= -DPython3_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135 nia 330: . endif
1.80 drochner 331: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
1.164 wiz 332: CMAKE_CONFIGURE_ARGS+= -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
1.116 dbj 333: # set this explicitly, as by default it will prefer the built in framework
1.126 bsiegert 334: # on Darwin
1.164 wiz 335: CMAKE_CONFIGURE_ARGS+= -DPYTHON_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
336: CMAKE_CONFIGURE_ARGS+= -DPYTHON_INCLUDE_PATH:PATH=${BUILDLINK_DIR}/${PYINC}
337: CMAKE_CONFIGURE_ARGS+= -DPYTHON_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
1.80 drochner 338: .endif
1.47 rillig 339:
1.131 rillig 340: _VARGROUPS+= pyversion
341: _USER_VARS.pyversion= PYTHON_VERSION_DEFAULT
342: _PKG_VARS.pyversion= \
343: PYTHON_VERSIONS_ACCEPTED PYTHON_VERSIONS_INCOMPATIBLE \
1.147 gdt 344: PYTHON_SELF_CONFLICT PYTHON_FOR_BUILD_ONLY USE_CMAKE BUILD_USES_CMAKE
1.131 rillig 345: _SYS_VARS.pyversion= \
1.161 hauke 346: PYTHON_VERSION PYTHON_VERSION_REQD PYPACKAGE PYVERSSUFFIX \
347: PYPKGSRCDIR PYPKGPREFIX PYTHONBIN PYTHONCONFIG PY_COMPILE_ALL \
1.164 wiz 348: PY_COMPILE_O_ALL PYINC PYLIB PYSITELIB CMAKE_CONFIGURE_ARGS \
1.150 riastrad 349: TOOL_PYTHONBIN
1.131 rillig 350: _USE_VARS.pyversion= \
351: PKGNAME_REQD PKGNAME_OLD LOCALBASE PREFIX BUILDLINK_DIR PKGNAME
352: _DEF_VARS.pyversion= \
353: CONFLICTS MULTI PLIST_VARS BUILDLINK_API_DEPENDS.${PYPACKAGE} \
354: PYDEPENDENCY PLIST.py2x PLIST.py3x PTHREAD_OPTS TOOL_DEPENDS \
355: TEST_DEPENDS BUILDLINK_DEPMETHOD.python PRINT_PLIST_AWK ALL_ENV \
356: _PYTHON_VERSIONS_ACCEPTED _PYTHON_VERSION
357: _IGN_VARS.pyversion= _PYTHON_*
358: _LISTED_VARS.pyversion= *_ARGS
359: _SORTED_VARS.pyversion= *_DEPENDS *_ENV
360:
1.2 drochner 361: .endif # PYTHON_PYVERSION_MK
CVSweb <webmaster@jp.NetBSD.org>