Till Wegmüller
2024-04-07 32d55185c6e52012a7f3fbcd5ff32dbce22c3104
make-rules/makemaker.mk
@@ -21,36 +21,9 @@
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
#
# Component defaults
COMPONENT_VERSION ?=      $(shell $(WS_TOOLS)/perl-version-convert $(COMPONENT_NAME) $(HUMAN_VERSION))
COMPONENT_CLASSIFICATION ?=   Development/Perl
COMPONENT_SRC ?=      $(COMPONENT_NAME)-$(HUMAN_VERSION)
COMPONENT_ARCHIVE ?=      $(COMPONENT_SRC).tar.gz
COMPONENT_FMRI ?=      library/perl-5/$(shell echo $(COMPONENT_NAME) | tr [A-Z]_ [a-z]-)
ifneq ($(strip $(COMPONENT_PERL_MODULE)),)
COMPONENT_PERL_DISTRIBUTION ?=   $(subst ::,-,$(COMPONENT_PERL_MODULE))
COMPONENT_PROJECT_URL ?=   https://metacpan.org/pod/$(COMPONENT_PERL_MODULE)
endif
ifneq ($(strip $(COMPONENT_PERL_DISTRIBUTION)),)
COMPONENT_NAME ?=      $(COMPONENT_PERL_DISTRIBUTION)
endif
ifneq ($(strip $(COMPONENT_CPAN_AUTHOR)),)
COMPONENT_CPAN_AUTHOR1 =   $(shell echo $(COMPONENT_CPAN_AUTHOR) | cut -c 1)
COMPONENT_CPAN_AUTHOR2 =   $(shell echo $(COMPONENT_CPAN_AUTHOR) | cut -c 1-2)
COMPONENT_CPAN_AUTHOR_URL =   $(COMPONENT_CPAN_AUTHOR1)/$(COMPONENT_CPAN_AUTHOR2)/$(COMPONENT_CPAN_AUTHOR)
COMPONENT_ARCHIVE_URL ?=   https://cpan.metacpan.org/authors/id/$(COMPONENT_CPAN_AUTHOR_URL)/$(COMPONENT_ARCHIVE)
endif
# Enable ASLR by default.  Component could disable ASLR by setting
# COMPONENT_ASLR to 'no'.
ifeq ($(strip $(COMPONENT_ASLR)),no)
ASLR_MODE = $(ASLR_DISABLE)
else
ASLR_MODE = $(ASLR_ENABLE)
endif
# Common perl environment
COMMON_PERL_ENV +=   MAKE=$(GMAKE)
COMMON_PERL_ENV +=   PATH=$(dir $(CC)):$(SPRO_VROOT)/bin:$(PATH)
COMMON_PERL_ENV +=   PATH=$(dir $(CC)):$(PATH)
COMMON_PERL_ENV +=   LANG=""
COMMON_PERL_ENV +=   CC="$(CC)"
COMMON_PERL_ENV +=   CFLAGS="$(CC_BITS) $(PERL_OPTIMIZE)"
@@ -68,6 +41,10 @@
$(BUILD_DIR)/%-$(1)/.installed:         PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested:         PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested-and-compared:   PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-build:      PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-runtime:      PERL_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.depend-test:      PERL_VERSION=$(1)
endef
$(foreach perlver,$(PERL_VERSIONS),$(eval $(call perl-version-rule,$(perlver))))
@@ -97,13 +74,15 @@
INSTALL_NO_ARCH = $(PERL_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.installed)
COMPONENT_CONFIGURE_ENV +=   $(COMMON_PERL_ENV)
# Avoid interactive behaviour for Module::AutoInstall
COMPONENT_CONFIGURE_ENV +=   PERL_AUTOINSTALL=--skipdeps
COMPONENT_CONFIGURE_ENV +=   PERL="$(PERL)"
$(BUILD_DIR)/%/.configured:   $(SOURCE_DIR)/.prep
   ($(RM) -r $(@D) ; $(MKDIR) $(@D))
   $(ENV) $(CLONEY_ARGS) $(CLONEY) $(SOURCE_DIR) $(@D)
   $(COMPONENT_PRE_CONFIGURE_ACTION)
   (cd $(@D) ; $(COMPONENT_CONFIGURE_ENV) $(PERL) $(PERL_FLAGS) \
            Makefile.PL $(PERL_STUDIO_OVERWRITE) $(CONFIGURE_OPTIONS))
            Makefile.PL $(CONFIGURE_OPTIONS))
   $(COMPONENT_POST_CONFIGURE_ACTION)
   $(TOUCH) $@
