xref: /titanic_44/usr/src/pkg/Makefile (revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa)
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)/developer-build-onbld.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= common_actions 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#
302PKGLISTS= \
303	$(REPOS:%=$(PDIR)/packages.%.current) \
304	$(REPOS:%=$(PDIR)/packages.%.renamed) \
305	$(REPOS:%=$(PDIR)/packages.%.obsolete)
306
307.KEEP_STATE:
308
309.PARALLEL: $(PKGS) $(PROC_PKGS) $(DEP_PKGS) \
310	$(PROC_SYNTH_PKGS) $(DEP_SYNTH_PKGS) $(PUB_PKGS)
311
312#
313# For a single manifest, the dependency chain looks like this:
314#
315#	raw manifest (mypkg.mf)
316#		|
317#		| use pkgmogrify to process raw manifest
318#		|
319#	processed manifest (mypkg.mog)
320#		|
321#	   *    | use pkgdepend generate to generate dependencies
322#		|
323#	manifest with TBD dependencies (mypkg.dep)
324#		|
325#	   %    | use pkgdepend resolve to resolve dependencies
326#		|
327#	manifest with dependencies resolved (mypkg.res)
328#		|
329#		| use pkgsend to publish the package
330#		|
331#	placeholder to indicate successful publication (mypkg.pub)
332#
333# * This may be suppressed via SUPPRESSPKGDEP.  The resulting
334#   packages will install correctly, but care must be taken to
335#   install all dependencies, because pkg will not have the input
336#   it needs to determine this automatically.
337#
338# % This is included in this diagram to make the picture complete, but
339#   this is a point of synchronization in the build process.
340#   Dependency resolution is actually done once on the entire set of
341#   manifests, not on a per-package basis.
342#
343# The full dependency chain for generating everything that needs to be
344# published, without actually publishing it, looks like this:
345#
346#	processed synthetic packages
347#		|		|
348#       package lists	    synthetic package manifests
349#		|
350#	processed real packages
351#	    |		|
352#	package dir	real package manifests
353#
354# Here, each item is a set of real or synthetic packages.  For this
355# portion of the build, no reference is made to the proto area.  It is
356# therefore suitable for the "all" target, as opposed to "install."
357#
358# Since each of these steps is expressed explicitly, "all" need only
359# depend on the head of the chain.
360#
361# From the end of manifest processing, the publication dependency
362# chain looks like this:
363#
364#		repository metadata (catalogs and search indices)
365#			|
366#			| pkg.depotd
367#			|
368#		published packages
369#		 |		|
370#		 |		| pkgsend publish
371#		 |		|
372#	  repositories 	    resolved dependencies
373#		 |			|
374# pkgsend	 |			| pkgdepend resolve
375# create-repository	 	 	|
376#		 |		generated dependencies
377#	 repo directories		|
378#					| pkgdepend
379#					|
380#				processed manifests
381#
382# Due to limitations in pkgdepend, we cannot simply treat synthetic
383# and real manifests identically.  But we don't really want to
384# maintain a separate chain for synthetic manifests, so for the left
385# side of this diagram, we actually do faux dependency generation and
386# resolution, so we end up with the expected set of files in $(PDIR),
387# per the individual file chain described above: mf, mog, dep, res,
388# and pub files for each manifest.
389#
390ALL_TARGETS= $(PROC_SYNTH_PKGS) proto_list_$(PKGMACH)
391
392all: $(ALL_TARGETS)
393
394#
395# This will build the directory to contain the processed manifests
396# and the metadata symlinks.
397#
398$(PDIR):
399	@print "Creating $(@)"
400	$(PKGDEBUG)$(INS.dir)
401
402#
403# This rule resolves dependencies across all published manifests.
404# We should be able to do this with
405#
406#    pkgdepend resolve -m $(PUB_PKGS:%.pub=%.dep)
407#
408# but until 14113 is fixed, the incorporations confuse pkgdepend, so we
409# just create the .res file for DEP_SYNTH_PKGS directly.
410#
411# We also shouldn't have to ignore the error from pkgdepend, but
412# until at least 14110 is resolved, pkgdepend will always exit with
413# an error.
414#
415$(PDIR)/gendeps: $(DEP_SYNTH_PKGS) $(DEP_PKGS)
416	-$(PKGDEBUG)if [ "$(SUPPRESSPKGDEP)" = "true" ]; then \
417		print "Suppressing dependency resolution"; \
418		for p in $(DEP_PKGS:%.dep=%); do \
419			$(CP) $$p.dep $$p.res; \
420		done; \
421	else \
422		print "Resolving dependencies"; \
423		pkgdepend resolve -m $(DEP_PKGS); \
424		for p in $(DEP_PKGS:%.dep=%); do \
425			if [ "$$(print $$p.metadata.*)" = \
426			     "$$(print $$p.metadata.noincorp.*)" ]; \
427			then \
428				print "Removing dependency versions from $$p"; \
429				$(PKGMOGRIFY) $(PKGMOG_VERBOSE) \
430				    -O $$p.res -I transforms \
431				    strip_versions $$p.dep.res; \
432				$(RM) $$p.dep.res; \
433			else \
434				$(MV) $$p.dep.res $$p.res; \
435			fi; \
436		done; \
437	fi
438	$(PKGDEBUG)for p in $(DEP_SYNTH_PKGS:%.dep=%); \
439	do \
440		$(CP) $$p.dep $$p.res; \
441	done
442	$(PKGDEBUG)$(TOUCH) $(@)
443
444install: $(ALL_TARGETS) repository-metadata
445
446repository-metadata: publish_pkgs
447	@print "Creating repository metadata"
448	$(PKGDEBUG)for r in $(REPOS); do \
449		/usr/lib/pkg.depotd -d $(PKGDEST)/repo.$$r \
450			--add-content --exit-ready; \
451		chmod a+r $(PKGDEST)/repo.$$r/cfg_cache; \
452	done
453
454#
455# Since we create zero-length processed manifests for a graceful abort
456# from pkgmogrify, we need to detect that here and make no effort to
457# publish the package.
458#
459# For all other packages, we publish them regardless of status.  We
460# derive the target repository as a component of the metadata-derived
461# symlink for each package.
462#
463publish_pkgs: $(REPOS:%=$(PKGDEST)/repo.%) $(PDIR)/gendeps .WAIT $(PUB_PKGS)
464
465$(PUB_PKGS): FRC
466
467#
468# Initialize the empty on-disk repositories
469#
470$(REPOS:%=$(PKGDEST)/repo.%):
471	@print "Initializing $(@F)"
472	$(PKGDEBUG)$(INS.dir)
473	$(PKGDEBUG)pkgsend -s file://$(@) create-repository \
474		--set-property publisher.prefix=$(PKGPUBLISHER)
475
476#
477# rule to process real manifests
478#
479# To allow redistributability and package status to change, we must
480# remove not only the actual build target (the processed manifest), but
481# also the incidental ones (the metadata-derived symlinks).
482#
483# If pkgmogrify exits cleanly but fails to create the specified output
484# file, it means that it encountered an abort directive.  That means
485# that this package should not be published for this particular build
486# environment.  Since we can't prune such packages from $(PKGS)
487# retroactively, we need to create an empty target file to keep make
488# from trying to rebuild it every time.  For these empty targets, we
489# do not create metadata symlinks.
490#
491# Automatic dependency resolution to files is also done at this phase of
492# processing.  The skipped packages are skipped due to existing bugs
493# in pkgdepend.
494#
495# The incorporation dependency is tricky: it needs to go into all
496# current and renamed manifests (ie all incorporated packages), but we
497# don't know which those are until after we run pkgmogrify.  So
498# instead of expressing it as a transform, we tack it on ex post facto.
499#
500# Implementation notes:
501#
502# - The first $(RM) must not match other manifests, or we'll run into
503#   race conditions with parallel manifest processing.
504#
505# - The make macros [ie $(MACRO)] are evaluated when the makefile is
506#   read in, and will result in a fixed, macro-expanded rule for each
507#   target enumerated in $(PROC_PKGS).
508#
509# - The shell variables (ie $$VAR) are assigned on the fly, as the rule
510#   is executed.  The results may only be referenced in the shell in
511#   which they are assigned, so from the perspective of make, all code
512#   that needs these variables needs to be part of the same line of
513#   code.  Hence the use of command separators and line continuation
514#   characters.
515#
516# - The extract_metadata transforms are designed to spit out shell
517#   variable assignments to stdout.  Those are published to the
518#   .vars temporary files, and then used as input to the eval
519#   statement.  This is done in stages specifically so that pkgmogrify
520#   can signal failure if the manifest has a syntactic or other error.
521#   The eval statement should begin with the default values, and the
522#   output from pkgmogrify (if any) should be in the form of a
523#   variable assignment to override those defaults.
524#
525# - When this rule completes execution, it must leave an updated
526#   target file ($@) in place, or make will reprocess the package
527#   every time it encounters it as a dependency.  Hence the "touch"
528#   statement to ensure that the target is created, even when
529#   pkgmogrify encounters an abort in the publish transforms.  This
530#   will not cause publication failures when switching build
531#   environments, because $(CLOSED_BUILD) and $(OPEN_ONLY) are
532#   referenced in $(PKGMOG_DEFINES), and changes will therefore
533#   trigger a rebuild for command dependency failure.  (Command
534#   dependency checking is turned on by .KEEP_STATE: above.)
535#
536
537.SUFFIXES: .mf .mog .dep .res .pub
538
539$(PDIR)/%.mog: manifests/%.mf
540	@print "Processing manifest $(<F)"
541	$(PKGDEBUG)$(RM) $(@) $(@:%.mog=%) $(@:%.mog=%.nodepend) \
542		$(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
543	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) \
544		$(PKGMOG_DEFINES:%=-D %) -P $(@).vars -O $(@) \
545		$(<) $(PM_TRANSFORMS)
546	$(PKGDEBUG)eval REPO=redist PKGSTAT=current NODEPEND=$(SUPPRESSPKGDEP) \
547		`$(CAT) -s $(@).vars`; \
548	if [ -f $(@) ]; then \
549		if [ "$$NODEPEND" != "false" ]; then \
550			 $(TOUCH) $(@:%.mog=%.nodepend); \
551		fi; \
552		$(LN) -s $(@F) \
553			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
554		if [ \( "$$PKGSTAT" = "current" \) -o \
555		     \( "$$PKGSTAT" = "renamed" \) ]; \
556			then print $(PKGDEP_INCORP) >> $(@); \
557		fi; \
558	else \
559		$(TOUCH) $(@); \
560	fi
561	$(PKGDEBUG)$(RM) $(@).vars
562
563$(PDIR)/%.dep: $(PDIR)/%.mog
564	@print "Generating dependencies for $(<F)"
565	$(PKGDEBUG)$(RM) $(@)
566	$(PKGDEBUG)if [ ! -f $(@:%.dep=%.nodepend) ]; then \
567		pkgdepend generate -m $(PKGDEP_TOKENS:%=-D %) $(<) \
568			$(PKGROOT) > $(@); \
569	else \
570		$(CP) $(<) $(@); \
571	fi
572
573#
574# The full chain implies that there should be a .dep.res suffix rule,
575# but dependency generation is done on a set of manifests, rather than
576# on a per-manifest basis.  Instead, see the gendeps rule above.
577#
578
579$(PDIR)/%.pub: $(PDIR)/%.res
580	$(PKGDEBUG)m=$$(basename $(@:%.pub=%).metadata.*); \
581	r=$${m#$(@F:%.pub=%.metadata.)+(?).}; \
582	if [ -s $(<) ]; then \
583		print "Publishing $(@F:%.pub=%) to $$r repository"; \
584		pkgsend -s file://$(PKGDEST)/repo.$$r publish \
585		    -d $(PKGROOT) -d $(TOOLSROOT) -d $(SRC)/pkg/license_files \
586		    -d $(SRC) --fmri-in-manifest --no-index --no-catalog $(<) \
587		    > /dev/null; \
588	fi; \
589	$(TOUCH) $(@);
590
591#
592# rule to build the synthetic manifests
593#
594# This rule necessarily has PKGDEP_TYPE that changes according to
595# the specific synthetic manifest.  Rather than escape command
596# dependency checking for the real manifest processing, or failing to
597# express the (indirect) dependency of synthetic manifests on real
598# manifests, we simply split this rule out from the one above.
599#
600# The implementation notes from the previous rule are applicable
601# here, too.
602#
603$(PROC_SYNTH_PKGS): $(PKGLISTS) $$(@F:%.mog=%.mf)
604	@print "Processing synthetic manifest $(@F:%.mog=%.mf)"
605	$(PKGDEBUG)$(RM) $(@) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
606	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) -I transforms -I $(PDIR) \
607		$(PKGMOG_DEFINES:%=-D %) -D PKGDEP_TYPE=$(PKGDEP_TYPE) \
608		-P $(@).vars -O $(@) $(@F:%.mog=%.mf) \
609		$(PM_TRANSFORMS) synthetic
610	$(PKGDEBUG)eval REPO=redist PKGSTAT=current `$(CAT) -s $(@).vars`; \
611	if [ -f $(@) ]; then \
612		$(LN) -s $(@F) \
613			$(PDIR)/$(@F:%.mog=%).metadata.$$PKGSTAT.$$REPO; \
614	else \
615		$(TOUCH) $(@); \
616	fi
617	$(PKGDEBUG)$(RM) $(@).vars
618
619$(DEP_SYNTH_PKGS): $$(@:%.dep=%.mog)
620	@print "Skipping dependency generation for $(@F:%.dep=%)"
621	$(PKGDEBUG)$(CP) $(@:%.dep=%.mog) $(@)
622
623clean:
624
625clobber: clean
626	$(RM) -r $(CLOBBERFILES)
627
628#
629# This rule assumes that all links in the $PKGSTAT directories
630# point to valid manifests, and will fail the make run if one
631# does not contain an fmri.
632#
633# We do this in the BEGIN action instead of using pattern matching
634# because we expect the fmri to be at or near the first line of each input
635# file, and this way lets us avoid reading the rest of the file after we
636# find what we need.
637#
638# We keep track of a failure to locate an fmri, so we can fail the
639# make run, but we still attempt to process each package in the
640# repo/pkgstat-specific subdir, in hopes of maybe giving some
641# additional useful info.
642#
643# The protolist is used for bfu archive creation, which may be invoked
644# interactively by the user.  Both protolist and PKGLISTS targets
645# depend on $(PROC_PKGS), but protolist builds them recursively.
646# To avoid collisions, we insert protolist into the dependency chain
647# here.  This has two somewhat subtle benefits: it allows bfu archive
648# creation to work correctly, even when -a was not part of NIGHTLY_OPTIONS,
649# and it ensures that a protolist file here will always correspond to the
650# contents of the processed manifests, which can vary depending on build
651# environment.
652#
653$(PKGLISTS): $(PROC_PKGS)
654	$(PKGDEBUG)sdotr=$(@F:packages.%=%); \
655	r=$${sdotr%.+(?)}; s=$${sdotr#+(?).}; \
656	print "Generating $$r $$s package list"; \
657	$(RM) $(@); $(TOUCH) $(@); \
658	$(NAWK) 'BEGIN { \
659		if (ARGC < 2) { \
660			exit; \
661		} \
662		retcode = 0; \
663		for (i = 1; i < ARGC; i++) { \
664			do { \
665				e = getline f < ARGV[i]; \
666			} while ((e == 1) && (f !~ /name=pkg.fmri/)); \
667			close(ARGV[i]); \
668			if (e == 1) { \
669				l = split(f, a, "="); \
670				print "depend fmri=" a[l], \
671					"type=$$(PKGDEP_TYPE)"; \
672			} else { \
673				print "no fmri in " ARGV[i] >> "/dev/stderr"; \
674				retcode = 2; \
675			} \
676		} \
677		exit retcode; \
678	}' `find $(PDIR) -type l -a \( $(PKGS:%=-name %.metadata.$$s.$$r -o) \
679		-name NOSUCHFILE \)` >> $(@)
680
681#
682# rules to validate proto area against manifests, check for safe
683# file permission modes, and generate a faux proto list
684#
685# For the check targets, the dependencies on $(PROC_PKGS) is specified
686# as a subordinate make process in order to suppress output.
687#
688makesilent:
689	@$(MAKE) -e $(PROC_PKGS) PKGMACH=$(PKGMACH) \
690		SUPPRESSPKGDEP=$(SUPPRESSPKGDEP) > /dev/null
691
692protocmp: makesilent
693	@validate_pkg -a $(PKGMACH) -v \
694		$(EXCEPTIONS:%=-e $(CODEMGR_WS)/exception_lists/%) \
695		-m $(PDIR) -p $(PKGROOT) -p $(TOOLSROOT)
696
697pmodes: makesilent
698	@validate_pkg -a $(PKGMACH) -M -m $(PDIR) \
699		-e $(CODEMGR_WS)/exception_lists/pmodes
700
701check: protocmp pmodes
702
703protolist: proto_list_$(PKGMACH)
704
705proto_list_$(PKGMACH): $(PROC_PKGS)
706	@validate_pkg -a $(PKGMACH) -L -m $(PDIR) > $(@)
707
708$(PROC_PKGS): $(PDIR)
709
710#
711# This is a convenience target to allow package names to function as
712# build targets.  Generally, using it is only useful when iterating on
713# development of a manifest.
714#
715# When processing a manifest, use the basename (without extension) of
716# the package.  When publishing, use the basename with a ".pub"
717# extension.
718#
719# Other than during manifest development, the preferred usage is to
720# avoid these targets and override PKGS on the make command line and
721# use the provided all and install targets.
722#
723$(PKGS) $(SYNTH_PKGS): $(PDIR)/$$(@:%=%.mog)
724
725$(PKGS:%=%.pub) $(SYNTH_PKGS:%=%.pub): $(PDIR)/$$(@)
726
727#
728# This is a convenience target to resolve dependencies without publishing
729# packages.
730#
731gendeps: $(PDIR)/gendeps
732
733#
734# These are convenience targets for cross-platform packaging.  If you
735# want to build any of "the normal" targets for a different
736# architecture, simply use "arch/target" as your build target.
737#
738# Since the most common use case for this is "install," the architecture
739# specific install targets have been further abbreviated to elide "/install."
740#
741i386/% sparc/%:
742	$(MAKE) -e $(@F) PKGMACH=$(@D) SUPPRESSPKGDEP=$(SUPPRESSPKGDEP)
743
744i386 sparc: $$(@)/install
745
746FRC:
747
748# EXPORT DELETE START
749XMOD_PKGS= \
750	BRCMbnx \
751	BRCMbnxe \
752	SUNWadpu320 \
753	SUNWcryptoint \
754	SUNWibsdpib \
755	SUNWkdc \
756	SUNWlsimega \
757	SUNWsvvs \
758	SUNWwbint \
759	SUNWwbsup
760
761EXPORT_SRC: CRYPT_SRC
762	$(RM) $(XMOD_PKGS:%=manifests/%.mf)
763	$(RM) Makefile+
764	$(SED) -e "/^# EXPORT DELETE START/,/^# EXPORT DELETE END/d" \
765		< Makefile > Makefile+
766	$(MV) -f Makefile+ Makefile
767	$(CHMOD) 444 Makefile
768
769CRYPT_SRC:
770	$(RM) manifests/SUNWcryptoint.mf+
771	$(SED) -e "/^# CRYPT DELETE START/,/^# CRYPT DELETE END/d" \
772		< manifests/SUNWcryptoint.mf > manifests/SUNWcryptoint.mf+
773	$(MV) manifests/SUNWcryptoint.mf+ manifests/SUNWcryptoint.mf
774	$(CHMOD) 444 manifests/SUNWcryptoint.mf
775
776# EXPORT DELETE END
777