Annotation of pkgsrc/lang/python/pyversion.mk, revision 1.170

1.170   ! wiz         1: # $NetBSD: pyversion.mk,v 1.169 2025/06/16 09:27:03 jperkin 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.170   ! wiz        14: #      Possible values: 27 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.170   ! wiz        33: #      Possible values: 313 312 311 27
        !            34: #      Default: 313 312 311
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.168     tnn       100: .include "../../mk/bsd.fast.prefs.mk"
1.1       drochner  101: 
1.46      rillig    102: BUILD_DEFS+=           PYTHON_VERSION_DEFAULT
                    103: BUILD_DEFS_EFFECTS+=   PYPACKAGE
                    104: 
1.163     wiz       105: PYTHON_VERSION_DEFAULT?=               312
1.170   ! wiz       106: PYTHON_VERSIONS_ACCEPTED?=             313 312 311
1.160     wiz       107: .if defined(PYTHON_27_ACCEPTED)
                    108: PYTHON_VERSIONS_ACCEPTED+=             27
                    109: .endif
1.56      joerg     110: PYTHON_VERSIONS_INCOMPATIBLE?=         # empty by default
                    111: 
1.1       drochner  112: # transform the list into individual variables
                    113: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.121     rillig    114: .  if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
1.1       drochner  115: _PYTHON_VERSION_${pv}_OK=      yes
1.56      joerg     116: _PYTHON_VERSIONS_ACCEPTED+=    ${pv}
1.121     rillig    117: .  endif
1.1       drochner  118: .endfor
                    119: 
                    120: #
                    121: # choose a python version where to add,
                    122: # try to be intelligent
                    123: #
1.136     gutterid  124: # if a version is explicitly required, take it
1.2       drochner  125: .if defined(PYTHON_VERSION_REQD)
1.40      joerg     126: # but check if it is acceptable first, error out otherwise
1.121     rillig    127: .  if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2       drochner  128: _PYTHON_VERSION=       ${PYTHON_VERSION_REQD}
1.121     rillig    129: .  endif
1.40      joerg     130: .else
                    131: # if the default is accepted, it is first choice
1.121     rillig    132: .  if !defined(_PYTHON_VERSION)
                    133: .    if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1       drochner  134: _PYTHON_VERSION=       ${PYTHON_VERSION_DEFAULT}
1.121     rillig    135: .    endif
                    136: .  endif
1.1       drochner  137: # prefer an already installed version, in order of "accepted"
1.121     rillig    138: .  if !defined(_PYTHON_VERSION)
                    139: .    for pv in ${PYTHON_VERSIONS_ACCEPTED}
                    140: .      if defined(_PYTHON_VERSION_${pv}_OK)
1.1       drochner  141: _PYTHON_VERSION?=      ${pv}
1.121     rillig    142: .      endif
                    143: .    endfor
                    144: .  endif
1.1       drochner  145: .endif
1.40      joerg     146: 
1.87      wiz       147: #
                    148: # Variable assignment for multi-python packages
                    149: MULTI+=        PYTHON_VERSION_REQD=${_PYTHON_VERSION}
                    150: 
1.40      joerg     151: # No supported version found, annotate to simplify statements below.
1.1       drochner  152: .if !defined(_PYTHON_VERSION)
1.40      joerg     153: _PYTHON_VERSION=       none
1.148     wiz       154: # since no supported version is found and no build will happen,
                    155: # choose a numeric default
                    156: PYTHON_VERSION=                0
1.115     obache    157: PKG_FAIL_REASON+=      "No valid Python version"
1.142     gdt       158: PYPKGPREFIX=           none
                    159: PYVERSSUFFIX=          none
1.148     wiz       160: .else
                    161: PYTHON_VERSION=                ${_PYTHON_VERSION:C/^(.)(.)$/\10\2/}
1.1       drochner  162: .endif
                    163: 
1.103     cheusov   164: # Additional CONFLICTS
                    165: .if ${PYTHON_SELF_CONFLICT:U:tl} == "yes"
1.121     rillig    166: .  for i in ${PYTHON_VERSIONS_ACCEPTED:N${_PYTHON_VERSION}}
1.134     nia       167: .    if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${i})
1.121     rillig    168: CONFLICTS+=    ${PKGNAME:S/py${_PYTHON_VERSION}/py${i}/:C/-[0-9].*$/-[0-9]*/}
1.134     nia       169: .    endif
1.121     rillig    170: .  endfor
1.103     cheusov   171: .endif # PYCONFLICTS
                    172: 
                    173: #
1.100     drochner  174: PLIST_VARS+=   py2x py3x
                    175: 
1.115     obache    176: .if empty(_PYTHON_VERSION:Mnone)
1.121     rillig    177: PYPACKAGE=                             python${_PYTHON_VERSION}
                    178: PYVERSSUFFIX=                          ${_PYTHON_VERSION:C/^([0-9])/\1./1}
                    179: BUILDLINK_API_DEPENDS.${PYPACKAGE}?=   ${PYPACKAGE}>=${PYVERSSUFFIX}
                    180: PYPKGSRCDIR=                           ../../lang/${PYPACKAGE}
