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