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

1.102   ! wiz         1: # $NetBSD: pyversion.mk,v 1.101 2012/09/16 20:03:50 cheusov 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.102   ! wiz        11: #      Possible values: 26 27 31 32
1.96      wiz        12: #      Default: 27
1.44      rillig     13: #
1.101     cheusov    14: # PYTHON_VERSION_REQD
                     15: #      Python version to use. This is a user variable and
                     16: #      should not be set in packages.
                     17: #      Normally it is used by bulk build tools.
                     18: #
                     19: #      Possible: ${PYTHON_VERSIONS_ACCEPTED}
                     20: #      Default:  ${PYTHON_VERSION_DEFAULT}
                     21: #
1.48      rillig     22: # === Package-settable variables ===
1.44      rillig     23: #
                     24: # PYTHON_VERSIONS_ACCEPTED
                     25: #      The Python versions that are acceptable for the package. The
1.48      rillig     26: #      order of the entries matters, since earlier entries are
1.62      joerg      27: #      preferred over later ones.
1.44      rillig     28: #
1.102   ! wiz        29: #      Possible values: 32 31 27 26
        !            30: #      Default: (32 31) 27 26
1.92      joerg      31: #
                     32: # PYTHON_VERSIONS_INCLUDE_3X
                     33: #      Wether the default PYTHON_VERSIONS_ACCEPTED should include
                     34: #      3.x versions for for this package or not.
                     35: #      This variable must be set before including bsd.prefs.mk.
                     36: #
                     37: #      Possible values: yes no
                     38: #      Default: no
1.44      rillig     39: #
                     40: # PYTHON_VERSIONS_INCOMPATIBLE
                     41: #      The Python versions that are NOT acceptable for the package.
                     42: #
1.102   ! wiz        43: #      Possible values: 26 27 31 32
1.44      rillig     44: #      Default: (depends on the platform)
                     45: #
                     46: # PYTHON_FOR_BUILD_ONLY
                     47: #      Whether Python is needed only at build time or at run time.
                     48: #
                     49: #      Possible values: (defined) (undefined)
                     50: #      Default: (undefined)
                     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]-*)
                     76: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
                     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]-*)
                     79: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
                     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.96      wiz        87: PYTHON_VERSION_DEFAULT?=               27
1.92      joerg      88: .if ${PYTHON_VERSIONS_INCLUDE_3X:U:tl} == "yes"
1.102   ! wiz        89: PYTHON_VERSIONS_ACCEPTED?=             32 31 27 26
1.92      joerg      90: .else
1.102   ! wiz        91: PYTHON_VERSIONS_ACCEPTED?=             27 26
1.92      joerg      92: .endif
1.56      joerg      93: PYTHON_VERSIONS_INCOMPATIBLE?=         # empty by default
                     94: 
1.70      snj        95: BUILDLINK_API_DEPENDS.python26?=               python26>=2.6
1.84      obache     96: BUILDLINK_API_DEPENDS.python27?=               python27>=2.7
1.89      reed       97: BUILDLINK_API_DEPENDS.python31?=               python31>=3.1
1.99      obache     98: BUILDLINK_API_DEPENDS.python32?=               python32>=3.2
1.4       drochner   99: 
1.1       drochner  100: # transform the list into individual variables
                    101: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.28      tv        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.28      tv        105: .endif
1.1       drochner  106: .endfor
                    107: 
                    108: #
                    109: # choose a python version where to add,
                    110: # try to be intelligent
                    111: #
1.2       drochner  112: # if a version is explicitely required, take it
                    113: .if defined(PYTHON_VERSION_REQD)
1.40      joerg     114: # but check if it is acceptable first, error out otherwise
                    115: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2       drochner  116: _PYTHON_VERSION=       ${PYTHON_VERSION_REQD}
1.40      joerg     117: . endif
                    118: .else
                    119: # if the default is accepted, it is first choice
                    120: . if !defined(_PYTHON_VERSION)
                    121: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1       drochner  122: _PYTHON_VERSION=       ${PYTHON_VERSION_DEFAULT}
1.40      joerg     123: . endif
                    124: . endif
1.1       drochner  125: # prefer an already installed version, in order of "accepted"
1.40      joerg     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.40      joerg     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.1       drochner  142: .endif
                    143: 
1.100     drochner  144: PLIST_VARS+=   py2x py3x
                    145: 
