Marcel Telka
2023-10-01 987d1521ca5b59199c4da5928069540d5c17d656
commit | author | age
9c75c0 1 #
NJ 2 # CDDL HEADER START
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 #
4505fe 21 # Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
b31a41 22 # Copyright 2014 Andrzej Szeszo. All rights reserved.
9c75c0 23 #
NJ 24
25 #
26 # Rules and Macros for generating an IPS package manifest and publishing an
27 # IPS package to a pkg depot.
28 #
29 # To use these rules, include ../make-rules/ips.mk in your Makefile
30 # and define an "install" target appropriate to building your component.
31 # Ex:
32 #
74300c 33 #    install:    $(BUILD_DIR)/build/$(MACH32)/.installed \
NJ 34 #             $(BUILD_DIR)/build/$(MACH64)/.installed
9c75c0 35 #
NJ 36 # This set of rules makes the "publish" target the default target for make(1)
37 #
dab0d0 38 .NOTPARALLEL:
9c75c0 39
NJ 40 PKGDEPEND =    /usr/bin/pkgdepend
6514ee 41 PKGFMT =    /usr/bin/pkgfmt
NJ 42 PKGMOGRIFY =    /usr/bin/pkgmogrify
43 PKGSEND =    /usr/bin/pkgsend
7bf47e 44 ifeq   ($(strip $(PKGLINT_COMPONENT)),)
1cba4c 45 PKGLINT =    /usr/bin/python /usr/bin/pkglint
7bf47e 46 else
MS 47 PKGLINT =    ${WS_TOOLS}/pkglint
48 endif
4158c0 49 PKGMANGLE =    $(WS_TOOLS)/userland-mangler
9c75c0 50
d180f2 51 WS_TRANSFORMS =    $(WS_TOP)/transforms
52
94deda 53 GENERATE_HISTORY= $(WS_TOOLS)/generate-history
AP 54 HISTORY=    history
55
6514ee 56 # Package headers should all pretty much follow the same format
NJ 57 METADATA_TEMPLATE =        $(WS_TOP)/transforms/manifest-metadata-template
58 COPYRIGHT_TEMPLATE =        $(WS_TOP)/transforms/copyright-template
9c75c0 59
6514ee 60 # order is important
NJ 61 GENERATE_TRANSFORMS +=        $(WS_TOP)/transforms/generate-cleanup
d2f7a3 62 ifeq    ($(strip $(DROP_STATIC_LIBRARIES)),yes)
aa9fb4 63 GENERATE_TRANSFORMS +=        $(WS_TOP)/transforms/archive-libraries-drop
MT 64 endif
5d461f 65
cf4b61 66 PKGMOGRIFY_TRANSFORMS +=    $(WS_TOP)/transforms/libtool-drop
7fd1f9 67 PKGMOGRIFY_TRANSFORMS +=    $(WS_TOP)/transforms/ignore-libs
90207d 68 PKGMOGRIFY_TRANSFORMS +=    $(WS_TOP)/transforms/ignore-gcc-usr-lib
AP 69
8c2f8f 70 LICENSE_TRANSFORMS =        $(WS_TOP)/transforms/license-changes
RB 71
6514ee 72 # order is important
8c2f8f 73 PUBLISH_TRANSFORMS +=    $(LICENSE_TRANSFORMS)
9dfd18 74 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/variant-cleanup
3cec7d 75 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/autopyc
797b9b 76 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/python
60713a 77 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/perl
6514ee 78 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/defaults
NJ 79 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/actuators
80 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/devel
81 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/docs
82 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/locale
a60de4 83 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/python-3-soabi
44f1c2 84 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/python-3-no-32bit
6514ee 85 PUBLISH_TRANSFORMS +=    $(PKGMOGRIFY_TRANSFORMS)
NJ 86 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/publish-cleanup
87
1080cc 88 FINAL_TRANSFORMS +=     $(WS_TOP)/transforms/final-cleanup
AP 89
e5ce0b 90 define add-limiting-variable
AP 91 PKG_VARS += $(1)
92 MANIFEST_LIMITING_VARS += -D $(1)="$(subst #,\#,$($(1)))"
93 endef
94
95 # Make all the limiting variables available to manifest processing
96 $(foreach var, $(filter PY3_%_NAMING,$(.VARIABLES)), \
97     $(eval $(call add-limiting-variable,$(var))))
98
99
280925 100 ifeq   ($(strip $(COMPONENT_AUTOGEN_MANIFEST)),yes)
AS 101 AUTOGEN_MANIFEST_TRANSFORMS +=        $(WS_TOP)/transforms/generate-cleanup
102 else
103 AUTOGEN_MANIFEST_TRANSFORMS +=        $(WS_TOP)/transforms/drop-all
104 endif
105
e5ce0b 106 # For items defined as variables or that may contain whitespace, add
AP 107 # them to a list to be expanded into PKG_OPTIONS later.
108 PKG_VARS += ARC_CASE TPNO
109 PKG_VARS += MACH MACH32 MACH64
110 PKG_VARS += BUILD_VERSION OS_VERSION PKG_SOLARIS_VERSION
e7f82d 111 PKG_VARS += GNU_TRIPLET
8dc1cb 112 PKG_VARS += GCC_GNU_TRIPLET
e5ce0b 113 PKG_VARS += CONSOLIDATION
AP 114 PKG_VARS += COMPONENT_VERSION IPS_COMPONENT_VERSION HUMAN_VERSION
115 PKG_VARS += COMPONENT_ARCHIVE_URL COMPONENT_PROJECT_URL COMPONENT_NAME
116 PKG_VARS += COMPONENT_FMRI COMPONENT_LICENSE_FILE
117 PKG_VARS += COMPONENT_SUMMARY COMPONENT_DESCRIPTION COMPONENT_LICENSE
118 PKG_VARS += HG_REPO HG_REV HG_URL COMPONENT_HG_URL COMPONENT_HG_REV
119 PKG_VARS += GIT_COMMIT_ID GIT_REPO GIT_TAG
120 PKG_VARS += PUBLISHER PUBLISHER_LOCALIZABLE
121 PKG_VARS += USERLAND_GIT_REMOTE USERLAND_GIT_BRANCH USERLAND_GIT_REV
72621a 122 PKG_VARS += COMPONENT
e5ce0b 123
AP 124 # For items that need special definition, add them to PKG_MACROS.
125 # IPS_COMPONENT_VERSION suitable for use in regular expressions.
126 PKG_MACROS += IPS_COMPONENT_RE_VERSION=$(subst .,\\.,$(IPS_COMPONENT_VERSION))
127 # COMPONENT_VERSION suitable for use in regular expressions.
128 PKG_MACROS += COMPONENT_RE_VERSION=$(subst .,\\.,$(COMPONENT_VERSION))
db59b9 129 # HUMAN_VERSION suitable for use in regular expressions.
MT 130 PKG_MACROS += HUMAN_VERSION_RE=$(subst .,\\.,$(HUMAN_VERSION))
6514ee 131
cce78d 132 PKG_OPTIONS +=        $(PKG_MACROS:%=-D %) \
e5ce0b 133                     -D COMPONENT_CLASSIFICATION="org.opensolaris.category.2008:$(strip $(COMPONENT_CLASSIFICATION))"
6514ee 134
15328e 135 define mach-list-generate-macros
AL 136 ifeq ($(MACH),$(1))
137 PKG_MACROS +=           $(1)_ONLY=
138 PKG_MACROS +=           $(1)_EXCL=\#
139 else
140 PKG_MACROS +=           $(1)_ONLY=\#
141 PKG_MACROS +=           $(1)_EXCL=
142 endif
143 endef
144 $(foreach isa,$(MACH_LIST),$(eval $(call mach-list-generate-macros,$(isa))))
145
6ce466 146 define python-generate-macros
AL 147 PKG_MACROS +=           PYTHON_$(1)_ONLY=\#
148 PKG_MACROS +=           PYTHON_$(1)_EXCL=
149 endef
150 $(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-generate-macros,$(ver))))
151
44f1c2 152 PKG_MACROS +=           PYTHON_32_ONLY=
bd5c30 153
4158c0 154 MANGLED_DIR =    $(PROTO_DIR)/mangled
NJ 155
156 PKG_PROTO_DIRS += $(MANGLED_DIR) $(PROTO_DIR) $(@D) $(COMPONENT_DIR) $(COMPONENT_SRC)
35a012 157
74300c 158 MANIFEST_BASE =        $(BUILD_DIR)/manifest-$(MACH)
6514ee 159
5b9db7 160 SAMPLE_MANIFEST_DIR =     $(COMPONENT_DIR)/manifests
161 SAMPLE_MANIFEST_FILE =    $(SAMPLE_MANIFEST_DIR)/sample-manifest.p5m
40754e 162 GENERIC_MANIFEST_FILE =    $(SAMPLE_MANIFEST_DIR)/generic-manifest.p5m
5b9db7 163
ff17eb 164 CANONICAL_MANIFESTS =    $(wildcard *.p5m)
94deda 165 ifneq ($(wildcard $(HISTORY)),)
AP 166 HISTORICAL_MANIFESTS = $(shell $(NAWK) -v FUNCTION=name -f $(GENERATE_HISTORY) < $(HISTORY))
167 endif
5ada66 168
0ae592 169 define ips-print-depend-require-rule
AL 170 $(shell cat $(1) $(WS_TOP)/transforms/print-depend-require |\
171     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 |\
a99182 172     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
0ae592 173 endef
AL 174
175 define ips-print-depend-require-versioned-rule
176 $(foreach v,$($(1)V_VALUES),\
177     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
178     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 179     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
0ae592 180 endef
AL 181
182 define ips-print-depend-require-type-rule
183 $(foreach m,$($(1)_MANIFESTS),$(call ips-print-depend-require-versioned-rule,$(1),$(m)))
184 endef
185
b9e7b2 186 define ips-print-names-rule
AL 187 $(shell cat $(1) $(WS_TOP)/transforms/print-pkgs |\
188     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 |\
a99182 189     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 190 endef
AL 191
192 define ips-print-names-versioned-rule
193 $(foreach v,$($(1)V_VALUES),\
194     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
195     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 196     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
74c605 197 endef
JMC 198
199 #
200 # In addition to the concrete per-version packages, we also need to emit the
201 # name of the generic package which pulls in the concrete packages.
202 #
203 define ips-print-names-generic-rule
204 $(shell cat $(2) $(WS_TOP)/transforms/mkgeneric $(BUILD_DIR)/mkgeneric-python \
205     $(WS_TOP)/transforms/print-pkgs |\
206     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=\#\#\# /dev/fd/0 |\
a99182 207     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 208 endef
AL 209
210 define ips-print-names-type-rule
74c605 211 $(foreach m,$($(1)_MANIFESTS),\
JMC 212     $(call ips-print-names-versioned-rule,$(1),$(m))\
213     $(call ips-print-names-generic-rule,$(1),$(m))\
214 )
b9e7b2 215 endef
AL 216
217 VERSIONED_MANIFEST_TYPES =
218 UNVERSIONED_MANIFESTS = $(filter-out %-GENFRAG.p5m, $(CANONICAL_MANIFESTS))
40754e 219 GENERATE_GENERIC_TRANSFORMS=
b9e7b2 220
5ada66 221 # Look for manifests which need to be duplicated for each version of python.
DD 222 ifeq ($(findstring -PYVER,$(CANONICAL_MANIFESTS)),-PYVER)
b9e7b2 223 VERSIONED_MANIFEST_TYPES+= PY
AL 224 NOPY_MANIFESTS = $(filter-out %-PYVER.p5m,$(UNVERSIONED_MANIFESTS))
5ada66 225 PY_MANIFESTS = $(filter %-PYVER.p5m,$(CANONICAL_MANIFESTS))
ccec59 226 PYV_VALUES = $(subst .,,$(PYTHON_VERSIONS))
b9e7b2 227 PYV_FMRI_VERSION = PYV
ccec59 228 PYV_MANIFESTS = $(foreach v,$(PYV_VALUES),$(PY_MANIFESTS:-PYVER.p5m=-$(v).p5m))
MT 229 PYNV_MANIFESTS = $(PY_MANIFESTS:-PYVER.p5m=.p5m)
74c605 230 MKGENERIC_SCRIPTS += $(BUILD_DIR)/mkgeneric-python
5ada66 231 else
b9e7b2 232 NOPY_MANIFESTS = $(UNVERSIONED_MANIFESTS)
5ada66 233 endif
DD 234
3129b3 235 # PYTHON_PYV_VALUES contains list of all possible PYV values we could encounter:
MT 236 # - for all currently supported python versions (from PYTHON_VERSIONS)
237 # - for all python versions we are currently obsoleting (from PYTHON_VERSIONS_OBSOLETING)
238 # - the $(PYV) string itself
ccec59 239 PYTHON_PYV_VALUES = $(subst .,,$(PYTHON_VERSIONS) $(PYTHON_VERSIONS_OBSOLETING)) $$(PYV)
3129b3 240 # Convert REQUIRED_PACKAGES to PYTHON_REQUIRED_PACKAGES for runtime/python
MT 241 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(PYTHON_PYV_VALUES), -e 's|^\(.*runtime/python\)-$(v)$$|PYTHON_\1|g')
242 # Convert REQUIRED_PACKAGES to PYTHON_REQUIRED_PACKAGES for library/python/*
243 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(PYTHON_PYV_VALUES), -e 's|^\(.*library/python/.*\)-$(v)$$|PYTHON_\1|g')
244
5ada66 245 # Look for manifests which need to be duplicated for each version of perl.
DD 246 ifeq ($(findstring -PERLVER,$(UNVERSIONED_MANIFESTS)),-PERLVER)
b9e7b2 247 VERSIONED_MANIFEST_TYPES+= PERL
AL 248 NOPERL_MANIFESTS = $(filter-out %-PERLVER.p5m,$(NOPY_MANIFESTS))
5ada66 249 PERL_MANIFESTS = $(filter %-PERLVER.p5m,$(UNVERSIONED_MANIFESTS))
ccec59 250 PERLV_VALUES = $(subst .,,$(PERL_VERSIONS))
b9e7b2 251 PERLV_FMRI_VERSION = PLV
ccec59 252 PERLV_MANIFESTS = $(foreach v,$(PERLV_VALUES),$(PERL_MANIFESTS:-PERLVER.p5m=-$(v).p5m))
MT 253 PERLNV_MANIFESTS = $(PERL_MANIFESTS:-PERLVER.p5m=.p5m)
5ada66 254 else
b9e7b2 255 NOPERL_MANIFESTS = $(NOPY_MANIFESTS)
5ada66 256 endif
DD 257
45844d 258 # PERL_PLV_VALUES contains list of all possible PLV values we could encounter:
MT 259 # - for all currently supported perl versions (from PERL_VERSIONS)
260 # - for all perl versions we are currently obsoleting (from PERL_VERSIONS_OBSOLETING)
261 # - the $(PLV) string itself
987d15 262 PERL_PLV_VALUES = $(subst .,,$(PERL_VERSIONS) $(PERL_VERSIONS_OBSOLETING)) $$(PLV)
45844d 263 # Convert REQUIRED_PACKAGES to PERL_REQUIRED_PACKAGES for runtime/perl
MT 264 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(PERL_PLV_VALUES), -e 's|^\(.*runtime/perl\)-$(v)$$|PERL_\1|g')
265 # Convert REQUIRED_PACKAGES to PERL_REQUIRED_PACKAGES for library/perl-5/*
266 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(PERL_PLV_VALUES), -e 's|^\(.*library/perl-5/.*\)-$(v)$$|PERL_\1|g')
267
18b823 268 # Look for manifests which need to be duplicated for each version of ruby.
AP 269 # NOPERL_MANIFESTS represents the manifests that are not Python or
270 # Perl manifests.  Extract the Ruby Manifests from NOPERL_MANIFESTS.
271 # Any remaining manifests are stored in NONRUBY_MANIFESTS
272 ifeq ($(findstring -RUBYVER,$(NOPERL_MANIFESTS)),-RUBYVER)
b9e7b2 273 VERSIONED_MANIFEST_TYPES+= RUBY
AL 274 NORUBY_MANIFESTS = $(filter-out %-RUBYVER.p5m,$(NOPERL_MANIFESTS))
18b823 275 RUBY_MANIFESTS = $(filter %-RUBYVER.p5m,$(NOPERL_MANIFESTS))
b9e7b2 276 RUBYV_VALUES = $(RUBY_VERSIONS)
AL 277 RUBYV_FMRI_VERSION = RUBYV
ccec59 278 RUBYV_MANIFESTS = $(foreach v,$(RUBY_VERSIONS),$(RUBY_MANIFESTS:-RUBYVER.p5m=-$(shell echo $(v) | cut -d. -f1,2 | tr -d .).p5m))
MT 279 RUBYNV_MANIFESTS = $(RUBY_MANIFESTS:-RUBYVER.p5m=.p5m)
18b823 280 else
AP 281 NORUBY_MANIFESTS = $(NOPERL_MANIFESTS)
282 endif
b9e7b2 283
AL 284 NONVER_MANIFESTS = $(NORUBY_MANIFESTS)
18b823 285
5ada66 286 VERSIONED_MANIFESTS = \
DD 287     $(PYV_MANIFESTS) $(PYNV_MANIFESTS) \
288     $(PERLV_MANIFESTS) $(PERLNV_MANIFESTS) \
18b823 289     $(RUBYV_MANIFESTS) $(RUBYNV_MANIFESTS) \
94deda 290     $(NORUBY_MANIFESTS) $(HISTORICAL_MANIFESTS)
5ada66 291
6514ee 292 GENERATED =        $(MANIFEST_BASE)-generated
NJ 293 COMBINED =        $(MANIFEST_BASE)-combined
5ada66 294 MANIFESTS =        $(VERSIONED_MANIFESTS:%=$(MANIFEST_BASE)-%)
6514ee 295
NJ 296
5ada66 297 DEPENDED=$(VERSIONED_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend)
DD 298 RESOLVED=$(VERSIONED_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend.res)
4221e1 299 PRE_PUBLISHED=$(RESOLVED:%.depend.res=%.pre-published)
93b18c 300 PUBLISHED=$(RESOLVED:%.depend.res=%.published)
9c75c0 301
7e871a 302 COPYRIGHT_FILE ?=    $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
d05a6f 303 IPS_COMPONENT_VERSION ?=    $(COMPONENT_VERSION)
153732 304
6514ee 305 .DEFAULT:        publish
153732 306
3dc823 307 .SECONDARY:
9c75c0 308
2ae1af 309 # allow publishing to be overridden, such as when
MS 310 # a package is for one architecture only.
4221e1 311 PRE_PUBLISH_STAMP ?= $(BUILD_DIR)/.pre-published-$(MACH)
2ae1af 312 PUBLISH_STAMP ?= $(BUILD_DIR)/.published-$(MACH)
MS 313
4221e1 314 # Do all that is needed to ensure the package is consistent for publishing,
JK 315 # except actually pushing to a repo, separately from the push to the repo.
86e587 316 pre-publish:    build install $(PRE_PUBLISH_STAMP)
7d5416 317 publish:        pre-publish update-metadata $(PUBLISH_STAMP)
9c75c0 318
ff17eb 319 sample-manifest:    $(GENERATED).p5m
9c75c0 320
f045de 321 $(GENERATED).p5m:    install $(GENERATE_EXTRA_DEPS)
5b9db7 322     [ ! -d $(SAMPLE_MANIFEST_DIR) ] && $(MKDIR) $(SAMPLE_MANIFEST_DIR) || true
ade6bb 323     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
NJ 324     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(GENERATE_TRANSFORMS) | \
856730 325         sed -e '/^$$/d' -e '/^#.*$$/d' \
053684 326         -e '/\.la$$/d' | \
c89418 327         $(PKGFMT) -u | \
f48e19 328         uniq | \
c89418 329         $(PKGFMT) | \
9c1e84 330         cat $(METADATA_TEMPLATE) - $(GENERATE_EXTRA_CMD) | \
5b9db7 331         $(TEE) $@ $(SAMPLE_MANIFEST_FILE) >/dev/null
40754e 332     if [ "$(GENERATE_GENERIC_TRANSFORMS)X" != "X" ]; \
AL 333     then sed $(GENERATE_GENERIC_TRANSFORMS) $(SAMPLE_MANIFEST_FILE) \
334         | gawk '!seen[$$0]++' > $(GENERIC_MANIFEST_FILE); fi;
6514ee 335
ade6bb 336 # copy the canonical manifest(s) to the build tree
86e587 337 $(MANIFEST_BASE)-%.generate:    %.p5m canonical-manifests
ade6bb 338     cat $(METADATA_TEMPLATE) $< >$@
6514ee 339
5ada66 340 # The text of a transform that will emit a dependency conditional on the
DD 341 # presence of a particular version of a runtime, which will then draw in the
342 # runtime-version-specific version of the package we're operating on.  $(1) is
343 # the name of the runtime package, and $(2) is the version suffix.
344 mkgeneric = \
345     echo "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
346         "-> emit depend nodrop=true type=conditional" \
347         "predicate=$(1)-$(2) fmri=%<1>-$(2)@%<2>>" >> $@;
348
c11706 349 mkgenericdep = \
AP 350     ( echo -n "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
351         "-> emit depend nodrop=true type=require-any " ;  \
352         for i in $(2); do echo -n "fmri=%<1>-$$i@%<2> " ; done ; \
353         echo ">" ) >> $@
354
5ada66 355 # Define and execute a macro that generates a rule to create a manifest for a
DD 356 # python module specific to a particular version of the python runtime.
357 define python-manifest-rule
6ce466 358 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_$(1)_ONLY= PYTHON_$(1)_EXCL=\#
bd5c30 359
44f1c2 360 ifneq ($(filter $(1),$(PYTHON_64_ONLY_VERSIONS)),)
e5ce0b 361 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_32_ONLY=\#
44f1c2 362 endif
AP 363
e5ce0b 364 $(MANIFEST_BASE)-%-$(2).p5m: %-PYVER.p5m
AP 365     $(PKGMOGRIFY) -D PYVER=$(1) $(MANIFEST_LIMITING_VARS) -D PYV=$(2)  $$< > $$@
5ada66 366 endef
ccec59 367 $(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-manifest-rule,$(ver),$(subst .,,$(ver)))))
5ada66 368
e299f6 369 ifeq ($(strip $(SINGLE_PYTHON_VERSION)),yes)
MT 370 PKG_MACROS += PYVER=$(PYTHON_VERSION)
ccec59 371 PKG_MACROS += PYV=$(subst .,,$(PYTHON_VERSION))
e299f6 372 endif
MT 373
5ada66 374 # A rule to create a helper transform package for python, that will insert the
DD 375 # appropriate conditional dependencies into a python library's
376 # runtime-version-generic package to pull in the version-specific bits when the
377 # corresponding version of python is on the system.
74c605 378 $(BUILD_DIR)/mkgeneric-python: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ) $(BUILD_DIR)
5ada66 379     $(RM) $@
ccec59 380     $(foreach ver,$(subst .,,$(PYTHON_VERSIONS)), \
5ada66 381         $(call mkgeneric,runtime/python,$(ver)))
ccec59 382     $(call mkgenericdep,runtime/python,$(subst .,,$(PYTHON_VERSIONS)))
5ada66 383
DD 384 # Build Python version-wrapping manifests from the generic version.
86e587 385 $(MANIFEST_BASE)-%.p5m: %-PYVER.p5m $(BUILD_DIR)/mkgeneric-python
525ed1 386     $(PKGMOGRIFY) -D PYV=### $(BUILD_DIR)/mkgeneric-python \
5ada66 387         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 388     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
389
9581d1 390 # Define and execute a macro that generates a rule to create a manifest for a
CM 391 # perl module specific to a particular version of the perl runtime.
392 define perl-manifest-rule
ccec59 393 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-PERLVER.p5m
MT 394     $(PKGMOGRIFY) -D PERLVER=$(1) -D PLV=$$(subst .,,$(1)) \
8478d1 395         -D PERL_ARCH=$$(call PERL_ARCH_FUNC,$$(PERL.$(1))) $$< > $$@
9581d1 396 endef
CM 397 $(foreach ver,$(PERL_VERSIONS),$(eval $(call perl-manifest-rule,$(ver))))
398
e299f6 399 ifeq ($(strip $(SINGLE_PERL_VERSION)),yes)
MT 400 PKG_MACROS += PERLVER=$(PERL_VERSION)
ccec59 401 PKG_MACROS += PLV=$(subst .,,$(PERL_VERSION))
e299f6 402 endif
MT 403
5ada66 404 # A rule to create a helper transform package for perl, that will insert the
DD 405 # appropriate conditional dependencies into a perl library's
406 # runtime-version-generic package to pull in the version-specific bits when the
407 # corresponding version of perl is on the system.
525ed1 408 $(BUILD_DIR)/mkgeneric-perl: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
5ada66 409     $(RM) $@
ccec59 410     $(foreach ver,$(subst .,,$(PERL_VERSIONS)), \
5ada66 411         $(call mkgeneric,runtime/perl,$(ver)))
ccec59 412     $(call mkgenericdep,runtime/perl,$(subst .,,$(PERL_VERSIONS)))
5ada66 413
DD 414 # Build Perl version-wrapping manifests from the generic version.
86e587 415 $(MANIFEST_BASE)-%.p5m: %-PERLVER.p5m $(BUILD_DIR)/mkgeneric-perl
525ed1 416     $(PKGMOGRIFY) -D PLV=### $(BUILD_DIR)/mkgeneric-perl \
5ada66 417         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 418     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
419
94deda 420 # Rule to generate historical manifests from the $(HISTORY) file.
AP 421 define history-manifest-rule
422 $(MANIFEST_BASE)-$(1): $(HISTORY) $(BUILD_DIR)
423     $(NAWK) -v TARGET=$(1) -v FUNCTION=manifest -f $(GENERATE_HISTORY) < \
424         $(HISTORY) > $$@
425 endef
426 $(foreach mfst,$(HISTORICAL_MANIFESTS),$(eval $(call history-manifest-rule,$(mfst))))
427
18b823 428 # Define and execute a macro that generates a rule to create a manifest for a
AP 429 # ruby module specific to a particular version of the ruby runtime.
430 # Creates build/manifest-*-modulename-##.p5m file where ## is replaced with
431 # the version number.
432 define ruby-manifest-rule
ccec59 433 $(MANIFEST_BASE)-%-$(subst .,,$(1)).mogrified: \
18b823 434         PKG_MACROS += RUBY_VERSION=$(1) RUBY_LIB_VERSION=$(2) \
AP 435             RUBYV=$(subst .,,$(1))
436
ccec59 437 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-RUBYVER.p5m
MT 438     if [ -f $$*-$(subst .,,$(1))GENFRAG.p5m ]; then \
439             cat $$*-$(subst .,,$(1))GENFRAG.p5m >> $$@; \
18b823 440     fi
AP 441     $(PKGMOGRIFY) -D RUBY_VERSION=$(1) -D RUBY_LIB_VERSION=$(2) \
ccec59 442         -D RUBYV=$(subst .,,$(1)) $$< > $$@
18b823 443 endef
AP 444 $(foreach ver,$(RUBY_VERSIONS),\
445         $(eval $(call ruby-manifest-rule,$(shell echo $(ver) | \
446             cut -d. -f1,2),$(ver))))
447
448 # A rule to create a helper transform package for ruby, that will insert the
449 # appropriate conditional dependencies into a ruby library's
450 # runtime-version-generic package to pull in the version-specific bits when the
451 # corresponding version of ruby is on the system.
525ed1 452 $(BUILD_DIR)/mkgeneric-ruby: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
18b823 453     $(RM) $@
AP 454     $(foreach ver,$(RUBY_VERSIONS),\
455             $(call mkgeneric,runtime/ruby,$(shell echo $(ver) | \
456                 cut -d. -f1,2 | tr -d .)))
c11706 457     $(call mkgenericdep,runtime/ruby,$(shell echo $(RUBY_VERSIONS) | cut -d. -f1,2 | tr -d .))
18b823 458
AP 459 # Build Ruby version-wrapping manifests from the generic version.
460 # Creates build/manifest-*-modulename.p5m file.
461 #
86e587 462 $(MANIFEST_BASE)-%.p5m: %-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
18b823 463     $(PKGMOGRIFY) -D RUBYV=### $(BUILD_DIR)/mkgeneric-ruby \
AP 464             $(WS_TOP)/transforms/mkgeneric $< > $@
465     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
466
9928c1 467 ifeq   ($(strip $(COMPONENT_AUTOGEN_MANIFEST)),yes)
280925 468 # auto-generate file/directory list
86e587 469 $(MANIFEST_BASE)-%.generated:    %.p5m $(BUILD_DIR)
280925 470     (cat $(METADATA_TEMPLATE); \
AS 471     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR)) | \
472     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(AUTOGEN_MANIFEST_TRANSFORMS) | \
473         sed -e '/^$$/d' -e '/^#.*$$/d' | $(PKGFMT) | \
474         cat $< - >$@
475
5ada66 476 # mogrify non-parameterized manifests
395f73 477 $(MANIFEST_BASE)-%.mogrified:    %.generated $(MAKEFILE_PREREQ)
cf5bf1 478     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 479         $(PUBLISH_TRANSFORMS) | \
480         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
481
482 # mogrify parameterized manifests
395f73 483 $(MANIFEST_BASE)-%.mogrified:    $(MANIFEST_BASE)-%.generated $(MAKEFILE_PREREQ)
cf5bf1 484     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 485         $(PUBLISH_TRANSFORMS) | \
486         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
487 else
488 # mogrify non-parameterized manifests
395f73 489 $(MANIFEST_BASE)-%.mogrified:    %.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
5ada66 490     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
DD 491         $(PUBLISH_TRANSFORMS) | \
492         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
493
494 # mogrify parameterized manifests
395f73 495 $(MANIFEST_BASE)-%.mogrified:    $(MANIFEST_BASE)-%.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
70eebe 496     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 497         $(PUBLISH_TRANSFORMS) | \
NJ 498         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
cf5bf1 499 endif
6514ee 500
4158c0 501 # mangle the file contents
c2319a 502 $(BUILD_DIR) $(MANGLED_DIR):
4158c0 503     $(MKDIR) $@
NJ 504
505 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
506 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
507     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
508
1aa2da 509 # generate dependencies
35a012 510 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 511 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 512     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 513
4505fe 514 # pkgdepend resolve builds a map of all installed packages by default.  This
RL 515 # makes dependency resolution particularly slow.  We can dramatically improve
516 # performance here by creating a file with a list of packages that we know
517 # are needed, dramatically reducing the overhead involved in creating and
518 # searching this map.
519 #
520 # Generate a resolve.deps file from the dependencies in the Makefile and
521 # fragments that it uses.
522 RESOLVE_DEPS=$(BUILD_DIR)/resolve.deps
9f160e 523
c0099a 524 $(RESOLVE_DEPS):    Makefile $(BUILD_DIR) $(DEPENDED)
AP 525     @(for pkg in $(REQUIRED_PACKAGES:%=/%) ; do \
4505fe 526         echo $${pkg} ; \
c0099a 527     done ; \
AP 528     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) | \
a99182 529         $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' ;) | $(SORT) -u >$@
9f160e 530
9bec61 531 $(BUILD_DIR)/runtime-perl.p5m: $(WS_TOOLS)/runtime-perl.p5m
MT 532     $(CP) $< $@
533
93b18c 534 # resolve the dependencies all at once
9bec61 535 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED) $(RESOLVE_DEPS) $(BUILD_DIR)/runtime-perl.p5m
MT 536     $(PKGDEPEND) resolve $(RESOLVE_DEPS:%=-e %) -m $(DEPENDED) $(BUILD_DIR)/runtime-perl.p5m
d05a6f 537     $(TOUCH) $@
NJ 538
f9fb69 539 # generate list of sed rules to filter out component's own packages from
MT 540 # REQUIRED_PACKAGES list
541 $(BUILD_DIR)/filter-own-pkgs: $(DEPENDED)
542     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) \
543         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' -e 's/^\///g' -e 's/\//\\\//g' \
a99182 544         | $(SORT) -u \
f9fb69 545         | $(GSED) -e 's/^\(.*\)$$/\/^REQUIRED_PACKAGES += \1$$\/d/g' >$@
MT 546
e6ade5 547 # Set REQUIRED_PACKAGES macro substitution rules
32921b 548 REQUIRED_PACKAGES_TRANSFORM += $(foreach p,$(REQUIRED_PACKAGES_SUBST), -e 's|$($(p))|$$($(p))|')
e6ade5 549
d180f2 550 #
1d4bf3 551 # Generate a set of REQUIRED_PACKAGES based on what is needed for pkgdepend to
MT 552 # resolve properly.  Automatically update the list in your Makefile for the
553 # truly lazy among us.  This is only a piece of the REQUIRED_PACKAGES puzzle.
d180f2 554 # You must still include packages for tools you build and test with.
555 #
372e47 556 REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs $(REQUIRED_PACKAGES_EXTRA_DEPS)
4d720d 557     $(GMAKE) RESOLVE_DEPS= $(BUILD_DIR)/.resolved-$(MACH)
1d4bf3 558     @$(GSED) -i -e '/^# Auto-generated dependencies$$/,$$d' Makefile
b80d3d 559     @echo "# Auto-generated dependencies" >>Makefile
91663e 560     $(PKGMOGRIFY) $(WS_TRANSFORMS)/$@ $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) \
MT 561         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' \
562         | tr '|' '\n' \
f9fb69 563         | $(GSED) -e 's,pkg:/,,g' -e 's/@.*$$//g' \
MT 564             -f $(BUILD_DIR)/filter-own-pkgs \
565             $(REQUIRED_PACKAGES_TRANSFORM) \
a99182 566         | $(SORT) -u >>Makefile
1d4bf3 567     @echo "*** Please edit your Makefile and verify the new or updated content at the end ***"
d180f2 568
569
d05a6f 570 # lint the manifests all at once
NJ 571 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
572     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 573     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
694ef3 574         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 575             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 576     $(TOUCH) $@
577
0f1b63 578 lintme: FRC
AC 579     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 580     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
0f1b63 581         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
AC 582             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
583
584 FRC:
585
3dc823 586
ade6bb 587 # published
69d0f5 588 PKGSEND_PUBLISH_OPTIONS = -s $(WS_REPO) publish --fmri-in-manifest
35a012 589 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
abb76c 590 PKGSEND_PUBLISH_OPTIONS += -T \*.py
4221e1 591
JK 592 # Do all the hard work that is needed to ensure the package is consistent
593 # and ready for publishing, except actually pushing bits to a repository
594 $(MANIFEST_BASE)-%.pre-published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
1080cc 595     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 596         $(FINAL_TRANSFORMS) | \
597         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
4221e1 598     @echo "NEW PACKAGE CONTENTS ARE LOCALLY VALIDATED AND READY TO GO"
JK 599
600 # Push to the repo
601 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.pre-published
35a012 602     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 603     $(PKGFMT) <$< >$@
4221e1 604
JK 605 $(BUILD_DIR)/.pre-published-$(MACH):    $(PRE_PUBLISHED)
606     $(TOUCH) $@
6514ee 607
d05a6f 608 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 609     $(TOUCH) $@
NJ 610
0ae592 611 print-depend-require:    canonical-manifests
AL 612     @echo $(call ips-print-depend-require-rule,$(NONVER_MANIFESTS)) \
613         $(foreach t,$(VERSIONED_MANIFEST_TYPES),$(call ips-print-depend-require-type-rule,$(t))) | tr ' ' '\n'
614
74c605 615 print-package-names:    canonical-manifests $(MKGENERIC_SCRIPTS)
b9e7b2 616     @echo $(call ips-print-names-rule,$(NONVER_MANIFESTS)) \
74c605 617         $(foreach t,$(VERSIONED_MANIFEST_TYPES),\
JMC 618             $(call ips-print-names-type-rule,$(t))) \
619         | tr ' ' '\n'
a325d4 620
NJ 621 print-package-paths:    canonical-manifests
b9e7b2 622     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
a325d4 623         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 624         sed -e '/^$$/d' -e '/^#.*$$/d' | \
a99182 625         $(SORT) -u
a325d4 626
3dc823 627 install-packages:    publish
NJ 628     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
5ada66 629         cat $(VERSIONED_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
4221e1 630         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 631         sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | \
a99182 632         $(SORT) -u | \
4221e1 633         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
JK 634      else ; \
3dc823 635         echo "unsafe to install package(s) automatically" ; \
4221e1 636      fi
3dc823 637
86e587 638 $(RESOLVED):    install
3dc823 639
NJ 640 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 641 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 642     # If there were no canonical manifests in the workspace, nothing will
643     # be published and we should fail.  A sample manifest can be generated
644     # with
645     #   $ gmake sample-manifest
646     # Once created, it will need to be reviewed, edited, and added to the
647     # workspace.
648     $(error Missing canonical manifest(s))
649 endif
a325d4 650
e5ce0b 651 # Component variables are expanded directly to PKG_OPTIONS instead of via
AP 652 # PKG_MACROS since the values may contain whitespace.
961188 653 mkdefine = -D $(1)="$$(strip $(2))"
e5ce0b 654
AP 655 # Expand PKG_VARS into defines via PKG_OPTIONS.
656 $(foreach var, $(PKG_VARS), \
657     $(eval PKG_OPTIONS += $(call mkdefine,$(var),$$($(var)))) \
658 )
659
a325d4 660 # This converts required paths to containing package names for be able to
NJ 661 # properly setup the build environment for a component.
662 required-pkgs.mk:    Makefile
663     @echo "generating $@ from Makefile REQUIRED_* data"
664     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
665         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
666
3dc823 667 pre-prep:    required-pkgs.mk
NJ 668
669
a325d4 670 CLEAN_PATHS +=    required-pkgs.mk
525ed1 671 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-perl
AP 672 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-python
673 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-ruby