fritzkink
2023-12-27 706019354bab81fc3f01995caf1ae1a2dfa346cf
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 #
7f9306 21 # Copyright (c) 2011, 2015, 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
280925 99 AUTOGEN_MANIFEST_TRANSFORMS +=        $(WS_TOP)/transforms/drop-all
AS 100
e5ce0b 101 # For items defined as variables or that may contain whitespace, add
AP 102 # them to a list to be expanded into PKG_OPTIONS later.
103 PKG_VARS += MACH MACH32 MACH64
104 PKG_VARS += BUILD_VERSION OS_VERSION PKG_SOLARIS_VERSION
e7f82d 105 PKG_VARS += GNU_TRIPLET
8dc1cb 106 PKG_VARS += GCC_GNU_TRIPLET
e5ce0b 107 PKG_VARS += CONSOLIDATION
AP 108 PKG_VARS += COMPONENT_VERSION IPS_COMPONENT_VERSION HUMAN_VERSION
109 PKG_VARS += COMPONENT_ARCHIVE_URL COMPONENT_PROJECT_URL COMPONENT_NAME
110 PKG_VARS += COMPONENT_FMRI COMPONENT_LICENSE_FILE
111 PKG_VARS += COMPONENT_SUMMARY COMPONENT_DESCRIPTION COMPONENT_LICENSE
112 PKG_VARS += HG_REPO HG_REV HG_URL COMPONENT_HG_URL COMPONENT_HG_REV
113 PKG_VARS += GIT_COMMIT_ID GIT_REPO GIT_TAG
114 PKG_VARS += PUBLISHER PUBLISHER_LOCALIZABLE
115 PKG_VARS += USERLAND_GIT_REMOTE USERLAND_GIT_BRANCH USERLAND_GIT_REV
72621a 116 PKG_VARS += COMPONENT
e5ce0b 117
AP 118 # For items that need special definition, add them to PKG_MACROS.
119 # IPS_COMPONENT_VERSION suitable for use in regular expressions.
120 PKG_MACROS += IPS_COMPONENT_RE_VERSION=$(subst .,\\.,$(IPS_COMPONENT_VERSION))
121 # COMPONENT_VERSION suitable for use in regular expressions.
122 PKG_MACROS += COMPONENT_RE_VERSION=$(subst .,\\.,$(COMPONENT_VERSION))
db59b9 123 # HUMAN_VERSION suitable for use in regular expressions.
MT 124 PKG_MACROS += HUMAN_VERSION_RE=$(subst .,\\.,$(HUMAN_VERSION))
6514ee 125
cce78d 126 PKG_OPTIONS +=        $(PKG_MACROS:%=-D %) \
e5ce0b 127                     -D COMPONENT_CLASSIFICATION="org.opensolaris.category.2008:$(strip $(COMPONENT_CLASSIFICATION))"
6514ee 128
15328e 129 define mach-list-generate-macros
AL 130 ifeq ($(MACH),$(1))
131 PKG_MACROS +=           $(1)_ONLY=
132 PKG_MACROS +=           $(1)_EXCL=\#
133 else
134 PKG_MACROS +=           $(1)_ONLY=\#
135 PKG_MACROS +=           $(1)_EXCL=
136 endif
137 endef
138 $(foreach isa,$(MACH_LIST),$(eval $(call mach-list-generate-macros,$(isa))))
139
6ce466 140 define python-generate-macros
AL 141 PKG_MACROS +=           PYTHON_$(1)_ONLY=\#
142 PKG_MACROS +=           PYTHON_$(1)_EXCL=
143 endef
144 $(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-generate-macros,$(ver))))
145
44f1c2 146 PKG_MACROS +=           PYTHON_32_ONLY=
bd5c30 147
4158c0 148 MANGLED_DIR =    $(PROTO_DIR)/mangled
NJ 149
150 PKG_PROTO_DIRS += $(MANGLED_DIR) $(PROTO_DIR) $(@D) $(COMPONENT_DIR) $(COMPONENT_SRC)
35a012 151
74300c 152 MANIFEST_BASE =        $(BUILD_DIR)/manifest-$(MACH)
6514ee 153
5b9db7 154 SAMPLE_MANIFEST_DIR =     $(COMPONENT_DIR)/manifests
155 SAMPLE_MANIFEST_FILE =    $(SAMPLE_MANIFEST_DIR)/sample-manifest.p5m
156
7f9306 157 CANONICAL_MANIFESTS =    $(filter-out dummy.p5m,$(wildcard *.p5m))
94deda 158 ifneq ($(wildcard $(HISTORY)),)
AP 159 HISTORICAL_MANIFESTS = $(shell $(NAWK) -v FUNCTION=name -f $(GENERATE_HISTORY) < $(HISTORY))
160 endif
5ada66 161
8930d5 162 # Support for arch specific manifests
MT 163 ARCH_MANIFESTS =    $(wildcard *.p5m.$(MACH))
164 GENERATED_ARCH_MANIFESTS =    $(ARCH_MANIFESTS:%.p5m.$(MACH)=%.p5m)
165 CANONICAL_MANIFESTS +=  $(GENERATED_ARCH_MANIFESTS)
166
167 %.p5m:     %.p5m.$(MACH)
168     $(CP) $< $@
169
0ae592 170 define ips-print-depend-require-rule
AL 171 $(shell cat $(1) $(WS_TOP)/transforms/print-depend-require |\
172     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 |\
a99182 173     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
0ae592 174 endef
AL 175
176 define ips-print-depend-require-versioned-rule
177 $(foreach v,$($(1)V_VALUES),\
178     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
179     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 180     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
0ae592 181 endef
AL 182
183 define ips-print-depend-require-type-rule
184 $(foreach m,$($(1)_MANIFESTS),$(call ips-print-depend-require-versioned-rule,$(1),$(m)))
185 endef
186
b9e7b2 187 define ips-print-names-rule
AL 188 $(shell cat $(1) $(WS_TOP)/transforms/print-pkgs |\
6383f6 189     $(PKGMOGRIFY) $(PKG_OPTIONS) $(call per-manifest-options,$(1:.p5m=)) /dev/fd/0 |\
a99182 190     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 191 endef
AL 192
193 define ips-print-names-versioned-rule
194 $(foreach v,$($(1)V_VALUES),\
195     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
196     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 197     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
74c605 198 endef
JMC 199
200 #
201 # In addition to the concrete per-version packages, we also need to emit the
202 # name of the generic package which pulls in the concrete packages.
203 #
204 define ips-print-names-generic-rule
205 $(shell cat $(2) $(WS_TOP)/transforms/mkgeneric $(BUILD_DIR)/mkgeneric-python \
206     $(WS_TOP)/transforms/print-pkgs |\
207     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=\#\#\# /dev/fd/0 |\
a99182 208     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 209 endef
AL 210
211 define ips-print-names-type-rule
74c605 212 $(foreach m,$($(1)_MANIFESTS),\
JMC 213     $(call ips-print-names-versioned-rule,$(1),$(m))\
214     $(call ips-print-names-generic-rule,$(1),$(m))\
215 )
b9e7b2 216 endef
AL 217
218 VERSIONED_MANIFEST_TYPES =
219 UNVERSIONED_MANIFESTS = $(filter-out %-GENFRAG.p5m, $(CANONICAL_MANIFESTS))
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
b2e48c 241 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PYTHON_PYV_VALUES)),-e 's|^\(.*runtime/python\)-$(v)$$|PYTHON_\1|g')
3129b3 242 # Convert REQUIRED_PACKAGES to PYTHON_REQUIRED_PACKAGES for library/python/*
b2e48c 243 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PYTHON_PYV_VALUES)),-e 's|^\(.*library/python/.*\)-$(v)$$|PYTHON_\1|g')
3129b3 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
b2e48c 264 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PERL_PLV_VALUES)),-e 's|^\(.*runtime/perl\)-$(v)$$|PERL_\1|g')
45844d 265 # Convert REQUIRED_PACKAGES to PERL_REQUIRED_PACKAGES for library/perl-5/*
b2e48c 266 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PERL_PLV_VALUES)),-e 's|^\(.*library/perl-5/.*\)-$(v)$$|PERL_\1|g')
45844d 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) \
7f9306 290     $(NORUBY_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)
7f9306 301
MT 302 PUBLISHED +=        $(HISTORICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.published)
9c75c0 303
7e871a 304 COPYRIGHT_FILE ?=    $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
d05a6f 305 IPS_COMPONENT_VERSION ?=    $(COMPONENT_VERSION)
153732 306
6514ee 307 .DEFAULT:        publish
153732 308
3dc823 309 .SECONDARY:
9c75c0 310
2ae1af 311 # allow publishing to be overridden, such as when
MS 312 # a package is for one architecture only.
4221e1 313 PRE_PUBLISH_STAMP ?= $(BUILD_DIR)/.pre-published-$(MACH)
2ae1af 314 PUBLISH_STAMP ?= $(BUILD_DIR)/.published-$(MACH)
MS 315
4221e1 316 # Do all that is needed to ensure the package is consistent for publishing,
JK 317 # except actually pushing to a repo, separately from the push to the repo.
86e587 318 pre-publish:    build install $(PRE_PUBLISH_STAMP)
7d5416 319 publish:        pre-publish update-metadata $(PUBLISH_STAMP)
9c75c0 320
ff17eb 321 sample-manifest:    $(GENERATED).p5m
9c75c0 322
f045de 323 $(GENERATED).p5m:    install $(GENERATE_EXTRA_DEPS)
d936ff 324     $(MKDIR) $(SAMPLE_MANIFEST_DIR)
ade6bb 325     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
NJ 326     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(GENERATE_TRANSFORMS) | \
856730 327         sed -e '/^$$/d' -e '/^#.*$$/d' \
053684 328         -e '/\.la$$/d' | \
c89418 329         $(PKGFMT) -u | \
f48e19 330         uniq | \
c89418 331         $(PKGFMT) | \
9c1e84 332         cat $(METADATA_TEMPLATE) - $(GENERATE_EXTRA_CMD) | \
5b9db7 333         $(TEE) $@ $(SAMPLE_MANIFEST_FILE) >/dev/null
6514ee 334
ade6bb 335 # copy the canonical manifest(s) to the build tree
86e587 336 $(MANIFEST_BASE)-%.generate:    %.p5m canonical-manifests
ade6bb 337     cat $(METADATA_TEMPLATE) $< >$@
6514ee 338
5ada66 339 # The text of a transform that will emit a dependency conditional on the
DD 340 # presence of a particular version of a runtime, which will then draw in the
341 # runtime-version-specific version of the package we're operating on.  $(1) is
342 # the name of the runtime package, and $(2) is the version suffix.
343 mkgeneric = \
344     echo "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
345         "-> emit depend nodrop=true type=conditional" \
346         "predicate=$(1)-$(2) fmri=%<1>-$(2)@%<2>>" >> $@;
347
c11706 348 mkgenericdep = \
AP 349     ( echo -n "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
350         "-> emit depend nodrop=true type=require-any " ;  \
351         for i in $(2); do echo -n "fmri=%<1>-$$i@%<2> " ; done ; \
352         echo ">" ) >> $@
353
5ada66 354 # Define and execute a macro that generates a rule to create a manifest for a
DD 355 # python module specific to a particular version of the python runtime.
356 define python-manifest-rule
6ce466 357 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_$(1)_ONLY= PYTHON_$(1)_EXCL=\#
bd5c30 358
44f1c2 359 ifneq ($(filter $(1),$(PYTHON_64_ONLY_VERSIONS)),)
e5ce0b 360 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_32_ONLY=\#
44f1c2 361 endif
AP 362
e5ce0b 363 $(MANIFEST_BASE)-%-$(2).p5m: %-PYVER.p5m
AP 364     $(PKGMOGRIFY) -D PYVER=$(1) $(MANIFEST_LIMITING_VARS) -D PYV=$(2)  $$< > $$@
5ada66 365 endef
ccec59 366 $(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-manifest-rule,$(ver),$(subst .,,$(ver)))))
5ada66 367
e299f6 368 ifeq ($(strip $(SINGLE_PYTHON_VERSION)),yes)
MT 369 PKG_MACROS += PYVER=$(PYTHON_VERSION)
ccec59 370 PKG_MACROS += PYV=$(subst .,,$(PYTHON_VERSION))
e299f6 371 endif
MT 372
5ada66 373 # A rule to create a helper transform package for python, that will insert the
DD 374 # appropriate conditional dependencies into a python library's
375 # runtime-version-generic package to pull in the version-specific bits when the
376 # corresponding version of python is on the system.
74c605 377 $(BUILD_DIR)/mkgeneric-python: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ) $(BUILD_DIR)
5ada66 378     $(RM) $@
ccec59 379     $(foreach ver,$(subst .,,$(PYTHON_VERSIONS)), \
5ada66 380         $(call mkgeneric,runtime/python,$(ver)))
ccec59 381     $(call mkgenericdep,runtime/python,$(subst .,,$(PYTHON_VERSIONS)))
5ada66 382
DD 383 # Build Python version-wrapping manifests from the generic version.
86e587 384 $(MANIFEST_BASE)-%.p5m: %-PYVER.p5m $(BUILD_DIR)/mkgeneric-python
525ed1 385     $(PKGMOGRIFY) -D PYV=### $(BUILD_DIR)/mkgeneric-python \
5ada66 386         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 387     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
388
9581d1 389 # Define and execute a macro that generates a rule to create a manifest for a
CM 390 # perl module specific to a particular version of the perl runtime.
391 define perl-manifest-rule
ccec59 392 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-PERLVER.p5m
MT 393     $(PKGMOGRIFY) -D PERLVER=$(1) -D PLV=$$(subst .,,$(1)) \
8478d1 394         -D PERL_ARCH=$$(call PERL_ARCH_FUNC,$$(PERL.$(1))) $$< > $$@
9581d1 395 endef
CM 396 $(foreach ver,$(PERL_VERSIONS),$(eval $(call perl-manifest-rule,$(ver))))
397
e299f6 398 ifeq ($(strip $(SINGLE_PERL_VERSION)),yes)
MT 399 PKG_MACROS += PERLVER=$(PERL_VERSION)
ccec59 400 PKG_MACROS += PLV=$(subst .,,$(PERL_VERSION))
e299f6 401 endif
MT 402
5ada66 403 # A rule to create a helper transform package for perl, that will insert the
DD 404 # appropriate conditional dependencies into a perl library's
405 # runtime-version-generic package to pull in the version-specific bits when the
406 # corresponding version of perl is on the system.
525ed1 407 $(BUILD_DIR)/mkgeneric-perl: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
5ada66 408     $(RM) $@
ccec59 409     $(foreach ver,$(subst .,,$(PERL_VERSIONS)), \
5ada66 410         $(call mkgeneric,runtime/perl,$(ver)))
ccec59 411     $(call mkgenericdep,runtime/perl,$(subst .,,$(PERL_VERSIONS)))
5ada66 412
DD 413 # Build Perl version-wrapping manifests from the generic version.
86e587 414 $(MANIFEST_BASE)-%.p5m: %-PERLVER.p5m $(BUILD_DIR)/mkgeneric-perl
525ed1 415     $(PKGMOGRIFY) -D PLV=### $(BUILD_DIR)/mkgeneric-perl \
5ada66 416         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 417     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
418
94deda 419 # Rule to generate historical manifests from the $(HISTORY) file.
AP 420 define history-manifest-rule
421 $(MANIFEST_BASE)-$(1): $(HISTORY) $(BUILD_DIR)
422     $(NAWK) -v TARGET=$(1) -v FUNCTION=manifest -f $(GENERATE_HISTORY) < \
423         $(HISTORY) > $$@
424 endef
425 $(foreach mfst,$(HISTORICAL_MANIFESTS),$(eval $(call history-manifest-rule,$(mfst))))
426
18b823 427 # Define and execute a macro that generates a rule to create a manifest for a
AP 428 # ruby module specific to a particular version of the ruby runtime.
429 # Creates build/manifest-*-modulename-##.p5m file where ## is replaced with
430 # the version number.
431 define ruby-manifest-rule
ccec59 432 $(MANIFEST_BASE)-%-$(subst .,,$(1)).mogrified: \
18b823 433         PKG_MACROS += RUBY_VERSION=$(1) RUBY_LIB_VERSION=$(2) \
AP 434             RUBYV=$(subst .,,$(1))
435
ccec59 436 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-RUBYVER.p5m
MT 437     if [ -f $$*-$(subst .,,$(1))GENFRAG.p5m ]; then \
438             cat $$*-$(subst .,,$(1))GENFRAG.p5m >> $$@; \
18b823 439     fi
AP 440     $(PKGMOGRIFY) -D RUBY_VERSION=$(1) -D RUBY_LIB_VERSION=$(2) \
ccec59 441         -D RUBYV=$(subst .,,$(1)) $$< > $$@
18b823 442 endef
AP 443 $(foreach ver,$(RUBY_VERSIONS),\
444         $(eval $(call ruby-manifest-rule,$(shell echo $(ver) | \
445             cut -d. -f1,2),$(ver))))
446
447 # A rule to create a helper transform package for ruby, that will insert the
448 # appropriate conditional dependencies into a ruby library's
449 # runtime-version-generic package to pull in the version-specific bits when the
450 # corresponding version of ruby is on the system.
525ed1 451 $(BUILD_DIR)/mkgeneric-ruby: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
18b823 452     $(RM) $@
AP 453     $(foreach ver,$(RUBY_VERSIONS),\
454             $(call mkgeneric,runtime/ruby,$(shell echo $(ver) | \
455                 cut -d. -f1,2 | tr -d .)))
c11706 456     $(call mkgenericdep,runtime/ruby,$(shell echo $(RUBY_VERSIONS) | cut -d. -f1,2 | tr -d .))
18b823 457
AP 458 # Build Ruby version-wrapping manifests from the generic version.
459 # Creates build/manifest-*-modulename.p5m file.
460 #
86e587 461 $(MANIFEST_BASE)-%.p5m: %-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
18b823 462     $(PKGMOGRIFY) -D RUBYV=### $(BUILD_DIR)/mkgeneric-ruby \
AP 463             $(WS_TOP)/transforms/mkgeneric $< > $@
464     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
465
6383f6 466 per-manifest-options = $(foreach var,$(PKG_VARS),$(if $($(var).$(1)),-D $(var)="$(strip $($(var).$(1)))")) \
MT 467     $(if $(COMPONENT_CLASSIFICATION.$(1)),-D COMPONENT_CLASSIFICATION="org.opensolaris.category.2008:$(strip $(COMPONENT_CLASSIFICATION.$(1)))")
468
cf5bf1 469 # mogrify non-parameterized manifests
395f73 470 $(MANIFEST_BASE)-%.mogrified:    %.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
6383f6 471     $(PKGMOGRIFY) $(PKG_OPTIONS) $(call per-manifest-options,$*) $< \
5ada66 472         $(PUBLISH_TRANSFORMS) | \
DD 473         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
474
475 # mogrify parameterized manifests
395f73 476 $(MANIFEST_BASE)-%.mogrified:    $(MANIFEST_BASE)-%.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
70eebe 477     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 478         $(PUBLISH_TRANSFORMS) | \
NJ 479         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
6514ee 480
4158c0 481 # mangle the file contents
c2319a 482 $(BUILD_DIR) $(MANGLED_DIR):
4158c0 483     $(MKDIR) $@
NJ 484
485 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
486 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
487     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
488
1aa2da 489 # generate dependencies
35a012 490 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 491 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 492     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 493
4505fe 494 # pkgdepend resolve builds a map of all installed packages by default.  This
RL 495 # makes dependency resolution particularly slow.  We can dramatically improve
496 # performance here by creating a file with a list of packages that we know
497 # are needed, dramatically reducing the overhead involved in creating and
498 # searching this map.
499 #
500 # Generate a resolve.deps file from the dependencies in the Makefile and
501 # fragments that it uses.
502 RESOLVE_DEPS=$(BUILD_DIR)/resolve.deps
9f160e 503
c0099a 504 $(RESOLVE_DEPS):    Makefile $(BUILD_DIR) $(DEPENDED)
AP 505     @(for pkg in $(REQUIRED_PACKAGES:%=/%) ; do \
4505fe 506         echo $${pkg} ; \
c0099a 507     done ; \
AP 508     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) | \
a99182 509         $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' ;) | $(SORT) -u >$@
9f160e 510
9bec61 511 $(BUILD_DIR)/runtime-perl.p5m: $(WS_TOOLS)/runtime-perl.p5m
MT 512     $(CP) $< $@
513
93b18c 514 # resolve the dependencies all at once
9bec61 515 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED) $(RESOLVE_DEPS) $(BUILD_DIR)/runtime-perl.p5m
MT 516     $(PKGDEPEND) resolve $(RESOLVE_DEPS:%=-e %) -m $(DEPENDED) $(BUILD_DIR)/runtime-perl.p5m
d05a6f 517     $(TOUCH) $@
NJ 518
f9fb69 519 # generate list of sed rules to filter out component's own packages from
MT 520 # REQUIRED_PACKAGES list
521 $(BUILD_DIR)/filter-own-pkgs: $(DEPENDED)
522     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) \
523         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' -e 's/^\///g' -e 's/\//\\\//g' \
a99182 524         | $(SORT) -u \
f9fb69 525         | $(GSED) -e 's/^\(.*\)$$/\/^REQUIRED_PACKAGES += \1$$\/d/g' >$@
MT 526
e6ade5 527 # Set REQUIRED_PACKAGES macro substitution rules
32921b 528 REQUIRED_PACKAGES_TRANSFORM += $(foreach p,$(REQUIRED_PACKAGES_SUBST), -e 's|$($(p))|$$($(p))|')
e6ade5 529
d180f2 530 #
1d4bf3 531 # Generate a set of REQUIRED_PACKAGES based on what is needed for pkgdepend to
MT 532 # resolve properly.  Automatically update the list in your Makefile for the
533 # truly lazy among us.  This is only a piece of the REQUIRED_PACKAGES puzzle.
d180f2 534 # You must still include packages for tools you build and test with.
535 #
372e47 536 REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs $(REQUIRED_PACKAGES_EXTRA_DEPS)
4d720d 537     $(GMAKE) RESOLVE_DEPS= $(BUILD_DIR)/.resolved-$(MACH)
1d4bf3 538     @$(GSED) -i -e '/^# Auto-generated dependencies$$/,$$d' Makefile
b80d3d 539     @echo "# Auto-generated dependencies" >>Makefile
91663e 540     $(PKGMOGRIFY) $(WS_TRANSFORMS)/$@ $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) \
MT 541         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' \
542         | tr '|' '\n' \
f9fb69 543         | $(GSED) -e 's,pkg:/,,g' -e 's/@.*$$//g' \
MT 544             -f $(BUILD_DIR)/filter-own-pkgs \
545             $(REQUIRED_PACKAGES_TRANSFORM) \
a99182 546         | $(SORT) -u >>Makefile
1d4bf3 547     @echo "*** Please edit your Makefile and verify the new or updated content at the end ***"
d180f2 548
549
d05a6f 550 # lint the manifests all at once
NJ 551 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
552     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 553     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
694ef3 554         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 555             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 556     $(TOUCH) $@
557
0f1b63 558 lintme: FRC
AC 559     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 560     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
0f1b63 561         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
AC 562             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
563
564 FRC:
565
3dc823 566
ade6bb 567 # published
69d0f5 568 PKGSEND_PUBLISH_OPTIONS = -s $(WS_REPO) publish --fmri-in-manifest
35a012 569 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
abb76c 570 PKGSEND_PUBLISH_OPTIONS += -T \*.py
4221e1 571
JK 572 # Do all the hard work that is needed to ensure the package is consistent
573 # and ready for publishing, except actually pushing bits to a repository
574 $(MANIFEST_BASE)-%.pre-published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
1080cc 575     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 576         $(FINAL_TRANSFORMS) | \
577         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
4221e1 578     @echo "NEW PACKAGE CONTENTS ARE LOCALLY VALIDATED AND READY TO GO"
JK 579
7f9306 580 $(MANIFEST_BASE)-%.histogrified: $(MANIFEST_BASE)-%.p5m
f10584 581     $(PKGMOGRIFY) -D CONSOLIDATION="$(CONSOLIDATION)" $< > $@
7f9306 582
4221e1 583 # Push to the repo
JK 584 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.pre-published
35a012 585     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 586     $(PKGFMT) <$< >$@
4221e1 587
7f9306 588 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.histogrified
MT 589     $(PKGSEND) -s $(PKG_REPO) publish --fmri-in-manifest --no-catalog $<
590     $(CP) $< $@
591
4221e1 592 $(BUILD_DIR)/.pre-published-$(MACH):    $(PRE_PUBLISHED)
JK 593     $(TOUCH) $@
6514ee 594
d05a6f 595 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 596     $(TOUCH) $@
NJ 597
0ae592 598 print-depend-require:    canonical-manifests
AL 599     @echo $(call ips-print-depend-require-rule,$(NONVER_MANIFESTS)) \
600         $(foreach t,$(VERSIONED_MANIFEST_TYPES),$(call ips-print-depend-require-type-rule,$(t))) | tr ' ' '\n'
601
74c605 602 print-package-names:    canonical-manifests $(MKGENERIC_SCRIPTS)
6383f6 603     @echo $(foreach m,$(NONVER_MANIFESTS),\
MT 604         $(call ips-print-names-rule,$(m))) \
74c605 605         $(foreach t,$(VERSIONED_MANIFEST_TYPES),\
JMC 606             $(call ips-print-names-type-rule,$(t))) \
607         | tr ' ' '\n'
a325d4 608
NJ 609 print-package-paths:    canonical-manifests
b9e7b2 610     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
a325d4 611         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 612         sed -e '/^$$/d' -e '/^#.*$$/d' | \
a99182 613         $(SORT) -u
a325d4 614
3dc823 615 install-packages:    publish
NJ 616     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
5ada66 617         cat $(VERSIONED_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
4221e1 618         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 619         sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | \
a99182 620         $(SORT) -u | \
4221e1 621         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
JK 622      else ; \
3dc823 623         echo "unsafe to install package(s) automatically" ; \
4221e1 624      fi
3dc823 625
86e587 626 $(RESOLVED):    install
3dc823 627
NJ 628 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 629 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 630     # If there were no canonical manifests in the workspace, nothing will
631     # be published and we should fail.  A sample manifest can be generated
632     # with
633     #   $ gmake sample-manifest
634     # Once created, it will need to be reviewed, edited, and added to the
635     # workspace.
636     $(error Missing canonical manifest(s))
637 endif
a325d4 638
e5ce0b 639 # Component variables are expanded directly to PKG_OPTIONS instead of via
AP 640 # PKG_MACROS since the values may contain whitespace.
961188 641 mkdefine = -D $(1)="$$(strip $(2))"
e5ce0b 642
AP 643 # Expand PKG_VARS into defines via PKG_OPTIONS.
644 $(foreach var, $(PKG_VARS), \
645     $(eval PKG_OPTIONS += $(call mkdefine,$(var),$$($(var)))) \
646 )
647
a325d4 648 # This converts required paths to containing package names for be able to
NJ 649 # properly setup the build environment for a component.
650 required-pkgs.mk:    Makefile
651     @echo "generating $@ from Makefile REQUIRED_* data"
652     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
653         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
654
3dc823 655 pre-prep:    required-pkgs.mk
NJ 656
657
a325d4 658 CLEAN_PATHS +=    required-pkgs.mk
525ed1 659 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-perl
AP 660 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-python
661 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-ruby
8930d5 662 CLEAN_PATHS +=    $(GENERATED_ARCH_MANIFESTS)