@@ -128,11 +107,11 @@
   $(COMPONENT_POST_INSTALL_ACTION)
   $(TOUCH) $@
# Define bit specific and Perl version specific filenames.
# Define Perl version specific filenames for tests.
ifeq ($(strip $(USE_COMMON_TEST_MASTER)),no)
COMPONENT_TEST_MASTER = $(COMPONENT_TEST_RESULTS_DIR)/results-$(PERL_VERSION).master
endif
COMPONENT_TEST_BUILD_DIR = $(BUILD_DIR)/test
COMPONENT_TEST_BUILD_DIR = $(BUILD_DIR)/test-$(PERL_VERSION)
COMPONENT_TEST_OUTPUT = $(COMPONENT_TEST_BUILD_DIR)/test-$(PERL_VERSION)-results
COMPONENT_TEST_DIFFS =  $(COMPONENT_TEST_BUILD_DIR)/test-$(PERL_VERSION)-diffs
COMPONENT_TEST_SNAPSHOT = $(COMPONENT_TEST_BUILD_DIR)/results-$(PERL_VERSION).snapshot
@@ -145,7 +124,8 @@
COMPONENT_TEST_TRANSFORMS += '-e "/^make\[/d"'         # delete make logs
# Add the expected 'test_harness' line if it is missing in the test results.
COMPONENT_POST_TEST_ACTION += $(GNU_GREP) -q test_harness $(COMPONENT_TEST_OUTPUT) \
COMPONENT_POST_TEST_ACTION += \
   $(GNU_GREP) -q test_harness $(COMPONENT_TEST_OUTPUT) \
   || $(GSED) -i -e '1i\test_harness' $(COMPONENT_TEST_OUTPUT) ;
COMPONENT_TEST_TARGETS =   test
@@ -163,7 +143,7 @@
endif
# test the built source
$(BUILD_DIR)/%/.tested-and-compared:    $(BUILD_DIR)/%/.built
$(BUILD_DIR)/%/.tested-and-compared:    $(COMPONENT_TEST_DEP)
   $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
   $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
   $(COMPONENT_PRE_TEST_ACTION)
@@ -179,58 +159,94 @@
   $(COMPONENT_TEST_CLEANUP)
   $(TOUCH) $@
$(BUILD_DIR)/%/.tested:    $(BUILD_DIR)/%/.built
$(BUILD_DIR)/%/.tested:    SHELLOPTS=pipefail
$(BUILD_DIR)/%/.tested:    $(COMPONENT_TEST_DEP)
   $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
   $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
   $(COMPONENT_PRE_TEST_ACTION)
   (cd $(COMPONENT_TEST_DIR) ; \
      $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
      $(COMPONENT_TEST_CMD) \
      $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS))
      $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
      |& $(TEE) $(COMPONENT_TEST_OUTPUT)
   $(COMPONENT_POST_TEST_ACTION)
   $(COMPONENT_TEST_CREATE_TRANSFORMS)
   $(COMPONENT_TEST_PERFORM_TRANSFORM)
   $(COMPONENT_TEST_CLEANUP)
   $(TOUCH) $@
# We need to add -$(PLV) to package fmri and generate runtime dependencies based on META.json
GENERATE_EXTRA_DEPS += $(BUILD_DIR)/META.json
GENERATE_EXTRA_CMD ?= \
# We need to add -$(PLV) to package fmri and add runtime dependencies from metadata to generated manifest
GENERATE_EXTRA_DEPS += $(BUILD_DIR)/META.depend-runtime.res
GENERATE_EXTRA_CMD += | \
   $(GSED) -e 's/^\(set name=pkg.fmri [^@]*\)\(.*\)$$/\1-$$(PLV)\2/' | \
   $(CAT) - <( \
      echo "" ; \
      echo "\# perl modules are unusable without perl runtime binary" ; \
      echo "depend type=require fmri=__TBD pkg.debug.depend.file=perl \\" ; \
      echo "    pkg.debug.depend.path=usr/perl5/\$$(PERLVER)/bin" ; \
      $(CAT) $(BUILD_DIR)/META.json \
         | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) \
         | $(GSED) -e 's|^\(depend.*pkg:/runtime/perl-\$$(PLV).*\)$$|\#\1|g' \
      echo "" ; \
      echo "\# Automatically generated dependencies based on distribution metadata" ; \
      $(CAT) $(BUILD_DIR)/META.depend-runtime.res $(MANGLE_DEPEND_RUNTIME) | $(PKGFMT) \
   )
