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

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

CVSweb <webmaster@jp.NetBSD.org>