Thu, 12 Oct 2017 21:27:07 +0800
merge
1 #
2 # Copyright (c) 1999, 2013, 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.
8 #
9 # This code is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # version 2 for more details (a copy is included in the LICENSE file that
13 # accompanied this code).
14 #
15 # You should have received a copy of the GNU General Public License version
16 # 2 along with this work; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 # or visit www.oracle.com if you need additional information or have any
21 # questions.
22 #
23 #
25 #
26 # This file has been modified by Loongson Technology in 2015. These
27 # modifications are Copyright (c) 2015 Loongson Technology, and are made
28 # available on the same license terms set forth above.
29 #
31 # Rules to build JVM and related libraries, included from vm.make in the build
32 # directory.
34 # Common build rules.
35 MAKEFILES_DIR=$(GAMMADIR)/make/$(Platform_os_family)/makefiles
36 include $(MAKEFILES_DIR)/rules.make
37 include $(GAMMADIR)/make/altsrc.make
39 default: build
41 #----------------------------------------------------------------------
42 # Defs
44 GENERATED = ../generated
45 DEP_DIR = $(GENERATED)/dependencies
47 # reads the generated files defining the set of .o's and the .o .h dependencies
48 -include $(DEP_DIR)/*.d
50 # read machine-specific adjustments (%%% should do this via buildtree.make?)
51 ifeq ($(findstring true, $(JVM_VARIANT_ZERO) $(JVM_VARIANT_ZEROSHARK)), true)
52 include $(MAKEFILES_DIR)/zeroshark.make
53 else
54 include $(MAKEFILES_DIR)/$(BUILDARCH).make
55 -include $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/$(BUILDARCH).make
56 endif
58 # set VPATH so make knows where to look for source files
59 # Src_Dirs_V is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
60 # The adfiles directory contains ad_<arch>.[ch]pp.
61 # The jvmtifiles directory contains jvmti*.[ch]pp
62 Src_Dirs_V += $(GENERATED)/adfiles $(GENERATED)/jvmtifiles $(GENERATED)/tracefiles
63 VPATH += $(Src_Dirs_V:%=%:)
65 # set INCLUDES for C preprocessor.
66 Src_Dirs_I += $(GENERATED)
67 # The order is important for the precompiled headers to work.
68 INCLUDES += $(PRECOMPILED_HEADER_DIR:%=-I%) $(Src_Dirs_I:%=-I%)
70 # SYMFLAG is used by {jsig,saproc}.make
71 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
72 # always build with debug info when we can create .debuginfo files
73 SYMFLAG = -g
74 else
75 ifeq (${VERSION}, debug)
76 SYMFLAG = -g
77 else
78 SYMFLAG =
79 endif
80 endif
82 # HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined
83 # in $(GAMMADIR)/make/defs.make
84 ifeq ($(HOTSPOT_BUILD_VERSION),)
85 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)\""
86 else
87 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)\""
88 endif
90 # The following variables are defined in the generated flags.make file.
91 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HS_BUILD_VER)\""
92 JRE_VERSION = -DJRE_RELEASE_VERSION="\"$(JRE_RELEASE_VER)\""
93 HS_LIB_ARCH = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
94 BUILD_TARGET = -DHOTSPOT_BUILD_TARGET="\"$(TARGET)\""
95 BUILD_USER = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
96 VM_DISTRO = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
98 CXXFLAGS = \
99 ${SYSDEFS} \
100 ${INCLUDES} \
101 ${BUILD_VERSION} \
102 ${BUILD_TARGET} \
103 ${BUILD_USER} \
104 ${HS_LIB_ARCH} \
105 ${VM_DISTRO}
107 ifeq ($(MIPS_ABI),n32)
108 CXXFLAGS += -DN32
109 else
110 ifeq ($(MIPS_ABI),n64)
111 CXXFLAGS += -DN64
112 endif
113 endif
114 # This is VERY important! The version define must only be supplied to vm_version.o
115 # If not, ccache will not re-use the cache at all, since the version string might contain
116 # a time and date.
117 CXXFLAGS/vm_version.o += ${JRE_VERSION}
119 CXXFLAGS/BYFILE = $(CXXFLAGS/$@)
121 # File specific flags
122 CXXFLAGS += $(CXXFLAGS/BYFILE)
124 # Large File Support
125 ifneq ($(LP64), 1)
126 CXXFLAGS/ostream.o += -D_FILE_OFFSET_BITS=64
127 endif # ifneq ($(LP64), 1)
129 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
130 CFLAGS += $(CFLAGS_WARN/BYFILE)
132 # Do not use C++ exception handling
133 CFLAGS += $(CFLAGS/NOEX)
135 # Extra flags from gnumake's invocation or environment
136 CFLAGS += $(EXTRA_CFLAGS)
137 LFLAGS += $(EXTRA_CFLAGS)
139 # Don't set excutable bit on stack segment
140 # the same could be done by separate execstack command
141 LFLAGS += -Xlinker -z -Xlinker noexecstack
143 LIBS += -lm -ldl -lpthread
145 # By default, link the *.o into the library, not the executable.
146 LINK_INTO$(LINK_INTO) = LIBJVM
148 JDK_LIBDIR = $(JAVA_HOME)/jre/lib/$(LIBARCH)
150 #----------------------------------------------------------------------
151 # jvm_db & dtrace
152 include $(MAKEFILES_DIR)/dtrace.make
154 #----------------------------------------------------------------------
155 # JVM
157 JVM = jvm
158 LIBJVM = lib$(JVM).so
160 LIBJVM_DEBUGINFO = lib$(JVM).debuginfo
161 LIBJVM_DIZ = lib$(JVM).diz
163 SPECIAL_PATHS:=adlc c1 gc_implementation opto shark libadt
165 SOURCE_PATHS=\
166 $(shell find $(HS_COMMON_SRC)/share/vm/* -type d \! \
167 \( -name DUMMY $(foreach dir,$(SPECIAL_PATHS),-o -name $(dir)) \))
168 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/$(Platform_os_family)/vm
169 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm
170 SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm
171 SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm
173 CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path))
174 CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles
176 ifneq ($(INCLUDE_TRACE), false)
177 CORE_PATHS+=$(shell if [ -d $(HS_ALT_SRC)/share/vm/jfr ]; then \
178 find $(HS_ALT_SRC)/share/vm/jfr -type d; \
179 fi)
180 endif
182 COMPILER1_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/c1)
183 COMPILER1_PATHS += $(HS_COMMON_SRC)/share/vm/c1
185 COMPILER2_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/opto)
186 COMPILER2_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/libadt)
187 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/opto
188 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/libadt
189 COMPILER2_PATHS += $(GENERATED)/adfiles
191 SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark
193 # Include dirs per type.
194 Src_Dirs/CORE := $(CORE_PATHS)
195 Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
196 Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
197 Src_Dirs/TIERED := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
198 Src_Dirs/ZERO := $(CORE_PATHS)
199 Src_Dirs/SHARK := $(CORE_PATHS) $(SHARK_PATHS)
200 Src_Dirs := $(Src_Dirs/$(TYPE))
202 COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp c2_\* runtime_\*
203 COMPILER1_SPECIFIC_FILES := c1_\*
204 SHARK_SPECIFIC_FILES := shark
205 ZERO_SPECIFIC_FILES := zero
207 # Always exclude these.
208 Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
210 # Exclude per type.
211 Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
212 Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
213 Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
214 Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
215 Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
216 Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
218 Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE))
220 # Special handling of arch model.
221 ifeq ($(Platform_arch_model), x86_32)
222 Src_Files_EXCLUDE += \*x86_64\*
223 endif
224 ifeq ($(Platform_arch_model), x86_64)
225 Src_Files_EXCLUDE += \*x86_32\*
226 endif
227 ifeq ($(Platform_arch_model), mips_32)
228 Src_Files_EXCLUDE += \*mips_64\*
229 endif
230 ifeq ($(Platform_arch_model), mips_64)
231 Src_Files_EXCLUDE += \*mips_32\*
232 endif
234 # Alternate vm.make
235 # This has to be included here to allow changes to the source
236 # directories and excluded files before they are expanded
237 # by the definition of Src_Files.
238 -include $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/vm.make
240 # Locate all source files in the given directory, excluding files in Src_Files_EXCLUDE.
241 define findsrc
242 $(notdir $(shell find $(1)/. ! -name . -prune \
243 -a \( -name \*.c -o -name \*.cpp -o -name \*.s \) \
244 -a ! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \)))
245 endef
247 Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
249 Obj_Files = $(sort $(addsuffix .o,$(basename $(Src_Files))))
251 JVM_OBJ_FILES = $(Obj_Files)
253 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
255 mapfile : $(MAPFILE) vm.def mapfile_ext
256 rm -f $@
257 awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE") \
258 { system ("cat mapfile_ext"); system ("cat vm.def"); } \
259 else \
260 { print $$0 } \
261 }' > $@ < $(MAPFILE)
263 mapfile_reorder : mapfile $(REORDERFILE)
264 rm -f $@
265 cat $^ > $@
267 vm.def: $(Res_Files) $(Obj_Files)
268 sh $(GAMMADIR)/make/linux/makefiles/build_vm_def.sh *.o > $@
270 mapfile_ext:
271 rm -f $@
272 touch $@
273 if [ -f $(HS_ALT_MAKE)/linux/makefiles/mapfile-ext ]; then \
274 cat $(HS_ALT_MAKE)/linux/makefiles/mapfile-ext > $@; \
275 fi
277 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
278 STATIC_CXX = false
279 else
280 ifeq ($(ZERO_LIBARCH), ppc64)
281 STATIC_CXX = false
282 else
283 STATIC_CXX = true
284 endif
285 endif
287 ifeq ($(LINK_INTO),AOUT)
288 LIBJVM.o =
289 LIBJVM_MAPFILE =
290 LIBS_VM = $(LIBS)
291 else
292 LIBJVM.o = $(JVM_OBJ_FILES)
293 LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
294 LFLAGS_VM$(LDNOMAP) += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
295 LFLAGS_VM += $(SONAMEFLAG:SONAME=$(LIBJVM))
297 # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
298 # get around library dependency and compatibility issues. Must use gcc not
299 # g++ to link.
300 ifeq ($(STATIC_CXX), true)
301 LFLAGS_VM += $(STATIC_LIBGCC)
302 LIBS_VM += $(STATIC_STDCXX)
303 else
304 LIBS_VM += -lstdc++
305 endif
307 LIBS_VM += $(LIBS)
308 endif
309 ifeq ($(JVM_VARIANT_ZERO), true)
310 LIBS_VM += $(LIBFFI_LIBS)
311 endif
312 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
313 LIBS_VM += $(LIBFFI_LIBS) $(LLVM_LIBS)
314 LFLAGS_VM += $(LLVM_LDFLAGS)
315 endif
317 LINK_VM = $(LINK_LIB.CC)
319 # rule for building precompiled header
320 $(PRECOMPILED_HEADER):
321 $(QUIETLY) echo Generating precompiled header $@
322 $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
323 $(QUIETLY) $(COMPILE.CXX) $(DEPFLAGS) -x c++-header $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
325 # making the library:
327 ifneq ($(JVM_BASE_ADDR),)
328 # By default shared library is linked at base address == 0. Modify the
329 # linker script if JVM prefers a different base location. It can also be
330 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
331 # our build platform (AS-2.1).
332 LD_SCRIPT = libjvm.so.lds
333 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
334 $(QUIETLY) { \
335 rm -rf $@; \
336 $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1 | \
337 sed -e '/^======/,/^======/!d' \
338 -e '/^======/d' \
339 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/' \
340 > $@; \
341 }
342 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
343 endif
345 # With more recent Redhat releases (or the cutting edge version Fedora), if
346 # SELinux is configured to be enabled, the runtime linker will fail to apply
347 # the text relocation to libjvm.so considering that it is built as a non-PIC
348 # DSO. To workaround that, we run chcon to libjvm.so after it is built. See
349 # details in bug 6538311.
350 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
351 $(QUIETLY) { \
352 echo Linking vm...; \
353 $(LINK_LIB.CXX/PRE_HOOK) \
354 $(LINK_VM) $(LD_SCRIPT_FLAG) \
355 $(LFLAGS_VM) -o $@ $(sort $(LIBJVM.o)) $(LIBS_VM); \
356 $(LINK_LIB.CXX/POST_HOOK) \
357 rm -f $@.1; ln -s $@ $@.1; \
358 if [ \"$(CROSS_COMPILE_ARCH)\" = \"\" ] ; then \
359 if [ -x /usr/sbin/selinuxenabled ] ; then \
360 /usr/sbin/selinuxenabled; \
361 if [ $$? = 0 ] ; then \
362 /usr/bin/chcon -t textrel_shlib_t $@; \
363 if [ $$? != 0 ]; then \
364 echo "ERROR: Cannot chcon $@"; \
365 fi \
366 fi \
367 fi \
368 fi \
369 }
371 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
372 $(QUIETLY) $(OBJCOPY) --only-keep-debug $@ $(LIBJVM_DEBUGINFO)
373 $(QUIETLY) $(OBJCOPY) --add-gnu-debuglink=$(LIBJVM_DEBUGINFO) $@
374 ifeq ($(STRIP_POLICY),all_strip)
375 $(QUIETLY) $(STRIP) $@
376 else
377 ifeq ($(STRIP_POLICY),min_strip)
378 $(QUIETLY) $(STRIP) -g $@
379 # implied else here is no stripping at all
380 endif
381 endif
382 ifeq ($(ZIP_DEBUGINFO_FILES),1)
383 $(ZIPEXE) -q -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
384 $(RM) $(LIBJVM_DEBUGINFO)
385 endif
386 endif
388 DEST_SUBDIR = $(JDK_LIBDIR)/$(VM_SUBDIR)
389 DEST_JVM = $(DEST_SUBDIR)/$(LIBJVM)
390 DEST_JVM_DEBUGINFO = $(DEST_SUBDIR)/$(LIBJVM_DEBUGINFO)
391 DEST_JVM_DIZ = $(DEST_SUBDIR)/$(LIBJVM_DIZ)
393 install_jvm: $(LIBJVM)
394 @echo "Copying $(LIBJVM) to $(DEST_JVM)"
395 $(QUIETLY) test -f $(LIBJVM_DEBUGINFO) && \
396 cp -f $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
397 $(QUIETLY) test -f $(LIBJVM_DIZ) && \
398 cp -f $(LIBJVM_DIZ) $(DEST_JVM_DIZ)
399 $(QUIETLY) cp -f $(LIBJVM) $(DEST_JVM) && echo "Done"
401 #----------------------------------------------------------------------
402 # Other files
404 # Signal interposition library
405 include $(MAKEFILES_DIR)/jsig.make
407 # Serviceability agent
408 include $(MAKEFILES_DIR)/saproc.make
410 #----------------------------------------------------------------------
412 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(BUILDLIBSAPROC) dtraceCheck
414 install: install_jvm install_jsig install_saproc
416 .PHONY: default build install install_jvm $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/$(BUILDARCH).make $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/vm.make