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