# Support for adding dependencies from META.json to REQUIRED_PACKAGES
REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend.res
$(BUILD_DIR)/META.depend.res: $(BUILD_DIR)/META.json
   $(CAT) $(BUILD_DIR)/META.json | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) $(PERL_VERSION) > $@
# Add build dependencies from metadata to REQUIRED_PACKAGES.
REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend-build.res
$(BUILD_DIR)/META.json: $(SOURCE_DIR)/.prep
   $(MKDIR) $(BUILD_DIR)
   if [ -f $(SOURCE_DIR)/META.json ] ; then \
      $(CAT) $(SOURCE_DIR)/META.json ; \
   elif [ -f $(SOURCE_DIR)/META.yml ] ; then \
      $(CAT) $(SOURCE_DIR)/META.yml \
         | python -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
         | jq '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
   fi > $@
# Generate list of TEST_REQUIRED_PACKAGES entries
REQUIRED_PACKAGES_EXTRA_DEPS += $(BUILD_DIR)/META.depend-test.required
$(BUILD_DIR)/META.depend-test.required: $(BUILD_DIR)/META.depend-test.res
   $(GSED) -e 's|^depend.*pkg:/\(library/perl-5/.*\)-\$$(PLV).*$$|TEST_REQUIRED_PACKAGES.perl += \1|' \
      -e '/^TEST_REQUIRED_PACKAGES\.perl/!s/.*/\# TODO: &/' < $< > $@
# perl-meta-deps requires jq
# Add META.depend-test.required to the generated list of REQUIRED_PACKAGES
REQUIRED_PACKAGES_TRANSFORM += -e '$$r $(BUILD_DIR)/META.depend-test.required'
# The configure target should create the MYMETA.json file.  If it does not we
# need a fallback to use either META.json or META.yml.  We probably (and
# hopefully) currently have no component requiring such fallback.
$(BUILD_DIR)/%/MYMETA.json:   $(BUILD_DIR)/%/.configured
   if [ ! -f $@ ] ; then \
      if [ -e $(@D)/META.json ] ; then \
         $(CAT) $(@D)/META.json ; \
      elif [ -e $(@D)/META.yml ] ; then \
         $(CAT) $(@D)/META.yml \
            | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
            | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
      fi > $@ ; \
   fi ; \
   $(TOUCH) $@
$(BUILD_DIR)/%/.depend-build:   $(BUILD_DIR)/%/MYMETA.json
   $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) configure build $(PERL_VERSION) < $< > $@
   # Get configure requirements from META.json/META.yml too
   if [ -e $(@D)/META.json ] ; then \
      $(CAT) $(@D)/META.json ; \
   elif [ -e $(@D)/META.yml ] ; then \
      $(CAT) $(@D)/META.yml \
         | $(PYTHON) -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \
         | $(JQ) '{prereqs:{configure:{requires:.configure_requires},build:{requires:.build_requires},runtime:{requires}}}' ; \
   fi | $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) configure $(PERL_VERSION) >> $@ ; \
   $(TOUCH) $@
$(BUILD_DIR)/%/.depend-runtime:   $(BUILD_DIR)/%/MYMETA.json
   $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) < $< > $@
$(BUILD_DIR)/%/.depend-test:   $(BUILD_DIR)/%/MYMETA.json
   $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test $(PERL_VERSION) < $< > $@
   $(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test runtime suggests $(PERL_VERSION) < $< >> $@
$(BUILD_DIR)/META.depend-build.res:   $(BUILD_$(MK_BITS):%.built=%.depend-build)
   $(CAT) $^ | $(SORT) -u > $@
$(BUILD_DIR)/META.depend-runtime.res:   $(BUILD_$(MK_BITS):%.built=%.depend-runtime)
   $(CAT) $^ | $(SORT) -u > $@
$(BUILD_DIR)/META.depend-test.res:   $(BUILD_$(MK_BITS):%.built=%.depend-test)
   $(CAT) $^ | $(SORT) -u > $@
# jq is needed for perl-meta-deps and to convert META.yml to JSON format
USERLAND_REQUIRED_PACKAGES += text/jq
# pyyaml is needed to convert META.yml to META.json
# pyyaml is needed to convert META.yml to MYMETA.json
USERLAND_REQUIRED_PACKAGES += library/python/pyyaml
ifeq   ($(strip $(PARFAIT_BUILD)),yes)
parfait: build
else
parfait:
   $(MAKE) PARFAIT_BUILD=yes parfait
endif
clean:: 
   $(RM) -r $(BUILD_DIR) $(PROTO_DIR)