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