@@ -35,12 +35,6 @@ include NativeCompilation.gmk
3535# Hook to include the corresponding custom file, if present.
3636$(eval $(call IncludeCustomExtension, common/JdkNativeCompilation.gmk))
3737
38- FindSrcDirsForLib += \
39- $(call uniq, $(wildcard \
40- $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/lib$(strip $2) \
41- $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/lib$(strip $2) \
42- $(TOPDIR)/src/$(strip $1)/share/native/lib$(strip $2)))
43-
4438FindSrcDirsForComponent += \
4539 $(call uniq, $(wildcard \
4640 $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/$(strip $2) \
@@ -104,14 +98,17 @@ JDK_RCFLAGS=$(RCFLAGS) \
10498 -D"JDK_NAME=$(JDK_RC_NAME) $(VERSION_SHORT)" \
10599 -D"JDK_FVER=$(subst .,$(COMMA),$(VERSION_NUMBER_FOUR_POSITIONS))"
106100
107- # Setup make rules for creating a native shared library with suitable defaults
108- # for the OpenJDK project.
101+ # Setup make rules for creating a native binary with suitable defaults
102+ # for the OpenJDK project. This macro is mostly considered to be an internal
103+ # support version. Please use SetupJdkLibrary or SetupJdkExecutable instead.
109104#
110105# Parameter 1 is the name of the rule. This name is used as variable prefix,
111106# and the targets generated are listed in a variable by that name.
112107#
113108# Remaining parameters are named arguments. These are all passed on to
114- # SetupNativeCompilation, except for
109+ # SetupNativeCompilation. This macro also adds the following additional
110+ # arguments:
111+ #
115112# EXTRA_RCFLAGS -- additional RCFLAGS to append.
116113# EXTRA_HEADER_DIRS -- additional directories to look for headers in
117114# EXTRA_SRC -- additional directories to look for source in
@@ -122,19 +119,46 @@ JDK_RCFLAGS=$(RCFLAGS) \
122119# SRC -- this is passed on, but preprocessed to accept source dir designations
123120# RC_FILEDESC -- override the default FILEDESC for Windows version.rc
124121# such as "java.base:headers".
125- SetupJdkLibrary = $(NamedParamsMacroTemplate)
126- define SetupJdkLibraryBody
122+ # JDK_LIBS -- libraries generated by the JDK build system to link against
123+ # JDK_LIBS_<os> or JDK_LIBS_<osType> -- additional JDK_LIBS for the given OS
124+ # or OS type only
125+ # DEFAULT_CFLAGS -- if false, do not add default CFLAGS and CXXFLAGS
126+ # CFLAGS_FILTER_OUT -- flags to filter out from default CFLAGS
127+ # CXXFLAGS_FILTER_OUT -- flags to filter out from default CXXFLAGS
128+ # LDFLAGS_FILTER_OUT -- flags to filter out from default LDFLAGS
129+ # LD_SET_ORIGIN -- if false, do not add SET_*_ORIGIN flags to LDFLAGS
130+ # APPEND_LDFLAGS -- a quirk to have additional LDFLAGS that will be set after
131+ # the origin flags
132+ #
133+ SetupJdkNativeCompilation = $(NamedParamsMacroTemplate)
134+ define SetupJdkNativeCompilationBody
135+ ifeq ($$($1_TYPE), EXECUTABLE)
136+ $1_NATIVE_DIR_PREFIX :=
137+ $1_MODULES_PATH := modules_cmds
138+ $1_RC_EXT := exe
139+ $1_RC_FTYPE := 0x1L
140+ else
141+ $1_NATIVE_DIR_PREFIX := lib
142+ $1_MODULES_PATH := modules_libs
143+ $1_RC_EXT := dll
144+ $1_RC_FTYPE := 0x2L
145+ endif
146+
127147 ifeq ($$($1_OUTPUT_DIR), )
128148 ifneq ($$(MODULE), )
129- $1_OUTPUT_DIR := $$(call FindLibDirForModule, $$(MODULE))
149+ ifeq ($$($1_TYPE), STATIC_LIBRARY)
150+ $1_OUTPUT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)
151+ else
152+ $1_OUTPUT_DIR := $$(SUPPORT_OUTPUTDIR)/$$($1_MODULES_PATH)/$$(strip $$(MODULE))
153+ endif
130154 else
131155 $$(error Must specify OUTPUT_DIR in a MODULE free context)
132156 endif
133157 endif
134158
135159 ifeq ($$($1_OBJECT_DIR), )
136160 ifneq ($$(MODULE), )
137- $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/lib $$($1_NAME)
161+ $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/$$($1_NATIVE_DIR_PREFIX) $$($1_NAME)
138162 else
139163 $$(error Must specify OBJECT_DIR in a MODULE free context)
140164 endif
@@ -146,7 +170,7 @@ define SetupJdkLibraryBody
146170
147171 ifeq ($$($1_SRC), )
148172 ifneq ($$(MODULE), )
149- $1_SRC := $$(call FindSrcDirsForLib , $$(MODULE), $$($1_NAME))
173+ $1_SRC := $$(call FindSrcDirsForComponent , $$(MODULE), $$($1_NATIVE_DIR_PREFIX) $$($1_NAME))
150174 else
151175 $$(error Must specify SRC in a MODULE free context)
152176 endif
@@ -171,12 +195,11 @@ define SetupJdkLibraryBody
171195 ifeq ($$($1_RC_FILEDESC), )
172196 $1_RC_FILEDESC := $(JDK_RC_NAME) binary
173197 endif
174-
175198 $1_RCFLAGS := $(JDK_RCFLAGS) \
176- -D"JDK_FILEDESC=$$(strip $$($ 1_RC_FILEDESC) )" \
177- -D"JDK_FNAME=$$($1_NAME).dll " \
199+ -D"JDK_FILEDESC=$$($ 1_RC_FILEDESC)" \
200+ -D"JDK_FNAME=$$($1_NAME).$$($1_RC_EXT) " \
178201 -D"JDK_INTERNAL_NAME=$$($1_NAME)" \
179- -D"JDK_FTYPE=0x2L " \
202+ -D"JDK_FTYPE=$$($1_RC_FTYPE) " \
180203 -I$(TOPDIR)/src/java.base/windows/native/common \
181204 $$($1_EXTRA_RCFLAGS)
182205
@@ -199,11 +222,19 @@ define SetupJdkLibraryBody
199222 endif
200223
201224 ifneq ($$($1_DEFAULT_CFLAGS), false)
202- # Set the default flags first to be able to override
203- $1_CFLAGS := $$(filter-out $$($1_CFLAGS_FILTER_OUT), $$(CFLAGS_JDKLIB)) $$($1_CFLAGS)
225+ ifeq ($$($1_TYPE), EXECUTABLE)
226+ # Set the default flags first to be able to override
227+ $1_CFLAGS := $$(filter-out $$($1_CFLAGS_FILTER_OUT), $$(CFLAGS_JDKEXE)) $$($1_CFLAGS)
204228
205- # Set the default flags first to be able to override
206- $1_CXXFLAGS := $$(filter-out $$($1_CXXFLAGS_FILTER_OUT), $$(CXXFLAGS_JDKLIB)) $$($1_CXXFLAGS)
229+ # Set the default flags first to be able to override
230+ $1_CXXFLAGS := $$(filter-out $$($1_CXXFLAGS_FILTER_OUT), $$(CXXFLAGS_JDKEXE)) $$($1_CXXFLAGS)
231+ else
232+ # Set the default flags first to be able to override
233+ $1_CFLAGS := $$(filter-out $$($1_CFLAGS_FILTER_OUT), $$(CFLAGS_JDKLIB)) $$($1_CFLAGS)
234+
235+ # Set the default flags first to be able to override
236+ $1_CXXFLAGS := $$(filter-out $$($1_CXXFLAGS_FILTER_OUT), $$(CXXFLAGS_JDKLIB)) $$($1_CXXFLAGS)
237+ endif
207238 endif
208239
209240 ifneq ($$($1_CFLAGS), )
@@ -217,125 +248,67 @@ define SetupJdkLibraryBody
217248 endif
218249
219250 ifneq ($$($1_DEFAULT_LDFLAGS), false)
220- # Set the default flags first to be able to override
221- $1_LDFLAGS := $$(filter-out $$($1_LDFLAGS_FILTER_OUT), $$(LDFLAGS_JDKLIB)) $$($1_LDFLAGS)
251+ ifeq ($$($1_TYPE), EXECUTABLE)
252+ # Set the default flags first to be able to override
253+ $1_LDFLAGS := $$(filter-out $$($1_LDFLAGS_FILTER_OUT), $$(LDFLAGS_JDKEXE)) $$($1_LDFLAGS)
254+ else
255+ # Set the default flags first to be able to override
256+ $1_LDFLAGS := $$(filter-out $$($1_LDFLAGS_FILTER_OUT), $$(LDFLAGS_JDKLIB)) $$($1_LDFLAGS)
257+ endif
222258 endif
223259
224260 ifneq ($$($1_LD_SET_ORIGIN), false)
225- $1_LDFLAGS += $$(call SET_SHARED_LIBRARY_ORIGIN)
261+ ifeq ($$($1_TYPE), EXECUTABLE)
262+ $1_LDFLAGS += $$(call SET_EXECUTABLE_ORIGIN)
263+ else
264+ $1_LDFLAGS += $$(call SET_SHARED_LIBRARY_ORIGIN)
265+ endif
226266 endif
227267 # APPEND_LDFLAGS, if it exists, must be set after the origin flags
228268 # This is a workaround to keep existing behavior
229269 $1_LDFLAGS += $$($1_APPEND_LDFLAGS)
230270
231271 # Since we reuse the rule name ($1), all our arguments will pass through.
232272 # We lose in transparency, but gain in brevity in this call...
233- $$(eval $$(call SetupNativeCompilation, $1, ))
273+ $$(eval $$(call SetupNativeCompilation, $1))
234274endef
235275
236- # Setup make rules for creating a native executable with suitable defaults for
237- # the OpenJDK project.
276+ # Setup make rules for creating a native library with suitable defaults
277+ # for the OpenJDK project. The default is to create a shared library,
278+ # but by passing TYPE := STATIC_LIBARY, a static library can be created.
238279#
239280# Parameter 1 is the name of the rule. This name is used as variable prefix,
240281# and the targets generated are listed in a variable by that name.
241282#
242283# Remaining parameters are named arguments. These are all passed on to
243- # SetupNativeCompilation, except for
244- # EXTRA_RCFLAGS -- additional RCFLAGS to append.
245- SetupJdkExecutable = $(NamedParamsMacroTemplate)
246- define SetupJdkExecutableBody
247- $1_TYPE := EXECUTABLE
248-
249- ifeq ($$($1_OUTPUT_DIR), )
250- ifneq ($$(MODULE), )
251- $1_OUTPUT_DIR := $$(call FindExecutableDirForModule, $$(MODULE))
252- else
253- $$(error Must specify OUTPUT_DIR in a MODULE free context)
254- endif
255- endif
256-
257- ifeq ($$($1_OBJECT_DIR), )
258- ifneq ($$(MODULE), )
259- $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/$$($1_NAME)
260- else
261- $$(error Must specify OBJECT_DIR in a MODULE free context)
262- endif
263- endif
264-
265- ifeq ($$($1_LINK_TYPE), C++)
266- $1_LIBS += $(LIBCXX)
267- endif
268-
269- ifeq ($$($1_SRC), )
270- ifneq ($$(MODULE), )
271- $1_SRC := $$(call FindSrcDirsForComponent, $$(MODULE), $$($1_NAME))
272- else
273- $$(error Must specify SRC in a MODULE free context)
274- endif
275- else
276- $1_SRC := $$(foreach dir, $$($1_SRC), $$(call ProcessDir, $$(dir)))
277- endif
278- ifneq ($$($1_EXTRA_SRC), )
279- $1_SRC += $$(foreach dir, $$($1_EXTRA_SRC), $$(call ProcessDir, $$(dir)))
280- endif
281-
282- ifeq ($$($1_VERSIONINFO_RESOURCE), )
283- $1_VERSIONINFO_RESOURCE := $$(GLOBAL_VERSION_INFO_RESOURCE)
284- endif
285-
286- $1_RCFLAGS := $(JDK_RCFLAGS) \
287- -D"JDK_FILEDESC=$(JDK_RC_NAME) binary" \
288- -D"JDK_FNAME=$$($1_NAME).exe" \
289- -D"JDK_INTERNAL_NAME=$$($1_NAME)" \
290- -D"JDK_FTYPE=0x1L" \
291- -I$(TOPDIR)/src/java.base/windows/native/common \
292- $$($1_EXTRA_RCFLAGS)
293-
294- ifneq ($$($1_HEADERS_FROM_SRC), false)
295- $1_SRC_HEADER_FLAGS := $$(addprefix -I, $$(wildcard $$($1_SRC)))
296- endif
297-
298- $1_JDK_LIBS += $$($1_JDK_LIBS_$$(OPENJDK_TARGET_OS))
299- $1_JDK_LIBS += $$($1_JDK_LIBS_$$(OPENJDK_TARGET_OS_TYPE))
300- # Prepend JDK libs before external libs
301- $1_LIBS := $$($1_JDK_LIBS) $$($1_LIBS)
302-
303- ifneq ($$($1_EXTRA_HEADER_DIRS), )
304- $1_PROCESSED_EXTRA_HEADER_DIRS := $$(foreach dir, $$($1_EXTRA_HEADER_DIRS), \
305- $$(call ProcessDir, $$(dir)))
306- $1_EXTRA_HEADER_FLAGS := $$(addprefix -I, $$($1_PROCESSED_EXTRA_HEADER_DIRS))
307- endif
308-
309- ifneq ($$($1_DEFAULT_CFLAGS), false)
310- # Set the default flags first to be able to override
311- $1_CFLAGS := $$(filter-out $$($1_CFLAGS_FILTER_OUT), $$(CFLAGS_JDKEXE)) $$($1_CFLAGS)
312-
313- # Set the default flags first to be able to override
314- $1_CXXFLAGS := $$(filter-out $$($1_CXXFLAGS_FILTER_OUT), $$(CXXFLAGS_JDKEXE)) $$($1_CXXFLAGS)
315- endif
316-
317- ifneq ($$($1_CFLAGS), )
318- $1_CFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
319- endif
320- ifneq ($$($1_CXXFLAGS), )
321- $1_CXXFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
322- endif
323- ifeq ($$($1_CFLAGS)$$($1_CXXFLAGS), )
324- $1_CFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
284+ # SetupJdkNativeCompilation. Please see that macro for details.
285+ SetupJdkLibrary = $(NamedParamsMacroTemplate)
286+ define SetupJdkLibraryBody
287+ # If type is unspecified, default to LIBRARY
288+ ifeq ($$($1_TYPE), )
289+ $1_TYPE := LIBRARY
325290 endif
326291
327- ifneq ($$($1_DEFAULT_LDFLAGS ), false)
328- # Set the default flags first to be able to override
329- $1_LDFLAGS := $$(filter-out $$($1_LDFLAGS_FILTER_OUT) , $$(LDFLAGS_JDKEXE)) $$($1_LDFLAGS )
330- endif
292+ # Since we reuse the rule name ($1 ), all our arguments will pass through.
293+ # We lose in transparency, but gain in brevity in this call...
294+ $$(eval $$(call SetupJdkNativeCompilation , $1) )
295+ endef
331296
332- ifneq ($$($1_LD_SET_ORIGIN), false)
333- $1_LDFLAGS += $$(call SET_EXECUTABLE_ORIGIN)
334- endif
297+ # Setup make rules for creating a native executable with suitable defaults
298+ # for the OpenJDK project.
299+ #
300+ # Parameter 1 is the name of the rule. This name is used as variable prefix,
301+ # and the targets generated are listed in a variable by that name.
302+ #
303+ # Remaining parameters are named arguments. These are all passed on to
304+ # SetupJdkNativeCompilation. Please see that macro for details.
305+ SetupJdkExecutable = $(NamedParamsMacroTemplate)
306+ define SetupJdkExecutableBody
307+ $1_TYPE := EXECUTABLE
335308
336309 # Since we reuse the rule name ($1), all our arguments will pass through.
337310 # We lose in transparency, but gain in brevity in this call...
338- $$(eval $$(call SetupNativeCompilation , $1))
311+ $$(eval $$(call SetupJdkNativeCompilation , $1))
339312endef
340313
341314endif # _JDK_NATIVE_COMPILATION_GMK
0 commit comments