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