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