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

1.66    ! joerg       1: # $NetBSD: pyversion.mk,v 1.65 2009/02/18 05:50:31 obache 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.60      snj        11: #      Possible values: 21 23 24 25
1.65      obache     12: #      Default: 25
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.60      snj        21: #      Possible values: 25 24 23 21
1.59      tnn        22: #      Default: 25 24 23
1.44      rillig     23: #
                     24: # PYTHON_VERSIONS_INCOMPATIBLE
                     25: #      The Python versions that are NOT acceptable for the package.
                     26: #
1.60      snj        27: #      Possible values: 21 23 24 25
1.44      rillig     28: #      Default: (depends on the platform)
                     29: #
                     30: # PYTHON_FOR_BUILD_ONLY
                     31: #      Whether Python is needed only at build time or at run time.
                     32: #
                     33: #      Possible values: (defined) (undefined)
                     34: #      Default: (undefined)
                     35: #
1.52      rillig     36: # === Defined variables ===
                     37: #
                     38: # PYPKGPREFIX
                     39: #      The prefix to use in PKGNAME for extensions which are meant
                     40: #      to be installed for multiple Python versions.
                     41: #
                     42: #      Example: py24
                     43: #
                     44: # PYVERSSUFFIX
                     45: #      The suffix to executables and in the library path, equal to
                     46: #      sys.version[0:3].
                     47: #
                     48: #      Example: 2.4
                     49: #
1.46      rillig     50: # Keywords: python
                     51: #
1.2       drochner   52: 
                     53: .if !defined(PYTHON_PYVERSION_MK)
                     54: PYTHON_PYVERSION_MK=   defined
1.1       drochner   55: 
1.66    ! joerg      56: # derive a python version from the package name if possible
        !            57: # optionally handled quoted package names
        !            58: .if defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:Mpy[0-9][0-9]-*) || \
        !            59:     defined(PKGNAME_REQD) && !empty(PKGNAME_REQD:M*-py[0-9][0-9]-*)
        !            60: PYTHON_VERSION_REQD?= ${PKGNAME_REQD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
        !            61: .elif defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:Mpy[0-9][0-9]-*) || \
        !            62:       defined(PKGNAME_OLD) && !empty(PKGNAME_OLD:M*-py[0-9][0-9]-*)
        !            63: PYTHON_VERSION_REQD?= ${PKGNAME_OLD:C/(^.*-|^)py([0-9][0-9])-.*/\2/}
        !            64: .endif
        !            65: 
1.1       drochner   66: .include "../../mk/bsd.prefs.mk"
                     67: 
1.46      rillig     68: BUILD_DEFS+=           PYTHON_VERSION_DEFAULT
                     69: BUILD_DEFS_EFFECTS+=   PYPACKAGE
                     70: 
1.64      joerg      71: PYTHON_VERSION_DEFAULT?=               25
1.59      tnn        72: PYTHON_VERSIONS_ACCEPTED?=             25 24 23
1.56      joerg      73: PYTHON_VERSIONS_INCOMPATIBLE?=         # empty by default
                     74: 
1.39      reed       75: BUILDLINK_API_DEPENDS.python23?=               python23>=2.3
                     76: BUILDLINK_API_DEPENDS.python24?=               python24>=2.4
1.50      xtraeme    77: BUILDLINK_API_DEPENDS.python25?=               python25>=2.5.1
1.4       drochner   78: 
1.1       drochner   79: # transform the list into individual variables
                     80: .for pv in ${PYTHON_VERSIONS_ACCEPTED}
1.28      tv         81: .if empty(PYTHON_VERSIONS_INCOMPATIBLE:M${pv})
1.1       drochner   82: _PYTHON_VERSION_${pv}_OK=      yes
1.56      joerg      83: _PYTHON_VERSIONS_ACCEPTED+=    ${pv}
1.28      tv         84: .endif
1.1       drochner   85: .endfor
                     86: 
                     87: #
                     88: # choose a python version where to add,
                     89: # try to be intelligent
                     90: #
1.2       drochner   91: # if a version is explicitely required, take it
                     92: .if defined(PYTHON_VERSION_REQD)
1.40      joerg      93: # but check if it is acceptable first, error out otherwise
                     94: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_REQD}_OK)
1.2       drochner   95: _PYTHON_VERSION=       ${PYTHON_VERSION_REQD}
1.40      joerg      96: . endif
                     97: .else
                     98: # if the default is accepted, it is first choice
                     99: . if !defined(_PYTHON_VERSION)
                    100: . if defined(_PYTHON_VERSION_${PYTHON_VERSION_DEFAULT}_OK)
1.1       drochner  101: _PYTHON_VERSION=       ${PYTHON_VERSION_DEFAULT}
1.40      joerg     102: . endif
                    103: . endif
