1 # 2 # Copyright (c) 1998, 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 # 24 25 #------------------------------------------------------------------------ 26 # CC, CXX & AS 27 28 # If a SPEC is not set already, then use these defaults. 29 ifeq ($(SPEC),) 30 CXX = g++ 31 CC = gcc 32 AS = $(CC) -c 33 MCS = /usr/ccs/bin/mcs 34 endif 35 36 Compiler = gcc 37 38 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 39 # prints the numbers (e.g. "2.95", "3.2.1") 40 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 41 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 42 43 # Check for the versions of C++ and C compilers ($CXX and $CC) used. 44 45 # Get the last thing on the line that looks like x.x+ (x is a digit). 46 COMPILER_REV := \ 47 $(shell $(CXX) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 48 CC_COMPILER_REV := \ 49 $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 50 51 52 # check for precompiled headers support 53 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 54 # Allow the user to turn off precompiled headers from the command line. 55 ifneq ($(USE_PRECOMPILED_HEADER),0) 56 PRECOMPILED_HEADER_DIR=. 57 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 58 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 59 endif 60 endif 61 62 63 #------------------------------------------------------------------------ 64 # Compiler flags 65 66 # position-independent code 67 PICFLAG = -fPIC 68 69 VM_PICFLAG/LIBJVM = $(PICFLAG) 70 VM_PICFLAG/AOUT = 71 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO)) 72 73 CFLAGS += $(VM_PICFLAG) 74 CFLAGS += -fno-rtti 75 CFLAGS += -fno-exceptions 76 CFLAGS += -D_REENTRANT 77 CFLAGS += -fcheck-new 78 79 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 80 81 ARCHFLAG/sparc = -m32 -mcpu=v9 82 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 83 ARCHFLAG/i486 = -m32 -march=i586 84 ARCHFLAG/amd64 = -m64 -march=k8 85 86 87 # Optional sub-directory in /usr/lib where BUILDARCH libraries are kept. 88 ISA_DIR=$(ISA_DIR/$(BUILDARCH)) 89 ISA_DIR/amd64=/amd64 90 ISA_DIR/i486= 91 ISA_DIR/sparcv9=/64 92 93 94 CFLAGS += $(ARCHFLAG) 95 AOUT_FLAGS += $(ARCHFLAG) 96 LFLAGS += $(ARCHFLAG) 97 ASFLAGS += $(ARCHFLAG) 98 99 ifeq ($(BUILDARCH), amd64) 100 ASFLAGS += -march=k8 -march=amd64 101 LFLAGS += -march=k8 102 endif 103 104 105 # Use C++ Interpreter 106 ifdef CC_INTERP 107 CFLAGS += -DCC_INTERP 108 endif 109 110 # Keep temporary files (.ii, .s) 111 ifdef NEED_ASM 112 CFLAGS += -save-temps 113 else 114 CFLAGS += -pipe 115 endif 116 117 118 # Compiler warnings are treated as errors 119 WARNINGS_ARE_ERRORS = -Werror 120 121 # Enable these warnings. See 'info gcc' about details on these options 122 WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef -Wformat=2 -Wno-error=format-nonliteral 123 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 124 125 # Special cases 126 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 127 128 # optimization control flags (Used by fastdebug and release variants) 129 OPT_CFLAGS/NOOPT=-O0 130 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" 131 # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination) 132 OPT_CFLAGS/DEBUG=-Og 133 +else 134 # Allow no optimizations. 135 OPT_CFLAGS/DEBUG=-O0 136 endif 137 OPT_CFLAGS/SIZE=-Os 138 OPT_CFLAGS/SPEED=-O3 139 140 OPT_CFLAGS_DEFAULT ?= SPEED 141 142 # Hotspot uses very unstrict aliasing turn this optimization off 143 # This option is added to CFLAGS rather than OPT_CFLAGS 144 # so that OPT_CFLAGS overrides get this option too. 145 CFLAGS += -fno-strict-aliasing 146 147 ifdef OPT_CFLAGS 148 ifneq ("$(origin OPT_CFLAGS)", "command line") 149 $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.") 150 endif 151 endif 152 153 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS) 154 155 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 156 # if we use expensive-optimizations 157 # Note: all ia64 setting reflect the ones for linux 158 # No actial testing was performed: there is no Solaris on ia64 presently 159 ifeq ($(BUILDARCH), ia64) 160 OPT_CFLAGS/bytecodeInterpreter.o += -fno-expensive-optimizations 161 endif 162 163 # Work around some compiler bugs. 164 ifeq ($(USE_CLANG), true) 165 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) 166 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) 167 endif 168 else 169 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 170 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) 171 OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) 172 endif 173 endif 174 175 # Flags for generating make dependency flags. 176 ifneq ($(CC_VER_MAJOR), 2) 177 DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 178 endif 179 180 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 181 ifeq ($(USE_PRECOMPILED_HEADER),0) 182 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 183 endif 184 185 #------------------------------------------------------------------------ 186 # Linker flags 187 188 # statically link libstdc++.so, work with gcc but ignored by g++ 189 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 190 191 192 ifdef USE_GNULD 193 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 194 ifneq ($(CC_VER_MAJOR), 2) 195 STATIC_LIBGCC += -static-libgcc 196 endif 197 198 # Enable linker optimization 199 LFLAGS += -Xlinker -O1 200 201 ifeq ($(VARIANT), DBG) 202 # for relocations read-only 203 LFLAGS += -Xlinker -z -Xlinker relro 204 205 ifeq ($(FASTDEBUG), false) 206 # disable incremental relocations linking 207 LFLAGS += -Xlinker -z -Xlinker now 208 endif 209 endif 210 211 ifeq ($(BUILDARCH), ia64) 212 # Note: all ia64 setting reflect the ones for linux 213 # No actual testing was performed: there is no Solaris on ia64 presently 214 LFLAGS += -Wl,-relax 215 endif 216 217 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 218 MAPFLAG = -Xlinker --version-script=FILENAME 219 else 220 MAPFLAG = -Xlinker -M -Xlinker FILENAME 221 endif 222 223 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 224 SONAMEFLAG = -Xlinker -soname=SONAME 225 226 # Build shared library 227 SHARED_FLAG = -shared 228 229 #------------------------------------------------------------------------ 230 # Debug flags 231 232 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" 233 # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination) 234 DEBUG_CFLAGS=-Og 235 else 236 # Allow no optimizations. 237 DEBUG_CFLAGS=-O0 238 endif 239 240 241 # Use the stabs format for debugging information (this is the default 242 # on gcc-2.91). It's good enough, has all the information about line 243 # numbers and local variables, and libjvm.so is only about 16M. 244 # Change this back to "-g" if you want the most expressive format. 245 # (warning: that could easily inflate libjvm.so to 150M!) 246 # Note: The Itanium gcc compiler crashes when using -gstabs. 247 DEBUG_CFLAGS/ia64 = -g 248 DEBUG_CFLAGS/amd64 = -g 249 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 250 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 251 DEBUG_CFLAGS += -gstabs 252 endif 253 254 # Enable bounds checking. 255 ifeq ($(VARIANT), DBG) 256 # _FORTIFY_SOURCE appears in GCC 4.0+ 257 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) )" "0" 258 ifeq ($(FASTDEBUG), true) 259 # compile time size bounds checks 260 CFLAGS += -D_FORTIFY_SOURCE=1 261 else 262 # and runtime size bounds checks and paranoid stack smashing checks. 263 CFLAGS += -D_FORTIFY_SOURCE=2 -fstack-protector-all --param ssp-buffer-size=1 264 endif 265 endif 266 endif 267