Annotation of pkgsrc/lang/python/pyversion.mk, revision 1.138
1.138 ! adam 1: # $NetBSD: pyversion.mk,v 1.137 2021/10/01 12:27:47 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.138 ! adam 11: # Possible values: 27 36 37 38 39 310
1.137 nia 12: # Default: 39
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.138 ! adam 30: # Possible values: 310 39 38 37 36 27
! 31: # Default: 310 39 38 37 36 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.138 ! adam 36: # Possible values: 27 36 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.137 nia 87: PYTHON_VERSION_DEFAULT?= 39
1.138 ! adam 88: PYTHON_VERSIONS_ACCEPTED?= 310 39 38 37 36 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.1 drochner 134: .endif
135:
1.103 cheusov 136: # Additional CONFLICTS
137: .if ${PYTHON_SELF_CONFLICT:U:tl} == "yes"
1.121 rillig 138: . for i in ${PYTHON_VERSIONS_ACCEPTED:N${_PYTHON_VERSION}}
1.134 nia 139: . if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${i})
1.121 rillig 140: CONFLICTS+= ${PKGNAME:S/py${_PYTHON_VERSION}/py${i}/:C/-[0-9].*$/-[0-9]*/}
1.134 nia 141: . endif
1.121 rillig 142: . endfor
1.103 cheusov 143: .endif # PYCONFLICTS
144:
145: #
1.100 drochner 146: PLIST_VARS+= py2x py3x
147:
1.115 obache 148: .if empty(_PYTHON_VERSION:Mnone)
1.121 rillig 149: PYPACKAGE= python${_PYTHON_VERSION}
150: PYVERSSUFFIX= ${_PYTHON_VERSION:C/^([0-9])/\1./1}
151: BUILDLINK_API_DEPENDS.${PYPACKAGE}?= ${PYPACKAGE}>=${PYVERSSUFFIX}
152: PYPKGSRCDIR= ../../lang/${PYPACKAGE}
153: PYDEPENDENCY= ${BUILDLINK_API_DEPENDS.${PYPACKAGE}}:${PYPKGSRCDIR}
154: PYPKGPREFIX= py${_PYTHON_VERSION}
1.115 obache 155: .endif
1.114 obache 156: .if !empty(_PYTHON_VERSION:M3*)
1.121 rillig 157: PLIST.py3x= yes
1.114 obache 158: .endif
159: .if !empty(_PYTHON_VERSION:M2*)
1.121 rillig 160: PLIST.py2x= yes
1.1 drochner 161: .endif
1.5 drochner 162:
1.38 rillig 163: PTHREAD_OPTS+= require
1.33 jlam 164: .include "../../mk/pthread.buildlink3.mk"
1.38 rillig 165:
1.109 riastrad 166: PYTHON_FOR_BUILD_ONLY?= no
1.37 kristerw 167: .if defined(PYPKGSRCDIR)
1.108 riastrad 168: . if !empty(PYTHON_FOR_BUILD_ONLY:M[tT][oO][oO][lL])
169: TOOL_DEPENDS+= ${PYDEPENDENCY}
1.125 ryoon 170: . elif !empty(PYTHON_FOR_BUILD_ONLY:M[tT][eE][sS][tT])
171: TEST_DEPENDS+= ${PYDEPENDENCY}
1.107 riastrad 172: . else
1.108 riastrad 173: . if !empty(PYTHON_FOR_BUILD_ONLY:M[yY][eE][sS])
174: BUILDLINK_DEPMETHOD.python?= build
175: . endif
1.107 riastrad 176: . include "${PYPKGSRCDIR}/buildlink3.mk"
177: . endif
1.37 kristerw 178: .endif
1.11 jlam 179:
180: PYTHONBIN= ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.127 markd 181: .if exists(${PYTHONBIN}m)
182: PYTHONCONFIG= ${LOCALBASE}/bin/python${PYVERSSUFFIX}m-config
183: .else
1.78 joerg 184: PYTHONCONFIG= ${LOCALBASE}/bin/python${PYVERSSUFFIX}-config
1.127 markd 185: .endif
1.73 joerg 186: PY_COMPILE_ALL= \
187: ${PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
188: PY_COMPILE_O_ALL= \
189: ${PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11 jlam 190:
1.61 snj 191: .if exists(${PYTHONBIN})
1.11 jlam 192: PYINC!= ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85 obache 193: print (distutils.sysconfig.get_python_inc(0, \"\"))" || ${ECHO} ""
1.11 jlam 194: PYLIB!= ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85 obache 195: print (distutils.sysconfig.get_python_lib(0, 1, \"\"))" || ${ECHO} ""
1.11 jlam 196: PYSITELIB!= ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85 obache 197: print (distutils.sysconfig.get_python_lib(0, 0, \"\"))" || ${ECHO} ""
1.72 joerg 198:
199: PRINT_PLIST_AWK+= /^${PYINC:S|/|\\/|g}/ \
1.82 obache 200: { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.72 joerg 201: PRINT_PLIST_AWK+= /^${PYSITELIB:S|/|\\/|g}/ \
1.82 obache 202: { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.72 joerg 203: PRINT_PLIST_AWK+= /^${PYLIB:S|/|\\/|g}/ \
1.82 obache 204: { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.6 drochner 205: .endif
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>