4737N/A# The contents of this file are subject to the terms of the
4737N/A# Common Development and Distribution License (the "License").
4737N/A# You may not use this file except in compliance with the License.
4737N/A# See the License for the specific language governing permissions
4737N/A# and limitations under the License.
4737N/A# When distributing Covered Code, include this CDDL HEADER in each
4737N/A# If applicable, add the following below this CDDL HEADER, with the
4737N/A# fields enclosed by brackets "[]" replaced with your own identifying
4737N/A# information: Portions Copyright [yyyy] [name of copyright owner]
5336N/A# Copyright (c) 2010, 2014, Oracle
and/or its affiliates. All rights reserved.
5680N/A# Rules and Macros for generating an IPS package manifest and publishing an
4737N/A# IPS package to a pkg depot.
5363N/A# and define an "install" target appropriate to building your component.
5363N/A# install: $(BUILD_DIR)/build/$(MACH32)/.installed \
4737N/A# $(BUILD_DIR)/build/$(MACH64)/.installed
4737N/A# This set of rules makes the "publish" target the default target for make(1)
4737N/Aifeq ($(strip $(PKGLINT_COMPONENT)),)
5680N/APKGLINT = ${WS_TOOLS}/pkglint
5690N/APKGMANGLE = $(WS_TOOLS)/userland-mangler
5690N/A# Package headers should all pretty much follow the same format
5487N/ACOMPARISON_TRANSFORMS += $(PKGMOGRIFY_TRANSFORMS)
5851N/APUBLISH_TRANSFORMS += $(LICENSE_TRANSFORMS)
5851N/APUBLISH_TRANSFORMS += $(PKGMOGRIFY_TRANSFORMS)
5851N/APKG_MACROS += MACH32=$(MACH32)
5851N/APKG_MACROS += MACH64=$(MACH64)
5851N/APKG_MACROS += PUBLISHER=$(PUBLISHER)
5851N/APKG_MACROS += PUBLISHER_LOCALIZABLE=$(PUBLISHER_LOCALIZABLE)
5851N/APKG_MACROS += CONSOLIDATION=$(CONSOLIDATION)
5851N/APKG_MACROS += BUILD_VERSION=$(BUILD_VERSION)
5594N/APKG_MACROS += SOLARIS_VERSION=$(SOLARIS_VERSION)
5851N/APKG_MACROS += OS_VERSION=$(OS_VERSION)
5851N/APKG_MACROS += PKG_SOLARIS_VERSION=$(PKG_SOLARIS_VERSION)
5851N/APKG_MACROS += HUMAN_VERSION=$(HUMAN_VERSION)
5680N/APKG_MACROS += IPS_COMPONENT_VERSION=$(IPS_COMPONENT_VERSION)
5851N/APKG_MACROS += COMPONENT_VERSION=$(COMPONENT_VERSION)
5851N/APKG_MACROS += COMPONENT_PROJECT_URL=$(COMPONENT_PROJECT_URL)
5851N/APKG_MACROS += COMPONENT_ARCHIVE_URL=$(COMPONENT_ARCHIVE_URL)
5851N/APKG_MACROS += COMPONENT_HG_URL=$(COMPONENT_HG_URL)
5851N/APKG_MACROS += COMPONENT_HG_REV=$(COMPONENT_HG_REV)
5851N/APKG_MACROS += COMPONENT_NAME=$(COMPONENT_NAME)
5851N/A# Add any TPNO_* Makefile macros to the pkgmogrify arguments.
5851N/A$(foreach macro, $(filter TPNO_%, $(.VARIABLES)), \
4737N/A $(eval PKG_MACROS += $(macro)=$$($(macro))) \
5851N/APKG_MACROS += PYTHON_2.6_ONLY=\#
4737N/APKG_MACROS += PYTHON_2.7_ONLY=\#
4737N/APKG_MACROS += PYTHON_3.4_ONLY=\#
4737N/APKG_OPTIONS += $(PKG_MACROS:%=-D %)
4737N/AMANGLED_DIR = $(PROTO_DIR)/mangled
4737N/APKG_PROTO_DIRS += $(MANGLED_DIR) $(PROTO_DIR) $(@D) $(COMPONENT_DIR) $(COMPONENT_SRC)
5680N/AMANIFEST_BASE = $(BUILD_DIR)/manifest-$(MACH)
4737N/ACANONICAL_MANIFESTS = $(wildcard *.p5m)
4737N/A# Look for manifests which need to be duplicated for each version of python.
4737N/Aifeq ($(findstring -PYVER,$(CANONICAL_MANIFESTS)),-PYVER)
4737N/APYV_MANIFESTS = $(foreach v,$(shell echo $(PYTHON_VERSIONS) | tr -d .),$(shell echo $(PY_MANIFESTS) | sed -e 's/
-PYVER.p5m/-$(v).p5m/g'))
4737N/APYNV_MANIFESTS = $(shell echo $(PY_MANIFESTS) | sed -e 's/-PYVER//')
4737N/AUNVERSIONED_MANIFESTS = $(CANONICAL_MANIFESTS)
4897N/A# Look for manifests which need to be duplicated for each version of perl.
4897N/Aifeq ($(findstring -PERLVER,$(UNVERSIONED_MANIFESTS)),-PERLVER)
4897N/APERLV_MANIFESTS = $(foreach v,$(shell echo $(PERL_VERSIONS) | tr -d .),$(shell echo $(PERL_MANIFESTS) | sed -e 's/
-PERLVER.p5m/-$(v).p5m/g'))
4737N/APERLNV_MANIFESTS = $(shell echo $(PERL_MANIFESTS) | sed -e 's/-PERLVER//')
4737N/ANOPERL_MANIFESTS = $(UNVERSIONED_MANIFESTS)
4737N/A# Look for manifests which need to be duplicated for each version of ruby.
4737N/A# NOPERL_MANIFESTS represents the manifests that are not Python or
5336N/A# Perl manifests. Extract the Ruby Manifests from NOPERL_MANIFESTS.
5336N/A# Any remaining manifests are stored in NONRUBY_MANIFESTS
5336N/Aifeq ($(findstring -RUBYVER,$(NOPERL_MANIFESTS)),-RUBYVER)
4897N/ARUBYV_MANIFESTS = $(foreach v,$(shell echo $(RUBY_VERSIONS)),\
5680N/A $(shell echo $(RUBY_MANIFESTS) |\
5680N/A cut -d. -f1,2 | tr -d .).p5m/g'))
5680N/ARUBYNV_MANIFESTS = $(shell echo $(RUBY_MANIFESTS) | sed -e 's/-RUBYVER//')
4897N/ANORUBY_MANIFESTS = $(NOPERL_MANIFESTS)
4737N/A $(PYV_MANIFESTS) $(PYNV_MANIFESTS) \
4737N/A $(PERLV_MANIFESTS) $(PERLNV_MANIFESTS) \
4737N/A $(RUBYV_MANIFESTS) $(RUBYNV_MANIFESTS) \
4737N/AGENERATED = $(MANIFEST_BASE)-generated
4896N/ACOMBINED = $(MANIFEST_BASE)-combined
4737N/AMANIFESTS = $(VERSIONED_MANIFESTS:%=$(MANIFEST_BASE)-%)
4737N/ADEPENDED=$(VERSIONED_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend)
4737N/ACOPYRIGHT_FILE ?= $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
4737N/AIPS_COMPONENT_VERSION ?= $(COMPONENT_VERSION)
# allow publishing to be overridden, such as when
# a package is for one architecture only.
PUBLISH_STAMP ?= $(BUILD_DIR)/.published-$(MACH)
publish: build install $(PUBLISH_STAMP)
sample-manifest: $(GENERATED).p5m
$(GENERATED).p5m: install
$(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
$(PKGMOGRIFY) $(PKG_OPTIONS)
/dev/fd/0 $(GENERATE_TRANSFORMS) | \
sed -e '/^$$/d' -e '/^#.*$$/d' | $(PKGFMT) | \
cat $(METADATA_TEMPLATE) - >$@
# copy the canonical manifest(s) to the build tree
$(MANIFEST_BASE)-%.generate: %.p5m canonical-manifests
cat $(METADATA_TEMPLATE) $< >$@
# The text of a transform that will emit a dependency conditional on the
# presence of a particular version of a runtime, which will then draw in the
# runtime-version-specific version of the package we're operating on. $(1) is
# the name of the runtime package, and $(2) is the version suffix.
echo "<transform set name=
pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#PYV\#\#\#@(.*)" \
"-> emit depend nodrop=true type=conditional" \
"predicate=$(1)-$(2) fmri=%<1>-$(2)@%<2>>" >> $@;
# Define and execute a macro that generates a rule to create a manifest for a
# python module specific to a particular version of the python runtime.
# Creates
build/manifest-*-modulename-##.p5m file where ## is replaced with
define python-manifest-rule
$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).mogrified: PKG_MACROS += PYTHON_$(1)_ONLY=
$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).p5m: %
-PYVER.p5m if [ -f $$*-$(shell echo $(1) | tr -d .)
GENFRAG.p5m ]; then cat $$*-$(shell echo $(1) | tr -d .)
GENFRAG.p5m >> $$@; fi
$(PKGMOGRIFY) -D PYVER=$(1) -D PYV=$(shell echo $(1) | tr -d .) $$< > $$@
$(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-manifest-rule,$(ver))))
# A rule to create a helper transform package for python, that will insert the
# appropriate conditional dependencies into a python library's
# runtime-version-generic package to pull in the version-specific bits when the
# corresponding version of python is on the system.
$(foreach ver,$(shell echo $(PYTHON_VERSIONS) | tr -d .), \
# Build Python version-wrapping manifests from the generic version.
$(MANIFEST_BASE)-%.p5m: %
-PYVER.p5m $(BUILD_DIR)/mkgeneric-python
$(PKGMOGRIFY) -D PYV=###PYV### $(BUILD_DIR)/mkgeneric-python \
# Define and execute a macro that generates a rule to create a manifest for a
# perl module specific to a particular version of the perl runtime.
define perl-manifest-rule
$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).p5m: %
-PERLVER.p5m $(PKGMOGRIFY) -D PERLVER=$(1) -D PLV=$(shell echo $(1) | tr -d .) \
-D PERL_ARCH=$(call PERL_ARCH_FUNC,$(PERL.$(1))) $$< > $$@
$(foreach ver,$(PERL_VERSIONS),$(eval $(call perl-manifest-rule,$(ver))))
# A rule to create a helper transform package for perl, that will insert the
# appropriate conditional dependencies into a perl library's
# runtime-version-generic package to pull in the version-specific bits when the
# corresponding version of perl is on the system.
$(foreach ver,$(shell echo $(PERL_VERSIONS) | tr -d .), \
# Build Perl version-wrapping manifests from the generic version.
$(MANIFEST_BASE)-%.p5m: %
-PERLVER.p5m $(BUILD_DIR)/mkgeneric-perl
$(PKGMOGRIFY) -D PLV=### $(BUILD_DIR)/mkgeneric-perl \
# Define and execute a macro that generates a rule to create a manifest for a
# ruby module specific to a particular version of the ruby runtime.
# Creates
build/manifest-*-modulename-##.p5m file where ## is replaced with
define ruby-manifest-rule
$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).mogrified: \
PKG_MACROS += RUBY_VERSION=$(1) RUBY_LIB_VERSION=$(2) \
$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).p5m: %
-RUBYVER.p5m if [ -f $$*-$(shell echo $(1) | tr -d .)
GENFRAG.p5m ]; then \
cat $$*-$(shell echo $(1) | tr -d .)
GENFRAG.p5m >> $$@; \
$(PKGMOGRIFY) -D RUBY_VERSION=$(1) -D RUBY_LIB_VERSION=$(2) \
-D RUBYV=$(shell echo $(1) | tr -d .) $$< > $$@
$(foreach ver,$(RUBY_VERSIONS),\
$(eval $(call ruby-manifest-rule,$(shell echo $(ver) | \
# A rule to create a helper transform package for ruby, that will insert the
# appropriate conditional dependencies into a ruby library's
# runtime-version-generic package to pull in the version-specific bits when the
# corresponding version of ruby is on the system.
$(foreach ver,$(RUBY_VERSIONS),\
cut -d. -f1,2 | tr -d .)))
# Build Ruby version-wrapping manifests from the generic version.
# ###PYV### is used here as the mkgeneric() call used to create
# mkgeneric-ruby uses this value version subsitute key. We also
# use the same key, ###PYV###, to pick up the required entry
# in mkgeneric when pkgmogrify is invoked
$(MANIFEST_BASE)-%.p5m: %
-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
$(PKGMOGRIFY) -D RUBYV=###PYV### $(BUILD_DIR)/mkgeneric-ruby \
# mogrify non-parameterized manifests
$(MANIFEST_BASE)-%.mogrified: %.p5m $(BUILD_DIR)
$(PKGMOGRIFY) $(PKG_OPTIONS) $< \
$(PUBLISH_TRANSFORMS) | \
sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
# mogrify parameterized manifests
$(MANIFEST_BASE)-%.mogrified: $(MANIFEST_BASE)-%.p5m $(BUILD_DIR)
$(PKGMOGRIFY) $(PKG_OPTIONS) $< \
$(PUBLISH_TRANSFORMS) | \
sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
# mangle the file contents
$(BUILD_DIR) $(MANGLED_DIR):
PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
$(MANIFEST_BASE)-%.mangled: $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
$(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
$(MANIFEST_BASE)-%.depend: $(MANIFEST_BASE)-%.mangled
$(ENV) $(COMPONENT_PUBLISH_ENV) $(PKGDEPEND) generate \
$(PKGDEPEND_GENERATE_OPTIONS) $< >$@
# These files should contain a list of packages that the component is known to
# depend on. Using
resolve.deps is not required, but significantly speeds up
# the "pkg resolve" step.
EXTDEPFILES ?= $(wildcard $(sort $(addsuffix ../
resolve.deps, $(dir $(DEPENDED)))))
# If the package contains no automatically discoverable dependencies, then
# we can speed up resolution by providing a dummy
resolve.deps to skip loading
# all the possible packages for resolution. Unfortunately, pkgdepend does not
# accept a completely empty
resolve.deps, so we pass the userland-incorporation
# as a quick, content-free placeholder.
# This is a target that should only be run by hand, and not something that
# .resolved-$(MACH) should depend on.
echo "<transform depend type=(require|require-any) -> print %(fmri)>" > rd-trans
for i in build/*.depend; do \
$(PKGMOGRIFY) -O
/dev/null $$i rd-trans | tr " " "\n" | sort -u > m1; \
$(PKGMOGRIFY) -O
/dev/null $$
i.res rd-trans | tr " " "\n" | sort -u > m2; \
done | sed -e 's/@[^ ]*//g' -e 's,pkg:/,,g' | sort -u >
resolve.deps echo "No computed dependencies found; removing empty
resolve.deps."; \
# resolve the dependencies all at once
$(BUILD_DIR)/.resolved-$(MACH): $(DEPENDED)
if [[ "$(EXTDEPFILES)" == "$(NULLDEPFILE)" ]] ; then \
$(PKGDEPEND) resolve $(EXTDEPFILES:%=-e %) -m $(DEPENDED)
# lint the manifests all at once
$(BUILD_DIR)/.linted-$(MACH): $(BUILD_DIR)/.resolved-$(MACH)
@echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
$(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)"\
SOLARIS_VERSION=$(SOLARIS_VERSION)\
$(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
-f $(WS_TOOLS)/pkglintrc $(RESOLVED)
@echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
$(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)"\
SOLARIS_VERSION=$(SOLARIS_VERSION)\
$(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
-f $(WS_TOOLS)/pkglintrc $(RESOLVED)
PKGSEND_PUBLISH_OPTIONS = -s $(PKG_REPO) publish --fmri-in-manifest
PKGSEND_PUBLISH_OPTIONS += --no-catalog
PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
PKGSEND_PUBLISH_OPTIONS += -T \*.py
$(MANIFEST_BASE)-%.published: $(MANIFEST_BASE)-%
.depend.res $(BUILD_DIR)/.linted-$(MACH)
$(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
$(BUILD_DIR)/.published-$(MACH): $(PUBLISHED)
ifndef DISABLE_IPS_CATALOG_AND_INDEX_UPDATES
$(PKGREPO) refresh -s $(PKG_REPO)
print-package-names: canonical-manifests
$(PKGMOGRIFY) $(PKG_OPTIONS)
/dev/fd/0 | \
sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
print-package-paths: canonical-manifests
$(PKGMOGRIFY) $(PKG_OPTIONS)
/dev/fd/0 | \
sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
install-packages: publish
@if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
$(PKGMOGRIFY) $(PKG_OPTIONS)
/dev/fd/0 | \
sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | sort -u | \
(cd $(PROTO_DIR) ; pfexec
/bin/cpio -dump $(ROOT)) ; \
echo "unsafe to install package(s) automatically" ; \
canonical-manifests: $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
ifeq ($(strip $(CANONICAL_MANIFESTS)),)
# If there were no canonical manifests in the workspace, nothing will
# be published and we should fail. A sample manifest can be generated
# $ gmake sample-manifest
# Once created, it will need to be reviewed, edited, and added to the
$(error Missing canonical manifest(s))
# This converts required paths to containing package names for be able to
# properly setup the build environment for a component.
@echo "generating $@ from Makefile REQUIRED_* data"
@pkg search -H -l '<$(DEPENDS:%=% OR)
/bin/true>' \
| sed -e '
s/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@