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