1 # 2 # Copyright (c) 1999, 2011, 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 # 24 25 OS_VENDOR = $(shell uname -s) 26 27 #------------------------------------------------------------------------ 28 # CC, CXX & AS 29 30 # If a SPEC is not set already, then use these defaults. 31 ifeq ($(SPEC),) 32 # When cross-compiling the ALT_COMPILER_PATH points 33 # to the cross-compilation toolset 34 ifdef CROSS_COMPILE_ARCH 35 CXX = $(ALT_COMPILER_PATH)/g++ 36 CC = $(ALT_COMPILER_PATH)/gcc 37 HOSTCXX = g++ 38 HOSTCC = gcc 39 else ifneq ($(OS_VENDOR), Darwin) 40 CXX = g++ 41 CC = gcc 42 HOSTCXX = $(CXX) 43 HOSTCC = $(CC) 44 endif 45 46 # i486 hotspot requires -mstackrealign on Darwin. 47 # llvm-gcc supports this in Xcode 3.2.6 and 4.0. 48 # gcc-4.0 supports this on earlier versions. 49 # Prefer llvm-gcc where available. 50 ifeq ($(OS_VENDOR), Darwin) 51 ifeq ($(origin CXX), default) 52 CXX = llvm-g++ 53 endif 54 ifeq ($(origin CC), default) 55 CC = llvm-gcc 56 endif 57 58 ifeq ($(ARCH), i486) 59 LLVM_SUPPORTS_STACKREALIGN := $(shell \ 60 [ "0"`llvm-gcc -v 2>&1 | grep LLVM | sed -E "s/.*LLVM build ([0-9]+).*/\1/"` -gt "2333" ] \ 61 && echo true || echo false) 62 63 ifeq ($(LLVM_SUPPORTS_STACKREALIGN), true) 64 CXX32 ?= llvm-g++ 65 CC32 ?= llvm-gcc 66 else 67 CXX32 ?= g++-4.0 68 CC32 ?= gcc-4.0 69 endif 70 CXX = $(CXX32) 71 CC = $(CC32) 72 endif 73 74 HOSTCXX = $(CXX) 75 HOSTCC = $(CC) 76 endif 77 78 AS = $(CC) -c -x assembler-with-cpp 79 endif 80 81 82 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 83 # prints the numbers (e.g. "2.95", "3.2.1") 84 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 85 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 86 87 # check for precompiled headers support 88 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 89 # Allow the user to turn off precompiled headers from the command line. 90 ifneq ($(USE_PRECOMPILED_HEADER),0) 91 PRECOMPILED_HEADER_DIR=. 92 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 93 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 94 endif 95 endif 96 97 98 #------------------------------------------------------------------------ 99 # Compiler flags 100 101 # position-independent code 102 PICFLAG = -fPIC 103 104 VM_PICFLAG/LIBJVM = $(PICFLAG) 105 VM_PICFLAG/AOUT = 106 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO)) 107 108 ifeq ($(JVM_VARIANT_ZERO), true) 109 CFLAGS += $(LIBFFI_CFLAGS) 110 endif 111 ifeq ($(JVM_VARIANT_ZEROSHARK), true) 112 CFLAGS += $(LIBFFI_CFLAGS) 113 CFLAGS += $(LLVM_CFLAGS) 114 endif 115 CFLAGS += $(VM_PICFLAG) 116 CFLAGS += -fno-rtti 117 CFLAGS += -fno-exceptions 118 CFLAGS += -pthread 119 CFLAGS += -fcheck-new 120 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 121 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 122 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 123 CFLAGS += -fvisibility=hidden 124 endif 125 126 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 127 ARCHFLAG/i486 = -m32 -march=i586 128 ARCHFLAG/amd64 = -m64 129 ARCHFLAG/ia64 = 130 ARCHFLAG/sparc = -m32 -mcpu=v9 131 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 132 ARCHFLAG/zero = $(ZERO_ARCHFLAG) 133 134 # Darwin-specific build flags 135 ifeq ($(OS_VENDOR), Darwin) 136 # Ineffecient 16-byte stack re-alignment on Darwin/IA32 137 ARCHFLAG/i486 += -mstackrealign 138 endif 139 140 CFLAGS += $(ARCHFLAG) 141 AOUT_FLAGS += $(ARCHFLAG) 142 LFLAGS += $(ARCHFLAG) 143 ASFLAGS += $(ARCHFLAG) 144 145 ifdef E500V2 146 CFLAGS += -DE500V2 147 endif 148 149 # Use C++ Interpreter 150 ifdef CC_INTERP 151 CFLAGS += -DCC_INTERP 152 endif 153 154 # Build for embedded targets 155 ifdef JAVASE_EMBEDDED 156 CFLAGS += -DJAVASE_EMBEDDED 157 endif 158 159 # Keep temporary files (.ii, .s) 160 ifdef NEED_ASM 161 CFLAGS += -save-temps 162 else 163 CFLAGS += -pipe 164 endif 165 166 # Compiler warnings are treated as errors 167 ifneq ($(COMPILER_WARNINGS_FATAL),false) 168 WARNINGS_ARE_ERRORS = -Werror 169 endif 170 171 # Except for a few acceptable ones 172 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 173 # conversions which might affect the values. To avoid that, we need to turn 174 # it off explicitly. 175 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 176 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare 177 else 178 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare 179 endif 180 181 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS) 182 # Special cases 183 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 184 # XXXDARWIN: for _dyld_bind_fully_image_containing_address 185 ifeq ($(OS_VENDOR), Darwin) 186 CFLAGS_WARN/os_bsd.o = $(CFLAGS_WARN/DEFAULT) -Wno-deprecated-declarations 187 endif 188 189 190 # The flags to use for an Optimized g++ build 191 ifeq ($(OS_VENDOR), Darwin) 192 # use -Os by default, unless -O3 can be proved to be worth the cost, as per policy 193 # <http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port+Compilers> 194 OPT_CFLAGS += -Os 195 else 196 OPT_CFLAGS += -O3 197 endif 198 199 # Hotspot uses very unstrict aliasing turn this optimization off 200 OPT_CFLAGS += -fno-strict-aliasing 201 202 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 203 # if we use expensive-optimizations 204 ifeq ($(BUILDARCH), ia64) 205 OPT_CFLAGS += -fno-expensive-optimizations 206 endif 207 208 OPT_CFLAGS/NOOPT=-O0 209 210 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 211 ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0" 212 OPT_CFLAGS/mulnode.o += -O0 213 endif 214 215 # Flags for generating make dependency flags. 216 ifneq ("${CC_VER_MAJOR}", "2") 217 DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 218 endif 219 220 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 221 ifeq ($(USE_PRECOMPILED_HEADER),0) 222 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 223 endif 224 225 #------------------------------------------------------------------------ 226 # Linker flags 227 228 # statically link libstdc++.so, work with gcc but ignored by g++ 229 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 230 231 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 232 ifneq ("${CC_VER_MAJOR}", "2") 233 STATIC_LIBGCC += -static-libgcc 234 endif 235 236 ifeq ($(BUILDARCH), ia64) 237 LFLAGS += -Wl,-relax 238 endif 239 240 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 241 MAPFLAG = -Xlinker --version-script=FILENAME 242 243 # 244 # Shared Library 245 # 246 ifeq ($(OS_VENDOR), Darwin) 247 # Standard linker flags 248 LFLAGS += 249 250 # Darwin doesn't use ELF and doesn't support version scripts 251 LDNOMAP = true 252 253 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 254 SONAMEFLAG = 255 256 # Build shared library 257 SHARED_FLAG = -Wl,-install_name,@rpath/$(@F) -dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $(VM_PICFLAG) 258 259 # Keep symbols even they are not used 260 #AOUT_FLAGS += -Xlinker -export-dynamic 261 else 262 # Enable linker optimization 263 LFLAGS += -Xlinker -O1 264 265 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 266 SONAMEFLAG = -Xlinker -soname=SONAME 267 268 # Build shared library 269 SHARED_FLAG = -shared $(VM_PICFLAG) 270 271 # Keep symbols even they are not used 272 AOUT_FLAGS += -Xlinker -export-dynamic 273 endif 274 275 #------------------------------------------------------------------------ 276 # Debug flags 277 278 # Use the stabs format for debugging information (this is the default 279 # on gcc-2.91). It's good enough, has all the information about line 280 # numbers and local variables, and libjvm_g.so is only about 16M. 281 # Change this back to "-g" if you want the most expressive format. 282 # (warning: that could easily inflate libjvm_g.so to 150M!) 283 # Note: The Itanium gcc compiler crashes when using -gstabs. 284 DEBUG_CFLAGS/ia64 = -g 285 DEBUG_CFLAGS/amd64 = -g 286 DEBUG_CFLAGS/arm = -g 287 DEBUG_CFLAGS/ppc = -g 288 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 289 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 290 DEBUG_CFLAGS += -gstabs 291 endif 292 293 # DEBUG_BINARIES overrides everything, use full -g debug information 294 ifeq ($(DEBUG_BINARIES), true) 295 DEBUG_CFLAGS = -g 296 CFLAGS += $(DEBUG_CFLAGS) 297 endif 298 299 # If we are building HEADLESS, pass on to VM 300 # so it can set the java.awt.headless property 301 ifdef HEADLESS 302 CFLAGS += -DHEADLESS 303 endif 304 305 # We are building Embedded for a small device 306 # favor code space over speed 307 ifdef MINIMIZE_RAM_USAGE 308 CFLAGS += -DMINIMIZE_RAM_USAGE 309 endif