1.149     riastrad  181: PYDEPENDENCY=                          ${BUILDLINK_API_DEPENDS.${PYPACKAGE}:=:${PYPKGSRCDIR}}
1.121     rillig    182: PYPKGPREFIX=                           py${_PYTHON_VERSION}
1.115     obache    183: .endif
1.114     obache    184: .if !empty(_PYTHON_VERSION:M3*)
1.121     rillig    185: PLIST.py3x=                            yes
1.114     obache    186: .endif
                    187: .if !empty(_PYTHON_VERSION:M2*)
1.121     rillig    188: PLIST.py2x=                            yes
1.1       drochner  189: .endif
1.5       drochner  190: 
1.38      rillig    191: PTHREAD_OPTS+= require
1.33      jlam      192: .include "../../mk/pthread.buildlink3.mk"
1.38      rillig    193: 
1.109     riastrad  194: PYTHON_FOR_BUILD_ONLY?=                no
1.37      kristerw  195: .if defined(PYPKGSRCDIR)
1.108     riastrad  196: .  if !empty(PYTHON_FOR_BUILD_ONLY:M[tT][oO][oO][lL])
                    197: TOOL_DEPENDS+=                 ${PYDEPENDENCY}
1.125     ryoon     198: .  elif !empty(PYTHON_FOR_BUILD_ONLY:M[tT][eE][sS][tT])
                    199: TEST_DEPENDS+=                 ${PYDEPENDENCY}
1.107     riastrad  200: .  else
1.108     riastrad  201: .    if !empty(PYTHON_FOR_BUILD_ONLY:M[yY][eE][sS])
                    202: BUILDLINK_DEPMETHOD.python?=   build
1.169     jperkin   203: .    else
                    204: BUILDLINK_DEPMETHOD.python?=   full
1.108     riastrad  205: .    endif
1.107     riastrad  206: .    include "${PYPKGSRCDIR}/buildlink3.mk"
1.167     riastrad  207: .    if ${USE_CROSS_COMPILE:tl} == "yes"
1.150     riastrad  208: TOOL_DEPENDS+=                 ${PYDEPENDENCY}
                    209: MAKE_ENV+=                     PYTHONPATH=${WRKDIR:Q}/.pysite:${_CROSS_DESTDIR:Q}${LOCALBASE:Q}/${PYLIB:Q}
                    210: pre-configure: ${WRKDIR}/.pysite/sitecustomize.py
1.151     riastrad  211: .include "${PYPKGSRCDIR}/platname.mk"
1.150     riastrad  212: ${WRKDIR}/.pysite/sitecustomize.py:
                    213:        @${STEP_MSG} "Creating Python sitecustomize.py for cross-compiling"
                    214:        ${RUN} ${MKDIR} ${.TARGET:H}
                    215:        ${RUN} ( \
                    216:                ${ECHO} "import sys" && \
1.151     riastrad  217:                ${PRINTF} "sys.platform = '%s'\\n" ${PY_PLATNAME:Q} && \
1.150     riastrad  218:                for v in \
                    219:                        sys.base_exec_prefix \
                    220:                        sys.base_prefix \
                    221:                        sys.exec_prefix \
                    222:                        sys.prefix \
                    223:                ; do \
                    224:                        ${PRINTF} "%s = '%s'\\n" "$$v" ${LOCALBASE:Q}; \
                    225:                done; \
                    226:        ) >${.TARGET}.tmp
                    227:        ${RUN} ${MV} -f ${.TARGET}.tmp ${.TARGET}
                    228: .    endif
1.107     riastrad  229: .  endif
1.37      kristerw  230: .endif
1.11      jlam      231: 
                    232: PYTHONBIN=     ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.150     riastrad  233: TOOL_PYTHONBIN=        ${TOOLBASE}/bin/python${PYVERSSUFFIX}
                    234: .if exists(${TOOL_PYTHONBIN}m)
                    235: PYTHONCONFIG=  ${TOOLBASE}/bin/python${PYVERSSUFFIX}m-config
