Till Wegmüller
2024-04-07 32d55185c6e52012a7f3fbcd5ff32dbce22c3104
commit | author | age
5a9d2b 1
6bc9bf 2 # CDDL HEADER START
CM 3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
702558 21 # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
6bc9bf 22 #
CM 23
de49ed 24 # Common perl environment
6bc9bf 25 COMMON_PERL_ENV +=    MAKE=$(GMAKE)
0f8a2f 26 COMMON_PERL_ENV +=    PATH=$(dir $(CC)):$(PATH)
6bc9bf 27 COMMON_PERL_ENV +=    LANG=""
CM 28 COMMON_PERL_ENV +=    CC="$(CC)"
e552f1 29 COMMON_PERL_ENV +=    CFLAGS="$(CC_BITS) $(PERL_OPTIMIZE)"
6bc9bf 30
20542b 31 # Particular perl runtime is always required (at least to run Makefile.PL)
MT 32 PERL_REQUIRED_PACKAGES += runtime/perl
33
6bc9bf 34 # Yes.  Perl is just scripts, for now, but we need architecture
CM 35 # directories so that it populates all architecture prototype
36 # directories.
37
ecce9a 38 define perl-version-rule
MT 39 $(BUILD_DIR)/%-$(1)/.configured:        PERL_VERSION=$(1)
40 $(BUILD_DIR)/%-$(1)/.built:            PERL_VERSION=$(1)
41 $(BUILD_DIR)/%-$(1)/.installed:            PERL_VERSION=$(1)
42 $(BUILD_DIR)/%-$(1)/.tested:            PERL_VERSION=$(1)
43 $(BUILD_DIR)/%-$(1)/.tested-and-compared:    PERL_VERSION=$(1)
372e47 44
MT 45 $(BUILD_DIR)/%-$(1)/.depend-build:        PERL_VERSION=$(1)
46 $(BUILD_DIR)/%-$(1)/.depend-runtime:        PERL_VERSION=$(1)
47 $(BUILD_DIR)/%-$(1)/.depend-test:        PERL_VERSION=$(1)
ecce9a 48 endef
MT 49 $(foreach perlver,$(PERL_VERSIONS),$(eval $(call perl-version-rule,$(perlver))))
50
6b1597 51 $(BUILD_DIR)/$(MACH32)-%/.configured:    BITS=32
TM 52 $(BUILD_DIR)/$(MACH64)-%/.configured:    BITS=64
6bc9bf 53
6b1597 54 $(BUILD_DIR)/$(MACH32)-%/.built:    BITS=32
TM 55 $(BUILD_DIR)/$(MACH64)-%/.built:    BITS=64
74a265 56
6b1597 57 $(BUILD_DIR)/$(MACH32)-%/.installed:    BITS=32
TM 58 $(BUILD_DIR)/$(MACH64)-%/.installed:    BITS=64
8d70f8 59
6b1597 60 $(BUILD_DIR)/$(MACH32)-%/.tested:    BITS=32
TM 61 $(BUILD_DIR)/$(MACH64)-%/.tested:    BITS=64
8d70f8 62
6b1597 63 $(BUILD_DIR)/$(MACH32)-%/.tested-and-compared:    BITS=32
TM 64 $(BUILD_DIR)/$(MACH64)-%/.tested-and-compared:    BITS=64
cacdb3 65
6b1597 66 PERL_32_ONLY_VERSIONS = $(filter-out $(PERL_64_ONLY_VERSIONS), $(PERL_VERSIONS))
6bc9bf 67
6b1597 68 BUILD_32 =    $(PERL_32_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.built)
TM 69 BUILD_64 =    $(PERL_64_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.built)
70 BUILD_NO_ARCH =    $(PERL_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.built)
71
72 INSTALL_32 = $(PERL_32_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.installed)
73 INSTALL_64 = $(PERL_64_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.installed)
74 INSTALL_NO_ARCH = $(PERL_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.installed)
6bc9bf 75
CM 76 COMPONENT_CONFIGURE_ENV +=    $(COMMON_PERL_ENV)
891e6c 77 # Avoid interactive behaviour for Module::AutoInstall
MT 78 COMPONENT_CONFIGURE_ENV +=    PERL_AUTOINSTALL=--skipdeps
6bc9bf 79 COMPONENT_CONFIGURE_ENV +=    PERL="$(PERL)"
9581d1 80 $(BUILD_DIR)/%/.configured:    $(SOURCE_DIR)/.prep
6bc9bf 81     ($(RM) -r $(@D) ; $(MKDIR) $(@D))
6feee0 82     $(ENV) $(CLONEY_ARGS) $(CLONEY) $(SOURCE_DIR) $(@D)
6bc9bf 83     $(COMPONENT_PRE_CONFIGURE_ACTION)
CM 84     (cd $(@D) ; $(COMPONENT_CONFIGURE_ENV) $(PERL) $(PERL_FLAGS) \
0f8a2f 85                 Makefile.PL $(CONFIGURE_OPTIONS))
6bc9bf 86     $(COMPONENT_POST_CONFIGURE_ACTION)
CM 87     $(TOUCH) $@
88
89
90 COMPONENT_BUILD_ENV +=    $(COMMON_PERL_ENV)
9581d1 91 $(BUILD_DIR)/%/.built:    $(BUILD_DIR)/%/.configured
6bc9bf 92     $(COMPONENT_PRE_BUILD_ACTION)
CM 93     (cd $(@D) ; $(ENV) $(COMPONENT_BUILD_ENV) \
c99122 94         $(GMAKE) $(COMPONENT_BUILD_GMAKE_ARGS) $(COMPONENT_BUILD_ARGS) \
DH 95         $(COMPONENT_BUILD_TARGETS))
6bc9bf 96     $(COMPONENT_POST_BUILD_ACTION)
CM 97     $(TOUCH) $@
98
99
100 COMPONENT_INSTALL_ARGS +=    DESTDIR="$(PROTO_DIR)"
101 COMPONENT_INSTALL_TARGETS =    install_vendor
102 COMPONENT_INSTALL_ENV +=    $(COMMON_PERL_ENV)
9581d1 103 $(BUILD_DIR)/%/.installed:    $(BUILD_DIR)/%/.built
6bc9bf 104     $(COMPONENT_PRE_INSTALL_ACTION)
CM 105     (cd $(@D) ; $(ENV) $(COMPONENT_INSTALL_ENV) $(GMAKE) \
106             $(COMPONENT_INSTALL_ARGS) $(COMPONENT_INSTALL_TARGETS))
107     $(COMPONENT_POST_INSTALL_ACTION)
108     $(TOUCH) $@
109
40031f 110 # Define Perl version specific filenames for tests.
f82b69 111 ifeq ($(strip $(USE_COMMON_TEST_MASTER)),no)
4d6c70 112 COMPONENT_TEST_MASTER = $(COMPONENT_TEST_RESULTS_DIR)/results-$(PERL_VERSION).master
f82b69 113 endif
5d7921 114 COMPONENT_TEST_BUILD_DIR = $(BUILD_DIR)/test-$(PERL_VERSION)
4d6c70 115 COMPONENT_TEST_OUTPUT = $(COMPONENT_TEST_BUILD_DIR)/test-$(PERL_VERSION)-results
MT 116 COMPONENT_TEST_DIFFS =  $(COMPONENT_TEST_BUILD_DIR)/test-$(PERL_VERSION)-diffs
117 COMPONENT_TEST_SNAPSHOT = $(COMPONENT_TEST_BUILD_DIR)/results-$(PERL_VERSION).snapshot
118 COMPONENT_TEST_TRANSFORM_CMD = $(COMPONENT_TEST_BUILD_DIR)/transform-$(PERL_VERSION)-results
a4588e 119
MT 120 # Normalize perl test results.
96719f 121 COMPONENT_TEST_TRANSFORMS += '-e "0,/test_harness/d"'        # delete any lines up through test_harness
a4588e 122 COMPONENT_TEST_TRANSFORMS += '-e "s/,  *[0-9]* wallclock.*//"'    # delete timings
MT 123 COMPONENT_TEST_TRANSFORMS += '-e "/^\#/d"'            # delete comments
124 COMPONENT_TEST_TRANSFORMS += '-e "/^make\[/d"'            # delete make logs
6bc9bf 125
96719f 126 # Add the expected 'test_harness' line if it is missing in the test results.
89aae0 127 COMPONENT_POST_TEST_ACTION += \
e51347 128     $(GNU_GREP) -q test_harness $(COMPONENT_TEST_OUTPUT) \
96719f 129     || $(GSED) -i -e '1i\test_harness' $(COMPONENT_TEST_OUTPUT) ;
MT 130
5a9d2b 131 COMPONENT_TEST_TARGETS =    test
6bc9bf 132 COMPONENT_TEST_ENV +=    $(COMMON_PERL_ENV)
8d70f8 133
RB 134 # determine the type of tests we want to run.
135 ifeq ($(strip $(wildcard $(COMPONENT_TEST_RESULTS_DIR)/results-*.master)),)
6b1597 136 TEST_32 =    $(PERL_32_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.tested)
TM 137 TEST_64 =    $(PERL_64_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.tested)
138 TEST_NO_ARCH =    $(PERL_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.tested)
8d70f8 139 else
6b1597 140 TEST_32 =    $(PERL_32_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.tested-and-compared)
TM 141 TEST_64 =    $(PERL_64_ONLY_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.tested-and-compared)
142 TEST_NO_ARCH = $(PERL_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.tested-and-compared)
7999b2 143 endif
8d70f8 144
RB 145 # test the built source
b6799e 146 $(BUILD_DIR)/%/.tested-and-compared:    $(COMPONENT_TEST_DEP)
237543 147     $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
AP 148     $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
8d70f8 149     $(COMPONENT_PRE_TEST_ACTION)
RB 150     -(cd $(COMPONENT_TEST_DIR) ; \
151         $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
152         $(COMPONENT_TEST_CMD) \
153         $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
154         &> $(COMPONENT_TEST_OUTPUT)
155     $(COMPONENT_POST_TEST_ACTION)
156     $(COMPONENT_TEST_CREATE_TRANSFORMS)
157     $(COMPONENT_TEST_PERFORM_TRANSFORM)
158     $(COMPONENT_TEST_COMPARE)
159     $(COMPONENT_TEST_CLEANUP)
6bc9bf 160     $(TOUCH) $@
CM 161
89aae0 162 $(BUILD_DIR)/%/.tested:    SHELLOPTS=pipefail
b6799e 163 $(BUILD_DIR)/%/.tested:    $(COMPONENT_TEST_DEP)
89aae0 164     $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
MT 165     $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
8d70f8 166     $(COMPONENT_PRE_TEST_ACTION)
RB 167     (cd $(COMPONENT_TEST_DIR) ; \
168         $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
169         $(COMPONENT_TEST_CMD) \
89aae0 170         $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
MT 171         |& $(TEE) $(COMPONENT_TEST_OUTPUT)
8d70f8 172     $(COMPONENT_POST_TEST_ACTION)
89aae0 173     $(COMPONENT_TEST_CREATE_TRANSFORMS)
MT 174     $(COMPONENT_TEST_PERFORM_TRANSFORM)
8d70f8 175     $(COMPONENT_TEST_CLEANUP)
RB 176     $(TOUCH) $@
177
32921b 178
372e47 179 # We need to add -$(PLV) to package fmri and add runtime dependencies from metadata to generated manifest
MT 180 GENERATE_EXTRA_DEPS += $(BUILD_DIR)/META.depend-runtime.res
9c1e84 181 GENERATE_EXTRA_CMD += | \
32921b 182     $(GSED) -e 's/^\(set name=pkg.fmri [^@]*\)\(.*\)$$/\1-$$(PLV)\2/' | \
d8670c 183     $(CAT) - <( \
MT 184         echo "" ; \
185         echo "\# perl modules are unusable without perl runtime binary" ; \
186         echo "depend type=require fmri=__TBD pkg.debug.depend.file=perl \\" ; \
187         echo "    pkg.debug.depend.path=usr/perl5/\$$(PERLVER)/bin" ; \
372e47 188         echo "" ; \
MT 189         echo "\# Automatically generated dependencies based on distribution metadata" ; \
5a8b4e 190         $(CAT) $(BUILD_DIR)/META.depend-runtime.res $(MANGLE_DEPEND_RUNTIME) | $(PKGFMT) \
d8670c 191     )
32921b 192
372e47 193 # Add build dependencies from metadata to REQUIRED_PACKAGES.
0d899f 194 REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend-build.res
f045de 195
0d899f 196 # Generate list of TEST_REQUIRED_PACKAGES entries
372e47 197 REQUIRED_PACKAGES_EXTRA_DEPS += $(BUILD_DIR)/META.depend-test.required
MT 198 $(BUILD_DIR)/META.depend-test.required: $(BUILD_DIR)/META.depend-test.res
15b975 199     $(GSED) -e 's|^depend.*pkg:/\(library/perl-5/.*\)-\$$(PLV).*$$|TEST_REQUIRED_PACKAGES.perl += \1|' \
9140e0 200         -e '/^TEST_REQUIRED_PACKAGES\.perl/!s/.*/\# TODO: &/' < $< > $@
0d899f 201
MT 202 # Add META.depend-test.required to the generated list of REQUIRED_PACKAGES
203 REQUIRED_PACKAGES_TRANSFORM += -e '$$r $(BUILD_DIR)/META.depend-test.required'
204
32921b 205
372e47 206 # The configure target should create the MYMETA.json file.  If it does not we
MT 207 # need a fallback to use either META.json or META.yml.  We probably (and
208 # hopefully) currently have no component requiring such fallback.
209 $(BUILD_DIR)/%/MYMETA.json:    $(BUILD_DIR)/%/.configured
210     if [ ! -f $@ ] ; then \
211         if [ -e $(@D)/META.json ] ; then \
212             $(CAT) $(@D)/META.json ; \
213         elif [ -e $(@D)/META.yml ] ; then \
214             $(CAT) $(@D)/META.yml \
215                 | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
216                 | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
217         fi > $@ ; \
4d1e46 218     fi ; \
MT 219     $(TOUCH) $@
372e47 220
MT 221 $(BUILD_DIR)/%/.depend-build:    $(BUILD_DIR)/%/MYMETA.json
4d1e46 222     $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) configure build $(PERL_VERSION) < $< > $@
MT 223     # Get configure requirements from META.json/META.yml too
224     if [ -e $(@D)/META.json ] ; then \
225         $(CAT) $(@D)/META.json ; \
226     elif [ -e $(@D)/META.yml ] ; then \
227         $(CAT) $(@D)/META.yml \
228             | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
229             | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
230     fi | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) configure $(PERL_VERSION) >> $@ ; \
231     $(TOUCH) $@
372e47 232 $(BUILD_DIR)/%/.depend-runtime:    $(BUILD_DIR)/%/MYMETA.json
MT 233     $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) < $< > $@
234 $(BUILD_DIR)/%/.depend-test:    $(BUILD_DIR)/%/MYMETA.json
235     $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test $(PERL_VERSION) < $< > $@
8f1b0e 236     $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test runtime suggests $(PERL_VERSION) < $< >> $@
372e47 237
MT 238 $(BUILD_DIR)/META.depend-build.res:    $(BUILD_$(MK_BITS):%.built=%.depend-build)
239     $(CAT) $^ | $(SORT) -u > $@
240 $(BUILD_DIR)/META.depend-runtime.res:    $(BUILD_$(MK_BITS):%.built=%.depend-runtime)
241     $(CAT) $^ | $(SORT) -u > $@
242 $(BUILD_DIR)/META.depend-test.res:    $(BUILD_$(MK_BITS):%.built=%.depend-test)
243     $(CAT) $^ | $(SORT) -u > $@
244
4d1e46 245 # jq is needed for perl-meta-deps and to convert META.yml to JSON format
32921b 246 USERLAND_REQUIRED_PACKAGES += text/jq
372e47 247 # pyyaml is needed to convert META.yml to MYMETA.json
f045de 248 USERLAND_REQUIRED_PACKAGES += library/python/pyyaml
32921b 249
MT 250
6bc9bf 251 clean:: 
CM 252     $(RM) -r $(BUILD_DIR) $(PROTO_DIR)