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