1.1       drochner  104: # prefer an already installed version, in order of "accepted"
1.40      joerg     105: . if !defined(_PYTHON_VERSION)
                    106: . for pv in ${PYTHON_VERSIONS_ACCEPTED}
                    107: . if defined(_PYTHON_VERSION_${pv}_OK)
1.1       drochner  108: _PYTHON_VERSION?=      ${pv}
1.40      joerg     109: . endif
                    110: . endfor
                    111: . endif
1.1       drochner  112: .endif
1.40      joerg     113: 
                    114: # No supported version found, annotate to simplify statements below.
1.1       drochner  115: .if !defined(_PYTHON_VERSION)
1.40      joerg     116: _PYTHON_VERSION=       none
1.1       drochner  117: .endif
                    118: 
1.57      tnn       119: .if ${_PYTHON_VERSION} == "25"
                    120: PYPKGSRCDIR=   ../../lang/python25
1.50      xtraeme   121: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python25}:${PYPKGSRCDIR}
                    122: PYPACKAGE=     python25
                    123: PYVERSSUFFIX=  2.5
                    124: PYPKGPREFIX=   py25
                    125: .elif ${_PYTHON_VERSION} == "24"
1.30      recht     126: PYPKGSRCDIR=   ../../lang/python24
1.39      reed      127: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python24}:${PYPKGSRCDIR}
1.30      recht     128: PYPACKAGE=     python24
                    129: PYVERSSUFFIX=  2.4
                    130: PYPKGPREFIX=   py24
                    131: .elif ${_PYTHON_VERSION} == "23"
1.21      drochner  132: PYPKGSRCDIR=   ../../lang/python23
1.39      reed      133: PYDEPENDENCY=  ${BUILDLINK_API_DEPENDS.python23}:${PYPKGSRCDIR}
1.21      drochner  134: PYPACKAGE=     python23
                    135: PYVERSSUFFIX=  2.3
                    136: PYPKGPREFIX=   py23
1.8       drochner  137: .else
1.48      rillig    138: PKG_FAIL_REASON+=   "No valid Python version"
1.1       drochner  139: .endif
1.5       drochner  140: 
1.38      rillig    141: PTHREAD_OPTS+= require
1.33      jlam      142: .include "../../mk/pthread.buildlink3.mk"
1.38      rillig    143: 
1.33      jlam      144: .if defined(PYTHON_FOR_BUILD_ONLY)
1.36      seb       145: BUILDLINK_DEPMETHOD.python?=   build
1.11      jlam      146: .endif
1.37      kristerw  147: .if defined(PYPKGSRCDIR)
1.33      jlam      148: .include "${PYPKGSRCDIR}/buildlink3.mk"
1.37      kristerw  149: .endif
1.11      jlam      150: 
                    151: PYTHONBIN=     ${LOCALBASE}/bin/python${PYVERSSUFFIX}
                    152: 
1.61      snj       153: .if exists(${PYTHONBIN})
1.11      jlam      154: PYINC!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
                    155:        print distutils.sysconfig.get_python_inc(0, \"\")" || ${ECHO} ""
                    156: PYLIB!=        ${PYTHONBIN} -c "import distutils.sysconfig; \
                    157:        print distutils.sysconfig.get_python_lib(0, 1, \"\")" || ${ECHO} ""
                    158: PYSITELIB!=    ${PYTHONBIN} -c "import distutils.sysconfig; \
                    159:        print distutils.sysconfig.get_python_lib(0, 0, \"\")" || ${ECHO} ""
1.29      recht     160: 
                    161: PRINT_PLIST_AWK+=      /^@dirrm ${PYINC:S|/|\\/|g}$$/ { next; }
                    162: PRINT_PLIST_AWK+=      /^@dirrm ${PYSITELIB:S|/|\\/|g}$$/ { next; }
                    163: PRINT_PLIST_AWK+=      /^@dirrm ${PYLIB:S|/|\\/|g}$$/ { next; }
                    164: 
                    165: PRINT_PLIST_AWK+=      /^(@dirrm )?${PYINC:S|/|\\/|g}/ \
                    166:                        { gsub(/${PYINC:S|/|\\/|g}/, "$${PYINC}"); \
                    167:                                print; next; }
                    168: PRINT_PLIST_AWK+=      /^(@dirrm )?${PYSITELIB:S|/|\\/|g}/ \
                    169:                        { gsub(/${PYSITELIB:S|/|\\/|g}/, "$${PYSITELIB}"); \
                    170:                                print; next; }
                    171: PRINT_PLIST_AWK+=      /^(@dirrm )?${PYLIB:S|/|\\/|g}/ \
                    172:                        { gsub(/${PYLIB:S|/|\\/|g}/, "$${PYLIB}"); \
                    173:                                print; next; }
1.6       drochner  174: .endif
1.2       drochner  175: 
1.47      rillig    176: ALL_ENV+=      PYTHON=${PYTHONBIN}
                    177: 
1.2       drochner  178: .endif # PYTHON_PYVERSION_MK

CVSweb <webmaster@jp.NetBSD.org>