1 #
   2 # Copyright (c) 2014, 2018, 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 include Modules.gmk
  31 
  32 TOOL_TARGETS :=
  33 JDK_TARGETS :=
  34 JRE_TARGETS :=
  35 
  36 # Hook to include the corresponding custom file, if present.
  37 $(eval $(call IncludeCustomExtension, Images-pre.gmk))
  38 
  39 ############################################################################
  40 
  41 # All modules for the current target platform.
  42 ALL_MODULES := $(call FindAllModules)
  43 
  44 $(eval $(call ReadImportMetaData))
  45 
  46 JRE_MODULES += $(filter $(ALL_MODULES), $(BOOT_MODULES) \
  47     $(PLATFORM_MODULES) $(JRE_TOOL_MODULES))
  48 JDK_MODULES += $(ALL_MODULES)
  49 
  50 JRE_MODULES_LIST := $(call CommaList, $(JRE_MODULES))
  51 JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES))
  52 
  53 ################################################################################
  54 
  55 BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release
  56 
  57 JMODS := $(wildcard $(IMAGES_OUTPUTDIR)/jmods/*.jmod)
  58 
  59 # Use this file inside the image as target for make rule
  60 JIMAGE_TARGET_FILE := bin/java$(EXE_SUFFIX)
  61 
  62 JLINK_ORDER_RESOURCES := **module-info.class
  63 JLINK_JLI_CLASSES :=
  64 ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
  65   JLINK_ORDER_RESOURCES += @$(SUPPORT_OUTPUTDIR)/link_opt/classlist
  66   JLINK_JLI_CLASSES := --generate-jli-classes=@$(SUPPORT_OUTPUTDIR)/link_opt/default_jli_trace.txt
  67 endif
  68 JLINK_ORDER_RESOURCES += \
  69     /java.base/java/** \
  70     /java.base/jdk/** \
  71     /java.base/sun/** \
  72     /java.base/com/** \
  73     /jdk.localedata/** \
  74     #
  75 
  76 JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \
  77     --module-path $(IMAGES_OUTPUTDIR)/jmods \
  78     --endian $(OPENJDK_TARGET_CPU_ENDIAN) \
  79     --release-info $(BASE_RELEASE_FILE) \
  80     --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
  81     --dedup-legal-notices=error-if-not-same-content \
  82     $(JLINK_JLI_CLASSES) \
  83     #
  84 
  85 JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
  86 
  87 ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
  88   JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
  89 endif
  90 
  91 $(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \
  92     $(call DependOnVariable, JDK_MODULES_LIST) $(BASE_RELEASE_FILE)
  93         $(call LogWarn, Creating jdk image)
  94         $(RM) -r $(JDK_IMAGE_DIR)
  95         $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jdk, \
  96             $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \
  97                 $(JLINK_JDK_EXTRA_OPTS) \
  98                 --output $(JDK_IMAGE_DIR) \
  99         )
 100         ifeq ($(BUILD_CDS_ARCHIVE), true)
 101           $(call LogWarn, Creating CDS archive for jdk image)
 102           $(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO)
 103         endif
 104         $(TOUCH) $@
 105 
 106 $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \
 107     $(call DependOnVariable, JRE_MODULES_LIST) $(BASE_RELEASE_FILE)
 108         $(call LogWarn, Creating legacy jre image)
 109         $(RM) -r $(JRE_IMAGE_DIR)
 110         $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jre, \
 111             $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \
 112                 $(JLINK_JRE_EXTRA_OPTS) \
 113                 --output $(JRE_IMAGE_DIR) \
 114         )
 115         ifeq ($(BUILD_CDS_ARCHIVE), true)
 116           $(call LogWarn, Creating CDS archive for jre image)
 117           $(JRE_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO)
 118         endif
 119         $(TOUCH) $@
 120 
 121 TOOL_JRE_TARGETS := $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE)
 122 TOOL_JDK_TARGETS := $(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE)
 123 
 124 ################################################################################
 125 # src.zip
 126 
 127 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
 128         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 129         $(install-file)
 130 
 131 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
 132 
 133 ################################################################################
 134 # /demo dir
 135 # Avoid doing the expensive find unless called with "jdk" as target.
 136 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
 137 
 138   DEMO_FILES := \
 139       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
 140         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
 141             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
 142       )
 143 
 144   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 145     ifeq ($(OPENJDK_TARGET_OS), macosx)
 146       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
 147     else
 148       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
 149     endif
 150   endif
 151 
 152   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
 153       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
 154       DEST := $(JDK_IMAGE_DIR)/demo, \
 155       FILES := $(DEMO_FILES), \
 156   ))
 157 
 158   JDK_TARGETS += $(JDK_COPY_DEMOS)
 159 endif
 160 
 161 ################################################################################
 162 # Code coverage data files
 163 
 164 ifeq ($(GCOV_ENABLED), true)
 165 
 166   GCOV_FIND_EXPR := -type f -name "*.gcno"
 167 
 168   $(eval $(call SetupCopyFiles,COPY_HOTSPOT_GCOV_GCNO, \
 169       SRC := $(OUTPUTDIR), \
 170       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
 171       FILES := $(shell $(FIND) $(HOTSPOT_OUTPUTDIR) $(GCOV_FIND_EXPR))))
 172 
 173   SYMBOLS_TARGETS += $(COPY_HOTSPOT_GCOV_GCNO)
 174 
 175   $(eval $(call SetupCopyFiles,COPY_JDK_GCOV_GCNO, \
 176       SRC := $(OUTPUTDIR), \
 177       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
 178       FILES := $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/native $(GCOV_FIND_EXPR))))
 179 
 180   SYMBOLS_TARGETS += $(COPY_JDK_GCOV_GCNO)
 181 
 182 endif
 183 
 184 ################################################################################
 185 # Debug symbols
 186 # Since debug symbols are not included in the jmod files, they need to be copied
 187 # in manually after generating the images.
 188 
 189 ALL_JDK_MODULES := $(JDK_MODULES)
 190 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
 191     $(call FindTransitiveDepsForModule, $m)))
 192 
 193 ifeq ($(OPENJDK_TARGET_OS), windows)
 194   LIBS_TARGET_SUBDIR := bin
 195 else
 196   LIBS_TARGET_SUBDIR := lib
 197 endif
 198 
 199 # Param 1 - dir to find debuginfo files in
 200 FindDebuginfoFiles = \
 201     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
 202         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
 203         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
 204 
 205 # Pick the correct debug info files to copy, either zipped or not.
 206 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 207   DEBUGINFO_SUFFIXES += .diz
 208 else
 209   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
 210   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
 211   # dirs.
 212   ifeq ($(OPENJDK_TARGET_OS), macosx)
 213     $(eval $(call FillCacheFind, \
 214         $(SUPPORT_OUTPUTDIR)/modules_cmds $(SUPPORT_OUTPUTDIR)/modules_libs))
 215     FindDebuginfoFiles = \
 216         $(if $(wildcard $1), $(call containing, .dSYM/, $(call CacheFind, $1)))
 217   endif
 218 endif
 219 
 220 # Param 1 - either JDK or JRE
 221 SetupCopyDebuginfo = \
 222     $(foreach m, $(ALL_$1_MODULES), \
 223       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
 224           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
 225           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
 226           FILES := $(call FindDebuginfoFiles, \
 227               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
 228       )) \
 229       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
 230     )
 231 
 232 # No space before argument to avoid having to put $(strip ) everywhere in
 233 # implementation above.
 234 $(call SetupCopyDebuginfo,JDK)
 235 $(call SetupCopyDebuginfo,JRE)
 236 
 237 ################################################################################
 238 
 239 # Include custom post hook here to make it possible to augment the target lists
 240 # before actual target prerequisites are declared.
 241 $(eval $(call IncludeCustomExtension, Images-post.gmk))
 242 
 243 ################################################################################
 244 
 245 $(JRE_TARGETS): $(TOOL_JRE_TARGETS)
 246 $(JDK_TARGETS): $(TOOL_JDK_TARGETS)
 247 
 248 jdk: $(TOOL_JDK_TARGETS) $(JDK_TARGETS)
 249 jre: $(TOOL_JRE_TARGETS) $(JRE_TARGETS)
 250 symbols: $(SYMBOLS_TARGETS)
 251 
 252 all: jdk jre symbols
 253 
 254 .PHONY: default all jdk jre symbols