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