2
# Copyright (c) 2016, 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
30
include TextFileProcessing.gmk
34
JVM_VARIANT := $(JVM_VARIANT_MAIN)
35
include hotspot/HotspotCommon.gmk
36
include hotspot/lib/JvmFeatures.gmk
37
include hotspot/lib/JvmOverrideFiles.gmk
38
include hotspot/lib/JvmFlags.gmk
40
# Random number generation, with the amount of specified digits
41
# No need to check if the parameter passed is a valid number, the shell will
42
# be more than happy to complain if it isn't ;)
44
$(shell od -An -N8 -d /dev/urandom | sed -e 's| ||g' -e 's|\(.\{$(strip $1)\}\).*|\1|')
46
# Modified version of utility from JdkNativeCompilation.gmk
47
# The full path could be omitted, but it was chosen not to so wildcard
48
# can work properly for existing directories. The pathsubst below that
49
# this necessitates is a relatively small price to pay.
50
FindModuleNativeDirs = \
51
$(call uniq, $(wildcard \
52
$(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native \
53
$(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native \
54
$(TOPDIR)/src/$(strip $1)/share/native))
56
# Taken from JdkNativeCompilation.gmk
58
$(if $(strip $1),$(wildcard $(SUPPORT_OUTPUTDIR)/headers/$(strip $1)))
60
JAVA_DIRS := $(strip $(foreach module, $(call FindAllModules), \
61
$(patsubst $(TOPDIR)/%,%,$(filter-out $(OUTPUTDIR)%, \
62
$(call FindModuleSrcDirs, $(module))))))
64
NATIVE_DIRS := $(strip $(foreach module, $(call FindAllModules), \
65
$(patsubst $(TOPDIR)/%,%,$(call FindModuleNativeDirs, $(module)))))
67
# Emit the defines extracted from the list of options specified in the first parameter into
68
# the language settings file, in Eclipse format.
69
EmitExtractedDefines = \
70
$(shell echo $(1) | grep -o "\-D\s\?")
72
################################################################################
73
# Create an Eclipse Workspace with the specified nature
75
# Parameter 1 is the name of the rule. This name is used as variable prefix,
76
# and the targets generated are listed in a variable by that name.
78
# Remaining parameter(s) are named arguments:
79
# NATURE - Which Eclipse Workspace nature to generate for the Workspace. Can
80
# be one of JAVA, HOTSPOT, NATIVE, or MIXED.
81
SetupEclipseWorkspace = $(NamedParamsMacroTemplate)
82
define SetupEclipseWorkspaceBody
86
$1_LINKED_RESOURCES :=
88
ifeq ($$($1_NATURE), )
89
$$(error No nature specified for Eclipse Workspace, cannot continue)
92
ifeq ($$(findstring $$($1_NATURE), JAVA HOTSPOT NATIVE MIXED), )
93
$$(error Unrecognised nature $$($1_NATURE) specified for Eclipse Workspace)
96
$1_IDE_OUTPUTDIR := $(OUTPUTDIR)/ide/eclipse
97
$1_CLASSPATH_FILE := $$($1_IDE_OUTPUTDIR)/.classpath
98
$1_WORKSPACE_FILE := $$($1_IDE_OUTPUTDIR)/.project
99
$1_NATIVE_FILE := $$($1_IDE_OUTPUTDIR)/.cproject
100
$1_SETTINGS_FILE := $$($1_IDE_OUTPUTDIR)/.settings/language.settings.xml
101
$$(call MakeDir, $$($1_IDE_OUTPUTDIR))
103
ifneq ($$(findstring $$($1_NATURE), HOTSPOT NATIVE MIXED), )
104
ifeq ($$(call isCompiler, microsoft), true)
105
$$(error Visual C++ is not yet supported as an indexer for Native Workspaces!)
109
ifneq ($$(findstring $$($1_NATURE), JAVA MIXED), )
113
# Eclipse crashes when processing multiple module-info.java files
114
# This is an annoying bug that has not been fixed for some time now
115
$1_CLASSPATH += $$(foreach src,$(JAVA_DIRS), \
116
<classpathentry excluding="module-info.java|module-info.java.extra" kind="src" path="$$(src)"/>$$(NEWLINE))
118
$$(eval $$(call SetupTextFileProcessing, $1_CREATE_CLASSPATH_FILE, \
119
SOURCE_FILES := $(TOPDIR)/make/ide/eclipse/classpath.template, \
120
OUTPUT_FILE := $$($1_CLASSPATH_FILE), \
122
@@CLASSPATH@@ => $$($1_CLASSPATH), \
125
TARGETS += $$($1_CREATE_CLASSPATH_FILE)
127
$1_NATURES += <nature>org.eclipse.jdt.core.javanature</nature>$$(NEWLINE)
131
ifneq ($$(findstring $$($1_NATURE), HOTSPOT NATIVE MIXED), )
135
$1_BUILD_MANAGERS += \
137
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> \
138
<triggers>clean$$(COMMA)full$$(COMMA)incremental$$(COMMA)</triggers> \
143
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> \
144
<triggers>full$$(COMMA)incremental$$(COMMA)</triggers> \
147
</buildCommand>$$(NEWLINE)
150
<nature>org.eclipse.cdt.core.cnature</nature> \
151
<nature>org.eclipse.cdt.core.ccnature</nature> \
152
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> \
153
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>$$(NEWLINE)
155
# This is always emitted, no matter which of the 3 natures were selected
157
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src/hotspot"/>$$(NEWLINE)
159
ifneq ($$(findstring $$($1_NATURE), NATIVE MIXED), )
160
$1_NATIVE_SRCS += $$(foreach src,$(NATIVE_DIRS), \
161
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="$$(strip $$(src))"/>$$(NEWLINE))
164
$1_WORKSPACE_MAJOR := $$(call RandomDigits, 10)
165
$1_WORKSPACE_MINOR := $$(call RandomDigits, 9)
167
# FixPath already removes $(FIXPATH) automatically, but if we rely on FixPath
168
# to do it for us dir won't be able to handle the converted path (if on Windows).
169
# Reversing the order causes dir to mangle the preceeding $(FIXPATH) which breaks
170
# the ability of FixPath to remove it, so it has to be manually removed here.
172
# Note that the workspace setup system currently does not support Visual C++ when
173
# extracting compiler and/or system headers vital to the build!
174
$1_ENV := $$(call FixPath, $$(dir $$(patsubst $(FIXPATH), , $(CC))))
176
# Sidestep annoying issue of WSL path conversion not working properly with true
177
# Unix paths. Eclipse can't run the WSL make by itself anyway, even if we could
178
# properly convert the path.
179
ifeq ($$(call isBuildOsEnv, windows.wsl1 windows.wsl2), true)
180
$1_MAKE := wsl.exe $(MAKE)
182
$1_MAKE := $$(call FixPath, $(MAKE))
185
# make reconfigure omitted since it is sensitive to which make was used
186
# make dist-clean omitted since it would delete the Workspace as well
187
$1_MATCHING_MAKE_TARGETS :=
188
$1_PLAIN_MAKE_TARGETS := update-build-docs docs gensrc gendata copy java \
189
launchers libs hotspot jdk product-images product-bundles all-images test-image clean
191
$1_MATCHING_MAKE_TARGETS += $$(foreach name,$$($1_PLAIN_MAKE_TARGETS), \
192
<target name="$$(strip $$(name))" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> \
193
<buildCommand>$$($1_MAKE)</buildCommand> \
194
<buildArguments>-C $$(call FixPath, $(TOPDIR))</buildArguments> \
195
<buildTarget>$$(strip $$(name))</buildTarget> \
196
<stopOnError>true</stopOnError> \
197
<useDefaultCommand>false</useDefaultCommand> \
198
<runAllBuilders>true</runAllBuilders> \
199
</target>$$(NEWLINE))
201
$$(eval $$(call SetupTextFileProcessing, $1_CREATE_NATIVE_FILE, \
202
SOURCE_FILES := $(TOPDIR)/make/ide/eclipse/native.template, \
203
OUTPUT_FILE := $$($1_NATIVE_FILE), \
205
@@DIR@@ => $$(call FixPath, $(TOPDIR)) ; \
206
@@ENV@@ => $$($1_ENV) ; \
207
@@WORKSPACE@@ => $$($1_WORKSPACE_MAJOR) ; \
208
@@MINOR@@ => $$($1_WORKSPACE_MINOR) ; \
209
@@MAKE@@ => $$($1_MAKE) ; \
210
@@SRC@@ => $$($1_NATIVE_SRCS) ; \
211
@@MAKE_TARGETS@@ => $$($1_MATCHING_MAKE_TARGETS), \
214
TARGETS += $$($1_CREATE_NATIVE_FILE)
216
$$(call MakeDir, $$($1_IDE_OUTPUTDIR)/.settings)
221
ifneq ($$(findstring $$($1_NATURE), NATIVE MIXED), )
222
$1_CSETTINGS += $$(foreach module, $$(call FindAllModules), $$(if $$(call FindJavaHeaderDir, $$(module)), \
223
$$(foreach dirs, $$(strip $$(patsubst $(TOPDIR)/%,%,$$(call FindModuleNativeDirs, $$(module)))), \
224
<resource project-relative-path="$$(dirs)"> \
225
<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $$(call FindJavaHeaderDir, $$(module)))"/> \
226
$$(if $$(findstring jdk.sctp,$$(module)), <entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $$(call FindJavaHeaderDir, java.base))"/>) \
227
</resource>$$(NEWLINE))))
229
# main.c source file used for generic launchers
231
<resource project-relative-path="src/java.base/share/native/launcher/main.c"> \
232
<entry kind="macro" name="LAUNCHER_NAME" value=""$(LAUNCHER_NAME)""/> \
233
</resource>$$(NEWLINE)
237
$1_CXXSETTINGS += <resource project-relative-path="src/hotspot">$$(NEWLINE)
239
# If only the Java Virtual Machine sources were requested, headers from other parts of
240
# the native source that it needs will not be available. Add them as include paths here
242
ifeq ($$($1_NATURE), HOTSPOT)
243
$1_CXXSETTINGS += $$(foreach src, $$(strip $$(patsubst %,%/include,$$(call FindModuleNativeDirs, java.base))), \
244
$(X) $(X)<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $$(src))"/>$$(NEWLINE))
245
$1_CXXSETTINGS += $(X) $(X)<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $(TOPDIR)/src/java.base/share/native/libjimage)"/>$$(NEWLINE)
248
$1_CXXSETTINGS += $(X) $(X)<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $(JVM_VARIANT_OUTPUTDIR)/gensrc)"/>$$(NEWLINE)
250
ifeq ($$(call check-jvm-feature, compiler2), true)
251
$1_CXXSETTINGS += $(X) $(X)<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $(JVM_VARIANT_OUTPUTDIR)/gensrc/adfiles)"/>$$(NEWLINE)
254
$1_CXXSETTINGS += </resource>$$(NEWLINE)
257
<resource project-relative-path="src/hotspot/share/runtime/abstract_vm_version.cpp"> \
258
<entry kind="macro" name="HOTSPOT_VERSION_STRING" value=""$(VERSION_STRING)""/> \
259
<entry kind="macro" name="DEBUG_LEVEL" value=""$(DEBUG_LEVEL)""/> \
260
<entry kind="macro" name="HOTSPOT_VM_DISTRO" value=""$(HOTSPOT_VM_DISTRO)""/> \
261
<entry kind="macro" name="CPU" value=""$(OPENJDK_TARGET_CPU_VM_VERSION)""/> \
262
<entry kind="macro" name="HOTSPOT_BUILD_TIME" value=""$(if $(HOTSPOT_BUILD_TIME),$(HOTSPOT_BUILD_TIME),$(call EpochToISO8601,$(shell $(DATE) +"%s")))""/> \
264
<resource project-relative-path="src/hotspot/share/runtime/arguments.cpp"> \
265
<entry kind="macro" name="HOTSPOT_VERSION_STRING" value=""$(VERSION_STRING)""/> \
266
<entry kind="macro" name="DEBUG_LEVEL" value=""$(DEBUG_LEVEL)""/> \
267
<entry kind="macro" name="HOTSPOT_VM_DISTRO" value=""$(HOTSPOT_VM_DISTRO)""/> \
268
<entry kind="macro" name="CPU" value=""$(OPENJDK_TARGET_CPU_VM_VERSION)""/> \
269
<entry kind="macro" name="HOTSPOT_BUILD_TIME" value=""$(if $(HOTSPOT_BUILD_TIME),$(HOTSPOT_BUILD_TIME),$(call EpochToISO8601,$(shell $(DATE) +"%s")))""/> \
270
</resource>$$(NEWLINE)
272
# Now the rest of the C++ sources in the codebase
273
ifneq ($$(findstring $$($1_NATURE), NATIVE MIXED), )
274
$1_CXXSETTINGS += $$(foreach module, $$(call FindAllModules), $$(if $$(call FindJavaHeaderDir, $$(module)), \
275
$$(foreach dirs, $$(strip $$(patsubst $(TOPDIR)/%,%,$$(call FindModuleNativeDirs, $$(module)))), \
276
<resource project-relative-path="$$(dirs)"> \
277
<entry flags="LOCAL" kind="includePath" name="$$(call FixPath, $$(call FindJavaHeaderDir, $$(module)))"/> \
278
</resource>$$(NEWLINE))))
281
$$(eval $$(call SetupTextFileProcessing, $1_CREATE_SETTINGS_FILE, \
282
SOURCE_FILES := $(TOPDIR)/make/ide/eclipse/settings.template, \
283
OUTPUT_FILE := $$($1_SETTINGS_FILE), \
285
@@WORKSPACE@@ => $$($1_WORKSPACE_MAJOR) ; \
286
@@CSETTINGS@@ => $$($1_CSETTINGS) ; \
287
@@CXXSETTINGS@@ => $$($1_CXXSETTINGS), \
290
TARGETS += $$($1_CREATE_SETTINGS_FILE)
294
ifneq ($$(findstring $$($1_NATURE), JAVA MIXED), )
295
$1_LINKED_RESOURCES += $$(foreach src,$(JAVA_DIRS), \
297
<name>$$(strip $$(src))</name> \
299
<location>$$(subst \\,/,$$(call FixPath, $(TOPDIR)/$$(src)))</location> \
303
ifneq ($$(findstring $$($1_NATURE), HOTSPOT NATIVE MIXED), )
304
# CDT includes a Makefile editor, so if CDT support was indicated there's no harm in
305
# including the make sources as well, since the cost of indexing them is miniscule
306
$1_LINKED_RESOURCES += \
310
<location>$$(subst \\,/,$$(call FixPath, $(TOPDIR)/make))</location> \
313
<name>src/hotspot</name> \
315
<location>$$(subst \\,/,$$(call FixPath, $(TOPDIR)/src/hotspot))</location> \
319
ifneq ($$(findstring $$($1_NATURE), NATIVE MIXED), )
320
$1_LINKED_RESOURCES += $$(foreach src,$(NATIVE_DIRS), \
322
<name>$$(strip $$(src))</name> \
324
<location>$$(subst \\,/,$$(call FixPath, $(TOPDIR)/$$(src)))</location> \
328
$$(eval $$(call SetupTextFileProcessing, $1_CREATE_WORKSPACE_FILE, \
329
SOURCE_FILES := $(TOPDIR)/make/ide/eclipse/workspace.template, \
330
OUTPUT_FILE := $$($1_WORKSPACE_FILE), \
332
@@BUILD_MANAGERS@@ => $$($1_BUILD_MANAGERS) ; \
333
@@NATURES@@ => $$($1_NATURES) ; \
334
@@LINKED_RESOURCES@@ => $$($1_LINKED_RESOURCES), \
337
TARGETS += $$($1_CREATE_WORKSPACE_FILE)
341
ifeq ($(WORKSPACE), java)
342
$(eval $(call SetupEclipseWorkspace, SETUP_WORKSPACE, \
345
else ifeq ($(WORKSPACE), hotspot)
346
$(eval $(call SetupEclipseWorkspace, SETUP_WORKSPACE, \
349
else ifeq ($(WORKSPACE), native)
350
$(eval $(call SetupEclipseWorkspace, SETUP_WORKSPACE, \
354
$(eval $(call SetupEclipseWorkspace, SETUP_WORKSPACE, \