1.127     markd     236: .else
1.150     riastrad  237: PYTHONCONFIG=  ${TOOLBASE}/bin/python${PYVERSSUFFIX}-config
1.127     markd     238: .endif
1.73      joerg     239: PY_COMPILE_ALL= \
1.150     riastrad  240:        ${TOOL_PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.73      joerg     241: PY_COMPILE_O_ALL= \
1.150     riastrad  242:        ${TOOL_PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11      jlam      243: 
1.139     adam      244: PYINC=         include/python${PYVERSSUFFIX}
                    245: PYLIB=         lib/python${PYVERSSUFFIX}
                    246: PYSITELIB=     ${PYLIB}/site-packages
1.72      joerg     247: 
1.161     hauke     248: # Expect paths directly under PREFIX, but allow for ${PLIST.*} prefix(es)
                    249: PRINT_PLIST_AWK+=      /(^|^\$$.+\})${PYINC:S|/|\\/|g}/ \
1.82      obache    250:                        { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.161     hauke     251: PRINT_PLIST_AWK+=      /(^|^\$$.+\})${PYSITELIB:S|/|\\/|g}/ \
1.82      obache    252:                        { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.161     hauke     253: PRINT_PLIST_AWK+=      /(^|^\$$.+\})${PYLIB:S|/|\\/|g}/ \
1.82      obache    254:                        { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.2       drochner  255: 
1.150     riastrad  256: ALL_ENV+=              PYTHON=${TOOL_PYTHONBIN}
1.147     gdt       257: .if defined(USE_CMAKE) || defined(BUILD_USES_CMAKE)
1.135     nia       258: # used by FindPython
1.164     wiz       259: CMAKE_CONFIGURE_ARGS+=         -DPython_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
                    260: CMAKE_CONFIGURE_ARGS+=         -DPython_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135     nia       261: # used by FindPython2
                    262: .  if !empty(_PYTHON_VERSION:M2*)
1.164     wiz       263: CMAKE_CONFIGURE_ARGS+=         -DPython2_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
                    264: CMAKE_CONFIGURE_ARGS+=         -DPython2_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135     nia       265: .  endif
                    266: # used by FindPython3
                    267: .  if !empty(_PYTHON_VERSION:M3*)
1.164     wiz       268: CMAKE_CONFIGURE_ARGS+=         -DPython3_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
                    269: CMAKE_CONFIGURE_ARGS+=         -DPython3_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
1.135     nia       270: .  endif
1.80      drochner  271: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
1.164     wiz       272: CMAKE_CONFIGURE_ARGS+=         -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
1.116     dbj       273: # set this explicitly, as by default it will prefer the built in framework
1.126     bsiegert  274: # on Darwin
1.164     wiz       275: CMAKE_CONFIGURE_ARGS+=         -DPYTHON_INCLUDE_DIR:PATH=${BUILDLINK_DIR}/${PYINC}
                    276: CMAKE_CONFIGURE_ARGS+=         -DPYTHON_INCLUDE_PATH:PATH=${BUILDLINK_DIR}/${PYINC}
                    277: CMAKE_CONFIGURE_ARGS+=         -DPYTHON_EXECUTABLE:FILEPATH=${TOOL_PYTHONBIN}
1.80      drochner  278: .endif
1.47      rillig    279: 
1.131     rillig    280: _VARGROUPS+=           pyversion
                    281: _USER_VARS.pyversion=  PYTHON_VERSION_DEFAULT
                    282: _PKG_VARS.pyversion=   \
                    283:        PYTHON_VERSIONS_ACCEPTED PYTHON_VERSIONS_INCOMPATIBLE           \
1.147     gdt       284:        PYTHON_SELF_CONFLICT PYTHON_FOR_BUILD_ONLY USE_CMAKE BUILD_USES_CMAKE
1.131     rillig    285: _SYS_VARS.pyversion=   \
1.161     hauke     286:        PYTHON_VERSION PYTHON_VERSION_REQD PYPACKAGE PYVERSSUFFIX       \
                    287:        PYPKGSRCDIR PYPKGPREFIX PYTHONBIN PYTHONCONFIG PY_COMPILE_ALL   \
1.164     wiz       288:        PY_COMPILE_O_ALL PYINC PYLIB PYSITELIB CMAKE_CONFIGURE_ARGS             \
1.150     riastrad  289:        TOOL_PYTHONBIN
1.131     rillig    290: _USE_VARS.pyversion=   \
                    291:        PKGNAME_REQD PKGNAME_OLD LOCALBASE PREFIX BUILDLINK_DIR PKGNAME
                    292: _DEF_VARS.pyversion=   \
                    293:        CONFLICTS MULTI PLIST_VARS BUILDLINK_API_DEPENDS.${PYPACKAGE}   \
                    294:        PYDEPENDENCY PLIST.py2x PLIST.py3x PTHREAD_OPTS TOOL_DEPENDS    \
                    295:        TEST_DEPENDS BUILDLINK_DEPMETHOD.python PRINT_PLIST_AWK ALL_ENV \
                    296:        _PYTHON_VERSIONS_ACCEPTED _PYTHON_VERSION
                    297: _IGN_VARS.pyversion=   _PYTHON_*
                    298: _LISTED_VARS.pyversion=        *_ARGS
                    299: _SORTED_VARS.pyversion=        *_DEPENDS *_ENV
                    300: 
1.2       drochner  301: .endif # PYTHON_PYVERSION_MK

CVSweb <webmaster@jp.NetBSD.org>