pkg-perl.mk 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ################################################################################
  2. # Perl package infrastructure
  3. #
  4. # This file implements an infrastructure that eases development of
  5. # package .mk files for Perl packages.
  6. #
  7. # See the Buildroot documentation for details on the usage of this
  8. # infrastructure
  9. #
  10. # In terms of implementation, this perl infrastructure requires
  11. # the .mk file to only specify metadata information about the
  12. # package: name, version, download URL, etc.
  13. #
  14. # We still allow the package .mk file to override what the different
  15. # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
  16. # already defined, it is used as the list of commands to perform to
  17. # build the package, instead of the default perl behaviour. The
  18. # package can also define some post operation hooks.
  19. #
  20. ################################################################################
  21. PERL_ARCHNAME = $(ARCH)-linux
  22. PERL_RUN = PERL5LIB= PERL_USE_UNSAFE_INC=1 $(HOST_DIR)/bin/perl
  23. ################################################################################
  24. # inner-perl-package -- defines how the configuration, compilation and
  25. # installation of a perl package should be done, implements a
  26. # few hooks to tune the build process for perl specifities and
  27. # calls the generic package infrastructure to generate the necessary
  28. # make targets
  29. #
  30. # argument 1 is the lowercase package name
  31. # argument 2 is the uppercase package name, including a HOST_ prefix
  32. # for host packages
  33. # argument 3 is the uppercase package name, without the HOST_ prefix
  34. # for host packages
  35. # argument 4 is the type (target or host)
  36. ################################################################################
  37. define inner-perl-package
  38. # Target packages need both the perl interpreter on the target (for
  39. # runtime) and the perl interpreter on the host (for
  40. # compilation). However, host packages only need the perl
  41. # interpreter on the host.
  42. ifeq ($(4),target)
  43. $(2)_DEPENDENCIES += host-perl perl
  44. else
  45. $(2)_DEPENDENCIES += host-perl
  46. endif
  47. # From http://perldoc.perl.org/CPAN.html#Config-Variables - prefer_installer
  48. # legal values are MB and EUMM: if a module comes
  49. # with both a Makefile.PL and a Build.PL, use the
  50. # former (EUMM) or the latter (MB); if the module
  51. # comes with only one of the two, that one will be
  52. # used no matter the setting
  53. $(2)_PREFER_INSTALLER ?= MB
  54. #
  55. # Configure step. Only define it if not already defined by the package
  56. # .mk file. And take care of the differences between host and target
  57. # packages.
  58. #
  59. ifndef $(2)_CONFIGURE_CMDS
  60. ifeq ($(4),target)
  61. # Configure package for target
  62. define $(2)_CONFIGURE_CMDS
  63. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  64. $$($(2)_CONF_ENV) \
  65. PERL_MM_USE_DEFAULT=1 \
  66. $$(PERL_RUN) Build.PL \
  67. --config ar="$$(TARGET_AR)" \
  68. --config full_ar="$$(TARGET_AR)" \
  69. --config cc="$$(TARGET_CC)" \
  70. --config ccflags="$$(TARGET_CFLAGS)" \
  71. --config optimize=" " \
  72. --config ld="$$(TARGET_CC)" \
  73. --config lddlflags="-shared $$(TARGET_LDFLAGS)" \
  74. --config ldflags="$$(TARGET_LDFLAGS)" \
  75. --include_dirs $$(STAGING_DIR)/usr/lib/perl5/$$(PERL_VERSION)/$$(PERL_ARCHNAME)/CORE \
  76. --destdir $$(TARGET_DIR) \
  77. --installdirs vendor \
  78. --install_path lib=/usr/lib/perl5/site_perl/$$(PERL_VERSION) \
  79. --install_path arch=/usr/lib/perl5/site_perl/$$(PERL_VERSION)/$$(PERL_ARCHNAME) \
  80. --install_path bin=/usr/bin \
  81. --install_path script=/usr/bin \
  82. --install_path bindoc=/usr/share/man/man1 \
  83. --install_path libdoc=/usr/share/man/man3 \
  84. $$($(2)_CONF_OPTS); \
  85. else \
  86. $$($(2)_CONF_ENV) \
  87. PERL_MM_USE_DEFAULT=1 \
  88. PERL_AUTOINSTALL=--skipdeps \
  89. $$(PERL_RUN) Makefile.PL \
  90. AR="$$(TARGET_AR)" \
  91. FULL_AR="$$(TARGET_AR)" \
  92. CC="$$(TARGET_CC)" \
  93. CCFLAGS="$$(TARGET_CFLAGS)" \
  94. OPTIMIZE=" " \
  95. LD="$$(TARGET_CC)" \
  96. LDDLFLAGS="-shared $$(TARGET_LDFLAGS)" \
  97. LDFLAGS="$$(TARGET_LDFLAGS)" \
  98. PERL_ARCHLIB=$$(STAGING_DIR)/usr/lib/perl5/$$(PERL_VERSION)/$$(PERL_ARCHNAME) \
  99. DESTDIR=$$(TARGET_DIR) \
  100. INSTALLDIRS=vendor \
  101. INSTALLVENDORLIB=/usr/lib/perl5/site_perl/$$(PERL_VERSION) \
  102. INSTALLVENDORARCH=/usr/lib/perl5/site_perl/$$(PERL_VERSION)/$$(PERL_ARCHNAME) \
  103. INSTALLVENDORBIN=/usr/bin \
  104. INSTALLVENDORSCRIPT=/usr/bin \
  105. INSTALLVENDORMAN1DIR=/usr/share/man/man1 \
  106. INSTALLVENDORMAN3DIR=/usr/share/man/man3 \
  107. $$($(2)_CONF_OPTS); \
  108. fi
  109. endef
  110. else
  111. # Configure package for host
  112. define $(2)_CONFIGURE_CMDS
  113. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  114. $$($(2)_CONF_ENV) \
  115. PERL_MM_USE_DEFAULT=1 \
  116. $$(PERL_RUN) Build.PL \
  117. $$($(2)_CONF_OPTS); \
  118. else \
  119. $$($(2)_CONF_ENV) \
  120. PERL_MM_USE_DEFAULT=1 \
  121. PERL_AUTOINSTALL=--skipdeps \
  122. $$(PERL_RUN) Makefile.PL \
  123. $$($(2)_CONF_OPTS); \
  124. fi
  125. endef
  126. endif
  127. endif
  128. #
  129. # Build step. Only define it if not already defined by the package .mk
  130. # file. And take care of the differences between host and target
  131. # packages.
  132. #
  133. ifndef $(2)_BUILD_CMDS
  134. ifeq ($(4),target)
  135. # Build package for target
  136. define $(2)_BUILD_CMDS
  137. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  138. $$(PERL_RUN) Build $$($(2)_BUILD_OPTS) build; \
  139. else \
  140. $$(MAKE1) \
  141. FIXIN=: \
  142. $$($(2)_BUILD_OPTS) pure_all; \
  143. fi
  144. endef
  145. else
  146. # Build package for host
  147. define $(2)_BUILD_CMDS
  148. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  149. $$(PERL_RUN) Build $$($(2)_BUILD_OPTS) build; \
  150. else \
  151. $$(MAKE1) $$($(2)_BUILD_OPTS) pure_all; \
  152. fi
  153. endef
  154. endif
  155. endif
  156. #
  157. # Host installation step. Only define it if not already defined by the
  158. # package .mk file.
  159. #
  160. ifndef $(2)_INSTALL_CMDS
  161. define $(2)_INSTALL_CMDS
  162. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  163. $$(PERL_RUN) Build $$($(2)_INSTALL_TARGET_OPTS) install; \
  164. else \
  165. $$(MAKE1) $$($(2)_INSTALL_TARGET_OPTS) pure_install; \
  166. fi
  167. endef
  168. endif
  169. #
  170. # Target installation step. Only define it if not already defined by
  171. # the package .mk file.
  172. #
  173. ifndef $(2)_INSTALL_TARGET_CMDS
  174. define $(2)_INSTALL_TARGET_CMDS
  175. cd $$($$(PKG)_SRCDIR) && if [ -f Build.PL ] && [ $$($(2)_PREFER_INSTALLER) != "EUMM" ] ; then \
  176. $$(PERL_RUN) Build $$($(2)_INSTALL_TARGET_OPTS) install; \
  177. else \
  178. $$(MAKE1) $$($(2)_INSTALL_TARGET_OPTS) pure_install; \
  179. fi
  180. endef
  181. endif
  182. # Call the generic package infrastructure to generate the necessary
  183. # make targets
  184. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  185. # Upgrade helper
  186. ifneq ($$($(3)_DISTNAME),)
  187. $(1)-upgrade:
  188. utils/scancpan -force -$(4) $$($(3)_DISTNAME)
  189. .PHONY: $(1)-upgrade
  190. endif
  191. endef
  192. ################################################################################
  193. # perl-package -- the target generator macro for Perl packages
  194. ################################################################################
  195. perl-package = $(call inner-perl-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  196. host-perl-package = $(call inner-perl-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)