1 #
   2 # Copyright (c) 2016, 2019, 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 
 236   # remove the stripped pdb files from symbols bundle, we include only the full pdbs
 237   JDK_SYMBOLS_BUNDLE_FILES := \
 238       $(filter \
 239           $(JDK_SYMBOLS_EXCLUDE_PATTERN) \
 240           $(SYMBOLS_EXCLUDE_PATTERN) \
 241           , \
 242           $(filter-out \
 243               $(JDK_IMAGE_HOMEDIR)/demo/%  %.stripped.pdb \
 244               , \
 245               $(ALL_JDK_SYMBOLS_FILES) \
 246           ) \
 247       ) \
 248       $(call FindFiles, $(SYMBOLS_IMAGE_DIR))
 249 
 250   TEST_DEMOS_BUNDLE_FILES := $(filter $(JDK_DEMOS_IMAGE_HOMEDIR)/demo/%, \
 251       $(ALL_JDK_DEMOS_FILES))
 252 
 253   ALL_JRE_FILES := $(call ShellFindFiles, $(JRE_IMAGE_DIR))
 254 
 255   # Create special filter rules when dealing with unzipped .dSYM directories on
 256   # macosx
 257   ifeq ($(OPENJDK_TARGET_OS), macosx)
 258     ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 259       JRE_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
 260           $(call containing, .dSYM/, $(patsubst $(JRE_IMAGE_DIR)/%, %, $(ALL_JRE_FILES))))
 261     endif
 262   endif
 263   
 264   # include stripped pdb files in jdk image bundle
 265   ifeq ($(call isTargetOs, windows), true)
 266   JRE_STRIPPED_PDB_FILES := \
 267       $(filter \
 268            %.stripped.pdb \
 269           , \
 270           $(ALL_JRE_FILES) \
 271       )
 272   endif
 273 
 274   JRE_BUNDLE_FILES := $(filter-out \
 275       $(JRE_SYMBOLS_EXCLUDE_PATTERN) \
 276       $(SYMBOLS_EXCLUDE_PATTERN), \
 277       $(ALL_JRE_FILES))
 278 
 279   $(eval $(call SetupBundleFile, BUILD_JDK_BUNDLE, \
 280       BUNDLE_NAME := $(JDK_BUNDLE_NAME), \
 281       FILES := $(JDK_BUNDLE_FILES) $(JDK_STRIPPED_PDB_FILES), \
 282       SPECIAL_INCLUDES := $(JDK_SPECIAL_INCLUDES), \
 283       BASE_DIRS := $(JDK_IMAGE_DIR), \
 284       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 285   ))
 286 
 287   PRODUCT_TARGETS += $(BUILD_JDK_BUNDLE)
 288 
 289   $(eval $(call SetupBundleFile, BUILD_JRE_BUNDLE, \
 290       BUNDLE_NAME := $(JRE_BUNDLE_NAME) $(JRE_STRIPPED_PDB_FILES), \
 291       FILES := $(JRE_BUNDLE_FILES), \
 292       BASE_DIRS := $(JRE_IMAGE_DIR), \
 293       SUBDIR := $(JRE_BUNDLE_SUBDIR), \
 294   ))
 295 
 296   LEGACY_TARGETS += $(BUILD_JRE_BUNDLE)
 297 
 298   ifeq ($(COPY_DEBUG_SYMBOLS), true)
 299     $(eval $(call SetupBundleFile, BUILD_JDK_SYMBOLS_BUNDLE, \
 300         BUNDLE_NAME := $(JDK_SYMBOLS_BUNDLE_NAME), \
 301         FILES := $(JDK_SYMBOLS_BUNDLE_FILES), \
 302         BASE_DIRS := $(JDK_SYMBOLS_IMAGE_DIR) $(wildcard $(SYMBOLS_IMAGE_DIR)), \
 303         SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 304         UNZIP_DEBUGINFO := true, \
 305     ))
 306 
 307     PRODUCT_TARGETS += $(BUILD_JDK_SYMBOLS_BUNDLE)
 308   endif
 309 
 310   # The demo bundle is only created to support client tests. Ideally it should
 311   # be built with the main test bundle, but since the prerequisites match
 312   # better with the product build, it makes more sense to keep it there for now.
 313   $(eval $(call SetupBundleFile, BUILD_TEST_DEMOS_BUNDLE, \
 314       BUNDLE_NAME := $(TEST_DEMOS_BUNDLE_NAME), \
 315       FILES := $(TEST_DEMOS_BUNDLE_FILES), \
 316       BASE_DIRS := $(JDK_DEMOS_IMAGE_DIR), \
 317       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 318   ))
 319 
 320   PRODUCT_TARGETS += $(BUILD_TEST_DEMOS_BUNDLE)
 321 endif
 322 
 323 ################################################################################
 324 
 325 ifneq ($(filter test-bundles, $(MAKECMDGOALS)), )
 326   TEST_BUNDLE_FILES := $(call FindFiles, $(TEST_IMAGE_DIR))
 327 
 328   $(eval $(call SetupBundleFile, BUILD_TEST_BUNDLE, \
 329       BUNDLE_NAME := $(TEST_BUNDLE_NAME), \
 330       FILES := $(TEST_BUNDLE_FILES), \
 331       BASE_DIRS := $(TEST_IMAGE_DIR), \
 332   ))
 333 
 334   TEST_TARGETS += $(BUILD_TEST_BUNDLE)
 335 endif
 336 
 337 ################################################################################
 338 
 339 ifneq ($(filter docs-bundles, $(MAKECMDGOALS)), )
 340   DOCS_BUNDLE_FILES := $(call FindFiles, $(DOCS_IMAGE_DIR))
 341 
 342   $(eval $(call SetupBundleFile, BUILD_DOCS_BUNDLE, \
 343       BUNDLE_NAME := $(DOCS_BUNDLE_NAME), \
 344       FILES := $(DOCS_BUNDLE_FILES), \
 345       BASE_DIRS := $(DOCS_IMAGE_DIR), \
 346       SUBDIR := docs, \
 347   ))
 348 
 349   DOCS_TARGETS += $(BUILD_DOCS_BUNDLE)
 350 endif
 351 
 352 ################################################################################
 353 
 354 ifneq ($(filter jcov-bundles, $(MAKECMDGOALS)), )
 355   JCOV_BUNDLE_FILES := $(call FindFiles, $(JCOV_IMAGE_DIR))
 356 
 357   $(eval $(call SetupBundleFile, BUILD_JCOV_BUNDLE, \
 358       BUNDLE_NAME := $(JCOV_BUNDLE_NAME), \
 359       FILES := $(JCOV_BUNDLE_FILES), \
 360       BASE_DIRS := $(JCOV_IMAGE_DIR), \
 361       SUBDIR := $(JDK_BUNDLE_SUBDIR), \
 362   ))
 363 
 364   JCOV_TARGETS += $(BUILD_JCOV_BUNDLE)
 365 endif
 366 
 367 ################################################################################
 368 
 369 ifneq ($(filter static-libs-bundles, $(MAKECMDGOALS)), )
 370   STATIC_LIBS_BUNDLE_FILES := $(call FindFiles, $(STATIC_LIBS_IMAGE_DIR))
 371 
 372   ifeq ($(OPENJDK_TARGET_OS)-$(DEBUG_LEVEL), macosx-release)
 373     STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_MACOSX_CONTENTS_SUBDIR)/Home
 374   else
 375     STATIC_LIBS_BUNDLE_SUBDIR := $(JDK_BUNDLE_SUBDIR)
 376   endif
 377 
 378   $(eval $(call SetupBundleFile, BUILD_STATIC_LIBS_BUNDLE, \
 379       BUNDLE_NAME := $(STATIC_LIBS_BUNDLE_NAME), \
 380       FILES := $(STATIC_LIBS_BUNDLE_FILES), \
 381       BASE_DIRS := $(STATIC_LIBS_IMAGE_DIR), \
 382       SUBDIR := $(STATIC_LIBS_BUNDLE_SUBDIR), \
 383   ))
 384 
 385   STATIC_LIBS_TARGETS += $(BUILD_STATIC_LIBS_BUNDLE)
 386 endif
 387 
 388 ################################################################################
 389 
 390 # Hook to include the corresponding custom file, if present.
 391 $(eval $(call IncludeCustomExtension, Bundles.gmk))
 392 
 393 ################################################################################
 394 
 395 product-bundles: $(PRODUCT_TARGETS)
 396 legacy-bundles: $(LEGACY_TARGETS)
 397 test-bundles: $(TEST_TARGETS)
 398 docs-bundles: $(DOCS_TARGETS)
 399 static-libs-bundles: $(STATIC_LIBS_TARGETS)
 400 jcov-bundles: $(JCOV_TARGETS)
 401 
 402 .PHONY: all default product-bundles test-bundles docs-bundles \
 403     static-libs-bundles jcov-bundles