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

1.97    ! wiz         1: # $NetBSD: pyversion.mk,v 1.96 2012/03/08 11:44:06 wiz 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.97    ! wiz        11: #      Possible values: 25 26 27 31
1.96      wiz        12: #      Default: 27
1.44      rillig     13: #
1.48      rillig     14: # === Package-settable variables ===
1.44      rillig     15: #
                     16: # PYTHON_VERSIONS_ACCEPTED
                     17: #      The Python versions that are acceptable for the package. The
1.48      rillig     18: #      order of the entries matters, since earlier entries are
1.62      joerg      19: #      preferred over later ones.
1.44      rillig     20: #
1.97    ! wiz        21: #      Possible values: 31 27 26 25
        !            22: #      Default: (31) 27 26 25
1.92      joerg      23: #
                     24: # PYTHON_VERSIONS_INCLUDE_3X
                     25: #      Wether the default PYTHON_VERSIONS_ACCEPTED should include
                     26: #      3.x versions for for this package or not.
                     27: #      This variable must be set before including bsd.prefs.mk.
                     28: #
                     29: #      Possible values: yes no
                     30: #      Default: no
1.44      rillig     31: #
                     32: # PYTHON_VERSIONS_INCOMPATIBLE
                     33: #      The Python versions that are NOT acceptable for the package.
                     34: #
1.97    ! wiz        35: #      Possible values: 25 26 27 31
1.44      rillig     36: #      Default: (depends on the platform)
                     37: #
                     38: # PYTHON_FOR_BUILD_ONLY
                     39: #      Whether Python is needed only at build time or at run time.
                     40: #
                     41: #      Possible values: (defined) (undefined)
                     42: #      Default: (undefined)
                     43: #
1.52      rillig     44: # === Defined variables ===
                     45: #
                     46: # PYPKGPREFIX
                     47: #      The prefix to use in PKGNAME for extensions which are meant
                     48: #      to be installed for multiple Python versions.
                     49: #
1.96      wiz        50: #      Example: py27
1.52      rillig     51: #
                     52: # PYVERSSUFFIX
                     53: #      The suffix to executables and in the library path, equal to
                     54: #      sys.version[0:3].
                     55: #
1.96      wiz        56: #      Example: 2.7
1.52      rillig     57: #
1.46      rillig     58: # Keywords: python
                     59: #
1.2       drochner   60: 
                     61: .if !defined(PYTHON_PYVERSION_MK)
                     62: PYTHON_PYVERSION_MK=   defined
1.1       drochner   63: 
1.66      joerg      64: # derive a python version from the package name if possible
                     65: # optionally handled quoted package names
                     66: .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
                     67:     defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9]-*)
                     68: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
                     69: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
                     70:       defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9]-*)
                     71: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
                     72: .endif
                     73: 
1.1       drochner   74: .include "../../mk/bsd.prefs.mk"
                     75: 
1.46      rillig     76: BUILD_DEFS+=           PYTHON_VERSION_DEFAULT
                     77: BUILD_DEFS_EFFECTS+=   PYPACKAGE
                     78: 
1.96      wiz        79: PYTHON_VERSION_DEFAULT?=               27
1.92      joerg      80: .if ${PYTHON_VERSIONS_INCLUDE_3X:U:tl} == "yes"
1.97    ! wiz        81: PYTHON_VERSIONS_ACCEPTED?=             31 27 26 25
1.92      joerg      82: .else
1.97    ! wiz        83: PYTHON_VERSIONS_ACCEPTED?=             27 26 25
1.92      joerg      84: .endif
1.56      joerg      85: PYTHON_VERSIONS_INCOMPATIBLE?=         # empty by default
                     86: 
1.50      xtraeme    87: BUILDLINK_API_DEPENDS.python25?=               python25>=2.5.1
1.70      snj        88: BUILDLINK_API_DEPENDS.python26?=               python26>=2.6
1.84      obache     89: BUILDLINK_API_DEPENDS.python27?=               python27>=2.7
1.89      reed       90: BUILDLINK_API_DEPENDS.python31?=               python31>=3.1
1.4       drochner   91: 
1.1       drochner   92: # transform the list into individual variables
                     93: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.28      tv         94: .if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
1.1       drochner   95: _PYTHON_VERSION_${pv}_OK=      yes
1.56      joerg      96: _PYTHON_VERSIONS_ACCEPTED+=    ${pv}
1.28      tv         97: .endif
1.1       drochner   98: .endfor
                     99: 
                    100: #
                    101: # choose a python version where to add,
                    102: # try to be intelligent
                    103: #
1.2       drochner  104: # if a version is explicitely required, take it
                    105: .if defined(PYTHON_VERSION_REQD)
1.40      joerg     106: # but check if it is acceptable first, error out otherwise
                    107: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2       drochner  108: _PYTHON_VERSION=       ${PYTHON_VERSION_REQD}
1.40      joerg     109: . endif
                    110: .else
                    111: # if the default is accepted, it is first choice
                    112: . if !defined(_PYTHON_VERSION)
                    113: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1       drochner  114: _PYTHON_VERSION=       ${PYTHON_VERSION_DEFAULT}
1.40      joerg     115: . endif
                    116: . endif
1.1       drochner  117: # prefer an already installed version, in order of "accepted"
1.40      joerg     118: . if !defined(_PYTHON_VERSION)
                    119: . for pv in ${PYTHON_VERSIONS_ACCEPTED}
                    120: . if defined(_PYTHON_VERSION_${pv}_OK)
1.1       drochner  121: _PYTHON_VERSION?=      ${pv}
1.40      joerg     122: . endif
                    123: . endfor
                    124: . endif
