1 #
   2 # Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 default: all
  27 
  28 include $(SPEC)
  29 include MakeBase.gmk
  30 
  31 PRODUCT_TARGETS :=
  32 LEGACY_TARGETS :=
  33 TEST_TARGETS :=
  34 DOCS_TARGETS :=
  35 
  36 # On Windows tar frequently complains that "file changed as we read it" for
  37 # some random source files. This seems to be cause by anti virus scanners and
  38 # is most likely safe to ignore. When it happens, tar returns '1'.
  39 ifeq ($(call isBuildOs, windows), true)
  40   TAR_IGNORE_EXIT_VALUE := || test "$$$$?" = "1"
  41 endif
  42 
  43 # Hook to include the corresponding custom file, if present.
  44 $(eval $(call IncludeCustomExtension, Bundles-pre.gmk))
  45 ################################################################################
  46 # BUNDLE : Name of bundle to create
  47 # FILES : Files in BASE_DIRS to add to bundle
  48 # SPECIAL_INCLUDES : List of directories inside BASE_DIRS to look for additional
  49 #     files in. These files will not get proper dependency handling. Use when
  50 #     files or directories may contain spaces.
  51 # BASE_DIRS : Base directories for the root dir in the bundle.
  52 # SUBDIR : Optional name of root dir in bundle.
  53 # OUTPUTDIR : Optionally override output dir
  54 SetupBundleFile = $(NamedParamsMacroTemplate)
  55 define SetupBundleFileBody
  56 
  57   $$(foreach d, $$($1_BASE_DIRS), \
  58     $$(eval $1_$$d_RELATIVE_FILES := $$$$(patsubst $$d/%, %, \
  59         $$$$(filter $$d/%, $$$$($1_FILES)))) \
  60     $$(eval $1_$$d_LIST_FILE := \
  61         $(SUPPORT_OUTPUTDIR)/bundles/_$1_$$$$(subst /,_,$$$$(patsubst $(OUTPUTDIR)/%,%,$$d)_files)) \
  62   )
  63 
  64   ifneq ($$(filter %.tar.gz, $$($1_BUNDLE_NAME)), )
  65     $1_TYPE := tar.gz
  66   else ifneq ($$(filter %.zip, $$($1_BUNDLE_NAME)), )
  67     $1_TYPE := zip
  68   else
  69     $$(error Unknown bundle type $$($1_BUNDLE_NAME))
  70   endif
  71 
  72   $$(call SetIfEmpty, $1_UNZIP_DEBUGINFO, false)
  73 
  74   $$(call SetIfEmpty, $1_OUTPUTDIR, $$(BUNDLES_OUTPUTDIR))
  75 
  76   $$($1_OUTPUTDIR)/$$($1_BUNDLE_NAME): $$($1_FILES)
  77         $$(call MakeTargetDir)
  78         $$(call LogWarn, Creating $$($1_BUNDLE_NAME))
  79         # If any of the files contain a space in the file name, FindFiles
  80         # will have replaced it with ?. Tar does not accept that so need to
  81         # switch it back.
  82         $$(foreach d, $$($1_BASE_DIRS), \
  83           $$(eval $$(call ListPathsSafely, \
  84               $1_$$d_RELATIVE_FILES, $$($1_$$d_LIST_FILE))) \
  85           $$(CAT) $$($1_$$d_LIST_FILE) | $$(TR) '?' ' ' > $$($1_$$d_LIST_FILE).tmp \
  86               && $(MV) $$($1_$$d_LIST_FILE).tmp $$($1_$$d_LIST_FILE) $$(NEWLINE) \
  87         )
  88         ifneq ($$($1_SPECIAL_INCLUDES), )
  89           $$(foreach i, $$($1_SPECIAL_INCLUDES), \
  90             $$(foreach d, $$($1_BASE_DIRS), \
  91               ($(CD) $$d && $(FIND) $$i >> $$($1_$$d_LIST_FILE)) ; ))
  92         endif
  93         ifeq ($$($1_SUBDIR)-$$($1_TYPE)-$$($1_UNZIP_DEBUGINFO), .-zip-false)
  94           # If no subdir is specified, zip can be done directly from BASE_DIRS.
  95           $$(foreach d, $$($1_BASE_DIRS), \
  96             ( $(CD) $$d \
  97             && $(ZIPEXE) -qru $$@ . -i@$$($1_$$d_LIST_FILE) \
  98             || test "$$$$?" = "12" )$$(NEWLINE))
  99         else ifeq ($$($1_SUBDIR)-$$($1_TYPE)-$$($1_UNZIP_DEBUGINFO)-$$(words $$($1_BASE_DIRS)), \
 100             .-tar.gz-false-1)
 101           # If no subdir is specified and only one BASE_DIR, tar.gz can be done
 102           # directly from BASE_DIR.
 103           $(CD) $$($1_BASE_DIRS) \
 104               && ( $(TAR) cf - $(TAR_CREATE_EXTRA_PARAM) \
 105                   -$(TAR_INCLUDE_PARAM) $$($1_$$($1_BASE_DIRS)_LIST_FILE) \
 106                   $(TAR_IGNORE_EXIT_VALUE) ) \
 107               | $(GZIP) > $$@
 108         else ifeq ($$($1_TYPE)-$(TAR_SUPPORTS_TRANSFORM)-$$($1_UNZIP_DEBUGINFO)-$$(words $$($1_BASE_DIRS)), \
 109             tar.gz-true-false-1)
 110           # If only one BASE_DIR, but with a SUBDIR set, tar.gz can use the
 111           # transform option to create bundle directly from the BASE_DIR.
 112           $(CD) $$($1_BASE_DIRS) \
 113               && ( $(TAR) cf - $(TAR_CREATE_EXTRA_PARAM) \
 114                   -$(TAR_INCLUDE_PARAM) $$($1_$$($1_BASE_DIRS)_LIST_FILE) \
 115                   $$(if $$($1_SUBDIR), --transform 's|^|$$($1_SUBDIR)/|S') \
 116                   $(TAR_IGNORE_EXIT_VALUE) ) \
 117               | $(GZIP) > $$@
 118         else
 119           # In all other cases, need to copy all files into a temporary location
 120           # before creation bundle.
 121           $(RM) -r $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR)
 122           $(MKDIR) -p $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR)
 123           $$(foreach d, $$($1_BASE_DIRS), \
 124             ( $(CD) $$d \
 125             && $(TAR) cf - -$(TAR_INCLUDE_PARAM) $$($1_$$d_LIST_FILE) \
 126                 $(TAR_IGNORE_EXIT_VALUE) ) \
 127             | ( $(CD) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) && $(TAR) xf - )$$(NEWLINE) )
 128           # Rename stripped pdb files
 129             for f in `$(FIND) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) -name "*.stripped.pdb"`; do \
 130               $(ECHO) found stripped pdb file $$$${f}, we rename it to: $$$${f%stripped.pdb}pdb; \
 131               $(MV) $$$${f} $$$${f%stripped.pdb}pdb; \
 132             done
 133           # Unzip any zipped debuginfo files
 134           ifeq ($$($1_UNZIP_DEBUGINFO), true)
 135             for f in `$(FIND) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) -name "*.diz"`; do \
 136               $(CD) $$$${f%/*} && $(UNZIP) -q $$$${f} && $(RM) $$$${f}; \
 137             done
 138           endif
 139           ifeq ($$($1_TYPE), tar.gz)
 140             $(CD) $(SUPPORT_OUTPUTDIR)/bundles/$1 && \
 141             ( $(TAR) cf - $(TAR_CREATE_EXTRA_PARAM) \
 142                 $$(if $$($1_SUBDIR), $$($1_SUBDIR), .) $(TAR_IGNORE_EXIT_VALUE) ) \
 143             | $(GZIP) > $$@
 144           else ifeq ($$($1_TYPE), zip)
 145             $(CD) $(SUPPORT_OUTPUTDIR)/bundles/$1 && $(ZIPEXE) -qr $$@ .
 146           endif
 147         endif
 148 
 149   $1 += $$($1_OUTPUTDIR)/$$($1_BUNDLE_NAME)
 150 
 151 endef
 152 
 153 ################################################################################
 154 
 155 # On Macosx, we bundle up the macosx specific images which already have the
 156 # correct base directories.
 157 ifeq ($(call isTargetOs, macosx)+$(DEBUG_LEVEL), true+release)
 158   JDK_IMAGE_DIR := $(JDK_MACOSX_BUNDLE_DIR)
 159   JRE_IMAGE_DIR := $(JRE_MACOSX_BUNDLE_DIR)
 160   JDK_IMAGE_HOMEDIR := $(JDK_MACOSX_CONTENTS_DIR)/Home
 161   JRE_IMAGE_HOMEDIR := $(JRE_MACOSX_CONTENTS_DIR)/Home
 162   JDK_BUNDLE_SUBDIR :=
 163   JRE_BUNDLE_SUBDIR :=
 164   # In certain situations, the JDK_IMAGE_DIR points to an image without the
 165   # the symbols and demos. If so, the symobls and demos can be found in a
 166   # separate image. These variables allow for overriding from a custom makefile.
 167   JDK_SYMBOLS_IMAGE_DIR ?= $(JDK_IMAGE_DIR)
 168   JDK_DEMOS_IMAGE_DIR ?= $(JDK_IMAGE_DIR)
 169   JDK_DEMOS_IMAGE_HOMEDIR ?= $(JDK_DEMOS_IMAGE_DIR)/$(JDK_MACOSX_CONTENTS_SUBDIR)/Home
 170 else
 171   JDK_IMAGE_HOMEDIR := $(JDK_IMAGE_DIR)
 172   JRE_IMAGE_HOMEDIR := $(JRE_IMAGE_DIR)
 173   JDK_BUNDLE_SUBDIR := jdk-$(VERSION_NUMBER)
 174   JRE_BUNDLE_SUBDIR := jre-$(VERSION_NUMBER)
 175   ifneq ($(DEBUG_LEVEL), release)
 176     JDK_BUNDLE_SUBDIR := $(JDK_BUNDLE_SUBDIR)/$(DEBUG_LEVEL)
 177     JRE_BUNDLE_SUBDIR := $(JRE_BUNDLE_SUBDIR)/$(DEBUG_LEVEL)
 178   endif
 179   # In certain situations, the JDK_IMAGE_DIR points to an image without the
 180   # the symbols and demos. If so, the symobls and demos can be found in a
 181   # separate image. These variables allow for overriding from a custom makefile.
 182   JDK_SYMBOLS_IMAGE_DIR ?= $(JDK_IMAGE_DIR)
 183   JDK_DEMOS_IMAGE_DIR ?= $(JDK_IMAGE_DIR)
 184   JDK_DEMOS_IMAGE_HOMEDIR ?= $(JDK_DEMOS_IMAGE_DIR)
 185 endif
 186 
 187 ################################################################################
 188 
 189 ifneq ($(filter product-bundles% legacy-bundles, $(MAKECMDGOALS)), )
 190 
 191   SYMBOLS_EXCLUDE_PATTERN := %.debuginfo %.diz %.pdb %.map
 192 
 193   # There may be files with spaces in the names, so use ShellFindFiles
 194   # explicitly.
 195   ALL_JDK_FILES := $(call ShellFindFiles, $(JDK_IMAGE_DIR))
 196   ifneq ($(JDK_IMAGE_DIR), $(JDK_SYMBOLS_IMAGE_DIR))
 197     ALL_JDK_SYMBOLS_FILES := $(call ShellFindFiles, $(JDK_SYMBOLS_IMAGE_DIR))
 198   else
 199     ALL_JDK_SYMBOLS_FILES := $(ALL_JDK_FILES)
 200   endif
 201   ifneq ($(JDK_IMAGE_DIR), $(JDK_DEMOS_IMAGE_DIR))
 202     ALL_JDK_DEMOS_FILES := $(call ShellFindFiles, $(JDK_DEMOS_IMAGE_DIR))
 203   else
 204     ALL_JDK_DEMOS_FILES := $(ALL_JDK_FILES)
 205   endif
 206 
 207   # Create special filter rules when dealing with unzipped .dSYM directories on
 208   # macosx
 209   ifeq ($(call isTargetOs, macosx), true)
 210     ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 211       JDK_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
 212           $(call containing, .dSYM/, $(patsubst $(JDK_IMAGE_DIR)/%, %, \
 213           $(ALL_JDK_SYMBOLS_FILES))))
 214     endif
 215   endif
 216 
 217   JDK_BUNDLE_FILES := \
 218       $(filter-out \
 219           $(JDK_SYMBOLS_EXCLUDE_PATTERN) \
 220           $(JDK_EXTRA_EXCLUDES) \
 221           $(SYMBOLS_EXCLUDE_PATTERN) \
 222           $(JDK_IMAGE_HOMEDIR)/demo/% \
 223           , \
 224           $(ALL_JDK_FILES) \
 225       )
 226 
 227   # include stripped pdb files in jdk image bundle
 228   ifeq ($(call isTargetOs, windows), true)
 229   JDK_STRIPPED_PDB_FILES := \
 230       $(filter \
 231            %.stripped.pdb \
 232           , \
 233           $(ALL_JDK_FILES) \
 234       )
 235   endif
 236 
 237   # remove the stripped pdb files from symbols bundle, we include only the full pdbs
 238   JDK_SYMBOLS_BUNDLE_FILES := \
 239       $(filter \
 240           $(JDK_SYMBOLS_EXCLUDE_PATTERN) \
 241           $(SYMBOLS_EXCLUDE_PATTERN) \
 242           , \
 243           $(filter-out \
 244               $(JDK_IMAGE_HOMEDIR)/demo/%  %.stripped.pdb \
 245               , \
 246               $(ALL_JDK_SYMBOLS_FILES) \
 247           ) \
 248       ) \
 249       $(call FindFiles, $(SYMBOLS_IMAGE_DIR))
 250 
 251   TEST_DEMOS_BUNDLE_FILES := $(filter $(JDK_DEMOS_IMAGE_HOMEDIR)/demo/%, \
 252       $(ALL_JDK_DEMOS_FILES))
 253 
 254   ALL_JRE_FILES := $(call ShellFindFiles, $(JRE_IMAGE_DIR))
 255 
 256   # Create special filter rules when dealing with unzipped .dSYM directories on
 257   # macosx
 258   ifeq ($(OPENJDK_TARGET_OS), macosx)
 259     ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 260       JRE_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
 261           $(call containing, .dSYM/, $(patsubst $(JRE_IMAGE_DIR)/%, %, $(ALL_JRE_FILES))))
 262     endif
 263   endif
 264   
 265   # include stripped pdb files in jdk image bundle
 266   ifeq ($(call isTargetOs, windows), true)
 267   JRE_STRIPPED_PDB_FILES := \
 268       $(filter \
 269            %.stripped.pdb \
 270           , \
 271           $(ALL_JRE_FILES) \
 272       )
 273   endif
 274 
 275   JRE_BUNDLE_FILES := $(filter-out \
 276       $(JRE_SYMBOLS_EXCLUDE_PATTERN) \
 277       $(SYMBOLS_EXCLUDE_PATTERN), \
 278       $(ALL_JRE_FILES))
 279 
 280   $(eval $(call SetupBundleFile, BUILD_JDK_BUNDLE, \
 281       BUNDLE_NAME := $(JDK_BUNDLE_NAME), \
 282       FILES := $(JDK_BUNDLE_FILES) $(JDK_STRIPPED_PDB_FILES), \
 283       SPECIAL_INCLUDES := $(JDK_SPECIAL_INCLUDES), \
 284       BASE_DIRS := $(JDK_IMAGE_DIR), \
 285       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 286   ))
 287 
 288   PRODUCT_TARGETS += $(BUILD_JDK_BUNDLE)
 289 
 290   $(eval $(call SetupBundleFile, BUILD_JRE_BUNDLE, \
 291       BUNDLE_NAME := $(JRE_BUNDLE_NAME) $(JRE_STRIPPED_PDB_FILES), \
 292       FILES := $(JRE_BUNDLE_FILES), \
 293       BASE_DIRS := $(JRE_IMAGE_DIR), \
 294       SUBDIR := $(JRE_BUNDLE_SUBDIR), \
 295   ))
 296 
 297   LEGACY_TARGETS += $(BUILD_JRE_BUNDLE)
 298 
 299   ifeq ($(COPY_DEBUG_SYMBOLS), true)
 300     $(eval $(call SetupBundleFile, BUILD_JDK_SYMBOLS_BUNDLE, \
 301         BUNDLE_NAME := $(JDK_SYMBOLS_BUNDLE_NAME), \
 302         FILES := $(JDK_SYMBOLS_BUNDLE_FILES), \
 303         BASE_DIRS := $(JDK_SYMBOLS_IMAGE_DIR) $(wildcard $(SYMBOLS_IMAGE_DIR)), \
 304         SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 305         UNZIP_DEBUGINFO := true, \
 306     ))
 307 
 308     PRODUCT_TARGETS += $(BUILD_JDK_SYMBOLS_BUNDLE)
 309   endif
 310 
 311   # The demo bundle is only created to support client tests. Ideally it should
 312   # be built with the main test bundle, but since the prerequisites match
 313   # better with the product build, it makes more sense to keep it there for now.
 314   $(eval $(call SetupBundleFile, BUILD_TEST_DEMOS_BUNDLE, \
 315       BUNDLE_NAME := $(TEST_DEMOS_BUNDLE_NAME), \
 316       FILES := $(TEST_DEMOS_BUNDLE_FILES), \
 317       BASE_DIRS := $(JDK_DEMOS_IMAGE_DIR), \
 318       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 319   ))
 320 
 321   PRODUCT_TARGETS += $(BUILD_TEST_DEMOS_BUNDLE)
 322 endif
 323 
 324 ################################################################################
 325 
 326 ifneq ($(filter test-bundles, $(MAKECMDGOALS)), )
 327   TEST_BUNDLE_FILES := $(call FindFiles, $(TEST_IMAGE_DIR))
 328 
 329   $(eval $(call SetupBundleFile, BUILD_TEST_BUNDLE, \
 330       BUNDLE_NAME := $(TEST_BUNDLE_NAME), \
 331       FILES := $(TEST_BUNDLE_FILES), \
 332       BASE_DIRS := $(TEST_IMAGE_DIR), \
 333   ))
 334 
 335   TEST_TARGETS += $(BUILD_TEST_BUNDLE)
 336 endif
 337 
 338 ################################################################################
 339 
 340 ifneq ($(filter docs-bundles, $(MAKECMDGOALS)), )
 341   DOCS_BUNDLE_FILES := $(call FindFiles, $(DOCS_IMAGE_DIR))
 342 
 343   $(eval $(call SetupBundleFile, BUILD_DOCS_BUNDLE, \
 344       BUNDLE_NAME := $(DOCS_BUNDLE_NAME), \
 345       FILES := $(DOCS_BUNDLE_FILES), \
 346       BASE_DIRS := $(DOCS_IMAGE_DIR), \
 347       SUBDIR := docs, \
 348   ))
 349 
 350   DOCS_TARGETS += $(BUILD_DOCS_BUNDLE)
 351 endif
 352 
 353 ################################################################################
 354 
 355 ifneq ($(filter jcov-bundles, $(MAKECMDGOALS)), )
 356   JCOV_BUNDLE_FILES := $(call FindFiles, $(JCOV_IMAGE_DIR))
 357 
 358   $(eval $(call SetupBundleFile, BUILD_JCOV_BUNDLE, \
 359       BUNDLE_NAME := $(JCOV_BUNDLE_NAME), \
 360       FILES := $(JCOV_BUNDLE_FILES), \
 361       BASE_DIRS := $(JCOV_IMAGE_DIR), \
 362       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 363   ))
 364 
 365   JCOV_TARGETS += $(BUILD_JCOV_BUNDLE)
 366 endif
 367 
 368 ################################################################################
 369 
 370 ifneq ($(filter static-libs-bundles, $(MAKECMDGOALS)), )
 371   STATIC_LIBS_BUNDLE_FILES := $(call FindFiles, $(STATIC_LIBS_IMAGE_DIR))
 372 
 373   ifeq ($(OPENJDK_TARGET_OS)-$(DEBUG_LEVEL), macosx-release)
 374     STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_MACOSX_CONTENTS_SUBDIR)/Home
 375   else
 376     STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_BUNDLE_SUBDIR)
 377   endif
 378 
 379   $(eval $(call SetupBundleFile, BUILD_STATIC_LIBS_BUNDLE, \
 380       BUNDLE_NAME := $(STATIC_LIBS_BUNDLE_NAME), \
 381       FILES := $(STATIC_LIBS_BUNDLE_FILES), \
 382       BASE_DIRS := $(STATIC_LIBS_IMAGE_DIR), \
 383       SUBDIR := $(STATIC_LIBS_BUNDLE_SUBDIR), \
 384   ))
 385 
 386   STATIC_LIBS_TARGETS += $(BUILD_STATIC_LIBS_BUNDLE)
 387 endif
 388 
 389 ################################################################################
 390 
 391 # Hook to include the corresponding custom file, if present.
 392 $(eval $(call IncludeCustomExtension, Bundles.gmk))
 393 
 394 ################################################################################
 395 
 396 product-bundles: $(PRODUCT_TARGETS)
 397 legacy-bundles: $(LEGACY_TARGETS)
 398 test-bundles: $(TEST_TARGETS)
 399 docs-bundles: $(DOCS_TARGETS)
 400 static-libs-bundles: $(STATIC_LIBS_TARGETS)
 401 jcov-bundles: $(JCOV_TARGETS)
 402 
 403 .PHONY: all default product-bundles test-bundles docs-bundles \
 404     static-libs-bundles jcov-bundles