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 include Coverage.gmk
  32 
  33 TOOL_TARGETS :=
  34 JDK_TARGETS :=
  35 JRE_TARGETS :=
  36 
  37 # Hook to include the corresponding custom file, if present.
  38 $(eval $(call IncludeCustomExtension, Images-pre.gmk))
  39 
  40 ############################################################################
  41 
  42 # All modules for the current target platform.
  43 ALL_MODULES := $(call FindAllModules)
  44 
  45 $(eval $(call ReadImportMetaData))
  46 
  47 JRE_MODULES += $(filter $(ALL_MODULES), $(BOOT_MODULES) \
  48     $(PLATFORM_MODULES) $(JRE_TOOL_MODULES))
  49 JDK_MODULES += $(ALL_MODULES)
  50 
  51 JRE_MODULES_LIST := $(call CommaList, $(JRE_MODULES))
  52 JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES))
  53 
  54 ################################################################################
  55 
  56 BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release
  57 
  58 JMODS := $(wildcard $(IMAGES_OUTPUTDIR)/jmods/*.jmod)
  59 
  60 # Use this file inside the image as target for make rule
  61 JIMAGE_TARGET_FILE := bin/java$(EXE_SUFFIX)
  62 
  63 JLINK_ORDER_RESOURCES := **module-info.class
  64 JLINK_JLI_CLASSES :=
  65 ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
  66   JLINK_ORDER_RESOURCES += @$(SUPPORT_OUTPUTDIR)/link_opt/classlist
  67   JLINK_JLI_CLASSES := --generate-jli-classes=@$(SUPPORT_OUTPUTDIR)/link_opt/default_jli_trace.txt
  68 endif
  69 JLINK_ORDER_RESOURCES += \
  70     /java.base/java/** \
  71     /java.base/jdk/** \
  72     /java.base/sun/** \
  73     /java.base/com/** \
  74     /jdk.localedata/** \
  75     #
  76 
  77 JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \
  78     --module-path $(IMAGES_OUTPUTDIR)/jmods \
  79     --endian $(OPENJDK_TARGET_CPU_ENDIAN) \
  80     --release-info $(BASE_RELEASE_FILE) \
  81     --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
  82     --dedup-legal-notices=error-if-not-same-content \
  83     $(JLINK_JLI_CLASSES) \
  84     #
  85 
  86 JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
  87 
  88 ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
  89   JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
  90 endif
  91 
  92 $(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \
  93     $(call DependOnVariable, JDK_MODULES_LIST) $(BASE_RELEASE_FILE)
  94         $(call LogWarn, Creating jdk image)
  95         $(RM) -r $(JDK_IMAGE_DIR)
  96         $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jdk, \
  97             $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \
  98                 $(JLINK_JDK_EXTRA_OPTS) \
  99                 --output $(JDK_IMAGE_DIR) \
 100         )
 101         ifeq ($(BUILD_CDS_ARCHIVE), true)
 102           $(call LogWarn, Creating CDS archive for jdk image)
 103           $(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO)
 104         endif
 105         $(TOUCH) $@
 106 
 107 $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \
 108     $(call DependOnVariable, JRE_MODULES_LIST) $(BASE_RELEASE_FILE)
 109         $(call LogWarn, Creating legacy jre image)
 110         $(RM) -r $(JRE_IMAGE_DIR)
 111         $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jre, \
 112             $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \
 113                 $(JLINK_JRE_EXTRA_OPTS) \
 114                 --output $(JRE_IMAGE_DIR) \
 115         )
 116         ifeq ($(BUILD_CDS_ARCHIVE), true)
 117           $(call LogWarn, Creating CDS archive for jre image)
 118           $(JRE_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO)
 119         endif
 120         $(TOUCH) $@
 121 
 122 TOOL_JRE_TARGETS := $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE)
 123 TOOL_JDK_TARGETS := $(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE)
 124 
 125 ################################################################################
 126 # /man dir
 127 #
 128 # All variables in this section are assigned with simple =, without :, to enable
 129 # more selective overriding from the custom version of this file.
 130 #
 131 # Avoid evaluating this whole section on windows for speed and stability
 132 ifneq ($(OPENJDK_TARGET_OS), windows)
 133   ifeq ($(BUILD_MANPAGES), true)
 134     JRE_MAN_PAGES += \
 135         java.1 \
 136         jjs.1 \
 137         keytool.1 \
 138         orbd.1 \
 139         pack200.1 \
 140         rmid.1 \
 141         rmiregistry.1 \
 142         servertool.1 \
 143         unpack200.1
 144 
 145     JDK_MAN_PAGES += \
 146         $(JRE_MAN_PAGES) \
 147         idlj.1 \
 148         jar.1 \
 149         jarsigner.1 \
 150         javac.1 \
 151         javadoc.1 \
 152         javap.1 \
 153         jconsole.1 \
 154         jcmd.1 \
 155         jdb.1 \
 156         jdeps.1 \
 157         jinfo.1 \
 158         jmap.1 \
 159         jps.1 \
 160         jrunscript.1 \
 161         jstack.1 \
 162         jstat.1 \
 163         jstatd.1 \
 164         rmic.1 \
 165         serialver.1
 166 
 167     # This variable is potentially overridden in the closed makefile.
 168     MAN_SRC_BASEDIR ?= $(TOPDIR)/src
 169 
 170     ifeq ($(OPENJDK_TARGET_OS), linux)
 171       MAN_SRC_DIR = $(MAN_SRC_BASEDIR)/linux/doc
 172       MAN1_SUBDIR = man
 173     endif
 174     ifeq ($(OPENJDK_TARGET_OS), solaris)
 175       MAN_SRC_DIR = $(MAN_SRC_BASEDIR)/solaris/doc
 176       MAN1_SUBDIR = sun/man/man1
 177     endif
 178     ifeq ($(OPENJDK_TARGET_OS), macosx)
 179       MAN_SRC_DIR = $(MAN_SRC_BASEDIR)/bsd/doc
 180       MAN1_SUBDIR = man
 181     endif
 182 
 183     $(JRE_IMAGE_DIR)/man/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/%
 184         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 185         $(install-file)
 186 
 187     $(JDK_IMAGE_DIR)/man/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/%
 188         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 189         $(install-file)
 190 
 191     $(JRE_IMAGE_DIR)/man/ja_JP.UTF-8/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/ja/%
 192         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 193         $(install-file)
 194 
 195     $(JDK_IMAGE_DIR)/man/ja_JP.UTF-8/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/ja/%
 196         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 197         $(install-file)
 198 
 199     ifeq ($(OPENJDK_TARGET_OS), solaris)
 200       $(JRE_IMAGE_DIR)/man/ja/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/ja/%
 201         $(call LogInfo, Converting $(patsubst $(OUTPUTDIR)/%,%,$@))
 202         $(install-file)
 203 
 204       $(JDK_IMAGE_DIR)/man/ja/man1/%: $(MAN_SRC_DIR)/$(MAN1_SUBDIR)/ja/%
 205         $(call LogInfo, Converting $(patsubst $(OUTPUTDIR)/%,%,$@))
 206         $(install-file)
 207     endif
 208 
 209     ifneq ($(findstring $(OPENJDK_TARGET_OS), linux macosx), )
 210       $(JRE_IMAGE_DIR)/man/ja:
 211         $(call LogInfo, Creating $(patsubst $(OUTPUTDIR)/%,%,$@))
 212         $(CD) $(@D) && $(RM) ja && $(LN) -s ja_JP.UTF-8 ja
 213 
 214       $(JDK_IMAGE_DIR)/man/ja:
 215         $(call LogInfo, Creating $(patsubst $(OUTPUTDIR)/%,%,$@))
 216         $(CD) $(@D) && $(RM) ja && $(LN) -s ja_JP.UTF-8 ja
 217     endif
 218 
 219     ifeq ($(OPENJDK_TARGET_OS), solaris)
 220       JRE_MAN_PAGE_LIST = $(addprefix $(JRE_IMAGE_DIR)/man/man1/, $(JRE_MAN_PAGES)) \
 221           $(addprefix $(JRE_IMAGE_DIR)/man/ja/man1/, $(JRE_MAN_PAGES)) \
 222           $(addprefix $(JRE_IMAGE_DIR)/man/ja_JP.UTF-8/man1/, $(JRE_MAN_PAGES)) \
 223           $(addprefix $(JRE_IMAGE_DIR)/man/ja_JP.PCK/man1/, $(JRE_MAN_PAGES))
 224 
 225       JDK_MAN_PAGE_LIST = $(addprefix $(JDK_IMAGE_DIR)/man/man1/, $(JDK_MAN_PAGES)) \
 226           $(addprefix $(JDK_IMAGE_DIR)/man/ja/man1/, $(JDK_MAN_PAGES)) \
 227           $(addprefix $(JDK_IMAGE_DIR)/man/ja_JP.UTF-8/man1/, $(JDK_MAN_PAGES)) \
 228           $(addprefix $(JDK_IMAGE_DIR)/man/ja_JP.PCK/man1/, $(JDK_MAN_PAGES))
 229     endif
 230 
 231     ifneq ($(findstring $(OPENJDK_TARGET_OS), linux macosx), )
 232       JRE_MAN_PAGE_LIST = $(addprefix $(JRE_IMAGE_DIR)/man/man1/, $(JRE_MAN_PAGES)) \
 233           $(addprefix $(JRE_IMAGE_DIR)/man/ja_JP.UTF-8/man1/, $(JRE_MAN_PAGES)) \
 234           $(JRE_IMAGE_DIR)/man/ja
 235 
 236       JDK_MAN_PAGE_LIST = $(addprefix $(JDK_IMAGE_DIR)/man/man1/, $(JDK_MAN_PAGES)) \
 237           $(addprefix $(JDK_IMAGE_DIR)/man/ja_JP.UTF-8/man1/, $(JDK_MAN_PAGES)) \
 238           $(JDK_IMAGE_DIR)/man/ja
 239     endif
 240 
 241     JRE_TARGETS += $(JRE_MAN_PAGE_LIST)
 242     JDK_TARGETS += $(JDK_MAN_PAGE_LIST)
 243   endif # BUILD_MANPAGES
 244 endif # Windows
 245 
 246 ################################################################################
 247 # src.zip
 248 
 249 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
 250         $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
 251         $(install-file)
 252 
 253 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
 254 
 255 ################################################################################
 256 # /demo dir
 257 # Avoid doing the expensive find unless called with "jdk" as target.
 258 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
 259 
 260   DEMO_FILES := \
 261       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
 262         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
 263             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
 264       )
 265 
 266   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 267     ifeq ($(OPENJDK_TARGET_OS), macosx)
 268       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
 269     else
 270       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
 271     endif
 272   endif
 273 
 274   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
 275       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
 276       DEST := $(JDK_IMAGE_DIR)/demo, \
 277       FILES := $(DEMO_FILES), \
 278   ))
 279 
 280   JDK_TARGETS += $(JDK_COPY_DEMOS)
 281 endif
 282 
 283 ################################################################################
 284 # Code coverage data files
 285 
 286 ifeq ($(GCOV_ENABLED), true)
 287 
 288   GCOV_FIND_EXPR := -type f -name "*.gcno"
 289 
 290   $(eval $(call SetupCopyFiles,COPY_HOTSPOT_GCOV_GCNO, \
 291       SRC := $(OUTPUTDIR), \
 292       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
 293       FILES := $(shell $(FIND) $(HOTSPOT_OUTPUTDIR) $(GCOV_FIND_EXPR))))
 294 
 295   SYMBOLS_TARGETS += $(COPY_HOTSPOT_GCOV_GCNO)
 296 
 297   $(eval $(call SetupCopyFiles,COPY_JDK_GCOV_GCNO, \
 298       SRC := $(OUTPUTDIR), \
 299       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
 300       FILES := $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/native $(GCOV_FIND_EXPR))))
 301 
 302   SYMBOLS_TARGETS += $(COPY_JDK_GCOV_GCNO)
 303 
 304 endif
 305 
 306 JCOV_TARGETS =
 307 
 308 ifeq ($(JCOV_ENABLED), true)
 309   JCOV_TARGETS += $(JDK_IMAGE_DIR)/../template.xml
 310 endif
 311 
 312 ################################################################################
 313 # Debug symbols
 314 # Since debug symbols are not included in the jmod files, they need to be copied
 315 # in manually after generating the images.
 316 
 317 ALL_JDK_MODULES := $(JDK_MODULES)
 318 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
 319     $(call FindTransitiveDepsForModule, $m)))
 320 
 321 ifeq ($(OPENJDK_TARGET_OS), windows)
 322   LIBS_TARGET_SUBDIR := bin
 323 else
 324   LIBS_TARGET_SUBDIR := lib
 325 endif
 326 
 327 # Param 1 - dir to find debuginfo files in
 328 FindDebuginfoFiles = \
 329     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
 330         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
 331         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
 332 
 333 # Pick the correct debug info files to copy, either zipped or not.
 334 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
 335   DEBUGINFO_SUFFIXES += .diz
 336 else
 337   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
 338   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
 339   # dirs.
 340   ifeq ($(OPENJDK_TARGET_OS), macosx)
 341     $(eval $(call FillCacheFind, \
 342         $(SUPPORT_OUTPUTDIR)/modules_cmds $(SUPPORT_OUTPUTDIR)/modules_libs))
 343     FindDebuginfoFiles = \
 344         $(if $(wildcard $1), $(call containing, .dSYM/, $(call CacheFind, $1)))
 345   endif
 346 endif
 347 
 348 # Param 1 - either JDK or JRE
 349 SetupCopyDebuginfo = \
 350     $(foreach m, $(ALL_$1_MODULES), \
 351       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
 352           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
 353           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
 354           FILES := $(call FindDebuginfoFiles, \
 355               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
 356       )) \
 357       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
 358     )
 359 
 360 # No space before argument to avoid having to put $(strip ) everywhere in
 361 # implementation above.
 362 $(call SetupCopyDebuginfo,JDK)
 363 $(call SetupCopyDebuginfo,JRE)
 364 
 365 ################################################################################
 366 
 367 # Include custom post hook here to make it possible to augment the target lists
 368 # before actual target prerequisites are declared.
 369 $(eval $(call IncludeCustomExtension, Images-post.gmk))
 370 
 371 ################################################################################
 372 
 373 $(JRE_TARGETS): $(TOOL_JRE_TARGETS)
 374 $(JDK_TARGETS): $(TOOL_JDK_TARGETS)
 375 
 376 jdk: $(TOOL_JDK_TARGETS) $(JDK_TARGETS) $(JCOV_TARGETS)
 377 jre: $(TOOL_JRE_TARGETS) $(JRE_TARGETS)
 378 symbols: $(SYMBOLS_TARGETS)
 379 
 380 all: jdk jre symbols
 381 
 382 .PHONY: default all jdk jre symbols