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