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