xref: /illumos-gate/usr/src/pkg/Makefile (revision ce8560eeb961d528e27685fcdd2ffb03e9478dbf)
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 2020 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	PYTHON_PKGVERS=$(PYTHON_PKGVERS) \
199	PYTHON3_PKGVERS=$(PYTHON3_PKGVERS) \
200	python2_ONLY=$(BUILDPY2) \
201	python3_ONLY=$(BUILDPY3) \
202	python2tools_ONLY=$(BUILDPY2TOOLS) \
203	python3tools_ONLY=$(BUILDPY3TOOLS) \
204	JAVA_11_ONLY=$(JAVA_11_ONLY) \
205	JAVA_8_ONLY=$(JAVA_8_ONLY)
206
207PKGDEP_TOKENS_i386= \
208	'PLATFORM=i86hvm' \
209	'PLATFORM=i86pc' \
210	'PLATFORM=i86xpv' \
211	'ISALIST=amd64' \
212	'ISALIST=i386'
213PKGDEP_TOKENS_sparc= \
214	'PLATFORM=sun4u' \
215	'PLATFORM=sun4v' \
216	'ISALIST=sparcv9' \
217	'ISALIST=sparc'
218PKGDEP_TOKENS= $(PKGDEP_TOKENS_$(PKGMACH))
219
220#
221# The package lists are generated with $(PKGDEP_TYPE) as their
222# dependency types, so that they can be included by either an
223# incorporation or a group package.
224#
225$(PDIR)/osnet-redist.mog := PKGDEP_TYPE= require
226$(PDIR)/osnet-incorporation.mog:= PKGDEP_TYPE= incorporate
227
228PKGDEP_INCORP= \
229	depend fmri=consolidation/osnet/osnet-incorporation type=require
230
231#
232# All packaging build products should go into $(PDIR), so they don't
233# need to be included separately in CLOBBERFILES.
234#
235CLOBBERFILES= $(PDIR) proto_list_$(PKGMACH) install-$(PKGMACH).out \
236	license-list
237
238#
239# By default, PKGS will list all manifests.  To build and/or publish a
240# subset of packages, override this on the command line or in the
241# build environment and then reference (implicitly or explicitly) the all
242# or install targets.
243#
244# We want some manifests to optionally build based on environment options, so
245# those are excluded when generating the list of manifests and added back in if
246# necessary. We also want a relatively easy way to add files to the list of
247# manifests given special treatment. Add any other special ones to the
248# SPECIAL_MANIFESTS variable. It can contain wildcards in regexp form, i.e.
249# SUNW.* as one useful example.
250#
251SPECIAL_MANIFESTS = system-library-python-.*
252LIST_MANIFESTS_CMD = (cd manifests ; /usr/bin/ls -1 *.mf |\
253	$(SED) $(SPECIAL_MANIFESTS:%=-e '/^%$$/d') )
254MANIFESTS = $(LIST_MANIFESTS_CMD:sh)
255
256# Conditionally add back python modules
257$(BUILDPY2) MANIFESTS += \
258	system-library-python-libbe-2.mf \
259	system-library-python-solaris-2.mf \
260	system-library-python-zfs-2.mf
261$(BUILDPY3) MANIFESTS += \
262	system-library-python-libbe-3.mf \
263	system-library-python-solaris-3.mf \
264	system-library-python-zfs-3.mf
265
266PKGS= $(MANIFESTS:%.mf=%)
267DEP_PKGS= $(PKGS:%=$(PDIR)/%.dep)
268PROC_PKGS= $(PKGS:%=$(PDIR)/%.mog)
269FIN_PKGS= $(PKGS:%=$(PDIR)/%.fin)
270
271#
272# Track the synthetic manifests separately so we can properly express
273# build rules and dependencies.  The synthetic and real packages use
274# different sets of transforms and macros for pkgmogrify.
275#
276SYNTH_PKGS= osnet-incorporation osnet-redist
277DEP_SYNTH_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.dep)
278PROC_SYNTH_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.mog)
279
280#
281# Root of pkg image to use for dependency resolution
282# Normally / on the machine used to build the binaries
283#
284PKGDEP_RESOLVE_IMAGE = /
285
286#
287# For each package, we determine the target repository based on
288# manifest-embedded metadata.  Because we make that determination on
289# the fly, the publication target cannot be expressed as a
290# subdirectory inside the unknown-by-the-makefile target repository.
291#
292# In order to limit the target set to real files in known locations,
293# we use a ".pub" file in $(PDIR) for each processed manifest, regardless
294# of content or target repository.
295#
296PUB_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.pub) $(PKGS:%=$(PDIR)/%.pub)
297
298#
299# Any given repository- and status-specific package list may be empty,
300# but we can only determine that dynamically, so we always generate all
301# lists for each repository we're building.
302#
303# The meanings of each package status are as follows:
304#
305#	PKGSTAT		meaning
306#	----------	----------------------------------------------------
307#	noincorp	Do not include in incorporation or group package
308#	obsolete	Include in incorporation, but not group package
309#	renamed		Include in incorporation, but not group package
310#	current		Include in incorporation and group package
311#
312# Since the semantics of the "noincorp" package status dictate that
313# such packages are not included in the incorporation or group packages,
314# there is no need to build noincorp package lists.
315#
316PKGLISTS= \
317	$(REPOS:%=$(PDIR)/packages.%.current) \
318	$(REPOS:%=$(PDIR)/packages.%.renamed) \
319	$(REPOS:%=$(PDIR)/packages.%.obsolete)
320
321.KEEP_STATE:
322
323.PARALLEL: $(PKGS) $(PROC_PKGS) $(DEP_PKGS) \
324	$(PROC_SYNTH_PKGS) $(DEP_SYNTH_PKGS) $(FIN_PKGS) $(PUB_PKGS)
325
326#
327# For a single manifest, the dependency chain looks like this:
328#
329#	raw manifest (mypkg.mf)
330#		|
331#		| use pkgmogrify to process raw manifest
332#		|
333#	processed manifest (mypkg.mog)
334#		|
335#	   *    | use pkgdepend generate to generate dependencies
336#		|
337#	manifest with TBD dependencies (mypkg.dep)
338#		|
339#	   %    | use pkgdepend resolve to resolve dependencies
340#		|
341#	manifest with dependencies resolved (mypkg.res)
342#		|
343#		| use pkgmogrify to apply final cleanups
344#		|
345#	cleaned up manifest (mypkg.fin)
346#		|
347#		| use pkgsend to publish the package
348#		|
349#	placeholder to indicate successful publication (mypkg.pub)
350#
351# * This may be suppressed via SUPPRESSPKGDEP.  The resulting
352#   packages will install correctly, but care must be taken to
353#   install all dependencies, because pkg will not have the input
354#   it needs to determine this automatically.
355#
356# % This is included in this diagram to make the picture complete, but
357#   this is a point of synchronization in the build process.
358#   Dependency resolution is actually done once on the entire set of
359#   manifests, not on a per-package basis.
360#
361# The full dependency chain for generating everything that needs to be
362# published, without actually publishing it, looks like this:
363#
364#	processed synthetic packages
365#		|		|
366#       package lists	    synthetic package manifests
367#		|
368#	processed real packages
369#	    |		|
370#	package dir	real package manifests
371#
372# Here, each item is a set of real or synthetic packages.  For this
373# portion of the build, no reference is made to the proto area.  It is
374# therefore suitable for the "all" target, as opposed to "install."
375#
376# Since each of these steps is expressed explicitly, "all" need only
377# depend on the head of the chain.
378#
379# From the end of manifest processing, the publication dependency
380# chain looks like this:
381#
382#		repository metadata (catalogs and search indices)
383#			|
384#			| pkgrepo refresh
385#			|
386#		published packages
387#		 |		|
388#		 |		| pkgsend publish
389#		 |		|
390#	  repositories	    final manifests
391#		 |			|
392# pkgsend	 |			| pkgmogrify final
393# create-repository			|
394#		 |		resolved dependencies
395#	 repo directories		|
396#					| pkgdepend resolve
397#					|
398#				    generated dependencies
399#					|
400#					| pkgdepend
401#					|
402#                                    processed manifests
403
404ALL_TARGETS= $(PROC_SYNTH_PKGS) proto_list_$(PKGMACH)
405
406all: $(ALL_TARGETS)
407
408#
409# This will build the directory to contain the processed manifests
410# and the metadata symlinks.
411#
412$(PDIR):
413	@print "Creating $(@)"
414	$(PKGDEBUG)$(INS.dir)
415
416#
417# This rule resolves dependencies across all published manifests.
418#
419$(PDIR)/gendeps: $(DEP_SYNTH_PKGS) $(DEP_PKGS)
420	$(PKGDEBUG)if [ "$(SUPPRESSPKGDEP)" = "true" ]; then \
421		print "Suppressing dependency resolution"; \
422		for p in $(DEP_PKGS:%.dep=%); do \
423			$(CP) $$p.dep $$p.res; \
424		done; \
425	else \
426		print "Resolving dependencies"; \
427		pkgdepend -R $(PKGDEP_RESOLVE_IMAGE) resolve \
428		    -m $(DEP_SYNTH_PKGS) $(DEP_PKGS); \
429		for p in $(DEP_SYNTH_PKGS:%.dep=%) $(DEP_PKGS:%.dep=%); do \
430			if [ "$$(print $$p.metadata.*)" = \
431			     "$$(print $$p.metadata.noincorp.*)" ]; \
432			then \
433				print "Removing dependency versions from $$p"; \
434				$(PKGMOGRIFY) $(PKGMOG_VERBOSE) \
435				    -O $$p.res -I transforms \
436				    strip_versions $$p.dep.res; \
437				$(RM) $$p.dep.res; \
438			else \
439				$(MV) $$p.dep.res $$p.res; \
440			fi; \
441		done; \
442	fi
443	$(PKGDEBUG)$(TOUCH) $(@)
444
445install: $(ALL_TARGETS) repository-metadata
446
447repository-metadata: publish_pkgs
448	$(PKGDEBUG)for r in $(REPOS); do \
449		pkgrepo refresh -s $(PKGDEST)/repo.$$r; \
450	done
451
452#
453# Since we create zero-length processed manifests for a graceful abort
454# from pkgmogrify, we need to detect that here and make no effort to
455# publish the package.
456#
457# For all other packages, we publish them regardless of status.  We
458# derive the target repository as a component of the metadata-derived
459# symlink for each package.
460#
461publish_pkgs: $(REPOS:%=$(PKGDEST)/repo.%) $(PDIR)/gendeps .WAIT $(PUB_PKGS)
462
463#
464# Before publishing, we want to pull the license files from $CODEMGR_WS
465# into the proto area.  This allows us to NOT pass $SRC (or
466# $CODEMGR_WS) as a basedir for publication.
467#
468$(PUB_PKGS): stage-licenses
469
470#
471# Initialize the empty on-disk repositories
472#
473$(REPOS:%=$(PKGDEST)/repo.%):
474	@print "Initializing $(@F)"
475	$(PKGDEBUG)$(INS.dir)
476	$(PKGDEBUG)pkgsend -s file://$(@) create-repository \
477		--set-property publisher.prefix=$(PKGPUBLISHER)
478
479#
480# rule to process real manifests
481#
482# To allow redistributability and package status to change, we must
483# remove not only the actual build target (the processed manifest), but
484# also the incidental ones (the metadata-derived symlinks).
485#
486# If pkgmogrify exits cleanly but fails to create the specified output
487# file, it means that it encountered an abort directive.  That means
488# that this package should not be published for this particular build
489# environment.  Since we can't prune such packages from $(PKGS)
490# retroactively, we need to create an empty target file to keep make
491# from trying to rebuild it every time.  For these empty targets, we
492# do not create metadata symlinks.
493#
494# Automatic dependency resolution to files is also done at this phase of
495# processing.  The skipped packages are skipped due to existing bugs
496# in pkgdepend.
497#
498# The incorporation dependency is tricky: it needs to go into all
499# current and renamed manifests (ie all incorporated packages), but we
500# don't know which those are until after we run pkgmogrify.  So
501# instead of expressing it as a transform, we tack it on ex post facto.
502#
503# Implementation notes:
504#
505# - The first $(RM) must not match other manifests, or we'll run into
506#   race conditions with parallel manifest processing.
507#
508# - The make macros [ie $(MACRO)] are evaluated when the makefile is
509#   read in, and will result in a fixed, macro-expanded rule for each
510#   target enumerated in $(PROC_PKGS).
511#
512# - The shell variables (ie $$VAR) are assigned on the fly, as the rule
513#   is executed.  The results may only be referenced in the shell in
514#   which they are assigned, so from the perspective of make, all code
515#   that needs these variables needs to be part of the same line of
516#   code.  Hence the use of command separators and line continuation
517#   characters.
518#
519# - The extract_metadata transforms are designed to spit out shell
520#   variable assignments to stdout.  Those are published to the
521#   .vars temporary files, and then used as input to the eval
522#   statement.  This is done in stages specifically so that pkgmogrify
523#   can signal failure if the manifest has a syntactic or other error.
524#   The eval statement should begin with the default values, and the
525#   output from pkgmogrify (if any) should be in the form of a
526#   variable assignment to override those defaults.
527#
528# - When this rule completes execution, it must leave an updated
529#   target file ($@) in place, or make will reprocess the package
530#   every time it encounters it as a dependency.  Hence the "touch"
531#   statement to ensure that the target is created, even when
532#   pkgmogrify encounters an abort in the publish transforms.
533#
534
535.SUFFIXES: .mf .mog .dep .res .fin .pub
536
537$(PDIR)/%.mog: manifests/%.mf
538	@print "Processing manifest $(<F)"
539	@env PKGFMT_OUTPUT=v1 pkgfmt -c $<
540	$(PKGDEBUG)$(RM) $(@) $(@:%.mog=%) $(@:%.mog=%.nodepend) \
541		$(@:%.mog=%.lics) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
542	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) \
543		$(PKGMOG_DEFINES:%=-D %) -P $(@).vars -O $(@) \
544		$(<) $(PM_TRANSFORMS)
545	$(PKGDEBUG)eval REPO=redist PKGSTAT=current NODEPEND=$(SUPPRESSPKGDEP) \
546		`$(CAT) -s $(@).vars`; \
547	if [ -f $(@) ]; then \
548		if [ "$$NODEPEND" != "false" ]; then \
549			 $(TOUCH) $(@:%.mog=%.nodepend); \
550		fi; \
551		$(LN) -s $(@F) \
552			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
553		if [ \( "$$PKGSTAT" = "current" \) -o \
554		     \( "$$PKGSTAT" = "renamed" \) ]; \
555			then print $(PKGDEP_INCORP) >> $(@); \
556		fi; \
557		print $$LICS > $(@:%.mog=%.lics); \
558	else \
559		$(TOUCH) $(@) $(@:%.mog=%.lics); \
560	fi
561	$(PKGDEBUG)$(RM) $(@).vars
562
563$(PDIR)/%.dep: $(PDIR)/%.mog
564	@print "Generating dependencies for $(<F)"
565	$(PKGDEBUG)$(RM) $(@)
566	$(PKGDEBUG)if [ ! -f $(@:%.dep=%.nodepend) ]; then \
567		pkgdepend generate -m $(PKGDEP_TOKENS:%=-D %) $(<) \
568			$(PKGROOT) > $(@); \
569	else \
570		$(CP) $(<) $(@); \
571	fi
572
573#
574# The full chain implies that there should be a .dep.res suffix rule,
575# but dependency generation is done on a set of manifests, rather than
576# on a per-manifest basis.  Instead, see the gendeps rule above.
577#
578
579$(PDIR)/%.fin: $(PDIR)/%.res
580	$(PKGDEBUG)$(RM) $(@)
581	$(PKGDEBUG)if [ -s $(<) ]; then \
582		print "Running final transforms for $(<F)"; \
583		$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) -O $(@) \
584		    $(<) $(PM_FINAL_TRANSFORMS); \
585	else \
586		$(TOUCH) $(@); \
587	fi
588
589$(PDIR)/%.pub: $(PDIR)/%.fin
590	$(PKGDEBUG)m=$$(basename $(@:%.pub=%).metadata.*); \
591	r=$${m#$(@F:%.pub=%.metadata.)+(?).}; \
592	if [ -s $(<) ]; then \
593		print "Publishing $(@F:%.pub=%) to $$r repository"; \
594		pkgsend -s file://$(PKGDEST)/repo.$$r publish \
595		    -d $(PKGROOT) -d $(TOOLSROOT) \
596		    -d license_files -d $(PKGROOT)/licenses \
597		    --fmri-in-manifest --no-index --no-catalog $(<) \
598		    > /dev/null; \
599	fi; \
600	$(TOUCH) $(@);
601
602#
603# rule to build the synthetic manifests
604#
605# This rule necessarily has PKGDEP_TYPE that changes according to
606# the specific synthetic manifest.  Rather than escape command
607# dependency checking for the real manifest processing, or failing to
608# express the (indirect) dependency of synthetic manifests on real
609# manifests, we simply split this rule out from the one above.
610#
611# The implementation notes from the previous rule are applicable
612# here, too.
613#
614$(PROC_SYNTH_PKGS): $(PKGLISTS) $$(@F:%.mog=%.mf)
615	@print "Processing synthetic manifest $(@F:%.mog=%.mf)"
616	$(PKGDEBUG)$(RM) $(@) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
617	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) -I transforms -I $(PDIR) \
618		$(PKGMOG_DEFINES:%=-D %) -D PKGDEP_TYPE=$(PKGDEP_TYPE) \
619		-P $(@).vars -O $(@) $(@F:%.mog=%.mf) \
620		$(PM_TRANSFORMS) synthetic
621	$(PKGDEBUG)eval REPO=redist PKGSTAT=current `$(CAT) -s $(@).vars`; \
622	if [ -f $(@) ]; then \
623		$(LN) -s $(@F) \
624			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
625	else \
626		$(TOUCH) $(@); \
627	fi
628	$(PKGDEBUG)$(RM) $(@).vars
629
630$(DEP_SYNTH_PKGS): $$(@:%.dep=%.mog)
631	@print "Skipping dependency generation for $(@F:%.dep=%)"
632	$(PKGDEBUG)$(CP) $(@:%.dep=%.mog) $(@)
633
634clean:
635
636clobber: clean
637	$(RM) -r $(CLOBBERFILES)
638
639#
640# This rule assumes that all links in the $PKGSTAT directories
641# point to valid manifests, and will fail the make run if one
642# does not contain an fmri.
643#
644# The protolist is used for bfu archive creation, which may be invoked
645# interactively by the user.  Both protolist and PKGLISTS targets
646# depend on $(PROC_PKGS), but protolist builds them recursively.
647# To avoid collisions, we insert protolist into the dependency chain
648# here.  This has two somewhat subtle benefits: it allows bfu archive
649# creation to work correctly, even when -a was not part of NIGHTLY_OPTIONS,
650# and it ensures that a protolist file here will always correspond to the
651# contents of the processed manifests, which can vary depending on build
652# environment.
653#
654$(PKGLISTS): scripts/pkglist.awk $(PROC_PKGS)
655	$(PKGDEBUG)sdotr=$(@F:packages.%=%); \
656	r=$${sdotr%.+(?)}; s=$${sdotr#+(?).}; \
657	print "Generating $$r $$s package list"; \
658	$(RM) $(@); $(TOUCH) $(@); \
659	$(AWK) -f scripts/pkglist.awk \
660	    `find $(PDIR) -type l -a \( $(PKGS:%=-name %.metadata.$$s.$$r -o) \
661	    -name NOSUCHFILE \)` >> $(@)
662
663#
664# rules to validate proto area against manifests, check for safe
665# file permission modes, and generate a faux proto list
666#
667# For the check targets, the dependencies on $(PROC_PKGS) is specified
668# as a subordinate make process in order to suppress output.
669#
670makesilent:
671	@$(MAKE) -e $(PROC_PKGS) PKGMACH=$(PKGMACH) \
672		SUPPRESSPKGDEP=$(SUPPRESSPKGDEP) > /dev/null
673
674#
675# The .lics files were created during pkgmogrification, and list the
676# set of licenses to pull from $SRC for each package.  Because
677# licenses may be duplicated between packages, we uniquify them as
678# well as aggregating them here.
679#
680license-list: makesilent
681	$(PKGDEBUG)( for l in `cat $(PROC_PKGS:%.mog=%.lics)`; \
682		do print $$l; done ) | sort -u > $@
683
684#
685# Staging the license and description files in the proto area allows
686# us to do proper unreferenced file checking of both license and
687# description files without blanket exceptions, and to pull license
688# content without reference to $CODEMGR_WS during publication.
689#
690stage-licenses: license-list FRC
691	$(PKGDEBUG)$(MAKE) -e -f Makefile.lic \
692		PKGDEBUG=$(PKGDEBUG) LICROOT=$(PKGROOT)/licenses \
693		`$(AWK) '{ \
694			print "$(PKGROOT)/licenses/" $$0; \
695			print "$(PKGROOT)/licenses/" $$0 ".descrip"; \
696		}' license-list` > /dev/null;
697
698protocmp: makesilent
699	@validate_pkg -a $(PKGMACH) -v \
700		$(EXCEPTIONS:%=-e $(CODEMGR_WS)/exception_lists/%) \
701		-m $(PDIR) -p $(PKGROOT) -p $(TOOLSROOT)
702
703pmodes: makesilent
704	@validate_pkg -a $(PKGMACH) -M -m $(PDIR) \
705		-e $(CODEMGR_WS)/exception_lists/pmodes
706
707pkglint: makesilent
708	$(PKGDEBUG)$(CP) etc/pkglintrc $(PDIR)/pkglintrc
709	$(PKGDEBUG)$(GREP) pkg:/ $(CODEMGR_WS)/exception_lists/packaging.deps \
710	    | sed 's/.*/    & \\/' >> $(PDIR)/pkglintrc
711	$(PKGDEBUG)echo "    pkg:/runtime/python$(PYTHON_PKGVERS) \\" \
712	     >> $(PDIR)/pkglintrc
713	$(PKGDEBUG)echo "    pkg:/runtime/python$(PYTHON3_PKGVERS) \\" \
714	     >> $(PDIR)/pkglintrc
715	$(PKGDEBUG) echo "    pkg:/runtime/perl$(PERL_PKGVERS) \\" \
716	     >> $(PDIR)/pkglintrc
717	$(PKGDEBUG)echo >> $(PDIR)/pkglintrc
718	$(PKGDEBUG)$(RM) -rf $(PKGDEST)/lint.image
719	$(PKGDEBUG)for r in $(REPOS); do \
720		pkglint \
721		    -f $(PDIR)/pkglintrc \
722		    -c $(PKGDEST)/lint.image \
723		    -r $(PKGDEST)/repo.$$r \
724		    `$(FIND) $(PDIR) -name \*.fin \! -size 0c -print`; \
725	done
726
727check: protocmp pmodes pkglint
728
729protolist: proto_list_$(PKGMACH)
730
731proto_list_$(PKGMACH): $(PROC_PKGS)
732	@validate_pkg -a $(PKGMACH) -L -m $(PDIR) > $(@)
733
734$(PROC_PKGS): $(PDIR)
735
736#
737# This is a convenience target to allow package names to function as
738# build targets.  Generally, using it is only useful when iterating on
739# development of a manifest.
740#
741# When processing a manifest, use the basename (without extension) of
742# the package.  When publishing, use the basename with a ".pub"
743# extension.
744#
745# Other than during manifest development, the preferred usage is to
746# avoid these targets and override PKGS on the make command line and
747# use the provided all and install targets.
748#
749$(PKGS) $(SYNTH_PKGS): $(PDIR)/$$(@:%=%.mog)
750
751$(PKGS:%=%.pub) $(SYNTH_PKGS:%=%.pub): $(PDIR)/$$(@)
752
753#
754# This is a convenience target to resolve dependencies without publishing
755# packages.
756#
757gendeps: $(PDIR)/gendeps
758
759#
760# These are convenience targets for cross-platform packaging.  If you
761# want to build any of "the normal" targets for a different
762# architecture, simply use "arch/target" as your build target.
763#
764# Since the most common use case for this is "install," the architecture
765# specific install targets have been further abbreviated to elide "/install."
766#
767i386/% sparc/%:
768	$(MAKE) -e $(@F) PKGMACH=$(@D) SUPPRESSPKGDEP=$(SUPPRESSPKGDEP)
769
770i386 sparc: $$(@)/install
771
772FRC:
773