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