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