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

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

CVSweb <webmaster@jp.NetBSD.org>