python.port.mk 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # $OpenBSD: python.port.mk,v 1.94 2017/04/19 07:41:00 ajacoutot Exp $
  2. #
  3. # python.port.mk - Xavier Santolaria <xavier@santolaria.net>
  4. # This file is in the public domain.
  5. CATEGORIES += lang/python
  6. # define the default versions
  7. MODPY_DEFAULT_VERSION_2 = 2.7
  8. MODPY_DEFAULT_VERSION_3 = 3.6
  9. .if !defined(MODPY_VERSION)
  10. FLAVOR ?=
  11. . if ${FLAVOR:Mpython3}
  12. # define default version 3
  13. MODPY_VERSION ?= ${MODPY_DEFAULT_VERSION_3}
  14. . else
  15. # without flavor, assume we use the default version 2
  16. MODPY_VERSION ?= ${MODPY_DEFAULT_VERSION_2}
  17. . endif
  18. # verify if MODPY_VERSION forced is correct
  19. .else
  20. . if ${MODPY_VERSION} != "2.7" && \
  21. ${MODPY_VERSION} != "3.4" && \
  22. ${MODPY_VERSION} != "3.5" && \
  23. ${MODPY_VERSION} != "3.6"
  24. ERRORS += "Fatal: unknown or unsupported MODPY_VERSION: ${MODPY_VERSION}"
  25. . endif
  26. .endif
  27. MODPY_MAJOR_VERSION = ${MODPY_VERSION:R}
  28. .if ${MODPY_MAJOR_VERSION} == 2
  29. MODPY_LIB_SUFFIX =
  30. MODPY_FLAVOR =
  31. MODPY_BIN_SUFFIX =
  32. MODPY_PY_PREFIX = py-
  33. MODPY_PYCACHE =
  34. MODPY_PYC_MAGIC_TAG =
  35. MODPY_COMMENT = "@comment "
  36. MODPY_ABI3SO =
  37. .elif ${MODPY_MAJOR_VERSION} == 3
  38. MODPY_LIB_SUFFIX = m
  39. # replace py- prefix by py3-
  40. FULLPKGNAME ?= ${PKGNAME:S/^py-/py3-/}${FLAVOR_EXT:S/-python3//}
  41. MODPY_FLAVOR = ,python3
  42. # use MODPY_SUFFIX for binaries to avoid conflict
  43. MODPY_BIN_SUFFIX = -3
  44. MODPY_PY_PREFIX = py3-
  45. MODPY_PYCACHE = "__pycache__/"
  46. MODPY_MAJORMINOR = ${MODPY_VERSION:C/\.//g}
  47. MODPY_PYC_MAGIC_TAG = "cpython-${MODPY_MAJORMINOR}."
  48. MODPY_COMMENT =
  49. MODPY_ABI3SO = ".abi3"
  50. .endif
  51. .if ${MODPY_VERSION} == "2.7" || ${MODPY_VERSION} == "3.4"
  52. MODPY_PYOEXTENSION = pyo
  53. .else
  54. MODPY_PYOEXTENSION ?= opt-1.pyc
  55. .endif
  56. MODPY_WANTLIB = python${MODPY_VERSION}${MODPY_LIB_SUFFIX}
  57. MODPY_RUN_DEPENDS = lang/python/${MODPY_VERSION}
  58. MODPY_LIB_DEPENDS = lang/python/${MODPY_VERSION}
  59. _MODPY_BUILD_DEPENDS = lang/python/${MODPY_VERSION}
  60. MODPY_BUILDDEP ?= Yes
  61. MODPY_RUNDEP ?= Yes
  62. .if ${NO_BUILD:L} == "no" && ${MODPY_BUILDDEP:L} == "yes"
  63. BUILD_DEPENDS += ${_MODPY_BUILD_DEPENDS}
  64. .endif
  65. .if ${MODPY_RUNDEP:L} == "yes"
  66. RUN_DEPENDS += ${MODPY_RUN_DEPENDS}
  67. .endif
  68. _MODPY_PRE_BUILD_STEPS = :
  69. .if defined(MODPY_SETUPTOOLS) && ${MODPY_SETUPTOOLS:L} == "yes"
  70. # The setuptools module provides a package locator (site.py) that is
  71. # required at runtime for the pkg_resources stuff to work
  72. MODPY_SETUPUTILS_DEPEND ?= devel/py-setuptools${MODPY_FLAVOR}>=28.6.1v0
  73. MODPY_RUN_DEPENDS += ${MODPY_SETUPUTILS_DEPEND}
  74. BUILD_DEPENDS += ${MODPY_SETUPUTILS_DEPEND}
  75. MODPY_SETUPUTILS = Yes
  76. # The setuptools uses test target
  77. TEST_TARGET ?= test
  78. _MODPY_USERBASE =
  79. _MODPY_PRE_BUILD_STEPS += ;${MODPY_CMD} egg_info || true
  80. .else
  81. # Try to detect the case where a port will build regardless of setuptools
  82. # but the final plist will be different if it's present.
  83. _MODPY_SETUPUTILS_FAKE_DIR = \
  84. ${WRKDIR}/lib/python${MODPY_VERSION}/site-packages/setuptools
  85. _MODPY_PRE_BUILD_STEPS += \
  86. ;mkdir -p ${_MODPY_SETUPUTILS_FAKE_DIR} \
  87. ;exec 3>&1 \
  88. ;exec >${_MODPY_SETUPUTILS_FAKE_DIR}/__init__.py \
  89. ;echo 'def setup(*args, **kwargs):' \
  90. ;echo ' msg = "OpenBSD ports: MODPY_SETUPTOOLS = Yes is required"' \
  91. ;echo ' raise Exception(msg)' \
  92. ;echo 'Extension = Feature = find_packages = setup' \
  93. ;exec 1>&3
  94. MODPY_SETUPUTILS = No
  95. _MODPY_USERBASE = ${WRKDIR}
  96. .endif
  97. .if defined(MODPY_PI) && ${MODPY_PI:L} == "yes"
  98. _MODPY_EGG_NAME = ${DISTNAME:S/-${MODPY_EGG_VERSION}//}
  99. MODPY_PI_DIR ?= ${DISTNAME:C/^([a-zA-Z0-9]).*/\1/}/${_MODPY_EGG_NAME}
  100. MASTER_SITES = ${MASTER_SITE_PYPI:=${MODPY_PI_DIR}/}
  101. HOMEPAGE ?= https://pypi.python.org/pypi/${_MODPY_EGG_NAME}
  102. .endif
  103. MODPY_TKINTER_DEPENDS = lang/python/${MODPY_VERSION},-tkinter
  104. MODPY_BIN = ${LOCALBASE}/bin/python${MODPY_VERSION}
  105. MODPY_INCDIR = ${LOCALBASE}/include/python${MODPY_VERSION}${MODPY_LIB_SUFFIX}
  106. MODPY_LIBDIR = ${LOCALBASE}/lib/python${MODPY_VERSION}
  107. MODPY_SITEPKG = ${MODPY_LIBDIR}/site-packages
  108. # usually setup.py but Setup.py can be found too
  109. MODPY_SETUP ?= setup.py
  110. # build or build_ext are commonly used
  111. MODPY_DISTUTILS_BUILD ?= build --build-base=${WRKSRC}
  112. .if ${MODPY_SETUPUTILS:L} == "yes"
  113. MODPY_DISTUTILS_INSTALL ?= install --prefix=${LOCALBASE} \
  114. --root=${DESTDIR} \
  115. --single-version-externally-managed
  116. .else
  117. MODPY_DISTUTILS_INSTALL ?= install --prefix=${LOCALBASE} \
  118. --root=${DESTDIR}
  119. .endif
  120. MAKE_ENV += CC=${CC} PYTHONUSERBASE=${_MODPY_USERBASE}
  121. CONFIGURE_ENV += PYTHON="${MODPY_BIN}"
  122. .if ${CONFIGURE_STYLE:Mgnu}
  123. CONFIGURE_ENV += ac_cv_prog_PYTHON="${MODPY_BIN}" \
  124. ac_cv_path_PYTHON="${MODPY_BIN}"
  125. .endif
  126. MODPY_CMD = cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
  127. ${MODPY_BIN} ./${MODPY_SETUP} \
  128. ${MODPY_SETUP_ARGS}
  129. MODPY_TEST_CMD = cd ${WRKSRC} && ${SETENV} ${ALL_TEST_ENV} \
  130. ${MODPY_BIN} ./${MODPY_SETUP} \
  131. ${MODPY_SETUP_ARGS}
  132. SUBST_VARS := MODPY_PYCACHE MODPY_COMMENT MODPY_ABI3SO MODPY_PYC_MAGIC_TAG \
  133. MODPY_BIN MODPY_EGG_VERSION MODPY_VERSION MODPY_BIN_SUFFIX \
  134. MODPY_PY_PREFIX MODPY_PYOEXTENSION ${SUBST_VARS}
  135. # set MODPY_BIN for executable scripts
  136. MODPY_BIN_ADJ = perl -pi \
  137. -e '$$. == 1 && s|^.*env +python.*$$|\#!${MODPY_BIN}|;' \
  138. -e '$$. == 1 && s|^.*bin/python.*$$|\#!${MODPY_BIN}|;' \
  139. -e 'close ARGV if eof;'
  140. MODPY_ADJ_FILES ?=
  141. .if !empty(MODPY_ADJ_FILES)
  142. MODPYTHON_pre-configure += for f in ${MODPY_ADJ_FILES}; do \
  143. ${MODPY_BIN_ADJ} ${WRKSRC}/$${f}; done
  144. .endif
  145. MODPY_BUILD_TARGET = ${_MODPY_PRE_BUILD_STEPS}; \
  146. ${MODPY_CMD} ${MODPY_DISTUTILS_BUILD} ${MODPY_DISTUTILS_BUILDARGS}
  147. MODPY_INSTALL_TARGET = \
  148. ${MODPY_CMD} ${MODPY_DISTUTILS_BUILD} ${MODPY_DISTUTILS_BUILDARGS} \
  149. ${MODPY_DISTUTILS_INSTALL} ${MODPY_DISTUTILS_INSTALLARGS}
  150. MODPY_TEST_TARGET = \
  151. ${MODPY_TEST_CMD} ${TEST_TARGET}
  152. # dirty way to do it with no modifications in bsd.port.mk
  153. .if empty(CONFIGURE_STYLE)
  154. . if !target(do-build)
  155. do-build:
  156. @${MODPY_BUILD_TARGET}
  157. . endif
  158. # extra documentation or scripts should be installed via post-install
  159. . if !target(do-install)
  160. do-install:
  161. @${MODPY_INSTALL_TARGET}
  162. . endif
  163. # setuptools supports regress testing from setup.py using a standard target
  164. . if !target(do-test) && ${MODPY_SETUPUTILS:L} == "yes"
  165. do-test:
  166. @${MODPY_TEST_TARGET}
  167. . endif
  168. .endif