1 #
  2 # Copyright (c) 2014, 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 include Execute.gmk
 31 include Modules.gmk
 32 
 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) jdk.jdwp.agent)
 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 $(JDK_IMAGE_DIR)/README: $(TOPDIR)/src/README
 58 	$(install-file)
 59 
 60 JDK_TARGETS += $(JDK_IMAGE_DIR)/README
 61 
 62 JMODS := $(wildcard $(IMAGES_OUTPUTDIR)/jmods/*.jmod)
 63 
 64 JLINK_ORDER_RESOURCES := **module-info.class
 65 JLINK_JLI_CLASSES :=
 66 ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
 67   JLINK_ORDER_RESOURCES += @$(SUPPORT_OUTPUTDIR)/link_opt/classlist
 68   JLINK_JLI_CLASSES := --generate-jli-classes=@$(SUPPORT_OUTPUTDIR)/link_opt/default_jli_trace.txt
 69 endif
 70 JLINK_ORDER_RESOURCES += \
 71     /java.base/java/** \
 72     /java.base/jdk/** \
 73     /java.base/sun/** \
 74     /java.base/com/** \
 75     /jdk.localedata/** \
 76     #
 77 
 78 JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \
 79     --module-path $(IMAGES_OUTPUTDIR)/jmods \
 80     --endian $(OPENJDK_TARGET_CPU_ENDIAN) \
 81     --release-info $(BASE_RELEASE_FILE) \
 82     --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
 83     --dedup-legal-notices=error-if-not-same-content \
 84     $(JLINK_JLI_CLASSES) \
 85     #
 86 
 87 JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
 88 
 89 ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
 90   JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
 91 endif
 92 
 93 JLINK_DISABLE_WARNINGS := | ( $(GREP) -v -e "WARNING: Using incubator module" || test "$$?" = "1" )
 94 
 95 $(eval $(call SetupExecute, jlink_jdk, \
 96     WARN := Creating jdk image, \
 97     DEPS := $(JMODS) $(BASE_RELEASE_FILE) \
 98         $(call DependOnVariable, JDK_MODULES_LIST), \
 99     OUTPUT_DIR := $(JDK_IMAGE_DIR), \
100     SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk, \
101     PRE_COMMAND := $(RM) -r $(JDK_IMAGE_DIR), \
102     COMMAND := $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \
103         $(JLINK_JDK_EXTRA_OPTS) --output $(JDK_IMAGE_DIR) \
104         $(JLINK_DISABLE_WARNINGS), \
105 ))
106 
107 JLINK_JDK_TARGETS := $(jlink_jdk)
108 
109 $(eval $(call SetupExecute, jlink_jre, \
110     WARN := Creating legacy jre image, \
111     DEPS := $(JMODS) $(BASE_RELEASE_FILE) \
112         $(call DependOnVariable, JDK_MODULES_LIST), \
113     OUTPUT_DIR := $(JRE_IMAGE_DIR), \
114     SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre, \
115     PRE_COMMAND := $(RM) -r $(JRE_IMAGE_DIR), \
116     COMMAND := $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \
117         $(JLINK_JRE_EXTRA_OPTS) --output $(JRE_IMAGE_DIR), \
118 ))
119 
120 JLINK_JRE_TARGETS := $(jlink_jre)
121 
122 ifeq ($(BUILD_CDS_ARCHIVE), true)
123   ifeq ($(OPENJDK_TARGET_OS), windows)
124     CDS_ARCHIVE := bin/server/classes.jsa
125     CDS_NOCOOPS_ARCHIVE := bin/server/classes_nocoops.jsa
126   else
127     CDS_ARCHIVE := lib/server/classes.jsa
128     CDS_NOCOOPS_ARCHIVE := lib/server/classes_nocoops.jsa
129   endif
130 
131   $(eval $(call SetupExecute, gen_cds_archive_jdk, \
132       WARN := Creating CDS archive for jdk image, \
133       DEPS := $(jlink_jdk), \
134       OUTPUT_FILE := $(JDK_IMAGE_DIR)/$(CDS_ARCHIVE), \
135       SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk, \
136       COMMAND := $(FIXPATH) $(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
137           -XX:SharedArchiveFile=$(JDK_IMAGE_DIR)/$(CDS_ARCHIVE) \
138           -Xmx128M -Xms128M $(LOG_INFO), \
139   ))
140 
141   JDK_TARGETS += $(gen_cds_archive_jdk)
142 
143   $(eval $(call SetupExecute, gen_cds_archive_jre, \
144       WARN := Creating CDS archive for jre image, \
145       DEPS := $(jlink_jre), \
146       OUTPUT_FILE := $(JRE_IMAGE_DIR)/$(CDS_ARCHIVE), \
147       SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre, \
148       COMMAND := $(FIXPATH) $(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
149           -XX:SharedArchiveFile=$(JRE_IMAGE_DIR)/$(CDS_ARCHIVE) \
150           -Xmx128M -Xms128M $(LOG_INFO), \
151   ))
152 
153   JRE_TARGETS += $(gen_cds_archive_jre)
154 
155   ifeq ($(call isTargetCpuBits, 64), true)
156     $(eval $(call SetupExecute, gen_cds_nocoops_archive_jdk, \
157         WARN := Creating CDS-NOCOOPS archive for jdk image, \
158         DEPS := $(jlink_jdk), \
159         OUTPUT_FILE := $(JDK_IMAGE_DIR)/$(CDS_NOCOOPS_ARCHIVE), \
160         SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk, \
161         COMMAND := $(FIXPATH) $(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
162             -XX:SharedArchiveFile=$(JDK_IMAGE_DIR)/$(CDS_NOCOOPS_ARCHIVE) \
163             -XX:-UseCompressedOops \
164             -Xmx128M -Xms128M $(LOG_INFO), \
165     ))
166 
167     JDK_TARGETS += $(gen_cds_nocoops_archive_jdk)
168 
169     $(eval $(call SetupExecute, gen_cds_nocoops_archive_jre, \
170         WARN := Creating CDS-NOCOOPS archive for jre image, \
171         DEPS := $(jlink_jre), \
172         OUTPUT_FILE := $(JRE_IMAGE_DIR)/$(CDS_NOCOOPS_ARCHIVE), \
173         SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre, \
174         COMMAND := $(FIXPATH) $(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
175             -XX:SharedArchiveFile=$(JRE_IMAGE_DIR)/$(CDS_NOCOOPS_ARCHIVE) \
176             -XX:-UseCompressedOops \
177             -Xmx128M -Xms128M $(LOG_INFO), \
178     ))
179 
180     JRE_TARGETS += $(gen_cds_nocoops_archive_jre)
181   endif
182 
183 endif
184 
185 ################################################################################
186 # src.zip
187 
188 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
189 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
190 	$(install-file)
191 
192 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
193 
194 ################################################################################
195 # /demo dir
196 # Avoid doing the expensive find unless called with "jdk" as target.
197 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
198 
199   DEMO_FILES := \
200       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
201         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
202             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
203       )
204 
205   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
206     ifeq ($(call isTargetOs, macosx), true)
207       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
208     else
209       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
210     endif
211   endif
212 
213   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
214       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
215       DEST := $(JDK_IMAGE_DIR)/demo, \
216       FILES := $(DEMO_FILES), \
217   ))
218 
219   JDK_TARGETS += $(JDK_COPY_DEMOS)
220 endif
221 
222 ################################################################################
223 # Code coverage data files
224 
225 ifeq ($(GCOV_ENABLED), true)
226 
227   $(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \
228       SRC := $(OUTPUTDIR), \
229       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
230       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
231           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
232   ))
233 
234   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
235 
236 endif
237 
238 ################################################################################
239 # Debug symbols
240 # Since debug symbols are not included in the jmod files, they need to be copied
241 # in manually after generating the images.
242 
243 ALL_JDK_MODULES := $(JDK_MODULES)
244 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
245     $(call FindTransitiveDepsForModule, $m)))
246 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
247 
248 ifeq ($(call isTargetOs, windows), true)
249   LIBS_TARGET_SUBDIR := bin
250 else
251   LIBS_TARGET_SUBDIR := lib
252 endif
253 CMDS_TARGET_SUBDIR := bin
254 
255 # Param 1 - dir to find debuginfo files in
256 FindDebuginfoFiles = \
257     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
258         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
259         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
260 
261 # Pick the correct debug info files to copy, either zipped or not.
262 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
263   DEBUGINFO_SUFFIXES += .diz
264 else
265   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
266   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
267   # dirs.
268   ifeq ($(call isTargetOs, macosx), true)
269     $(call FillFindCache, \
270         $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
271     FindDebuginfoFiles = \
272         $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
273   endif
274 endif
275 
276 FILTERED_PDBS := %jimage.stripped.pdb %jpackage.stripped.pdb %java.stripped.pdb \
277     %jimage.pdb %jpackage.pdb %java.pdb %jimage.map %jpackage.map %java.map
278 
279 # Param 1 - either JDK or JRE
280 SetupCopyDebuginfo = \
281     $(foreach m, $(ALL_$1_MODULES), \
282       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
283           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
284           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
285           FILES := $(call FindDebuginfoFiles, \
286               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
287       )) \
288       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
289       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
290           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
291           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
292           FILES := $(filter-out $(FILTERED_PDBS), $(call FindDebuginfoFiles, \
293               $(SUPPORT_OUTPUTDIR)/modules_cmds/$m)), \
294       )) \
295       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
296     )
297 
298 # No space before argument to avoid having to put $(strip ) everywhere in
299 # implementation above.
300 $(call SetupCopyDebuginfo,JDK)
301 $(call SetupCopyDebuginfo,JRE)
302 $(call SetupCopyDebuginfo,SYMBOLS)
303 
304 ################################################################################
305 
306 # Include custom post hook here to make it possible to augment the target lists
307 # before actual target prerequisites are declared.
308 $(eval $(call IncludeCustomExtension, Images-post.gmk))
309 
310 ################################################################################
311 
312 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
313 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
314 
315 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
316 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
317 symbols: $(SYMBOLS_TARGETS)
318 
319 all: jdk jre symbols
320 
321 .PHONY: default all jdk jre symbols