1.1       drochner  125: .endif
1.40      joerg     126: 
1.87      wiz       127: #
                    128: # Variable assignment for multi-python packages
                    129: MULTI+=        PYTHON_VERSION_REQD=${_PYTHON_VERSION}
                    130: 
1.40      joerg     131: # No supported version found, annotate to simplify statements below.
1.1       drochner  132: .if !defined(_PYTHON_VERSION)
1.40      joerg     133: _PYTHON_VERSION=       none
1.1       drochner  134: .endif
                    135: 
1.89      reed      136: .if ${_PYTHON_VERSION} == "31"
                    137: PYPKGSRCDIR=   ../../lang/python31
1.90      reed      138: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python31}:${PYPKGSRCDIR}
1.89      reed      139: PYPACKAGE=     python31
                    140: PYVERSSUFFIX=  3.1
                    141: PYPKGPREFIX=   py31
1.91      joerg     142: PYDISTUTILS_CREATES_EGGFILES=  yes
1.89      reed      143: .elif ${_PYTHON_VERSION} == "27"
1.83      obache    144: PYPKGSRCDIR=   ../../lang/python27
                    145: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python27}:${PYPKGSRCDIR}
                    146: PYPACKAGE=     python27
                    147: PYVERSSUFFIX=  2.7
                    148: PYPKGPREFIX=   py27
                    149: PYDISTUTILS_CREATES_EGGFILES=  yes
                    150: .elif ${_PYTHON_VERSION} == "26"
1.68      wiz       151: PYPKGSRCDIR=   ../../lang/python26
                    152: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python26}:${PYPKGSRCDIR}
                    153: PYPACKAGE=     python26
                    154: PYVERSSUFFIX=  2.6
                    155: PYPKGPREFIX=   py26
1.81      gdt       156: PYDISTUTILS_CREATES_EGGFILES=  yes
1.68      wiz       157: .elif ${_PYTHON_VERSION} == "25"
1.57      tnn       158: PYPKGSRCDIR=   ../../lang/python25
1.50      xtraeme   159: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python25}:${PYPKGSRCDIR}
                    160: PYPACKAGE=     python25
                    161: PYVERSSUFFIX=  2.5
                    162: PYPKGPREFIX=   py25
1.81      gdt       163: PYDISTUTILS_CREATES_EGGFILES=  yes
1.8       drochner  164: .else
1.48      rillig    165: PKG_FAIL_REASON+=   "No valid Python version"
1.91      joerg     166: PYDISTUTILS_CREATES_EGGFILES=  no
1.93      joerg     167: PYPKGPREFIX=
1.1       drochner  168: .endif
1.5       drochner  169: 
1.38      rillig    170: PTHREAD_OPTS+= require
1.33      jlam      171: .include "../../mk/pthread.buildlink3.mk"
1.38      rillig    172: 
1.33      jlam      173: .if defined(PYTHON_FOR_BUILD_ONLY)
1.36      seb       174: BUILDLINK_DEPMETHOD.python?=   build
1.11      jlam      175: .endif
1.37      kristerw  176: .if defined(PYPKGSRCDIR)
1.33      jlam      177: .include "${PYPKGSRCDIR}/buildlink3.mk"
1.37      kristerw  178: .endif
1.11      jlam      179: 
                    180: PYTHONBIN=     ${LOCALBASE}/bin/python${PYVERSSUFFIX}
1.78      joerg     181: PYTHONCONFIG=  ${LOCALBASE}/bin/python${PYVERSSUFFIX}-config
1.73      joerg     182: PY_COMPILE_ALL= \
                    183:        ${PYTHONBIN} ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
                    184: PY_COMPILE_O_ALL= \
                    185:        ${PYTHONBIN} -O ${PREFIX}/lib/python${PYVERSSUFFIX}/compileall.py -q
1.11      jlam      186: 
1.61      snj       187: .if exists(${PYTHONBIN})
1.11      jlam      188: PYINC!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    189:        print (distutils.sysconfig.get_python_inc(0, \"\"))" || ${ECHO} ""
1.11      jlam      190: PYLIB!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    191:        print (distutils.sysconfig.get_python_lib(0, 1, \"\"))" || ${ECHO} ""
1.11      jlam      192: PYSITELIB!=    ${PYTHONBIN} -c "import distutils.sysconfig; \
1.85      obache    193:        print (distutils.sysconfig.get_python_lib(0, 0, \"\"))" || ${ECHO} ""
1.72      joerg     194: 
                    195: PRINT_PLIST_AWK+=      /^${PYINC:S|/|\\/|g}/ \
1.82      obache    196:                        { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}") }
1.72      joerg     197: PRINT_PLIST_AWK+=      /^${PYSITELIB:S|/|\\/|g}/ \
1.82      obache    198:                        { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}") }
1.72      joerg     199: PRINT_PLIST_AWK+=      /^${PYLIB:S|/|\\/|g}/ \
1.82      obache    200:                        { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}") }
1.6       drochner  201: .endif
1.2       drochner  202: 
1.47      rillig    203: ALL_ENV+=      PYTHON=${PYTHONBIN}
1.80      drochner  204: .if defined(USE_CMAKE)
                    205: # used by FindPythonInterp.cmake and FindPythonLibs.cmake
                    206: CMAKE_ARGS+=   -DPYVERSSUFFIX:STRING=${PYVERSSUFFIX}
                    207: .endif
1.47      rillig    208: 
1.2       drochner  209: .endif # PYTHON_PYVERSION_MK

CVSweb <webmaster@jp.NetBSD.org>