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