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