2
# Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
36
$(error MODULE must be set when calling CreateJmods.gmk)
39
$(eval $(call IncludeCustomExtension, CreateJmods.gmk))
41
################################################################################
43
JMODS_DIR := $(IMAGES_OUTPUTDIR)/jmods
44
JMODS_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jmods
45
JMOD_FILE := $(MODULE).jmod
47
LIBS_DIR ?= $(firstword $(wildcard $(addsuffix /$(MODULE), \
48
$(SUPPORT_OUTPUTDIR)/modules_libs $(IMPORT_MODULES_LIBS))))
49
CMDS_DIR ?= $(firstword $(wildcard $(addsuffix /$(MODULE), \
50
$(SUPPORT_OUTPUTDIR)/modules_cmds $(IMPORT_MODULES_CMDS))))
51
CONF_DIR ?= $(firstword $(wildcard $(addsuffix /$(MODULE), \
52
$(SUPPORT_OUTPUTDIR)/modules_conf $(IMPORT_MODULES_CONF))))
53
CLASSES_DIR ?= $(wildcard $(JDK_OUTPUTDIR)/modules/$(MODULE))
54
INCLUDE_HEADERS_DIR ?= $(firstword $(wildcard $(addsuffix /$(MODULE), \
55
$(SUPPORT_OUTPUTDIR)/modules_include $(IMPORT_MODULES_INCLUDE_HEADERS))))
56
MAN_DIR ?= $(firstword $(wildcard $(addsuffix /$(MODULE), \
57
$(SUPPORT_OUTPUTDIR)/modules_man $(IMPORT_MODULES_MAN))))
59
$(call FillFindCache, \
60
$(LIBS_DIR) $(CMDS_DIR) $(CONF_DIR) $(CLASSES_DIR) \
64
DEPS += $(call FindFiles, $(LIBS_DIR))
65
ifeq ($(call isTargetOs, windows)+$(SHIP_DEBUG_SYMBOLS), true+public)
66
# For public debug symbols on Windows, we have to use stripped pdbs and rename them
67
rename_stripped = $(patsubst %.stripped.pdb,%.pdb,$1)
68
LIBS_DIR_FILTERED := $(subst modules_libs,modules_libs_filtered, $(LIBS_DIR))
69
FILES_LIBS := $(filter-out %.pdb, $(call FindFiles, $(LIBS_DIR))) \
70
$(filter %.stripped.pdb, $(call FindFiles, $(LIBS_DIR)))
71
$(eval $(call SetupCopyFiles, COPY_FILTERED_LIBS, \
73
DEST := $(LIBS_DIR_FILTERED), \
74
FILES := $(FILES_LIBS), \
75
NAME_MACRO := rename_stripped, \
77
DEPS += $(COPY_FILTERED_LIBS)
78
JMOD_FLAGS += --libs $(LIBS_DIR_FILTERED)
80
JMOD_FLAGS += --libs $(LIBS_DIR)
84
DEPS += $(call FindFiles, $(CMDS_DIR))
85
ifeq ($(call isTargetOs, windows)+$(SHIP_DEBUG_SYMBOLS), true+public)
86
# For public debug symbols on Windows, we have to use stripped pdbs and rename them
87
rename_stripped = $(patsubst %.stripped.pdb,%.pdb,$1)
88
CMDS_DIR_FILTERED := $(subst modules_cmds,modules_cmds_filtered, $(CMDS_DIR))
89
FILES_CMDS := $(filter-out %.pdb, $(call FindFiles, $(CMDS_DIR))) \
90
$(filter %.stripped.pdb, $(call FindFiles, $(CMDS_DIR)))
91
$(eval $(call SetupCopyFiles, COPY_FILTERED_CMDS, \
93
DEST := $(CMDS_DIR_FILTERED), \
94
FILES := $(FILES_CMDS), \
95
NAME_MACRO := rename_stripped, \
97
DEPS += $(COPY_FILTERED_CMDS)
98
JMOD_FLAGS += --cmds $(CMDS_DIR_FILTERED)
100
JMOD_FLAGS += --cmds $(CMDS_DIR)
104
JMOD_FLAGS += --config $(CONF_DIR)
105
DEPS += $(call FindFiles, $(CONF_DIR))
107
ifneq ($(CLASSES_DIR), )
108
JMOD_FLAGS += --class-path $(CLASSES_DIR)
109
DEPS += $(call FindFiles, $(CLASSES_DIR))
111
ifneq ($(INCLUDE_HEADERS_DIR), )
112
JMOD_FLAGS += --header-files $(INCLUDE_HEADERS_DIR)
113
DEPS += $(call FindFiles, $(INCLUDE_HEADERS_DIR))
116
JMOD_FLAGS += --man-pages $(MAN_DIR)
117
DEPS += $(call FindFiles, $(MAN_DIR))
120
# If a specific modules_legal dir exists for this module, only pick up files
121
# from there. These files were explicitly filtered or modified in <module>-copy
122
# targets. For the rest, just pick up everything from the source legal dirs.
124
$(wildcard $(SUPPORT_OUTPUTDIR)/modules_legal/common) \
125
$(if $(wildcard $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE)), \
126
$(wildcard $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE)), \
127
$(call FindModuleLegalSrcDirs, $(MODULE)) \
130
ifneq ($(strip $(LEGAL_NOTICES)), )
131
LEGAL_NOTICES_PATH := $(call PathList, $(LEGAL_NOTICES))
132
DEPS += $(call FindFiles, $(LEGAL_NOTICES))
134
JMOD_FLAGS += --legal-notices $(LEGAL_NOTICES_PATH)
137
ifeq ($(filter-out jdk.incubator.%, $(MODULE)), )
138
JMOD_FLAGS += --do-not-resolve-by-default
139
JMOD_FLAGS += --warn-if-resolved=incubating
142
# Add dependencies on other jmod files. Only java.base needs access to other
144
ifeq ($(MODULE), java.base)
145
# When creating a BUILDJDK, we don't need to add hashes to java.base
146
ifneq ($(CREATING_BUILDJDK), true)
147
# When creating interim versions of jmods, skip hashes
148
ifneq ($(INTERIM_JMOD), true)
149
ALL_UPGRADEABLE_MODULES := $(call FindAllUpgradeableModules)
150
DEPS += $(patsubst %, $(JMODS_DIR)/%.jmod, \
151
$(filter-out java.base $(ALL_UPGRADEABLE_MODULES), $(call FindAllModules)))
153
EXCLUDE_PATTERN := $(strip $(subst $(SPACE),$$|,$(strip $(ALL_UPGRADEABLE_MODULES))))
155
JMOD_FLAGS += --module-path $(JMODS_DIR) \
156
--hash-modules '^(?!$(EXCLUDE_PATTERN)$$)'
160
ifeq ($(call isTargetOs, windows), true)
161
# Only java.base needs to include the MSVC*_DLLs. Make sure no other module
162
# tries to include them (typically imported ones).
163
ifneq ($(MSVCR_DLL), )
164
ifneq ($(wildcard $(LIBS_DIR)/$(notdir $(MSVCR_DLL))), )
165
JMOD_FLAGS += --exclude '$(notdir $(MSVCR_DLL))'
168
ifneq ($(VCRUNTIME_1_DLL), )
169
ifneq ($(wildcard $(LIBS_DIR)/$(notdir $(VCRUNTIME_1_DLL))), )
170
JMOD_FLAGS += --exclude '$(notdir $(VCRUNTIME_1_DLL))'
173
ifneq ($(MSVCP_DLL), )
174
ifneq ($(wildcard $(LIBS_DIR)/$(notdir $(MSVCP_DLL))), )
175
JMOD_FLAGS += --exclude '$(notdir $(MSVCP_DLL))'
178
ifneq ($(UCRT_DLL_DIR), )
179
UCRT_DLL_FILES := $(notdir $(wildcard $(UCRT_DLL_DIR)/*.dll))
180
ifneq ($(wildcard $(LIBS_DIR)/$(firstword $(UCRT_DLL_FILES))), )
181
JMOD_FLAGS += $(patsubst %, --exclude '%', $(UCRT_DLL_FILES))
187
################################################################################
188
# Include module specific build settings
193
ifneq ($(JMOD_FLAGS_main_class), )
194
JMOD_FLAGS += $(JMOD_FLAGS_main_class)
197
# Changes to the jmod tool itself should also trigger a rebuild of all jmods.
198
# The variable JMOD_CMD could contain an environment variable assignment before
199
# the actual command. Filter that out using wildcard before adding to DEPS.
200
DEPS += $(wildcard $(JMOD_CMD))
201
ifeq ($(EXTERNAL_BUILDJDK), false)
202
DEPS += $(call FindFiles, $(JDK_OUTPUTDIR)/modules/jdk.jlink/jdk/tools/jmod)
205
# If creating interim versions of jmods, certain files need to be filtered out
206
# to avoid false incremental rebuilds.
207
ifeq ($(INTERIM_JMOD), true)
208
DEPS := $(filter-out $(SUPPORT_OUTPUTDIR)/modules_libs/java.base/classlist, $(DEPS))
209
INTERIM_MSG := interim$(SPACE)
212
ifeq ($(call isTargetOs, windows), true)
213
ifeq ($(SHIP_DEBUG_SYMBOLS), )
214
JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.pdb,*.map}'
216
JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.map}'
219
JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.debuginfo,*.dSYM/**,*.dSYM}'
222
# Unless we are creating a very large module, use the small tool JVM options
224
ifeq ($(findstring $(MODULE), java.base java.desktop jdk.localedata), )
225
JMOD_SMALL_FLAGS += $(JAVA_TOOL_FLAGS_SMALL)
228
ifeq ($(INTERIM_JMOD), true)
229
# Interim JMODs are not shipped anywhere, so there is no reason
230
# to compress them at all.
231
JMOD_FLAGS += --compress zip-0
233
JMOD_FLAGS += --compress $(JMOD_COMPRESS)
236
# Create jmods in the support dir and then move them into place to keep the
237
# module path in $(IMAGES_OUTPUTDIR)/jmods valid at all times.
238
$(eval $(call SetupExecute, create_$(JMOD_FILE), \
239
WARN := Creating $(INTERIM_MSG)$(JMOD_FILE), \
241
OUTPUT_FILE := $(JMODS_DIR)/$(JMOD_FILE), \
242
SUPPORT_DIR := $(JMODS_SUPPORT_DIR), \
243
PRE_COMMAND := $(RM) $(JMODS_DIR)/$(JMOD_FILE) $(JMODS_SUPPORT_DIR)/$(JMOD_FILE), \
244
COMMAND := $(JMOD) $(JMOD_SMALL_FLAGS) create --module-version $(VERSION_SHORT) \
245
--target-platform '$(OPENJDK_MODULE_TARGET_PLATFORM)' \
246
--module-path $(JMODS_DIR) $(JMOD_FLAGS) \
247
--date $(SOURCE_DATE_ISO_8601) \
248
$(JMODS_SUPPORT_DIR)/$(JMOD_FILE), \
249
POST_COMMAND := $(MV) $(JMODS_SUPPORT_DIR)/$(JMOD_FILE) $(JMODS_DIR)/$(JMOD_FILE), \
252
TARGETS += $(create_$(JMOD_FILE))
254
################################################################################
258
################################################################################