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