Annotation of pkgsrc/lang/python/pyversion.mk, revision 1.145
1.145 ! gdt 1: # $NetBSD: pyversion.mk,v 1.144 2022/11/06 13:27:57 gdt 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.143 adam 14: # Possible values: 27 37 38 39 310 311
1.141 nia 15: # Default: 310
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.143 adam 33: # Possible values: 311 310 39 38 37 27
1.144 gdt 34: # Default: 311 310 39 38 27
1.92 joerg 35: #
1.44 rillig 36: # PYTHON_VERSIONS_INCOMPATIBLE
37: # The Python versions that are NOT acceptable for the package.
38: #
1.143 adam 39: # Possible values: 27 37 38 39 310 311
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
50: # registering a conflict between pyNN-<modulename> packages.
51: #
52: # Possible values: yes no
53: # Default: no
54: #
1.52 rillig 55: # === Defined variables ===
56: #
57: # PYPKGPREFIX
58: # The prefix to use in PKGNAME for extensions which are meant
59: # to be installed for multiple Python versions.
60: #
1.96 wiz 61: # Example: py27
1.52 rillig 62: #
63: # PYVERSSUFFIX
64: # The suffix to executables and in the library path, equal to
65: # sys.version[0:3].
66: #
1.96 wiz 67: # Example: 2.7
1.52 rillig 68: #
1.46 rillig 69: # Keywords: python
70: #
1.2 drochner 71:
72: .if !defined(PYTHON_PYVERSION_MK)
73: PYTHON_PYVERSION_MK= defined
1.1 drochner 74:
1.66 joerg 75: # derive a python version from the package name if possible
76: # optionally handled quoted package names
77: .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
78: defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9]-*)
1.121 rillig 79: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
1.66 joerg 80: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
81: defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9]-*)
1.121 rillig 82: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
1.66 joerg 83: .endif
84:
1.1 drochner 85: .include "../../mk/bsd.prefs.mk"
86:
1.46 rillig 87: BUILD_DEFS+= PYTHON_VERSION_DEFAULT
88: BUILD_DEFS_EFFECTS+= PYPACKAGE
89:
1.141 nia 90: PYTHON_VERSION_DEFAULT?= 310
1.144 gdt 91: PYTHON_VERSIONS_ACCEPTED?= 311 310 39 38 27
1.56 joerg 92: PYTHON_VERSIONS_INCOMPATIBLE?= # empty by default
93:
1.1 drochner 94: # transform the list into individual variables
95: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.121 rillig 96: . if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
1.1 drochner 97: _PYTHON_VERSION_${pv}_OK= yes
1.56 joerg 98: _PYTHON_VERSIONS_ACCEPTED+= ${pv}
1.121 rillig 99: . endif
1.1 drochner 100: .endfor
101:
102: #
103: # choose a python version where to add,
104: # try to be intelligent
105: #
1.136 gutterid 106: # if a version is explicitly required, take it
1.2 drochner 107: .if defined(PYTHON_VERSION_REQD)
1.40 joerg 108: # but check if it is acceptable first, error out otherwise
1.121 rillig 109: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2 drochner 110: _PYTHON_VERSION= ${PYTHON_VERSION_REQD}
1.121 rillig 111: . endif
1.40 joerg 112: .else
113: # if the default is accepted, it is first choice
1.121 rillig 114: . if !defined(_PYTHON_VERSION)
115: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1 drochner 116: _PYTHON_VERSION= ${PYTHON_VERSION_DEFAULT}
1.121 rillig 117: . endif
118: . endif
1.1 drochner 119: # prefer an already installed version, in order of "accepted"
1.121 rillig 120: . if !defined(_PYTHON_VERSION)
121: . for pv in ${PYTHON_VERSIONS_ACCEPTED}
122: . if defined(_PYTHON_VERSION_${pv}_OK)
1.1 drochner 123: _PYTHON_VERSION?= ${pv}
1.121 rillig 124: . endif
125: . endfor
126: . endif
1.1 drochner 127: .endif
1.40 joerg 128:
1.87 wiz 129: #
130: # Variable assignment for multi-python packages
131: MULTI+= PYTHON_VERSION_REQD=${_PYTHON_VERSION}
132:
1.40 joerg 133: # No supported version found, annotate to simplify statements below.
1.1 drochner 134: .if !defined(_PYTHON_VERSION)
1.40 joerg 135: _PYTHON_VERSION= none
1.115 obache 136: PKG_FAIL_REASON+= "No valid Python version"
1.142 gdt 137: PYPKGPREFIX= none
138: PYVERSSUFFIX= none
1.1 drochner 139: .endif
140:
1.103 cheusov 141: # Additional CONFLICTS
142: .if ${PYTHON_SELF_CONFLICT:U:tl} == "yes"
1.121 rillig 143: . for i in ${PYTHON_VERSIONS_ACCEPTED:N${_PYTHON_VERSION}}
1.134 nia 144: . if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${i})
1.121 rillig 145: CONFLICTS+= ${PKGNAME:S/py${_PYTHON_VERSION}/py${i}/:C/-[0-9].*$/-[0-9]*/}
1.134 nia 146: . endif
1.121 rillig 147: . endfor
1.103 cheusov 148: .endif # PYCONFLICTS
149:
150: #
1.100 drochner 151: PLIST_VARS+= py2x py3x
152:
1.115 obache 153: .if empty(_PYTHON_VERSION:Mnone)
1.121 rillig 154: PYPACKAGE= python${_PYTHON_VERSION}
155: PYVERSSUFFIX= ${_PYTHON_VERSION:C/^([0-9])/\1./1}
156: BUILDLINK_API_DEPENDS.${PYPACKAGE}?= ${PYPACKAGE}>=${PYVERSSUFFIX}
157: PYPKGSRCDIR= ../../lang/${PYPACKAGE}
158: PYDEPENDENCY= ${BUILDLINK_API_DEPENDS.${PYPACKAGE}}:${PYPKGSRCDIR}
159: PYPKGPREFIX= py${_PYTHON_VERSION}
1.115 obache 160: .endif
1.114 obache 161: .if !empty(_PYTHON_VERSION:M3*)
1.121 rillig 162: PLIST.py3x= yes
1.114 obache 163: .endif
164: .if !empty(_PYTHON_VERSION:M2*)
1.121 rillig 165: PLIST.py2x= yes
1.1 drochner 166: .endif
1.5 drochner 167:
1.38 rillig 168: PTHREAD_OPTS+= require
1.33 jlam 169: .include "../../mk/pthread.buildlink3.mk"
1.38 rillig 170:
1.109 riastrad 171: PYTHON_FOR_BUILD_ONLY?= no
1.37 kristerw 172: .if defined(PYPKGSRCDIR)
1.108 riastrad 173: . if !empty(PYTHON_FOR_BUILD_ONLY:M[tT][oO][oO][lL])
174: TOOL_DEPENDS+= ${PYDEPENDENCY}
1.125 ryoon 175: . elif !empty(PYTHON_FOR_BUILD_ONLY:M[tT][eE][sS][tT])
176: TEST_DEPENDS+= ${PYDEPENDENCY}
1.107 riastrad 177: . else
1.108 riastrad 178: . if !empty(PYTHON_FOR_BUILD_ONLY:M[yY][eE][sS])
179: BUILDLINK_DEPMETHOD.python?= build
180: . endif
1.107 riastrad 181: . include "${PYPKGSRCDIR}/buildlink3.mk"
182: . endif
1.37 kristerw 183: .endif
1.11 jlam 184:
185: PYTHONBIN= ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.127 markd 186: .if exists(${PYTHONBIN}m)
187: PYTHONCONFIG= ${LOCALBASE}/bin/python${PYVERSSUFFIX}m-config
188: .else
1.78 joerg 189: PYTHONCONFIG= ${LOCALBASE}/bin/python${PYVERSSUFFIX}-config
1.127 markd 190: .endif
1.73 joerg 191: PY_COMPILE_ALL= \
192: ${PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
193: PY_COMPILE_O_ALL= \
194: ${PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11 jlam 195:
1.139 adam 196: PYINC= include/python${PYVERSSUFFIX}
197: PYLIB= lib/python${PYVERSSUFFIX}
198: PYSITELIB= ${PYLIB}/site-packages
1.72 joerg 199:
200: PRINT_PLIST_AWK+= /^${PYINC:S|/|\\/|g}/ \
1.82 obache 201: { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.72 joerg 202: PRINT_PLIST_AWK+= /^${PYSITELIB:S|/|\\/|g}/ \
1.82 obache 203: { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.72 joerg 204: PRINT_PLIST_AWK+= /^${PYLIB:S|/|\\/|g}/ \
1.82 obache 205: { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.2 drochner 206:
1.121 rillig 207: ALL_ENV+= PYTHON=${PYTHONBIN}
1.80 drochner 208: .if defined(USE_CMAKE)
1.135 nia 209: # used by FindPython
210: CMAKE_ARGS+= -DPython_EXECUTABLE:FILEPATH=${PYTHONBIN}
211: CMAKE_ARGS+= -DPython_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
212: # used by FindPython2
213: . if !empty(_PYTHON_VERSION:M2*)
214: CMAKE_ARGS+= -DPython2_EXECUTABLE:FILEPATH=${PYTHONBIN}
215: CMAKE_ARGS+= -DPython2_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
216: . endif
217: # used by FindPython3
218: . if !empty(_PYTHON_VERSION:M3*)
219: CMAKE_ARGS+= -DPython3_EXECUTABLE:FILEPATH=${PYTHONBIN}
220: CMAKE_ARGS+= -DPython3_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
221: . endif
1.80 drochner 222: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
1.121 rillig 223: CMAKE_ARGS+= -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
1.116 dbj 224: # set this explicitly, as by default it will prefer the built in framework
1.126 bsiegert 225: # on Darwin
226: CMAKE_ARGS+= -DPYTHON_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
227: CMAKE_ARGS+= -DPYTHON_INCLUDE_PATH:PATH=${BUILDLINK_DIR}/${PYINC}
228: CMAKE_ARGS+= -DPYTHON_EXECUTABLE:FILEPATH=${PYTHONBIN}
1.80 drochner 229: .endif
1.47 rillig 230:
1.131 rillig 231: _VARGROUPS+= pyversion
232: _USER_VARS.pyversion= PYTHON_VERSION_DEFAULT
233: _PKG_VARS.pyversion= \
234: PYTHON_VERSIONS_ACCEPTED PYTHON_VERSIONS_INCOMPATIBLE \
235: PYTHON_SELF_CONFLICT PYTHON_FOR_BUILD_ONLY USE_CMAKE
236: _SYS_VARS.pyversion= \
237: PYTHON_VERSION_REQD PYPACKAGE PYVERSSUFFIX PYPKGSRCDIR \
238: PYPKGPREFIX PYTHONBIN PYTHONCONFIG PY_COMPILE_ALL \
239: PY_COMPILE_O_ALL PYINC PYLIB PYSITELIB CMAKE_ARGS
240: _USE_VARS.pyversion= \
241: PKGNAME_REQD PKGNAME_OLD LOCALBASE PREFIX BUILDLINK_DIR PKGNAME
242: _DEF_VARS.pyversion= \
243: CONFLICTS MULTI PLIST_VARS BUILDLINK_API_DEPENDS.${PYPACKAGE} \
244: PYDEPENDENCY PLIST.py2x PLIST.py3x PTHREAD_OPTS TOOL_DEPENDS \
245: TEST_DEPENDS BUILDLINK_DEPMETHOD.python PRINT_PLIST_AWK ALL_ENV \
246: _PYTHON_VERSIONS_ACCEPTED _PYTHON_VERSION
247: _IGN_VARS.pyversion= _PYTHON_*
248: _LISTED_VARS.pyversion= *_ARGS
249: _SORTED_VARS.pyversion= *_DEPENDS *_ENV
250:
1.2 drochner 251: .endif # PYTHON_PYVERSION_MK
CVSweb <webmaster@jp.NetBSD.org>