make/linux/makefiles/gcc.make

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 183
f950ea9eb769
permissions
-rw-r--r--

Added MIPS 64-bit port.

     1 #
     2 # Copyright (c) 1999, 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 #
    25 #
    26 # This file has been modified by Loongson Technology in 2015. These
    27 # modifications are Copyright (c) 2015 Loongson Technology, and are made
    28 # available on the same license terms set forth above.
    29 #
    31 #------------------------------------------------------------------------
    32 # CC, CXX & AS
    34 # If a SPEC is not set already, then use these defaults.
    35 ifeq ($(SPEC),)
    36   # When cross-compiling the ALT_COMPILER_PATH points
    37   # to the cross-compilation toolset
    38   ifdef CROSS_COMPILE_ARCH
    39     CXX = $(ALT_COMPILER_PATH)/g++
    40     CC  = $(ALT_COMPILER_PATH)/gcc
    41     HOSTCXX = g++
    42     HOSTCC  = gcc
    43     STRIP = $(ALT_COMPILER_PATH)/strip
    44   else
    45     ifeq ($(USE_CLANG), true)
    46       CXX = clang++
    47       CC  = clang
    48     else
    49       CXX = g++
    50       CC  = gcc
    51     endif
    53     HOSTCXX = $(CXX)
    54     HOSTCC  = $(CC)
    55     STRIP = strip
    56   endif
    57   AS  = $(CC) -c
    58 endif
    61 ifeq ($(USE_CLANG), true)
    62   CC_VER_MAJOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f1)
    63   CC_VER_MINOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f2)
    64 else
    65   # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only
    66   # prints the numbers (e.g. "2.95", "3.2.1")
    67   CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1)
    68   CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2)
    69 endif
    72 ifeq ($(USE_CLANG), true)
    73   # Clang has precompiled headers support by default, but the user can switch
    74   # it off by using 'USE_PRECOMPILED_HEADER=0'.
    75   ifdef LP64
    76     ifeq ($(USE_PRECOMPILED_HEADER),)
    77       USE_PRECOMPILED_HEADER=1
    78     endif
    79   else
    80     # We don't support precompiled headers on 32-bit builds because there some files are
    81     # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make)
    82     # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit.
    83     USE_PRECOMPILED_HEADER=0
    84   endif
    86   ifeq ($(USE_PRECOMPILED_HEADER),1)
    88     ifndef LP64
    89       $(error " Precompiled Headers only supported on 64-bit platforms!")
    90     endif
    92     PRECOMPILED_HEADER_DIR=.
    93     PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
    94     PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch
    96     PCH_FLAG = -include precompiled.hpp
    97     PCH_FLAG/DEFAULT = $(PCH_FLAG)
    98     PCH_FLAG/NO_PCH = -DNO_PCH
    99     PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@))
   101     VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE)
   102     VM_PCH_FLAG/AOUT =
   103     VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO))
   105     # We only use precompiled headers for the JVM build
   106     CFLAGS += $(VM_PCH_FLAG)
   108     # There are some files which don't like precompiled headers
   109     # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build.
   110     # But Clang doesn't support a precompiled header which was compiled with -O3
   111     # to be used in a compilation unit which uses '-O0'. We could also prepare an
   112     # extra '-O0' PCH file for the opt build and use it here, but it's probably
   113     # not worth the effoert as long as only two files need this special handling.
   114     PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH)
   115     PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH)
   116     PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH)
   118   endif
   119 else # ($(USE_CLANG), true)
   120   # check for precompiled headers support
   121   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0"
   122     # Allow the user to turn off precompiled headers from the command line.
   123     ifneq ($(USE_PRECOMPILED_HEADER),0)
   124       PRECOMPILED_HEADER_DIR=.
   125       PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
   126       PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch
   127     endif
   128   endif
   129 endif
   131 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp.
   132 ifeq ($(USE_PRECOMPILED_HEADER),0)
   133   CFLAGS += -DDONT_USE_PRECOMPILED_HEADER
   134 endif
   137 #------------------------------------------------------------------------
   138 # Compiler flags
   140 # position-independent code
   141 PICFLAG = -fPIC
   143 VM_PICFLAG/LIBJVM = $(PICFLAG)
   144 VM_PICFLAG/AOUT   =
   145 VM_PICFLAG        = $(VM_PICFLAG/$(LINK_INTO))
   147 ifeq ($(JVM_VARIANT_ZERO), true)
   148 CFLAGS += $(LIBFFI_CFLAGS)
   149 endif
   150 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
   151 CFLAGS += $(LIBFFI_CFLAGS)
   152 CFLAGS += $(LLVM_CFLAGS)
   153 endif
   154 CFLAGS += $(VM_PICFLAG)
   155 CFLAGS += -fno-rtti
   156 CFLAGS += -fno-exceptions
   157 CFLAGS += -D_REENTRANT
   158 ifeq ($(USE_CLANG),)
   159   CFLAGS += -fcheck-new
   160   # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
   161   # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
   162   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
   163     CFLAGS += -fvisibility=hidden
   164   endif
   165 else
   166   CFLAGS += -fvisibility=hidden
   167 endif
   169 ifeq ($(USE_CLANG), true)
   170   # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm'
   171   # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment')
   172   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0"
   173     STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16
   174   else
   175     STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16
   176   endif
   177 endif
   179 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
   180 ARCHFLAG/i486    = -m32 -march=i586
   181 ARCHFLAG/amd64   = -m64 $(STACK_ALIGNMENT_OPT)
   182 ARCHFLAG/ia64    =
   183 ARCHFLAG/sparc   = -m32 -mcpu=v9
   184 ARCHFLAG/sparcv9 = -m64 -mcpu=v9
   185 ARCHFLAG/arm     =  -fsigned-char
   186 ARCHFLAG/zero    = $(ZERO_ARCHFLAG)
   187 ifndef E500V2
   188 ARCHFLAG/ppc     =  -mcpu=powerpc
   189 ARCHFLAG/mips64  = -mabi=64 -march=mips3
   190 endif
   191 ARCHFLAG/ppc64   =  -m64
   193 CFLAGS     += $(ARCHFLAG)
   194 AOUT_FLAGS += $(ARCHFLAG)
   195 LFLAGS     += $(ARCHFLAG)
   196 ASFLAGS    += $(ARCHFLAG)
   198 ifdef E500V2
   199 CFLAGS += -DE500V2
   200 endif
   202 # Use C++ Interpreter
   203 ifdef CC_INTERP
   204   CFLAGS += -DCC_INTERP
   205 endif
   207 # Keep temporary files (.ii, .s)
   208 ifdef NEED_ASM
   209   CFLAGS += -save-temps
   210 else
   211   CFLAGS += -pipe
   212 endif
   214 # Compiler warnings are treated as errors
   215 #compiler disassembler_mips.cpp:193:"if WARNINGS_ARE_ERRORS =, here from error to  warning ": deprecated conversion from string constant to 'char*'
   216 #WARNINGS_ARE_ERRORS = -Werror
   218 ifeq ($(USE_CLANG), true)
   219   # However we need to clean the code up before we can unrestrictedly enable this option with Clang
   220   WARNINGS_ARE_ERRORS += -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses
   221   WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare
   222   WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess
   223   WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body
   224 endif
   226 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value
   228 ifeq ($(USE_CLANG),)
   229   # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
   230   # conversions which might affect the values. Only enable it in earlier versions.
   231   ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
   232     WARNING_FLAGS += -Wconversion
   233   endif
   234 endif
   236 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS)
   237 # Special cases
   238 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 
   240 # The flags to use for an Optimized g++ build
   241 OPT_CFLAGS/SIZE=-Os
   242 OPT_CFLAGS/SPEED=-O3
   244 # Hotspot uses very unstrict aliasing turn this optimization off
   245 # This option is added to CFLAGS rather than OPT_CFLAGS
   246 # so that OPT_CFLAGS overrides get this option too.
   247 CFLAGS += -fno-strict-aliasing 
   249 OPT_CFLAGS_DEFAULT ?= SPEED
   251 ifdef OPT_CFLAGS
   252   ifneq ("$(origin OPT_CFLAGS)", "command line")
   253     $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.")
   254   endif
   255 endif
   257 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS)
   259 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 
   260 # if we use expensive-optimizations
   261 ifeq ($(BUILDARCH), ia64)
   262 OPT_CFLAGS += -fno-expensive-optimizations
   263 endif
   265 OPT_CFLAGS/NOOPT=-O0
   267 # Work around some compiler bugs.
   268 ifeq ($(USE_CLANG), true)
   269   ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1)
   270     OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT)
   271   endif
   272 else
   273   # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation.
   274   ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1)
   275     OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT)
   276   endif
   277 endif
   279 # Flags for generating make dependency flags.
   280 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
   281 ifeq ($(USE_CLANG),)
   282   ifneq ("${CC_VER_MAJOR}", "2")
   283     DEPFLAGS += -fpch-deps
   284   endif
   285 endif
   287 #------------------------------------------------------------------------
   288 # Linker flags
   290 # statically link libstdc++.so, work with gcc but ignored by g++
   291 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
   293 ifeq ($(USE_CLANG),)
   294   # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x.
   295   ifneq ("${CC_VER_MAJOR}", "2")
   296     STATIC_LIBGCC += -static-libgcc
   297   endif
   299   ifeq ($(BUILDARCH), ia64)
   300     LFLAGS += -Wl,-relax
   301   endif
   302 endif
   304 # Enable linker optimization
   305 LFLAGS += -Xlinker -O1
   307 ifeq ($(USE_CLANG),)
   308   # If this is a --hash-style=gnu system, use --hash-style=both
   309   #   The gnu .hash section won't work on some Linux systems like SuSE 10.
   310   _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
   311   ifneq ($(_HAS_HASH_STYLE_GNU),)
   312     LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
   313   endif
   314 else
   315   # Don't know how to find out the 'hash style' of a system as '-dumpspecs'
   316   # doesn't work for Clang. So for now we'll alwys use --hash-style=both
   317   LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
   318 endif
   320 LFLAGS += $(LDFLAGS_HASH_STYLE)
   322 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
   323 MAPFLAG = -Xlinker --version-script=FILENAME
   325 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
   326 SONAMEFLAG = -Xlinker -soname=SONAME
   328 # Build shared library
   329 SHARED_FLAG = -shared
   331 # Keep symbols even they are not used
   332 AOUT_FLAGS += -Xlinker -export-dynamic
   334 #------------------------------------------------------------------------
   335 # Debug flags
   337 ifeq ($(USE_CLANG), true)
   338   # Restrict the debug information created by Clang to avoid
   339   # too big object files and speed the build up a little bit
   340   # (see http://llvm.org/bugs/show_bug.cgi?id=7554)
   341   CFLAGS += -flimit-debug-info
   342 endif
   344 # DEBUG_BINARIES uses full -g debug information for all configs
   345 ifeq ($(DEBUG_BINARIES), true)
   346   CFLAGS += -g
   347 else
   348   # Use the stabs format for debugging information (this is the default
   349   # on gcc-2.91). It's good enough, has all the information about line
   350   # numbers and local variables, and libjvm.so is only about 16M.
   351   # Change this back to "-g" if you want the most expressive format.
   352   # (warning: that could easily inflate libjvm.so to 150M!)
   353   # Note: The Itanium gcc compiler crashes when using -gstabs.
   354   DEBUG_CFLAGS/ia64  = -g
   355   DEBUG_CFLAGS/amd64 = -g
   356   DEBUG_CFLAGS/mips64 = -g
   357   DEBUG_CFLAGS/arm   = -g
   358   DEBUG_CFLAGS/ppc   = -g
   359   DEBUG_CFLAGS/ppc64 = -g
   360   DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
   361   ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),)
   362       ifeq ($(USE_CLANG), true)
   363         # Clang doesn't understand -gstabs
   364         DEBUG_CFLAGS += -g
   365       else
   366         DEBUG_CFLAGS += -gstabs
   367       endif
   368   endif
   370   ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
   371     FASTDEBUG_CFLAGS/ia64  = -g
   372     FASTDEBUG_CFLAGS/amd64 = -g
   373     FASTDEBUG_CFLAGS/mips64 = -g
   374     FASTDEBUG_CFLAGS/arm   = -g
   375     FASTDEBUG_CFLAGS/ppc   = -g
   376     FASTDEBUG_CFLAGS/ppc64 = -g
   377     FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
   378     ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),)
   379       ifeq ($(USE_CLANG), true)
   380         # Clang doesn't understand -gstabs
   381         FASTDEBUG_CFLAGS += -g
   382       else
   383         FASTDEBUG_CFLAGS += -gstabs
   384       endif
   385     endif
   387     OPT_CFLAGS/ia64  = -g
   388     OPT_CFLAGS/amd64 = -g
   389     OPT_CFLAGS/mips64 = -g
   390     OPT_CFLAGS/arm   = -g
   391     OPT_CFLAGS/ppc   = -g
   392     OPT_CFLAGS/ppc64 = -g
   393     OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH))
   394     ifeq ($(OPT_CFLAGS/$(BUILDARCH)),)
   395       ifeq ($(USE_CLANG), true)
   396         # Clang doesn't understand -gstabs
   397         OPT_CFLAGS += -g
   398       else
   399         OPT_CFLAGS += -gstabs
   400       endif
   401     endif
   402   endif
   403 endif
   405 # If we are building HEADLESS, pass on to VM
   406 # so it can set the java.awt.headless property
   407 ifdef HEADLESS
   408 CFLAGS += -DHEADLESS
   409 endif
   411 # We are building Embedded for a small device
   412 # favor code space over speed
   413 ifdef MINIMIZE_RAM_USAGE
   414 CFLAGS += -DMINIMIZE_RAM_USAGE
   415 endif
   417 # Stack walking in the JVM relies on frame pointer (%rbp) to walk thread stack.
   418 # Explicitly specify -fno-omit-frame-pointer because it is off by default
   419 # starting with gcc 4.6.
   420 ifndef USE_SUNCC
   421   CFLAGS += -fno-omit-frame-pointer
   422 endif

mercurial