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