1 #
   2 # Copyright (c) 1999, 2009, 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, CPP & AS
  27 
  28 CPP = g++
  29 CC  = gcc
  30 AS  = $(CC) -c
  31 
  32 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only
  33 # prints the numbers (e.g. "2.95", "3.2.1")
  34 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1)
  35 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2)
  36 
  37 # check for precompiled headers support
  38 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0"
  39 USE_PRECOMPILED_HEADER=1
  40 PRECOMPILED_HEADER_DIR=.
  41 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/incls/_precompiled.incl.gch
  42 endif
  43 
  44 
  45 #------------------------------------------------------------------------
  46 # Compiler flags
  47 
  48 # position-independent code
  49 PICFLAG = -fPIC
  50 
  51 VM_PICFLAG/LIBJVM = $(PICFLAG)
  52 VM_PICFLAG/AOUT   =
  53 VM_PICFLAG        = $(VM_PICFLAG/$(LINK_INTO))
  54 
  55 ifeq ($(ZERO_BUILD), true)
  56 CFLAGS += $(LIBFFI_CFLAGS)
  57 endif
  58 ifeq ($(SHARK_BUILD), true)
  59 CFLAGS += $(LLVM_CFLAGS)
  60 endif
  61 CFLAGS += $(VM_PICFLAG)
  62 CFLAGS += -fno-rtti
  63 CFLAGS += -fno-exceptions
  64 CFLAGS += -D_REENTRANT
  65 CFLAGS += -fcheck-new
  66 
  67 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
  68 ARCHFLAG/i486    = -m32 -march=i586
  69 ARCHFLAG/amd64   = -m64
  70 ARCHFLAG/ia64    =
  71 ARCHFLAG/sparc   = -m32 -mcpu=v9
  72 ARCHFLAG/sparcv9 = -m64 -mcpu=v9
  73 ARCHFLAG/zero    = $(ZERO_ARCHFLAG)
  74 
  75 CFLAGS     += $(ARCHFLAG)
  76 AOUT_FLAGS += $(ARCHFLAG)
  77 LFLAGS     += $(ARCHFLAG)
  78 ASFLAGS    += $(ARCHFLAG)
  79 
  80 # Use C++ Interpreter
  81 ifdef CC_INTERP
  82   CFLAGS += -DCC_INTERP
  83 endif
  84 
  85 # Keep temporary files (.ii, .s)
  86 ifdef NEED_ASM
  87   CFLAGS += -save-temps
  88 else
  89   CFLAGS += -pipe
  90 endif
  91 
  92 # Compiler warnings are treated as errors
  93 WARNINGS_ARE_ERRORS = -Werror
  94 
  95 # Except for a few acceptable ones
  96 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
  97 # conversions which might affect the values. To avoid that, we need to turn
  98 # it off explicitly. 
  99 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
 100 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare
 101 else
 102 ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare
 103 endif
 104 
 105 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS)
 106 # Special cases
 107 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 
 108 
 109 # The flags to use for an Optimized g++ build
 110 OPT_CFLAGS += -O3
 111 
 112 # Hotspot uses very unstrict aliasing turn this optimization off
 113 OPT_CFLAGS += -fno-strict-aliasing
 114 
 115 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 
 116 # if we use expensive-optimizations
 117 ifeq ($(BUILDARCH), ia64)
 118 OPT_CFLAGS += -fno-expensive-optimizations
 119 endif
 120 
 121 OPT_CFLAGS/NOOPT=-O0
 122 
 123 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 
 124 ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0"
 125 OPT_CFLAGS/mulnode.o += -O0
 126 endif
 127 
 128 #------------------------------------------------------------------------
 129 # Linker flags
 130 
 131 # statically link libstdc++.so, work with gcc but ignored by g++
 132 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
 133 
 134 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x.
 135 ifneq ("${CC_VER_MAJOR}", "2")
 136 STATIC_LIBGCC += -static-libgcc
 137 endif
 138 
 139 ifeq ($(BUILDARCH), ia64)
 140 LFLAGS += -Wl,-relax
 141 endif
 142 
 143 # Enable linker optimization
 144 LFLAGS += -Xlinker -O1
 145 
 146 # If this is a --hash-style=gnu system, use --hash-style=both
 147 #   The gnu .hash section won't work on some Linux systems like SuSE 10.
 148 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
 149 ifneq ($(_HAS_HASH_STYLE_GNU),)
 150   LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
 151 endif
 152 LFLAGS += $(LDFLAGS_HASH_STYLE)
 153 
 154 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
 155 MAPFLAG = -Xlinker --version-script=FILENAME
 156 
 157 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
 158 SONAMEFLAG = -Xlinker -soname=SONAME
 159 
 160 # Build shared library
 161 SHARED_FLAG = -shared
 162 
 163 # Keep symbols even they are not used
 164 AOUT_FLAGS += -export-dynamic
 165 
 166 #------------------------------------------------------------------------
 167 # Debug flags
 168 
 169 # Use the stabs format for debugging information (this is the default
 170 # on gcc-2.91). It's good enough, has all the information about line
 171 # numbers and local variables, and libjvm_g.so is only about 16M.
 172 # Change this back to "-g" if you want the most expressive format.
 173 # (warning: that could easily inflate libjvm_g.so to 150M!)
 174 # Note: The Itanium gcc compiler crashes when using -gstabs.
 175 DEBUG_CFLAGS/ia64  = -g
 176 DEBUG_CFLAGS/amd64 = -g
 177 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
 178 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),)
 179 DEBUG_CFLAGS += -gstabs
 180 endif
 181 
 182 # DEBUG_BINARIES overrides everything, use full -g debug information
 183 ifeq ($(DEBUG_BINARIES), true)
 184   DEBUG_CFLAGS = -g
 185   CFLAGS += $(DEBUG_CFLAGS)
 186 endif