xref: /illumos-gate/usr/src/pkg/Makefile (revision a5619348a00282a0a129610076aefdb4dd7ab2ab)
1#
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#
21
22#
23# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24# Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
25# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
26# Copyright 2016 RackTop Systems.
27# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
28# Copyright 2020 Peter Tribble
29#
30
31include $(SRC)/Makefile.master
32include $(SRC)/Makefile.buildnum
33
34#
35# Make sure we're getting a consistent execution environment for the
36# embedded scripts.
37#
38SHELL= /usr/bin/ksh93
39
40#
41# To suppress package dependency generation on any system, regardless
42# of how it was installed, set SUPPRESSPKGDEP=true in the build
43# environment.
44#
45SUPPRESSPKGDEP= false
46
47#
48# Comment this line out or set "PKGDEBUG=" in your build environment
49# to get more verbose output from the make processes in usr/src/pkg
50#
51PKGDEBUG= @
52
53#
54# Cross platform packaging notes
55#
56# By default, we package the proto area from the same architecture as
57# the packaging build.  In other words, if you're running nightly or
58# bldenv on an x86 platform, it will take objects from the x86 proto
59# area and use them to create x86 repositories.
60#
61# If you want to create repositories for an architecture that's
62# different from $(uname -p), you do so by setting PKGMACH in your
63# build environment.
64#
65# For this to work correctly, the following must all happen:
66#
67#   1. You need the desired proto area, which you can get either by
68#      doing a gatekeeper-style build with the -U option to
69#      nightly(1), or by using rsync.  If you don't do this, you will
70#      get packaging failures building all packages, because pkgsend
71#      is unable to find the required binaries.
72#   2. You need the desired tools proto area, which you can get in the
73#      same ways as the normal proto area.  If you don't do this, you
74#      will get packaging failures building onbld, because pkgsend is
75#      unable to find the tools binaries.
76#   3. The remainder of this Makefile should never refer directly to
77#      $(MACH).  Instead, $(PKGMACH) should be used whenever an
78#      architecture-specific path or token is needed.  If this is done
79#      incorrectly, then packaging will fail, and you will see the
80#      value of $(uname -p) instead of the value of $(PKGMACH) in the
81#      commands that fail.
82#   4. Each time a rule in this Makefile invokes $(MAKE), it should
83#      pass PKGMACH=$(PKGMACH) explicitly on the command line.  If
84#      this is done incorrectly, then packaging will fail, and you
85#      will see the value of $(uname -p) instead of the value of
86#      $(PKGMACH) in the commands that fail.
87#
88# Refer also to the convenience targets defined later in this
89# Makefile.
90#
91PKGMACH=	$(MACH)
92
93#
94# ROOT, TOOLS_PROTO, and PKGARCHIVE should be set by nightly or
95# bldenv.  These macros translate them into terms of $PKGMACH, instead
96# of $ARCH.
97#
98PKGROOT.cmd=	print $(ROOT) | sed -e s:/root_$(MACH):/root_$(PKGMACH):
99PKGROOT=	$(PKGROOT.cmd:sh)
100TOOLSROOT.cmd=	print $(TOOLS_PROTO) | sed -e s:/root_$(MACH):/root_$(PKGMACH):
101TOOLSROOT=	$(TOOLSROOT.cmd:sh)
102PKGDEST.cmd=	print $(PKGARCHIVE) | sed -e s:/$(MACH)/:/$(PKGMACH)/:
103PKGDEST=	$(PKGDEST.cmd:sh)
104
105EXCEPTIONS= packaging
106
107PKGMOGRIFY= pkgmogrify
108
109#
110# Always build the redistributable repository, but only build the
111# nonredistributable bits if we have access to closed source.
112#
113# Some objects that result from the closed build are still
114# redistributable, and should be packaged as part of an open-only
115# build.  Access to those objects is provided via the closed-bins
116# tarball.  See usr/src/tools/scripts/bindrop.sh for details.
117#
118REPOS= redist
119
120#
121# The packages directory will contain the processed manifests as
122# direct build targets and subdirectories for package metadata extracted
123# incidentally during manifest processing.
124#
125# Nothing underneath $(PDIR) should ever be managed by SCM.
126#
127PDIR= packages.$(PKGMACH)
128
129#
130# The tools proto must be specified for dependency generation.
131# Publication from the tools proto area is managed in the
132# publication rule.
133#
134$(PDIR)/developer-build-onbld.dep:= PKGROOT= $(TOOLSROOT)
135
136PKGPUBLISHER= $(PKGPUBLISHER_REDIST)
137
138#
139# To get these defaults, manifests should simply refer to $(PKGVERS).
140#
141PKGVERS_COMPONENT= 0.$(RELEASE)
142PKGVERS_BUILTON= $(RELEASE)
143PKGVERS_BRANCH= 0.$(ONNV_BUILDNUM)
144PKGVERS= $(PKGVERS_COMPONENT),$(PKGVERS_BUILTON)-$(PKGVERS_BRANCH)
145
146#
147# The ARCH32 and ARCH64 macros are used in the manifests to express
148# architecture-specific subdirectories in the installation paths
149# for isaexec'd commands.
150#
151# We can't simply use $(MACH32) and $(MACH64) here, because they're
152# only defined for the build architecture.  To do cross-platform
153# packaging, we need both values.
154#
155i386_ARCH32= i86
156sparc_ARCH32= sparcv7
157i386_ARCH64= amd64
158sparc_ARCH64= sparcv9
159
160#
161# macros and transforms needed by pkgmogrify
162#
163# If you append to this list using target-specific assignments (:=),
164# be very careful that the targets are of the form $(PDIR)/pkgname.  If
165# you use a higher level target, or a package list, you'll trigger a
166# complete reprocessing of all manifests because they'll fail command
167# dependency checking.
168#
169PM_TRANSFORMS= common_actions publish restart_fmri facets defaults \
170	extract_metadata
171PM_FINAL_TRANSFORMS= strip_dependinfo
172PM_INC= transforms manifests
173
174JAVA_8_ONLY=
175JAVA_11_ONLY=
176$(BLD_JAVA_11)JAVA_8_ONLY=$(POUND_SIGN)
177$(JAVA_8_ONLY)JAVA_11_ONLY=$(POUND_SIGN)
178
179PKGMOG_DEFINES= \
180	i386_ONLY=$(POUND_SIGN) \
181	sparc_ONLY=$(POUND_SIGN) \
182	$(PKGMACH)_ONLY= \
183	ARCH=$(PKGMACH) \
184	ARCH32=$($(PKGMACH)_ARCH32) \
185	ARCH64=$($(PKGMACH)_ARCH64) \
186	PKGVERS_COMPONENT=$(PKGVERS_COMPONENT) \
187	PKGVERS_BUILTON=$(PKGVERS_BUILTON) \
188	PKGVERS_BRANCH=$(PKGVERS_BRANCH) \
189	PKGVERS=$(PKGVERS) \
190	PERL_ARCH=$(PERL_ARCH) \
191	PERL_ARCH64=$(PERL_ARCH64) \
192	PERL_VERSION=$(PERL_VERSION) \
193	PERL_PKGVERS=$(PERL_PKGVERS) \
194	BUILDPERL32=$(BUILDPERL32) \
195	BUILDPERL64=$(BUILDPERL64) \
196	PYTHON_VERSION=$(PYTHON_VERSION) \
197	PYTHON3_VERSION=$(PYTHON3_VERSION) \
198	PYTHON3b_VERSION=$(PYTHON3b_VERSION) \
199	PYTHON_PKGVERS=$(PYTHON_PKGVERS) \
200	PYTHON3_PKGVERS=$(PYTHON3_PKGVERS) \
201	PYTHON3b_PKGVERS=$(PYTHON3b_PKGVERS) \
202	python2_ONLY=$(BUILDPY2) \
203	python3_ONLY=$(BUILDPY3) \
204	python3b_ONLY=$(BUILDPY3b) \
205	python2tools_ONLY=$(BUILDPY2TOOLS) \
206	python3tools_ONLY=$(BUILDPY3TOOLS) \
207	JAVA_11_ONLY=$(JAVA_11_ONLY) \
208	JAVA_8_ONLY=$(JAVA_8_ONLY)
209
210PKGDEP_TOKENS_i386= \
211	'PLATFORM=i86hvm' \
212	'PLATFORM=i86pc' \
213	'PLATFORM=i86xpv' \
214	'ISALIST=amd64' \
215	'ISALIST=i386'
216PKGDEP_TOKENS_sparc= \
217	'PLATFORM=sun4u' \
218	'PLATFORM=sun4v' \
219	'ISALIST=sparcv9' \
220	'ISALIST=sparc'
221PKGDEP_TOKENS= $(PKGDEP_TOKENS_$(PKGMACH))
222
223#
224# The package lists are generated with $(PKGDEP_TYPE) as their
225# dependency types, so that they can be included by either an
226# incorporation or a group package.
227#
228$(PDIR)/osnet-redist.mog := PKGDEP_TYPE= require
229$(PDIR)/osnet-incorporation.mog:= PKGDEP_TYPE= incorporate
230
231PKGDEP_INCORP= \
232	depend fmri=consolidation/osnet/osnet-incorporation type=require
233
234#
235# All packaging build products should go into $(PDIR), so they don't
236# need to be included separately in CLOBBERFILES.
237#
238CLOBBERFILES= $(PDIR) proto_list_$(PKGMACH) install-$(PKGMACH).out \
239	license-list
240
241#
242# By default, PKGS will list all manifests.  To build and/or publish a
243# subset of packages, override this on the command line or in the
244# build environment and then reference (implicitly or explicitly) the all
245# or install targets.
246#
247# We want some manifests to optionally build based on environment options, so
248# those are excluded when generating the list of manifests and added back in if
249# necessary. We also want a relatively easy way to add files to the list of
250# manifests given special treatment. Add any other special ones to the
251# SPECIAL_MANIFESTS variable. It can contain wildcards in regexp form, i.e.
252# SUNW.* as one useful example.
253#
254SPECIAL_MANIFESTS = system-library-python-.*
255LIST_MANIFESTS_CMD = (cd manifests ; /usr/bin/ls -1 *.p5m |\
256	$(SED) $(SPECIAL_MANIFESTS:%=-e '/^%$$/d') )
257MANIFESTS = $(LIST_MANIFESTS_CMD:sh)
258
259# Conditionally add back python modules
260$(BUILDPY2) MANIFESTS += \
261	system-library-python-libbe-2.p5m \
262	system-library-python-solaris-2.p5m \
263	system-library-python-zfs-2.p5m
264$(BUILDPY3) MANIFESTS += \
265	system-library-python-libbe-3.p5m \
266	system-library-python-solaris-3.p5m \
267	system-library-python-zfs-3.p5m
268$(BUILDPY3b) MANIFESTS += \
269	system-library-python-libbe-3b.p5m \
270	system-library-python-solaris-3b.p5m \
271	system-library-python-zfs-3b.p5m
272
273PKGS= $(MANIFESTS:%.p5m=%)
274DEP_PKGS= $(PKGS:%=$(PDIR)/%.dep)
275PROC_PKGS= $(PKGS:%=$(PDIR)/%.mog)
276FIN_PKGS= $(PKGS:%=$(PDIR)/%.fin)
277
278#
279# Track the synthetic manifests separately so we can properly express
280# build rules and dependencies.  The synthetic and real packages use
281# different sets of transforms and macros for pkgmogrify.
282#
283SYNTH_PKGS= osnet-incorporation osnet-redist
284DEP_SYNTH_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.dep)
285PROC_SYNTH_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.mog)
286
287#
288# Root of pkg image to use for dependency resolution
289# Normally / on the machine used to build the binaries
290#
291PKGDEP_RESOLVE_IMAGE = /
292
293#
294# For each package, we determine the target repository based on
295# manifest-embedded metadata.  Because we make that determination on
296# the fly, the publication target cannot be expressed as a
297# subdirectory inside the unknown-by-the-makefile target repository.
298#
299# In order to limit the target set to real files in known locations,
300# we use a ".pub" file in $(PDIR) for each processed manifest, regardless
301# of content or target repository.
302#
303PUB_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.pub) $(PKGS:%=$(PDIR)/%.pub)
304
305#
306# Any given repository- and status-specific package list may be empty,
307# but we can only determine that dynamically, so we always generate all
308# lists for each repository we're building.
309#
310# The meanings of each package status are as follows:
311#
312#	PKGSTAT		meaning
313#	----------	----------------------------------------------------
314#	noincorp	Do not include in incorporation or group package
315#	obsolete	Include in incorporation, but not group package
316#	renamed		Include in incorporation, but not group package
317#	current		Include in incorporation and group package
318#
319# Since the semantics of the "noincorp" package status dictate that
320# such packages are not included in the incorporation or group packages,
321# there is no need to build noincorp package lists.
322#
323PKGLISTS= \
324	$(REPOS:%=$(PDIR)/packages.%.current) \
325	$(REPOS:%=$(PDIR)/packages.%.renamed) \
326	$(REPOS:%=$(PDIR)/packages.%.obsolete)
327
328.KEEP_STATE:
329
330.PARALLEL: $(PKGS) $(PROC_PKGS) $(DEP_PKGS) \
331	$(PROC_SYNTH_PKGS) $(DEP_SYNTH_PKGS) $(FIN_PKGS) $(PUB_PKGS)
332
333#
334# For a single manifest, the dependency chain looks like this:
335#
336#	raw manifest (mypkg.p5m)
337#		|
338#		| use pkgmogrify to process raw manifest
339#		|
340#	processed manifest (mypkg.mog)
341#		|
342#	   *    | use pkgdepend generate to generate dependencies
343#		|
344#	manifest with TBD dependencies (mypkg.dep)
345#		|
346#	   %    | use pkgdepend resolve to resolve dependencies
347#		|
348#	manifest with dependencies resolved (mypkg.res)
349#		|
350#		| use pkgmogrify to apply final cleanups
351#		|
352#	cleaned up manifest (mypkg.fin)
353#		|
354#		| use pkgsend to publish the package
355#		|
356#	placeholder to indicate successful publication (mypkg.pub)
357#
358# * This may be suppressed via SUPPRESSPKGDEP.  The resulting
359#   packages will install correctly, but care must be taken to
360#   install all dependencies, because pkg will not have the input
361#   it needs to determine this automatically.
362#
363# % This is included in this diagram to make the picture complete, but
364#   this is a point of synchronization in the build process.
365#   Dependency resolution is actually done once on the entire set of
366#   manifests, not on a per-package basis.
367#
368# The full dependency chain for generating everything that needs to be
369# published, without actually publishing it, looks like this:
370#
371#	processed synthetic packages
372#		|		|
373#       package lists	    synthetic package manifests
374#		|
375#	processed real packages
376#	    |		|
377#	package dir	real package manifests
378#
379# Here, each item is a set of real or synthetic packages.  For this
380# portion of the build, no reference is made to the proto area.  It is
381# therefore suitable for the "all" target, as opposed to "install."
382#
383# Since each of these steps is expressed explicitly, "all" need only
384# depend on the head of the chain.
385#
386# From the end of manifest processing, the publication dependency
387# chain looks like this:
388#
389#		repository metadata (catalogs and search indices)
390#			|
391#			| pkgrepo refresh
392#			|
393#		published packages
394#		 |		|
395#		 |		| pkgsend publish
396#		 |		|
397#	  repositories	    final manifests
398#		 |			|
399# pkgsend	 |			| pkgmogrify final
400# create-repository			|
401#		 |		resolved dependencies
402#	 repo directories		|
403#					| pkgdepend resolve
404#					|
405#				    generated dependencies
406#					|
407#					| pkgdepend
408#					|
409#                                    processed manifests
410
411ALL_TARGETS= $(PROC_SYNTH_PKGS) proto_list_$(PKGMACH)
412
413all: $(ALL_TARGETS)
414
415#
416# This will build the directory to contain the processed manifests
417# and the metadata symlinks.
418#
419$(PDIR):
420	@print "Creating $(@)"
421	$(PKGDEBUG)$(INS.dir)
422
423#
424# This rule resolves dependencies across all published manifests.
425#
426$(PDIR)/gendeps: $(DEP_SYNTH_PKGS) $(DEP_PKGS)
427	$(PKGDEBUG)if [ "$(SUPPRESSPKGDEP)" = "true" ]; then \
428		print "Suppressing dependency resolution"; \
429		for p in $(DEP_PKGS:%.dep=%); do \
430			$(CP) $$p.dep $$p.res; \
431		done; \
432	else \
433		print "Resolving dependencies"; \
434		pkgdepend -R $(PKGDEP_RESOLVE_IMAGE) resolve \
435		    -m $(DEP_SYNTH_PKGS) $(DEP_PKGS); \
436		for p in $(DEP_SYNTH_PKGS:%.dep=%) $(DEP_PKGS:%.dep=%); do \
437			if [ "$$(print $$p.metadata.*)" = \
438			     "$$(print $$p.metadata.noincorp.*)" ]; \
439			then \
440				print "Removing dependency versions from $$p"; \
441				$(PKGMOGRIFY) $(PKGMOG_VERBOSE) \
442				    -O $$p.res -I transforms \
443				    strip_versions $$p.dep.res; \
444				$(RM) $$p.dep.res; \
445			else \
446				$(MV) $$p.dep.res $$p.res; \
447			fi; \
448		done; \
449	fi
450	$(PKGDEBUG)$(TOUCH) $(@)
451
452install: $(ALL_TARGETS) repository-metadata
453
454repository-metadata: publish_pkgs
455	$(PKGDEBUG)for r in $(REPOS); do \
456		pkgrepo refresh -s $(PKGDEST)/repo.$$r; \
457	done
458
459#
460# Since we create zero-length processed manifests for a graceful abort
461# from pkgmogrify, we need to detect that here and make no effort to
462# publish the package.
463#
464# For all other packages, we publish them regardless of status.  We
465# derive the target repository as a component of the metadata-derived
466# symlink for each package.
467#
468publish_pkgs: $(REPOS:%=$(PKGDEST)/repo.%) $(PDIR)/gendeps .WAIT $(PUB_PKGS)
469
470#
471# Before publishing, we want to pull the license files from $CODEMGR_WS
472# into the proto area.  This allows us to NOT pass $SRC (or
473# $CODEMGR_WS) as a basedir for publication.
474#
475$(PUB_PKGS): stage-licenses
476
477#
478# Initialize the empty on-disk repositories
479#
480$(REPOS:%=$(PKGDEST)/repo.%):
481	@print "Initializing $(@F)"
482	$(PKGDEBUG)$(INS.dir)
483	$(PKGDEBUG)pkgsend -s file://$(@) create-repository \
484		--set-property publisher.prefix=$(PKGPUBLISHER)
485
486#
487# rule to process real manifests
488#
489# To allow redistributability and package status to change, we must
490# remove not only the actual build target (the processed manifest), but
491# also the incidental ones (the metadata-derived symlinks).
492#
493# If pkgmogrify exits cleanly but fails to create the specified output
494# file, it means that it encountered an abort directive.  That means
495# that this package should not be published for this particular build
496# environment.  Since we can't prune such packages from $(PKGS)
497# retroactively, we need to create an empty target file to keep make
498# from trying to rebuild it every time.  For these empty targets, we
499# do not create metadata symlinks.
500#
501# Automatic dependency resolution to files is also done at this phase of
502# processing.  The skipped packages are skipped due to existing bugs
503# in pkgdepend.
504#
505# The incorporation dependency is tricky: it needs to go into all
506# current and renamed manifests (ie all incorporated packages), but we
507# don't know which those are until after we run pkgmogrify.  So
508# instead of expressing it as a transform, we tack it on ex post facto.
509#
510# Implementation notes:
511#
512# - The first $(RM) must not match other manifests, or we'll run into
513#   race conditions with parallel manifest processing.
514#
515# - The make macros [ie $(MACRO)] are evaluated when the makefile is
516#   read in, and will result in a fixed, macro-expanded rule for each
517#   target enumerated in $(PROC_PKGS).
518#
519# - The shell variables (ie $$VAR) are assigned on the fly, as the rule
520#   is executed.  The results may only be referenced in the shell in
521#   which they are assigned, so from the perspective of make, all code
522#   that needs these variables needs to be part of the same line of
523#   code.  Hence the use of command separators and line continuation
524#   characters.
525#
526# - The extract_metadata transforms are designed to spit out shell
527#   variable assignments to stdout.  Those are published to the
528#   .vars temporary files, and then used as input to the eval
529#   statement.  This is done in stages specifically so that pkgmogrify
530#   can signal failure if the manifest has a syntactic or other error.
531#   The eval statement should begin with the default values, and the
532#   output from pkgmogrify (if any) should be in the form of a
533#   variable assignment to override those defaults.
534#
535# - When this rule completes execution, it must leave an updated
536#   target file ($@) in place, or make will reprocess the package
537#   every time it encounters it as a dependency.  Hence the "touch"
538#   statement to ensure that the target is created, even when
539#   pkgmogrify encounters an abort in the publish transforms.
540#
541
542.SUFFIXES: .p5m .mog .dep .res .fin .pub
543
544$(PDIR)/%.mog: manifests/%.p5m
545	@print "Processing manifest $(<F)"
546	@pkgfmt -fv2 -c $<
547	$(PKGDEBUG)$(RM) $(@) $(@:%.mog=%) $(@:%.mog=%.nodepend) \
548		$(@:%.mog=%.lics) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
549	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) \
550		$(PKGMOG_DEFINES:%=-D %) -P $(@).vars -O $(@) \
551		$(<) $(PM_TRANSFORMS)
552	$(PKGDEBUG)eval REPO=redist PKGSTAT=current NODEPEND=$(SUPPRESSPKGDEP) \
553		`$(CAT) -s $(@).vars`; \
554	if [ -f $(@) ]; then \
555		if [ "$$NODEPEND" != "false" ]; then \
556			 $(TOUCH) $(@:%.mog=%.nodepend); \
557		fi; \
558		$(LN) -s $(@F) \
559			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
560		if [ \( "$$PKGSTAT" = "current" \) -o \
561		     \( "$$PKGSTAT" = "renamed" \) ]; \
562			then print $(PKGDEP_INCORP) >> $(@); \
563		fi; \
564		print $$LICS > $(@:%.mog=%.lics); \
565	else \
566		$(TOUCH) $(@) $(@:%.mog=%.lics); \
567	fi
568	$(PKGDEBUG)$(RM) $(@).vars
569
570$(PDIR)/%.dep: $(PDIR)/%.mog
571	@print "Generating dependencies for $(<F)"
572	$(PKGDEBUG)$(RM) $(@)
573	$(PKGDEBUG)if [ ! -f $(@:%.dep=%.nodepend) ]; then \
574		pkgdepend generate -m $(PKGDEP_TOKENS:%=-D %) $(<) \
575			$(PKGROOT) > $(@); \
576	else \
577		$(CP) $(<) $(@); \
578	fi
579
580#
581# The full chain implies that there should be a .dep.res suffix rule,
582# but dependency generation is done on a set of manifests, rather than
583# on a per-manifest basis.  Instead, see the gendeps rule above.
584#
585
586$(PDIR)/%.fin: $(PDIR)/%.res
587	$(PKGDEBUG)$(RM) $(@)
588	$(PKGDEBUG)if [ -s $(<) ]; then \
589		print "Running final transforms for $(<F)"; \
590		$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) -O $(@) \
591		    $(<) $(PM_FINAL_TRANSFORMS); \
592	else \
593		$(TOUCH) $(@); \
594	fi
595
596$(PDIR)/%.pub: $(PDIR)/%.fin
597	$(PKGDEBUG)m=$$(basename $(@:%.pub=%).metadata.*); \
598	r=$${m#$(@F:%.pub=%.metadata.)+(?).}; \
599	if [ -s $(<) ]; then \
600		print "Publishing $(@F:%.pub=%) to $$r repository"; \
601		pkgsend -s file://$(PKGDEST)/repo.$$r publish \
602		    -d $(PKGROOT) -d $(TOOLSROOT) \
603		    -d license_files -d $(PKGROOT)/licenses \
604		    --fmri-in-manifest --no-index --no-catalog $(<) \
605		    > /dev/null; \
606	fi; \
607	$(TOUCH) $(@);
608
609#
610# rule to build the synthetic manifests
611#
612# This rule necessarily has PKGDEP_TYPE that changes according to
613# the specific synthetic manifest.  Rather than escape command
614# dependency checking for the real manifest processing, or failing to
615# express the (indirect) dependency of synthetic manifests on real
616# manifests, we simply split this rule out from the one above.
617#
618# The implementation notes from the previous rule are applicable
619# here, too.
620#
621$(PROC_SYNTH_PKGS): $(PKGLISTS) $$(@F:%.mog=%.p5m)
622	@print "Processing synthetic manifest $(@F:%.mog=%.p5m)"
623	$(PKGDEBUG)$(RM) $(@) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
624	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) -I transforms -I $(PDIR) \
625		$(PKGMOG_DEFINES:%=-D %) -D PKGDEP_TYPE=$(PKGDEP_TYPE) \
626		-P $(@).vars -O $(@) $(@F:%.mog=%.p5m) \
627		$(PM_TRANSFORMS) synthetic
628	$(PKGDEBUG)eval REPO=redist PKGSTAT=current `$(CAT) -s $(@).vars`; \
629	if [ -f $(@) ]; then \
630		$(LN) -s $(@F) \
631			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
632	else \
633		$(TOUCH) $(@); \
634	fi
635	$(PKGDEBUG)$(RM) $(@).vars
636
637$(DEP_SYNTH_PKGS): $$(@:%.dep=%.mog)
638	@print "Skipping dependency generation for $(@F:%.dep=%)"
639	$(PKGDEBUG)$(CP) $(@:%.dep=%.mog) $(@)
640
641clean:
642
643clobber: clean
644	$(RM) -r $(CLOBBERFILES)
645
646#
647# This rule assumes that all links in the $PKGSTAT directories
648# point to valid manifests, and will fail the make run if one
649# does not contain an fmri.
650#
651# The protolist is used for bfu archive creation, which may be invoked
652# interactively by the user.  Both protolist and PKGLISTS targets
653# depend on $(PROC_PKGS), but protolist builds them recursively.
654# To avoid collisions, we insert protolist into the dependency chain
655# here.  This has two somewhat subtle benefits: it allows bfu archive
656# creation to work correctly, even when -a was not part of NIGHTLY_OPTIONS,
657# and it ensures that a protolist file here will always correspond to the
658# contents of the processed manifests, which can vary depending on build
659# environment.
660#
661$(PKGLISTS): scripts/pkglist.awk $(PROC_PKGS)
662	$(PKGDEBUG)sdotr=$(@F:packages.%=%); \
663	r=$${sdotr%.+(?)}; s=$${sdotr#+(?).}; \
664	print "Generating $$r $$s package list"; \
665	$(RM) $(@); $(TOUCH) $(@); \
666	$(AWK) -f scripts/pkglist.awk \
667	    `find $(PDIR) -type l -a \( $(PKGS:%=-name %.metadata.$$s.$$r -o) \
668	    -name NOSUCHFILE \)` >> $(@)
669
670#
671# rules to validate proto area against manifests, check for safe
672# file permission modes, and generate a faux proto list
673#
674# For the check targets, the dependencies on $(PROC_PKGS) is specified
675# as a subordinate make process in order to suppress output.
676#
677makesilent:
678	@$(MAKE) -e $(PROC_PKGS) PKGMACH=$(PKGMACH) \
679		SUPPRESSPKGDEP=$(SUPPRESSPKGDEP) > /dev/null
680
681#
682# The .lics files were created during pkgmogrification, and list the
683# set of licenses to pull from $SRC for each package.  Because
684# licenses may be duplicated between packages, we uniquify them as
685# well as aggregating them here.
686#
687license-list: makesilent
688	$(PKGDEBUG)( for l in `cat $(PROC_PKGS:%.mog=%.lics)`; \
689		do print $$l; done ) | sort -u > $@
690
691#
692# Staging the license and description files in the proto area allows
693# us to do proper unreferenced file checking of both license and
694# description files without blanket exceptions, and to pull license
695# content without reference to $CODEMGR_WS during publication.
696#
697stage-licenses: license-list FRC
698	$(PKGDEBUG)$(MAKE) -e -f Makefile.lic \
699		PKGDEBUG=$(PKGDEBUG) LICROOT=$(PKGROOT)/licenses \
700		`$(AWK) '{ \
701			print "$(PKGROOT)/licenses/" $$0; \
702			print "$(PKGROOT)/licenses/" $$0 ".descrip"; \
703		}' license-list` > /dev/null;
704
705protocmp: makesilent
706	@validate_pkg -a $(PKGMACH) -v \
707		$(EXCEPTIONS:%=-e $(CODEMGR_WS)/exception_lists/%) \
708		-m $(PDIR) -p $(PKGROOT) -p $(TOOLSROOT)
709
710pmodes: makesilent
711	@validate_pkg -a $(PKGMACH) -M -m $(PDIR) \
712		-e $(CODEMGR_WS)/exception_lists/pmodes
713
714pkglint: makesilent
715	$(PKGDEBUG)$(CP) etc/pkglintrc $(PDIR)/pkglintrc
716	$(PKGDEBUG)$(GREP) pkg:/ $(CODEMGR_WS)/exception_lists/packaging.deps \
717	    | sed 's/.*/    & \\/' >> $(PDIR)/pkglintrc
718	$(PKGDEBUG)echo "    pkg:/runtime/python$(PYTHON_PKGVERS) \\" \
719	     >> $(PDIR)/pkglintrc
720	$(PKGDEBUG)echo "    pkg:/runtime/python$(PYTHON3_PKGVERS) \\" \
721	     >> $(PDIR)/pkglintrc
722	$(PKGDEBUG) echo "    pkg:/runtime/perl$(PERL_PKGVERS) \\" \
723	     >> $(PDIR)/pkglintrc
724	$(PKGDEBUG)echo >> $(PDIR)/pkglintrc
725	$(PKGDEBUG)$(RM) -rf $(PKGDEST)/lint.image
726	$(PKGDEBUG)for r in $(REPOS); do \
727		pkglint \
728		    -f $(PDIR)/pkglintrc \
729		    -c $(PKGDEST)/lint.image \
730		    -r $(PKGDEST)/repo.$$r \
731		    `$(FIND) $(PDIR) -name \*.fin \! -size 0c -print`; \
732	done
733
734check: protocmp pmodes pkglint
735
736protolist: proto_list_$(PKGMACH)
737
738proto_list_$(PKGMACH): $(PROC_PKGS)
739	@validate_pkg -a $(PKGMACH) -L -m $(PDIR) > $(@)
740
741$(PROC_PKGS): $(PDIR)
742
743#
744# This is a convenience target to allow package names to function as
745# build targets.  Generally, using it is only useful when iterating on
746# development of a manifest.
747#
748# When processing a manifest, use the basename (without extension) of
749# the package.  When publishing, use the basename with a ".pub"
750# extension.
751#
752# Other than during manifest development, the preferred usage is to
753# avoid these targets and override PKGS on the make command line and
754# use the provided all and install targets.
755#
756$(PKGS) $(SYNTH_PKGS): $(PDIR)/$$(@:%=%.mog)
757
758$(PKGS:%=%.pub) $(SYNTH_PKGS:%=%.pub): $(PDIR)/$$(@)
759
760#
761# This is a convenience target to resolve dependencies without publishing
762# packages.
763#
764gendeps: $(PDIR)/gendeps
765
766#
767# These are convenience targets for cross-platform packaging.  If you
768# want to build any of "the normal" targets for a different
769# architecture, simply use "arch/target" as your build target.
770#
771# Since the most common use case for this is "install," the architecture
772# specific install targets have been further abbreviated to elide "/install."
773#
774i386/% sparc/%:
775	$(MAKE) -e $(@F) PKGMACH=$(@D) SUPPRESSPKGDEP=$(SUPPRESSPKGDEP)
776
777i386 sparc: $$(@)/install
778
779FRC:
780