1.99      obache    146: .if ${_PYTHON_VERSION} == "32"
                    147: PYPKGSRCDIR=   ../../lang/python32
                    148: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python32}:${PYPKGSRCDIR}
                    149: PYPACKAGE=     python32
                    150: PYVERSSUFFIX=  3.2
                    151: PYPKGPREFIX=   py32
1.100     drochner  152: PLIST.py3x=    yes
1.99      obache    153: .elif ${_PYTHON_VERSION} == "31"
1.89      reed      154: PYPKGSRCDIR=   ../../lang/python31
1.90      reed      155: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python31}:${PYPKGSRCDIR}
1.89      reed      156: PYPACKAGE=     python31
                    157: PYVERSSUFFIX=  3.1
                    158: PYPKGPREFIX=   py31
1.100     drochner  159: PLIST.py3x=    yes
1.89      reed      160: .elif ${_PYTHON_VERSION} == "27"
1.83      obache    161: PYPKGSRCDIR=   ../../lang/python27
                    162: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python27}:${PYPKGSRCDIR}
                    163: PYPACKAGE=     python27
                    164: PYVERSSUFFIX=  2.7
                    165: PYPKGPREFIX=   py27
1.100     drochner  166: PLIST.py2x=    yes
1.83      obache    167: .elif ${_PYTHON_VERSION} == "26"
1.68      wiz       168: PYPKGSRCDIR=   ../../lang/python26
                    169: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python26}:${PYPKGSRCDIR}
                    170: PYPACKAGE=     python26
                    171: PYVERSSUFFIX=  2.6
                    172: PYPKGPREFIX=   py26
1.100     drochner  173: PLIST.py2x=    yes
1.8       drochner  174: .else
1.48      rillig    175: PKG_FAIL_REASON+=   "No valid Python version"
1.93      joerg     176: PYPKGPREFIX=
1.1       drochner  177: .endif
1.5       drochner  178: 
1.38      rillig    179: PTHREAD_OPTS+= require
1.33      jlam      180: .include "../../mk/pthread.buildlink3.mk"
1.38      rillig    181: 
1.33      jlam      182: .if defined(PYTHON_FOR_BUILD_ONLY)
1.36      seb       183: BUILDLINK_DEPMETHOD.python?=   build
1.11      jlam      184: .endif
1.37      kristerw  185: .if defined(PYPKGSRCDIR)
1.33      jlam      186: .include "${PYPKGSRCDIR}/buildlink3.mk"
1.37      kristerw  187: .endif
1.11      jlam      188: 
                    189: PYTHONBIN=     ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.78      joerg     190: PYTHONCONFIG=  ${LOCALBASE}/bin/python${PYVERSSUFFIX}-config
1.73      joerg     191: PY_COMPILE_ALL= \
                    192:        ${PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
                    193: PY_COMPILE_O_ALL= \
                    194:        ${PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11      jlam      195: 
1.61      snj       196: .if exists(${PYTHONBIN})
1.11      jlam      197: PYINC!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    198:        print (distutils.sysconfig.get_python_inc(0, \"\"))" || ${ECHO} ""
1.11      jlam      199: PYLIB!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    200:        print (distutils.sysconfig.get_python_lib(0, 1, \"\"))" || ${ECHO} ""
1.11      jlam      201: PYSITELIB!=    ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    202:        print (distutils.sysconfig.get_python_lib(0, 0, \"\"))" || ${ECHO} ""
1.72      joerg     203: 
                    204: PRINT_PLIST_AWK+=      /^${PYINC:S|/|\\/|g}/ \
1.82      obache    205:                        { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.72      joerg     206: PRINT_PLIST_AWK+=      /^${PYSITELIB:S|/|\\/|g}/ \
1.82      obache    207:                        { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.72      joerg     208: PRINT_PLIST_AWK+=      /^${PYLIB:S|/|\\/|g}/ \
1.82      obache    209:                        { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.6       drochner  210: .endif
1.2       drochner  211: 
1.47      rillig    212: ALL_ENV+=      PYTHON=${PYTHONBIN}
1.80      drochner  213: .if defined(USE_CMAKE)
                    214: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
                    215: CMAKE_ARGS+=   -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
                    216: .endif
1.47      rillig    217: 
1.2       drochner  218: .endif # PYTHON_PYVERSION_MK

CVSweb <webmaster@jp.NetBSD.org>