1 # 2 # Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 3 # Copyright (c) 2013 Red Hat, Inc. 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 # 6 # This code is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 only, as 8 # published by the Free Software Foundation. 9 # 10 # This code is distributed in the hope that it will be useful, but WITHOUT 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 # version 2 for more details (a copy is included in the LICENSE file that 14 # accompanied this code). 15 # 16 # You should have received a copy of the GNU General Public License version 17 # 2 along with this work; if not, write to the Free Software Foundation, 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 # 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 # or visit www.oracle.com if you need additional information or have any 22 # questions. 23 # 24 # 25 26 include $(GAMMADIR)/make/defs.make 27 28 #------------------------------------------------------------------------ 29 # CC, CXX & AS 30 31 # If a SPEC is not set already, then use these defaults. 32 ifeq ($(SPEC),) 33 # When cross-compiling the ALT_COMPILER_PATH points 34 # to the cross-compilation toolset 35 ifdef CROSS_COMPILE_ARCH 36 CXX = $(ALT_COMPILER_PATH)/g++ 37 CC = $(ALT_COMPILER_PATH)/gcc 38 HOSTCXX = g++ 39 HOSTCC = gcc 40 STRIP = $(ALT_COMPILER_PATH)/strip 41 else 42 CXX = g++ 43 CC = gcc 44 HOSTCXX = $(CXX) 45 HOSTCC = $(CC) 46 STRIP = strip 47 endif 48 AS = $(CC) -c 49 endif 50 51 52 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 53 # prints the numbers (e.g. "2.95", "3.2.1") 54 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 55 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 56 57 # check for precompiled headers support 58 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 59 # Allow the user to turn off precompiled headers from the command line. 60 ifneq ($(USE_PRECOMPILED_HEADER),0) 61 PRECOMPILED_HEADER_DIR=. 62 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 63 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 64 endif 65 endif 66 67 68 #------------------------------------------------------------------------ 69 # Compiler flags 70 71 # position-independent code 72 PICFLAG = -fPIC 73 74 VM_PICFLAG/LIBJVM = $(PICFLAG) 75 VM_PICFLAG/AOUT = 76 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO)) 77 78 ifeq ($(JVM_VARIANT_ZERO), true) 79 CFLAGS += $(LIBFFI_CFLAGS) 80 endif 81 ifeq ($(JVM_VARIANT_ZEROSHARK), true) 82 CFLAGS += $(LIBFFI_CFLAGS) 83 CFLAGS += $(LLVM_CFLAGS) 84 endif 85 CFLAGS += $(VM_PICFLAG) 86 CFLAGS += -fno-rtti 87 CFLAGS += -fno-exceptions 88 CFLAGS += -D_REENTRANT 89 CFLAGS += -fcheck-new 90 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 91 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 92 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 93 CFLAGS += -fvisibility=hidden 94 endif 95 96 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 97 ARCHFLAG/i486 = -m32 -march=i586 98 ARCHFLAG/amd64 = -m64 99 ARCHFLAG/ia64 = 100 ARCHFLAG/sparc = -m32 -mcpu=v9 101 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 102 ARCHFLAG/arm = -fsigned-char 103 ARCHFLAG/zero = $(ZERO_ARCHFLAG) 104 ifndef E500V2 105 ARCHFLAG/ppc = -mcpu=powerpc 106 endif 107 108 CFLAGS += $(ARCHFLAG) 109 AOUT_FLAGS += $(ARCHFLAG) 110 LFLAGS += $(ARCHFLAG) 111 ASFLAGS += $(ARCHFLAG) 112 113 ifdef E500V2 114 CFLAGS += -DE500V2 115 endif 116 117 # Use C++ Interpreter 118 ifdef CC_INTERP 119 CFLAGS += -DCC_INTERP 120 endif 121 122 # Build for embedded targets 123 ifdef JAVASE_EMBEDDED 124 CFLAGS += -DJAVASE_EMBEDDED 125 endif 126 127 # Keep temporary files (.ii, .s) 128 ifdef NEED_ASM 129 CFLAGS += -save-temps 130 else 131 CFLAGS += -pipe 132 endif 133 134 # Compiler warnings are treated as errors 135 WARNINGS_ARE_ERRORS = -Werror 136 137 # Except for a few acceptable ones 138 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 139 # conversions which might affect the values. To avoid that, we need to turn 140 # it off explicitly. 141 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 142 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare 143 else 144 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare 145 endif 146 147 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS) 148 # Special cases 149 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 150 151 # The flags to use for an Optimized g++ build 152 OPT_CFLAGS += -O3 153 154 # Hotspot uses very unstrict aliasing turn this optimization off 155 OPT_CFLAGS += -fno-strict-aliasing 156 157 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 158 # if we use expensive-optimizations 159 ifeq ($(BUILDARCH), ia64) 160 OPT_CFLAGS += -fno-expensive-optimizations 161 endif 162 163 OPT_CFLAGS/NOOPT=-O0 164 165 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 166 ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0" 167 OPT_CFLAGS/mulnode.o += -O0 168 endif 169 170 # Flags for generating make dependency flags. 171 ifneq ("${CC_VER_MAJOR}", "2") 172 DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 173 endif 174 175 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 176 ifeq ($(USE_PRECOMPILED_HEADER),0) 177 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 178 endif 179 180 #------------------------------------------------------------------------ 181 # Linker flags 182 183 # statically link libstdc++.so, work with gcc but ignored by g++ 184 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 185 186 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 187 ifneq ("${CC_VER_MAJOR}", "2") 188 STATIC_LIBGCC += -static-libgcc 189 endif 190 191 ifeq ($(BUILDARCH), ia64) 192 LFLAGS += -Wl,-relax 193 endif 194 195 # Enable linker optimization 196 LFLAGS += -Xlinker -O1 197 198 # If this is a --hash-style=gnu system, use --hash-style=both 199 # The gnu .hash section won't work on some Linux systems like SuSE 10. 200 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') 201 ifneq ($(_HAS_HASH_STYLE_GNU),) 202 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 203 endif 204 LFLAGS += $(LDFLAGS_HASH_STYLE) 205 206 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 207 MAPFLAG = -Xlinker --version-script=FILENAME 208 209 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 210 SONAMEFLAG = -Xlinker -soname=SONAME 211 212 # Build shared library 213 SHARED_FLAG = -shared 214 215 # Keep symbols even they are not used 216 AOUT_FLAGS += -Xlinker -export-dynamic 217 218 #------------------------------------------------------------------------ 219 # Debug flags 220 221 # DEBUG_BINARIES uses full -g debug information for all configs 222 ifeq ($(DEBUG_BINARIES), true) 223 CFLAGS += -g 224 else 225 # Use the stabs format for debugging information (this is the default 226 # on gcc-2.91). It's good enough, has all the information about line 227 # numbers and local variables, and libjvm_g.so is only about 16M. 228 # Change this back to "-g" if you want the most expressive format. 229 # (warning: that could easily inflate libjvm_g.so to 150M!) 230 # Note: The Itanium gcc compiler crashes when using -gstabs. 231 DEBUG_CFLAGS/ia64 = -g 232 DEBUG_CFLAGS/amd64 = -g 233 DEBUG_CFLAGS/arm = -g 234 DEBUG_CFLAGS/ppc = -g 235 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 236 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 237 DEBUG_CFLAGS += -gstabs 238 endif 239 240 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 241 FASTDEBUG_CFLAGS/ia64 = -g 242 FASTDEBUG_CFLAGS/amd64 = -g 243 FASTDEBUG_CFLAGS/arm = -g 244 FASTDEBUG_CFLAGS/ppc = -g 245 FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 246 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) 247 FASTDEBUG_CFLAGS += -gstabs 248 endif 249 250 OPT_CFLAGS/ia64 = -g 251 OPT_CFLAGS/amd64 = -g 252 OPT_CFLAGS/arm = -g 253 OPT_CFLAGS/ppc = -g 254 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) 255 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) 256 OPT_CFLAGS += -gstabs 257 endif 258 endif 259 endif 260 261 # If we are building HEADLESS, pass on to VM 262 # so it can set the java.awt.headless property 263 ifdef HEADLESS 264 CFLAGS += -DHEADLESS 265 endif 266 267 # We are building Embedded for a small device 268 # favor code space over speed 269 ifdef MINIMIZE_RAM_USAGE 270 CFLAGS += -DMINIMIZE_RAM_USAGE 271 endif