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

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

CVSweb <webmaster@jp.NetBSD.org>