Marcel Telka
2023-10-31 c9dd74fd2bc7576d38fb8beee6631bde225f6188
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
40754e 156 GENERIC_MANIFEST_FILE =    $(SAMPLE_MANIFEST_DIR)/generic-manifest.p5m
5b9db7 157
7f9306 158 CANONICAL_MANIFESTS =    $(filter-out dummy.p5m,$(wildcard *.p5m))
94deda 159 ifneq ($(wildcard $(HISTORY)),)
AP 160 HISTORICAL_MANIFESTS = $(shell $(NAWK) -v FUNCTION=name -f $(GENERATE_HISTORY) < $(HISTORY))
161 endif
5ada66 162
8930d5 163 # Support for arch specific manifests
MT 164 ARCH_MANIFESTS =    $(wildcard *.p5m.$(MACH))
165 GENERATED_ARCH_MANIFESTS =    $(ARCH_MANIFESTS:%.p5m.$(MACH)=%.p5m)
166 CANONICAL_MANIFESTS +=  $(GENERATED_ARCH_MANIFESTS)
167
168 %.p5m:     %.p5m.$(MACH)
169     $(CP) $< $@
170
0ae592 171 define ips-print-depend-require-rule
AL 172 $(shell cat $(1) $(WS_TOP)/transforms/print-depend-require |\
173     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 |\
a99182 174     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
0ae592 175 endef
AL 176
177 define ips-print-depend-require-versioned-rule
178 $(foreach v,$($(1)V_VALUES),\
179     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
180     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 181     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
0ae592 182 endef
AL 183
184 define ips-print-depend-require-type-rule
185 $(foreach m,$($(1)_MANIFESTS),$(call ips-print-depend-require-versioned-rule,$(1),$(m)))
186 endef
187
b9e7b2 188 define ips-print-names-rule
AL 189 $(shell cat $(1) $(WS_TOP)/transforms/print-pkgs |\
6383f6 190     $(PKGMOGRIFY) $(PKG_OPTIONS) $(call per-manifest-options,$(1:.p5m=)) /dev/fd/0 |\
a99182 191     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 192 endef
AL 193
194 define ips-print-names-versioned-rule
195 $(foreach v,$($(1)V_VALUES),\
196     $(shell cat $(2) $(WS_TOP)/transforms/print-pkgs |\
197     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=$(v) /dev/fd/0 |\
a99182 198     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u))
74c605 199 endef
JMC 200
201 #
202 # In addition to the concrete per-version packages, we also need to emit the
203 # name of the generic package which pulls in the concrete packages.
204 #
205 define ips-print-names-generic-rule
206 $(shell cat $(2) $(WS_TOP)/transforms/mkgeneric $(BUILD_DIR)/mkgeneric-python \
207     $(WS_TOP)/transforms/print-pkgs |\
208     $(PKGMOGRIFY) $(PKG_OPTIONS) -D $($(1)V_FMRI_VERSION)=\#\#\# /dev/fd/0 |\
a99182 209     sed -e '/^$$/d' -e '/^#.*$$/d' | $(SORT) -u)
b9e7b2 210 endef
AL 211
212 define ips-print-names-type-rule
74c605 213 $(foreach m,$($(1)_MANIFESTS),\
JMC 214     $(call ips-print-names-versioned-rule,$(1),$(m))\
215     $(call ips-print-names-generic-rule,$(1),$(m))\
216 )
b9e7b2 217 endef
AL 218
219 VERSIONED_MANIFEST_TYPES =
220 UNVERSIONED_MANIFESTS = $(filter-out %-GENFRAG.p5m, $(CANONICAL_MANIFESTS))
40754e 221 GENERATE_GENERIC_TRANSFORMS=
b9e7b2 222
5ada66 223 # Look for manifests which need to be duplicated for each version of python.
DD 224 ifeq ($(findstring -PYVER,$(CANONICAL_MANIFESTS)),-PYVER)
b9e7b2 225 VERSIONED_MANIFEST_TYPES+= PY
AL 226 NOPY_MANIFESTS = $(filter-out %-PYVER.p5m,$(UNVERSIONED_MANIFESTS))
5ada66 227 PY_MANIFESTS = $(filter %-PYVER.p5m,$(CANONICAL_MANIFESTS))
ccec59 228 PYV_VALUES = $(subst .,,$(PYTHON_VERSIONS))
b9e7b2 229 PYV_FMRI_VERSION = PYV
ccec59 230 PYV_MANIFESTS = $(foreach v,$(PYV_VALUES),$(PY_MANIFESTS:-PYVER.p5m=-$(v).p5m))
MT 231 PYNV_MANIFESTS = $(PY_MANIFESTS:-PYVER.p5m=.p5m)
74c605 232 MKGENERIC_SCRIPTS += $(BUILD_DIR)/mkgeneric-python
5ada66 233 else
b9e7b2 234 NOPY_MANIFESTS = $(UNVERSIONED_MANIFESTS)
5ada66 235 endif
DD 236
3129b3 237 # PYTHON_PYV_VALUES contains list of all possible PYV values we could encounter:
MT 238 # - for all currently supported python versions (from PYTHON_VERSIONS)
239 # - for all python versions we are currently obsoleting (from PYTHON_VERSIONS_OBSOLETING)
240 # - the $(PYV) string itself
ccec59 241 PYTHON_PYV_VALUES = $(subst .,,$(PYTHON_VERSIONS) $(PYTHON_VERSIONS_OBSOLETING)) $$(PYV)
3129b3 242 # Convert REQUIRED_PACKAGES to PYTHON_REQUIRED_PACKAGES for runtime/python
b2e48c 243 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PYTHON_PYV_VALUES)),-e 's|^\(.*runtime/python\)-$(v)$$|PYTHON_\1|g')
3129b3 244 # Convert REQUIRED_PACKAGES to PYTHON_REQUIRED_PACKAGES for library/python/*
b2e48c 245 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PYTHON_PYV_VALUES)),-e 's|^\(.*library/python/.*\)-$(v)$$|PYTHON_\1|g')
3129b3 246
5ada66 247 # Look for manifests which need to be duplicated for each version of perl.
DD 248 ifeq ($(findstring -PERLVER,$(UNVERSIONED_MANIFESTS)),-PERLVER)
b9e7b2 249 VERSIONED_MANIFEST_TYPES+= PERL
AL 250 NOPERL_MANIFESTS = $(filter-out %-PERLVER.p5m,$(NOPY_MANIFESTS))
5ada66 251 PERL_MANIFESTS = $(filter %-PERLVER.p5m,$(UNVERSIONED_MANIFESTS))
ccec59 252 PERLV_VALUES = $(subst .,,$(PERL_VERSIONS))
b9e7b2 253 PERLV_FMRI_VERSION = PLV
ccec59 254 PERLV_MANIFESTS = $(foreach v,$(PERLV_VALUES),$(PERL_MANIFESTS:-PERLVER.p5m=-$(v).p5m))
MT 255 PERLNV_MANIFESTS = $(PERL_MANIFESTS:-PERLVER.p5m=.p5m)
5ada66 256 else
b9e7b2 257 NOPERL_MANIFESTS = $(NOPY_MANIFESTS)
5ada66 258 endif
DD 259
45844d 260 # PERL_PLV_VALUES contains list of all possible PLV values we could encounter:
MT 261 # - for all currently supported perl versions (from PERL_VERSIONS)
262 # - for all perl versions we are currently obsoleting (from PERL_VERSIONS_OBSOLETING)
263 # - the $(PLV) string itself
987d15 264 PERL_PLV_VALUES = $(subst .,,$(PERL_VERSIONS) $(PERL_VERSIONS_OBSOLETING)) $$(PLV)
45844d 265 # Convert REQUIRED_PACKAGES to PERL_REQUIRED_PACKAGES for runtime/perl
b2e48c 266 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PERL_PLV_VALUES)),-e 's|^\(.*runtime/perl\)-$(v)$$|PERL_\1|g')
45844d 267 # Convert REQUIRED_PACKAGES to PERL_REQUIRED_PACKAGES for library/perl-5/*
b2e48c 268 REQUIRED_PACKAGES_TRANSFORM += $(foreach v,$(subst $,\$,$(PERL_PLV_VALUES)),-e 's|^\(.*library/perl-5/.*\)-$(v)$$|PERL_\1|g')
45844d 269
18b823 270 # Look for manifests which need to be duplicated for each version of ruby.
AP 271 # NOPERL_MANIFESTS represents the manifests that are not Python or
272 # Perl manifests.  Extract the Ruby Manifests from NOPERL_MANIFESTS.
273 # Any remaining manifests are stored in NONRUBY_MANIFESTS
274 ifeq ($(findstring -RUBYVER,$(NOPERL_MANIFESTS)),-RUBYVER)
b9e7b2 275 VERSIONED_MANIFEST_TYPES+= RUBY
AL 276 NORUBY_MANIFESTS = $(filter-out %-RUBYVER.p5m,$(NOPERL_MANIFESTS))
18b823 277 RUBY_MANIFESTS = $(filter %-RUBYVER.p5m,$(NOPERL_MANIFESTS))
b9e7b2 278 RUBYV_VALUES = $(RUBY_VERSIONS)
AL 279 RUBYV_FMRI_VERSION = RUBYV
ccec59 280 RUBYV_MANIFESTS = $(foreach v,$(RUBY_VERSIONS),$(RUBY_MANIFESTS:-RUBYVER.p5m=-$(shell echo $(v) | cut -d. -f1,2 | tr -d .).p5m))
MT 281 RUBYNV_MANIFESTS = $(RUBY_MANIFESTS:-RUBYVER.p5m=.p5m)
18b823 282 else
AP 283 NORUBY_MANIFESTS = $(NOPERL_MANIFESTS)
284 endif
b9e7b2 285
AL 286 NONVER_MANIFESTS = $(NORUBY_MANIFESTS)
18b823 287
5ada66 288 VERSIONED_MANIFESTS = \
DD 289     $(PYV_MANIFESTS) $(PYNV_MANIFESTS) \
290     $(PERLV_MANIFESTS) $(PERLNV_MANIFESTS) \
18b823 291     $(RUBYV_MANIFESTS) $(RUBYNV_MANIFESTS) \
7f9306 292     $(NORUBY_MANIFESTS)
5ada66 293
6514ee 294 GENERATED =        $(MANIFEST_BASE)-generated
NJ 295 COMBINED =        $(MANIFEST_BASE)-combined
5ada66 296 MANIFESTS =        $(VERSIONED_MANIFESTS:%=$(MANIFEST_BASE)-%)
6514ee 297
NJ 298
5ada66 299 DEPENDED=$(VERSIONED_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend)
DD 300 RESOLVED=$(VERSIONED_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend.res)
4221e1 301 PRE_PUBLISHED=$(RESOLVED:%.depend.res=%.pre-published)
93b18c 302 PUBLISHED=$(RESOLVED:%.depend.res=%.published)
7f9306 303
MT 304 HISTOGRIFIED =        $(HISTORICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.histogrified)
305 PUBLISHED +=        $(HISTORICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.published)
9c75c0 306
7e871a 307 COPYRIGHT_FILE ?=    $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
d05a6f 308 IPS_COMPONENT_VERSION ?=    $(COMPONENT_VERSION)
153732 309
6514ee 310 .DEFAULT:        publish
153732 311
3dc823 312 .SECONDARY:
9c75c0 313
2ae1af 314 # allow publishing to be overridden, such as when
MS 315 # a package is for one architecture only.
4221e1 316 PRE_PUBLISH_STAMP ?= $(BUILD_DIR)/.pre-published-$(MACH)
2ae1af 317 PUBLISH_STAMP ?= $(BUILD_DIR)/.published-$(MACH)
MS 318
4221e1 319 # Do all that is needed to ensure the package is consistent for publishing,
JK 320 # except actually pushing to a repo, separately from the push to the repo.
86e587 321 pre-publish:    build install $(PRE_PUBLISH_STAMP)
7d5416 322 publish:        pre-publish update-metadata $(PUBLISH_STAMP)
9c75c0 323
ff17eb 324 sample-manifest:    $(GENERATED).p5m
9c75c0 325
f045de 326 $(GENERATED).p5m:    install $(GENERATE_EXTRA_DEPS)
5b9db7 327     [ ! -d $(SAMPLE_MANIFEST_DIR) ] && $(MKDIR) $(SAMPLE_MANIFEST_DIR) || true
ade6bb 328     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
NJ 329     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(GENERATE_TRANSFORMS) | \
856730 330         sed -e '/^$$/d' -e '/^#.*$$/d' \
053684 331         -e '/\.la$$/d' | \
c89418 332         $(PKGFMT) -u | \
f48e19 333         uniq | \
c89418 334         $(PKGFMT) | \
9c1e84 335         cat $(METADATA_TEMPLATE) - $(GENERATE_EXTRA_CMD) | \
5b9db7 336         $(TEE) $@ $(SAMPLE_MANIFEST_FILE) >/dev/null
40754e 337     if [ "$(GENERATE_GENERIC_TRANSFORMS)X" != "X" ]; \
AL 338     then sed $(GENERATE_GENERIC_TRANSFORMS) $(SAMPLE_MANIFEST_FILE) \
339         | gawk '!seen[$$0]++' > $(GENERIC_MANIFEST_FILE); fi;
6514ee 340
ade6bb 341 # copy the canonical manifest(s) to the build tree
86e587 342 $(MANIFEST_BASE)-%.generate:    %.p5m canonical-manifests
ade6bb 343     cat $(METADATA_TEMPLATE) $< >$@
6514ee 344
5ada66 345 # The text of a transform that will emit a dependency conditional on the
DD 346 # presence of a particular version of a runtime, which will then draw in the
347 # runtime-version-specific version of the package we're operating on.  $(1) is
348 # the name of the runtime package, and $(2) is the version suffix.
349 mkgeneric = \
350     echo "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
351         "-> emit depend nodrop=true type=conditional" \
352         "predicate=$(1)-$(2) fmri=%<1>-$(2)@%<2>>" >> $@;
353
c11706 354 mkgenericdep = \
AP 355     ( echo -n "<transform set name=pkg.fmri value=(?:pkg:/)?(.+)-\#\#\#@(.*)" \
356         "-> emit depend nodrop=true type=require-any " ;  \
357         for i in $(2); do echo -n "fmri=%<1>-$$i@%<2> " ; done ; \
358         echo ">" ) >> $@
359
5ada66 360 # Define and execute a macro that generates a rule to create a manifest for a
DD 361 # python module specific to a particular version of the python runtime.
362 define python-manifest-rule
6ce466 363 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_$(1)_ONLY= PYTHON_$(1)_EXCL=\#
bd5c30 364
44f1c2 365 ifneq ($(filter $(1),$(PYTHON_64_ONLY_VERSIONS)),)
e5ce0b 366 $(MANIFEST_BASE)-%-$(2).mogrified: PKG_MACROS += PYTHON_32_ONLY=\#
44f1c2 367 endif
AP 368
e5ce0b 369 $(MANIFEST_BASE)-%-$(2).p5m: %-PYVER.p5m
AP 370     $(PKGMOGRIFY) -D PYVER=$(1) $(MANIFEST_LIMITING_VARS) -D PYV=$(2)  $$< > $$@
5ada66 371 endef
ccec59 372 $(foreach ver,$(PYTHON_VERSIONS),$(eval $(call python-manifest-rule,$(ver),$(subst .,,$(ver)))))
5ada66 373
e299f6 374 ifeq ($(strip $(SINGLE_PYTHON_VERSION)),yes)
MT 375 PKG_MACROS += PYVER=$(PYTHON_VERSION)
ccec59 376 PKG_MACROS += PYV=$(subst .,,$(PYTHON_VERSION))
e299f6 377 endif
MT 378
5ada66 379 # A rule to create a helper transform package for python, that will insert the
DD 380 # appropriate conditional dependencies into a python library's
381 # runtime-version-generic package to pull in the version-specific bits when the
382 # corresponding version of python is on the system.
74c605 383 $(BUILD_DIR)/mkgeneric-python: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ) $(BUILD_DIR)
5ada66 384     $(RM) $@
ccec59 385     $(foreach ver,$(subst .,,$(PYTHON_VERSIONS)), \
5ada66 386         $(call mkgeneric,runtime/python,$(ver)))
ccec59 387     $(call mkgenericdep,runtime/python,$(subst .,,$(PYTHON_VERSIONS)))
5ada66 388
DD 389 # Build Python version-wrapping manifests from the generic version.
86e587 390 $(MANIFEST_BASE)-%.p5m: %-PYVER.p5m $(BUILD_DIR)/mkgeneric-python
525ed1 391     $(PKGMOGRIFY) -D PYV=### $(BUILD_DIR)/mkgeneric-python \
5ada66 392         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 393     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
394
9581d1 395 # Define and execute a macro that generates a rule to create a manifest for a
CM 396 # perl module specific to a particular version of the perl runtime.
397 define perl-manifest-rule
ccec59 398 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-PERLVER.p5m
MT 399     $(PKGMOGRIFY) -D PERLVER=$(1) -D PLV=$$(subst .,,$(1)) \
8478d1 400         -D PERL_ARCH=$$(call PERL_ARCH_FUNC,$$(PERL.$(1))) $$< > $$@
9581d1 401 endef
CM 402 $(foreach ver,$(PERL_VERSIONS),$(eval $(call perl-manifest-rule,$(ver))))
403
e299f6 404 ifeq ($(strip $(SINGLE_PERL_VERSION)),yes)
MT 405 PKG_MACROS += PERLVER=$(PERL_VERSION)
ccec59 406 PKG_MACROS += PLV=$(subst .,,$(PERL_VERSION))
e299f6 407 endif
MT 408
5ada66 409 # A rule to create a helper transform package for perl, that will insert the
DD 410 # appropriate conditional dependencies into a perl library's
411 # runtime-version-generic package to pull in the version-specific bits when the
412 # corresponding version of perl is on the system.
525ed1 413 $(BUILD_DIR)/mkgeneric-perl: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
5ada66 414     $(RM) $@
ccec59 415     $(foreach ver,$(subst .,,$(PERL_VERSIONS)), \
5ada66 416         $(call mkgeneric,runtime/perl,$(ver)))
ccec59 417     $(call mkgenericdep,runtime/perl,$(subst .,,$(PERL_VERSIONS)))
5ada66 418
DD 419 # Build Perl version-wrapping manifests from the generic version.
86e587 420 $(MANIFEST_BASE)-%.p5m: %-PERLVER.p5m $(BUILD_DIR)/mkgeneric-perl
525ed1 421     $(PKGMOGRIFY) -D PLV=### $(BUILD_DIR)/mkgeneric-perl \
5ada66 422         $(WS_TOP)/transforms/mkgeneric $< > $@
DD 423     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
424
94deda 425 # Rule to generate historical manifests from the $(HISTORY) file.
AP 426 define history-manifest-rule
427 $(MANIFEST_BASE)-$(1): $(HISTORY) $(BUILD_DIR)
428     $(NAWK) -v TARGET=$(1) -v FUNCTION=manifest -f $(GENERATE_HISTORY) < \
429         $(HISTORY) > $$@
430 endef
431 $(foreach mfst,$(HISTORICAL_MANIFESTS),$(eval $(call history-manifest-rule,$(mfst))))
432
18b823 433 # Define and execute a macro that generates a rule to create a manifest for a
AP 434 # ruby module specific to a particular version of the ruby runtime.
435 # Creates build/manifest-*-modulename-##.p5m file where ## is replaced with
436 # the version number.
437 define ruby-manifest-rule
ccec59 438 $(MANIFEST_BASE)-%-$(subst .,,$(1)).mogrified: \
18b823 439         PKG_MACROS += RUBY_VERSION=$(1) RUBY_LIB_VERSION=$(2) \
AP 440             RUBYV=$(subst .,,$(1))
441
ccec59 442 $(MANIFEST_BASE)-%-$(subst .,,$(1)).p5m: %-RUBYVER.p5m
MT 443     if [ -f $$*-$(subst .,,$(1))GENFRAG.p5m ]; then \
444             cat $$*-$(subst .,,$(1))GENFRAG.p5m >> $$@; \
18b823 445     fi
AP 446     $(PKGMOGRIFY) -D RUBY_VERSION=$(1) -D RUBY_LIB_VERSION=$(2) \
ccec59 447         -D RUBYV=$(subst .,,$(1)) $$< > $$@
18b823 448 endef
AP 449 $(foreach ver,$(RUBY_VERSIONS),\
450         $(eval $(call ruby-manifest-rule,$(shell echo $(ver) | \
451             cut -d. -f1,2),$(ver))))
452
453 # A rule to create a helper transform package for ruby, that will insert the
454 # appropriate conditional dependencies into a ruby library's
455 # runtime-version-generic package to pull in the version-specific bits when the
456 # corresponding version of ruby is on the system.
525ed1 457 $(BUILD_DIR)/mkgeneric-ruby: $(WS_TOP)/make-rules/shared-macros.mk $(MAKEFILE_PREREQ)
18b823 458     $(RM) $@
AP 459     $(foreach ver,$(RUBY_VERSIONS),\
460             $(call mkgeneric,runtime/ruby,$(shell echo $(ver) | \
461                 cut -d. -f1,2 | tr -d .)))
c11706 462     $(call mkgenericdep,runtime/ruby,$(shell echo $(RUBY_VERSIONS) | cut -d. -f1,2 | tr -d .))
18b823 463
AP 464 # Build Ruby version-wrapping manifests from the generic version.
465 # Creates build/manifest-*-modulename.p5m file.
466 #
86e587 467 $(MANIFEST_BASE)-%.p5m: %-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
18b823 468     $(PKGMOGRIFY) -D RUBYV=### $(BUILD_DIR)/mkgeneric-ruby \
AP 469             $(WS_TOP)/transforms/mkgeneric $< > $@
470     if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
471
6383f6 472 per-manifest-options = $(foreach var,$(PKG_VARS),$(if $($(var).$(1)),-D $(var)="$(strip $($(var).$(1)))")) \
MT 473     $(if $(COMPONENT_CLASSIFICATION.$(1)),-D COMPONENT_CLASSIFICATION="org.opensolaris.category.2008:$(strip $(COMPONENT_CLASSIFICATION.$(1)))")
474
cf5bf1 475 # mogrify non-parameterized manifests
395f73 476 $(MANIFEST_BASE)-%.mogrified:    %.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
6383f6 477     $(PKGMOGRIFY) $(PKG_OPTIONS) $(call per-manifest-options,$*) $< \
5ada66 478         $(PUBLISH_TRANSFORMS) | \
DD 479         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
480
481 # mogrify parameterized manifests
395f73 482 $(MANIFEST_BASE)-%.mogrified:    $(MANIFEST_BASE)-%.p5m $(BUILD_DIR) $(MAKEFILE_PREREQ)
70eebe 483     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 484         $(PUBLISH_TRANSFORMS) | \
NJ 485         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
6514ee 486
4158c0 487 # mangle the file contents
c2319a 488 $(BUILD_DIR) $(MANGLED_DIR):
4158c0 489     $(MKDIR) $@
NJ 490
491 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
492 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
493     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
494
1aa2da 495 # generate dependencies
35a012 496 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 497 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 498     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 499
4505fe 500 # pkgdepend resolve builds a map of all installed packages by default.  This
RL 501 # makes dependency resolution particularly slow.  We can dramatically improve
502 # performance here by creating a file with a list of packages that we know
503 # are needed, dramatically reducing the overhead involved in creating and
504 # searching this map.
505 #
506 # Generate a resolve.deps file from the dependencies in the Makefile and
507 # fragments that it uses.
508 RESOLVE_DEPS=$(BUILD_DIR)/resolve.deps
9f160e 509
c0099a 510 $(RESOLVE_DEPS):    Makefile $(BUILD_DIR) $(DEPENDED)
AP 511     @(for pkg in $(REQUIRED_PACKAGES:%=/%) ; do \
4505fe 512         echo $${pkg} ; \
c0099a 513     done ; \
AP 514     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) | \
a99182 515         $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' ;) | $(SORT) -u >$@
9f160e 516
9bec61 517 $(BUILD_DIR)/runtime-perl.p5m: $(WS_TOOLS)/runtime-perl.p5m
MT 518     $(CP) $< $@
519
93b18c 520 # resolve the dependencies all at once
9bec61 521 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED) $(RESOLVE_DEPS) $(BUILD_DIR)/runtime-perl.p5m
MT 522     $(PKGDEPEND) resolve $(RESOLVE_DEPS:%=-e %) -m $(DEPENDED) $(BUILD_DIR)/runtime-perl.p5m
d05a6f 523     $(TOUCH) $@
NJ 524
f9fb69 525 # generate list of sed rules to filter out component's own packages from
MT 526 # REQUIRED_PACKAGES list
527 $(BUILD_DIR)/filter-own-pkgs: $(DEPENDED)
528     $(PKGMOGRIFY) $(WS_TRANSFORMS)/PRINT_COMPONENT_FMRIS $(DEPENDED) \
529         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' -e 's/^\///g' -e 's/\//\\\//g' \
a99182 530         | $(SORT) -u \
f9fb69 531         | $(GSED) -e 's/^\(.*\)$$/\/^REQUIRED_PACKAGES += \1$$\/d/g' >$@
MT 532
e6ade5 533 # Set REQUIRED_PACKAGES macro substitution rules
32921b 534 REQUIRED_PACKAGES_TRANSFORM += $(foreach p,$(REQUIRED_PACKAGES_SUBST), -e 's|$($(p))|$$($(p))|')
e6ade5 535
d180f2 536 #
1d4bf3 537 # Generate a set of REQUIRED_PACKAGES based on what is needed for pkgdepend to
MT 538 # resolve properly.  Automatically update the list in your Makefile for the
539 # truly lazy among us.  This is only a piece of the REQUIRED_PACKAGES puzzle.
d180f2 540 # You must still include packages for tools you build and test with.
541 #
372e47 542 REQUIRED_PACKAGES::     $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) $(BUILD_DIR)/filter-own-pkgs $(REQUIRED_PACKAGES_EXTRA_DEPS)
4d720d 543     $(GMAKE) RESOLVE_DEPS= $(BUILD_DIR)/.resolved-$(MACH)
1d4bf3 544     @$(GSED) -i -e '/^# Auto-generated dependencies$$/,$$d' Makefile
b80d3d 545     @echo "# Auto-generated dependencies" >>Makefile
91663e 546     $(PKGMOGRIFY) $(WS_TRANSFORMS)/$@ $(RESOLVED) $(REQUIRED_PACKAGES_RESOLVED) \
MT 547         | $(GSED) -e '/^[\t ]*$$/d' -e '/^#/d' \
548         | tr '|' '\n' \
f9fb69 549         | $(GSED) -e 's,pkg:/,,g' -e 's/@.*$$//g' \
MT 550             -f $(BUILD_DIR)/filter-own-pkgs \
551             $(REQUIRED_PACKAGES_TRANSFORM) \
a99182 552         | $(SORT) -u >>Makefile
1d4bf3 553     @echo "*** Please edit your Makefile and verify the new or updated content at the end ***"
d180f2 554
555
d05a6f 556 # lint the manifests all at once
NJ 557 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
558     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 559     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
694ef3 560         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 561             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 562     $(TOUCH) $@
563
0f1b63 564 lintme: FRC
AC 565     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
6185b3 566     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)" $(COMPONENT_PKGLINT_ENV)\
0f1b63 567         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
AC 568             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
569
570 FRC:
571
3dc823 572
ade6bb 573 # published
69d0f5 574 PKGSEND_PUBLISH_OPTIONS = -s $(WS_REPO) publish --fmri-in-manifest
35a012 575 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
abb76c 576 PKGSEND_PUBLISH_OPTIONS += -T \*.py
4221e1 577
JK 578 # Do all the hard work that is needed to ensure the package is consistent
579 # and ready for publishing, except actually pushing bits to a repository
580 $(MANIFEST_BASE)-%.pre-published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
1080cc 581     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
AP 582         $(FINAL_TRANSFORMS) | \
583         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
4221e1 584     @echo "NEW PACKAGE CONTENTS ARE LOCALLY VALIDATED AND READY TO GO"
JK 585
7f9306 586 $(MANIFEST_BASE)-%.histogrified: $(MANIFEST_BASE)-%.p5m
f10584 587     $(PKGMOGRIFY) -D CONSOLIDATION="$(CONSOLIDATION)" $< > $@
7f9306 588
4221e1 589 # Push to the repo
JK 590 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.pre-published
35a012 591     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 592     $(PKGFMT) <$< >$@
4221e1 593
7f9306 594 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.histogrified
MT 595     $(PKGSEND) -s $(PKG_REPO) publish --fmri-in-manifest --no-catalog $<
596     $(CP) $< $@
597
4221e1 598 $(BUILD_DIR)/.pre-published-$(MACH):    $(PRE_PUBLISHED)
JK 599     $(TOUCH) $@
6514ee 600
d05a6f 601 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 602     $(TOUCH) $@
NJ 603
0ae592 604 print-depend-require:    canonical-manifests
AL 605     @echo $(call ips-print-depend-require-rule,$(NONVER_MANIFESTS)) \
606         $(foreach t,$(VERSIONED_MANIFEST_TYPES),$(call ips-print-depend-require-type-rule,$(t))) | tr ' ' '\n'
607
74c605 608 print-package-names:    canonical-manifests $(MKGENERIC_SCRIPTS)
6383f6 609     @echo $(foreach m,$(NONVER_MANIFESTS),\
MT 610         $(call ips-print-names-rule,$(m))) \
74c605 611         $(foreach t,$(VERSIONED_MANIFEST_TYPES),\
JMC 612             $(call ips-print-names-type-rule,$(t))) \
613         | tr ' ' '\n'
a325d4 614
NJ 615 print-package-paths:    canonical-manifests
b9e7b2 616     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
a325d4 617         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 618         sed -e '/^$$/d' -e '/^#.*$$/d' | \
a99182 619         $(SORT) -u
a325d4 620
3dc823 621 install-packages:    publish
NJ 622     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
5ada66 623         cat $(VERSIONED_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
4221e1 624         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
74c605 625         sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | \
a99182 626         $(SORT) -u | \
4221e1 627         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
JK 628      else ; \
3dc823 629         echo "unsafe to install package(s) automatically" ; \
4221e1 630      fi
3dc823 631
86e587 632 $(RESOLVED):    install
3dc823 633
NJ 634 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 635 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 636     # If there were no canonical manifests in the workspace, nothing will
637     # be published and we should fail.  A sample manifest can be generated
638     # with
639     #   $ gmake sample-manifest
640     # Once created, it will need to be reviewed, edited, and added to the
641     # workspace.
642     $(error Missing canonical manifest(s))
643 endif
a325d4 644
e5ce0b 645 # Component variables are expanded directly to PKG_OPTIONS instead of via
AP 646 # PKG_MACROS since the values may contain whitespace.
961188 647 mkdefine = -D $(1)="$$(strip $(2))"
e5ce0b 648
AP 649 # Expand PKG_VARS into defines via PKG_OPTIONS.
650 $(foreach var, $(PKG_VARS), \
651     $(eval PKG_OPTIONS += $(call mkdefine,$(var),$$($(var)))) \
652 )
653
a325d4 654 # This converts required paths to containing package names for be able to
NJ 655 # properly setup the build environment for a component.
656 required-pkgs.mk:    Makefile
657     @echo "generating $@ from Makefile REQUIRED_* data"
658     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
659         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
660
3dc823 661 pre-prep:    required-pkgs.mk
NJ 662
663
a325d4 664 CLEAN_PATHS +=    required-pkgs.mk
525ed1 665 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-perl
AP 666 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-python
667 CLEAN_PATHS +=    $(BUILD_DIR)/mkgeneric-ruby
8930d5 668 CLEAN_PATHS +=    $(GENERATED_ARCH_MANIFESTS)