Andreas Wacknitz
2024-04-05 66ad05c0e247efdd40f6cd5d8fe7d2dd1a593878
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
914e3a 157 CANONICAL_MANIFESTS =    $(filter-out dummy.p5m %.ARCH.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))
914e3a 164 GENERATED_ARCH_MANIFESTS =    $(ARCH_MANIFESTS:%.p5m.$(MACH)=%.ARCH.p5m)
8930d5 165 CANONICAL_MANIFESTS +=  $(GENERATED_ARCH_MANIFESTS)
MT 166
914e3a 167 %.ARCH.p5m:     %.p5m.$(MACH)
8930d5 168     $(CP) $< $@
MT 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
ef84aa 278 RUBYV_MANIFESTS = $(foreach v,$(RUBY_VERSIONS),$(RUBY_MANIFESTS:-RUBYVER.p5m=-$(subst $(space),,$(wordlist 1,2,$(subst ., ,$(v)))).p5m))
ccec59 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) | \
813063 327         $(GSED) -e '/^$$/d' -e '/^#.*$$/d' \
MT 328             -e '/\.la$$/d' \
329             -e 's/$(subst .,\.,$(GCC_GNU_TRIPLET))/$$(GCC_GNU_TRIPLET)/g' | \
c89418 330         $(PKGFMT) -u | \
f48e19 331         uniq | \
c89418 332         $(PKGFMT) | \
813063 333         $(CAT) $(METADATA_TEMPLATE) - $(GENERATE_EXTRA_CMD) | \
5b9db7 334         $(TEE) $@ $(SAMPLE_MANIFEST_FILE) >/dev/null
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),\
ef84aa 445         $(eval $(call ruby-manifest-rule,$(subst $(space),.,$(wordlist 1,2,$(subst ., ,$(ver)))),$(ver))))
18b823 446
AP 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),\
ef84aa 454             $(call mkgeneric,runtime/ruby,$(subst $(space),,$(wordlist 1,2,$(subst ., ,$(ver))))))
MT 455     $(call mkgenericdep,runtime/ruby,$(subst $(space),,$(wordlist 1,2,$(subst ., ,$(RUBY_VERSIONS)))))
18b823 456
AP 457 # Build Ruby version-wrapping manifests from the generic version.
458 # Creates build/manifest-*-modulename.p5m file.
459 #
86e587 460 $(MANIFEST_BASE)-%.p5m: %-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
18b823 461     $(PKGMOGRIFY) -D RUBYV=### $(BUILD_DIR)/mkgeneric-ruby \
AP 462             $(WS_TOP)/transforms/mkgeneric $< > $@
463     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
464
6383f6 465 per-manifest-options = $(foreach var,$(PKG_VARS),$(if $($(var).$(1)),-D $(var)="$(strip $($(var).$(1)))")) \
MT 466     $(if $(COMPONENT_CLASSIFICATION.$(1)),-D COMPONENT_CLASSIFICATION="org.opensolaris.category.2008:$(strip $(COMPONENT_CLASSIFICATION.$(1)))")
467
cf5bf1 468 # mogrify non-parameterized manifests
395f73 469 $(MANIFEST_BASE)-%.mogrified:    %.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
6383f6 470     $(PKGMOGRIFY) $(PKG_OPTIONS) $(call per-manifest-options,$*) $< \
5ada66 471         $(PUBLISH_TRANSFORMS) | \
DD 472         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
473
474 # mogrify parameterized manifests
395f73 475 $(MANIFEST_BASE)-%.mogrified:    $(MANIFEST_BASE)-%.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
70eebe 476     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 477         $(PUBLISH_TRANSFORMS) | \
NJ 478         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
6514ee 479
4158c0 480 # mangle the file contents
c2319a 481 $(BUILD_DIR) $(MANGLED_DIR):
4158c0 482     $(MKDIR) $@
NJ 483
484 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
5f4d07 485 ifeq ($(strip $(USE_CTF)),yes)
BS 486 PKGMANGLE_OPTIONS += -c $(CTFCONVERT)
487 endif
4158c0 488 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
NJ 489     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
490
1aa2da 491 # generate dependencies
35a012 492 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 493 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 494     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 495
4505fe 496 # pkgdepend resolve builds a map of all installed packages by default.  This
RL 497 # makes dependency resolution particularly slow.  We can dramatically improve
498 # performance here by creating a file with a list of packages that we know
499 # are needed, dramatically reducing the overhead involved in creating and
500 # searching this map.
501 #
502 # Generate a resolve.deps file from the dependencies in the Makefile and
503 # fragments that it uses.
504 RESOLVE_DEPS=$(BUILD_DIR)/resolve.deps
9f160e 505
c0099a 506 $(RESOLVE_DEPS):    Makefile $(BUILD_DIR) $(DEPENDED)
AP 507     @(for pkg in $(REQUIRED_PACKAGES:%=/%) ; do \
4505fe 508         echo $${pkg} ; \
c0099a 509     done ; \
AP 510     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) | \
a99182 511         $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' ;) | $(SORT) -u >$@
9f160e 512
9bec61 513 $(BUILD_DIR)/runtime-perl.p5m: $(WS_TOOLS)/runtime-perl.p5m
MT 514     $(CP) $< $@
515
31cf6d 516 $(BUILD_DIR)/runtime-ruby.p5m: $(WS_TOOLS)/runtime-ruby.p5m
MT 517     $(CP) $< $@
518
93b18c 519 # resolve the dependencies all at once
31cf6d 520 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED) $(RESOLVE_DEPS) $(BUILD_DIR)/runtime-perl.p5m $(BUILD_DIR)/runtime-ruby.p5m
MT 521     $(PKGDEPEND) resolve $(RESOLVE_DEPS:%=-e %) -m $(DEPENDED) $(BUILD_DIR)/runtime-perl.p5m $(BUILD_DIR)/runtime-ruby.p5m
d05a6f 522     $(TOUCH) $@
NJ 523
f9fb69 524 # generate list of sed rules to filter out component's own packages from
MT 525 # REQUIRED_PACKAGES list
526 $(BUILD_DIR)/filter-own-pkgs: $(DEPENDED)
527     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) \
528         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' -e 's/^\///g' -e 's/\//\\\//g' \
a99182 529         | $(SORT) -u \
f9fb69 530         | $(GSED) -e 's/^\(.*\)$$/\/^REQUIRED_PACKAGES += \1$$\/d/g' >$@
MT 531
e6ade5 532 # Set REQUIRED_PACKAGES macro substitution rules
32921b 533 REQUIRED_PACKAGES_TRANSFORM += $(foreach p,$(REQUIRED_PACKAGES_SUBST), -e 's|$($(p))|$$($(p))|')
e6ade5 534
d180f2 535 #
1d4bf3 536 # Generate a set of REQUIRED_PACKAGES based on what is needed for pkgdepend to
MT 537 # resolve properly.  Automatically update the list in your Makefile for the
538 # truly lazy among us.  This is only a piece of the REQUIRED_PACKAGES puzzle.
d180f2 539 # You must still include packages for tools you build and test with.
540 #
372e47 541 REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs $(REQUIRED_PACKAGES_EXTRA_DEPS)
4d720d 542     $(GMAKE) RESOLVE_DEPS= $(BUILD_DIR)/.resolved-$(MACH)
1d4bf3 543     @$(GSED) -i -e '/^# Auto-generated dependencies$$/,$$d' Makefile
b80d3d 544     @echo "# Auto-generated dependencies" >>Makefile
91663e 545     $(PKGMOGRIFY) $(WS_TRANSFORMS)/$@ $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) \
MT 546         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' \
547         | tr '|' '\n' \
f9fb69 548         | $(GSED) -e 's,pkg:/,,g' -e 's/@.*$$//g' \
MT 549             -f $(BUILD_DIR)/filter-own-pkgs \
550             $(REQUIRED_PACKAGES_TRANSFORM) \
a99182 551         | $(SORT) -u >>Makefile
1d4bf3 552     @echo "*** Please edit your Makefile and verify the new or updated content at the end ***"
d180f2 553
554
d05a6f 555 # lint the manifests all at once
NJ 556 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
557     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 558     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
694ef3 559         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 560             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 561     $(TOUCH) $@
562
0f1b63 563 lintme: FRC
AC 564     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 565     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
0f1b63 566         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
AC 567             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
568
569 FRC:
570
3dc823 571
ade6bb 572 # published
69d0f5 573 PKGSEND_PUBLISH_OPTIONS = -s $(WS_REPO) publish --fmri-in-manifest
35a012 574 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
abb76c 575 PKGSEND_PUBLISH_OPTIONS += -T \*.py
4221e1 576
JK 577 # Do all the hard work that is needed to ensure the package is consistent
578 # and ready for publishing, except actually pushing bits to a repository
579 $(MANIFEST_BASE)-%.pre-published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
1080cc 580     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 581         $(FINAL_TRANSFORMS) | \
582         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
4221e1 583     @echo "NEW PACKAGE CONTENTS ARE LOCALLY VALIDATED AND READY TO GO"
JK 584
7f9306 585 $(MANIFEST_BASE)-%.histogrified: $(MANIFEST_BASE)-%.p5m
f10584 586     $(PKGMOGRIFY) -D CONSOLIDATION="$(CONSOLIDATION)" $< > $@
7f9306 587
4221e1 588 # Push to the repo
JK 589 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.pre-published
35a012 590     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 591     $(PKGFMT) <$< >$@
4221e1 592
7f9306 593 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.histogrified
MT 594     $(PKGSEND) -s $(PKG_REPO) publish --fmri-in-manifest --no-catalog $<
595     $(CP) $< $@
596
4221e1 597 $(BUILD_DIR)/.pre-published-$(MACH):    $(PRE_PUBLISHED)
JK 598     $(TOUCH) $@
6514ee 599
d05a6f 600 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 601     $(TOUCH) $@
NJ 602
0ae592 603 print-depend-require:    canonical-manifests
AL 604     @echo $(call ips-print-depend-require-rule,$(NONVER_MANIFESTS)) \
605         $(foreach t,$(VERSIONED_MANIFEST_TYPES),$(call ips-print-depend-require-type-rule,$(t))) | tr ' ' '\n'
606
74c605 607 print-package-names:    canonical-manifests $(MKGENERIC_SCRIPTS)
6383f6 608     @echo $(foreach m,$(NONVER_MANIFESTS),\
MT 609         $(call ips-print-names-rule,$(m))) \
74c605 610         $(foreach t,$(VERSIONED_MANIFEST_TYPES),\
JMC 611             $(call ips-print-names-type-rule,$(t))) \
7ac335 612         | tr ' ' '\n' | $(SORT) -u
a325d4 613
NJ 614 print-package-paths:    canonical-manifests
b9e7b2 615     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
a325d4 616         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 617         sed -e '/^$$/d' -e '/^#.*$$/d' | \
a99182 618         $(SORT) -u
a325d4 619
3dc823 620 install-packages:    publish
NJ 621     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
5ada66 622         cat $(VERSIONED_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
4221e1 623         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 624         sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | \
a99182 625         $(SORT) -u | \
4221e1 626         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
JK 627      else ; \
3dc823 628         echo "unsafe to install package(s) automatically" ; \
4221e1 629      fi
3dc823 630
86e587 631 $(RESOLVED):    install
3dc823 632
NJ 633 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 634 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 635     # If there were no canonical manifests in the workspace, nothing will
636     # be published and we should fail.  A sample manifest can be generated
637     # with
638     #   $ gmake sample-manifest
639     # Once created, it will need to be reviewed, edited, and added to the
640     # workspace.
641     $(error Missing canonical manifest(s))
642 endif
a325d4 643
e5ce0b 644 # Component variables are expanded directly to PKG_OPTIONS instead of via
AP 645 # PKG_MACROS since the values may contain whitespace.
961188 646 mkdefine = -D $(1)="$$(strip $(2))"
e5ce0b 647
AP 648 # Expand PKG_VARS into defines via PKG_OPTIONS.
649 $(foreach var, $(PKG_VARS), \
650     $(eval PKG_OPTIONS += $(call mkdefine,$(var),$$($(var)))) \
651 )
652
a325d4 653 # This converts required paths to containing package names for be able to
NJ 654 # properly setup the build environment for a component.
655 required-pkgs.mk:    Makefile
656     @echo "generating $@ from Makefile REQUIRED_* data"
657     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
658         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
659
3dc823 660 pre-prep:    required-pkgs.mk
NJ 661
662
a325d4 663 CLEAN_PATHS +=    required-pkgs.mk
525ed1 664 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-perl
AP 665 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-python
666 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-ruby
8930d5 667 CLEAN_PATHS +=    $(GENERATED_ARCH_MANIFESTS)