Expand divisions into libcalls
[oota-llvm.git] / Makefile.rules
index 9b8a84f304c80c52a9952c1e73e4dc24ef0d91bf..6658edce0471aafc4c38a9ba89434388f0b486d2 100644 (file)
@@ -229,43 +229,46 @@ endif
 CPP.Defines :=
 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
 # this can be overridden on the make command line.
-ifneq ($(OS),MingW)
-  OPTIMIZE_OPTION := -O3
-else
-  OPTIMIZE_OPTION := -O2
+ifndef OPTIMIZE_OPTION
+  ifneq ($(OS),MingW)
+    OPTIMIZE_OPTION := -O3
+  else
+    OPTIMIZE_OPTION := -O2
+  endif
 endif
 
-ifdef ENABLE_PROFILING
-  BuildMode := Profile
-  CXX.Flags += $(OPTIMIZE_OPTION) -pg -g
-  C.Flags   += $(OPTIMIZE_OPTION) -pg -g
-  LD.Flags  += $(OPTIMIZE_OPTION) -pg -g
-  KEEP_SYMBOLS := 1
-else
-  ifeq ($(ENABLE_OPTIMIZED),1)
-    BuildMode := Release
-    # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
-    ifneq ($(OS),FreeBSD)
-    ifneq ($(OS),Darwin)
-      OmitFramePointer := -fomit-frame-pointer
-    endif
-    endif
+ifeq ($(ENABLE_OPTIMIZED),1)
+  BuildMode := Release
+  # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
+  ifneq ($(OS),FreeBSD)
+  ifneq ($(OS),Darwin)
+    OmitFramePointer := -fomit-frame-pointer
+  endif
+  endif
 
-    # Darwin requires -fstrict-aliasing to be explicitly enabled.
-    ifeq ($(OS),Darwin)
-      EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
-    endif
+  # Darwin requires -fstrict-aliasing to be explicitly enabled.
+  # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
+  # with -fstrict-aliasing and ipa-type-escape radr://6756684
+  #ifeq ($(OS),Darwin)
+  #  EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
+  #endif
+  CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
+  C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
+  LD.Flags  += $(OPTIMIZE_OPTION)
+else
+  BuildMode := Debug
+  CXX.Flags += -g
+  C.Flags   += -g
+  LD.Flags  += -g
+  KEEP_SYMBOLS := 1
+endif
 
-    CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
-    C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
-    LD.Flags  += $(OPTIMIZE_OPTION)
-  else
-    BuildMode := Debug
-    CXX.Flags += -g
-    C.Flags   += -g
-    LD.Flags  += -g
-    KEEP_SYMBOLS := 1
-  endif
+ifeq ($(ENABLE_PROFILING),1)
+  BuildMode := $(BuildMode)+Profile
+  CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
+  C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
+  LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
+  KEEP_SYMBOLS := 1
 endif
 
 #ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
@@ -282,9 +285,18 @@ ifndef REQUIRES_RTTI
 #  CXX.Flags += -fno-rtti
 endif
 
+ifdef ENABLE_COVERAGE
+  BuildMode := $(BuildMode)+Coverage
+  # These only go to .NoRelink because otherwise we will end up
+  # linking -lgcov into the .o libraries that get built.
+  CXX.Flags.NoRelink += -ftest-coverage -fprofile-arcs
+  C.Flags.NoRelink   += -ftest-coverage -fprofile-arcs
+endif
+
 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
 # then disable assertions by defining the appropriate preprocessor symbols.
 ifdef DISABLE_ASSERTIONS
+  # Indicate that assertions are turned off using a minus sign
   BuildMode := $(BuildMode)-Asserts
   CPP.Defines += -DNDEBUG
 else
@@ -420,6 +432,26 @@ endif
 # Adjust to user's request
 #--------------------------------------------------------------------
 
+ifeq ($(OS),Darwin)
+  DARWIN_VERSION := `sw_vers -productVersion`
+  # Strip a number like 10.4.7 to 10.4
+  DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
+  # Get "4" out of 10.4 for later pieces in the makefile.
+  DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
+
+  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
+                    -dynamiclib -mmacosx-version-min=$(DARWIN_VERSION)
+  TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
+else
+  ifeq ($(OS),Cygwin)
+    SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
+                      -Wl,--enable-auto-import -Wl,--enable-auto-image-base \
+                      -Wl,--enable-runtime-pseudo-relocs
+  else
+    SharedLinkOptions=-shared
+  endif
+endif
+
 # Adjust LD.Flags depending on the kind of library that is to be built. Note
 # that if LOADABLE_MODULE is specified then the resulting shared library can
 # be opened with dlopen.
@@ -428,8 +460,10 @@ ifdef LOADABLE_MODULE
 endif
 
 ifdef SHARED_LIBRARY
+ifneq ($(DARWIN_MAJVERS),4)
   LD.Flags += $(RPATH) -Wl,$(LibDir)
 endif
+endif
 
 ifdef TOOL_VERBOSE
   C.Flags += -v
@@ -456,6 +490,7 @@ endif
 
 # Adjust linker flags for building an executable
 ifneq ($(OS),Darwin)
+ifneq ($(DARWIN_MAJVERS),4)
 ifdef TOOLNAME
 ifdef EXAMPLE_TOOL
   LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
@@ -464,20 +499,6 @@ else
 endif
 endif
 endif
-
-ifeq ($(OS),Darwin)
-  DARWIN_VERSION := `sw_vers -productVersion`
-  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress -bundle \
-                    -mmacosx-version-min=$(DARWIN_VERSION)
-  CompileCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
-else
-  ifeq ($(OS),Cygwin)
-    SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
-                      -Wl,--enable-auto-import -Wl,--enable-auto-image-base \
-                      -Wl,--enable-runtime-pseudo-relocs
-  else
-    SharedLinkOptions=-shared
-  endif
 endif
 
 #----------------------------------------------------------
@@ -516,6 +537,16 @@ ifdef UNIVERSAL
 
   # Building universal cannot compute dependencies automatically.
   DISABLE_AUTO_DEPENDENCIES=1
+else
+  ifeq ($(OS),Darwin)
+    ifeq ($(ARCH),x86_64)
+      TargetCommonOpts = -m64
+    else
+      ifeq ($(ARCH),x86)
+        TargetCommonOpts = -m32
+      endif
+    endif
+  endif
 endif
 
 ifeq ($(OS),SunOS)
@@ -531,29 +562,37 @@ CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
                 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
                 $(CPP.BaseFlags)
 
- ifeq ($(BUILD_COMPONENT), 1)
-  Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
-  Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
-  Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
-  Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
-                  $(LD.Flags) $(Strip)
-  Relink        = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
-                 $(Relink.Flags)
+ifeq ($(BUILD_COMPONENT), 1)
+  Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(C.Flags.NoRelink) \
+                  $(TargetCommonOpts) $(CompileCommonOpts) -c
+  Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+                  $(TargetCommonOpts) $(CompileCommonOpts) -c
+  Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(TargetCommonOpts) \
+                  $(CompileCommonOpts) $(CXX.Flags) $(CXX.Flags.NoRelink) -E
+  Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+                  $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
+  Relink        = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) \
+                  $(CompileCommonOpts) $(Relink.Flags)
 else
-  Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
-  Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
-  Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
-  Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
-                  $(LD.Flags) $(Strip)
-  Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
-                 $(Relink.Flags)
-endif
-
-BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
-Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
+  Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(C.Flags.NoRelink) \
+                  $(TargetCommonOpts) $(CompileCommonOpts) -c
+  Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+                  $(TargetCommonOpts) $(CompileCommonOpts) -c
+  Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) \
+                  $(CompileCommonOpts) $(CXX.Flags) $(CXX.Flags.NoRelink) -E
+  Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
+                  $(TargetCommonOpts)  $(CompileCommonOpts) $(LD.Flags) $(Strip)
+  Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(TargetCommonOpts) \
+                  $(CompileCommonOpts) $(Relink.Flags)
+endif
+
+BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) \
+                $(TargetCommonOpts) $(CompileCommonOpts)
+Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) \
+                $(TargetCommonOpts) $(CompileCommonOpts) -E
 
 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
-                $(CompileCommonOpts)
+                $(TargetCommonOpts) $(CompileCommonOpts)
 
 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
 ScriptInstall = $(INSTALL) -m 0755
@@ -1103,8 +1142,12 @@ endif
 # startup time by 4x on darwin in some cases.
 ifdef TOOL_NO_EXPORTS
 ifeq ($(OS),Darwin)
+
+# Tiger tools don't support this.
+ifneq ($(DARWIN_MAJVERS),4)
 LD.Flags += -Wl,-exported_symbol -Wl,_main
 endif
+endif
 
 ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
@@ -1327,9 +1370,6 @@ INCFiles := $(filter %.inc,$(BUILT_SOURCES))
 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
 
-# All of these files depend on tblgen and the .td files.
-$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
-
 # INCFiles rule: All of the tblgen generated files are emitted to
 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
 # us to only "touch" the real file if the contents of it change.  IOW, if
@@ -1351,6 +1391,9 @@ TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
 
+# All of these files depend on tblgen and the .td files.
+$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
+
 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) register names with tblgen"
@@ -1423,7 +1466,8 @@ endif # TARGET
 
 ifdef LLVMC_BUILD_AUTOGENERATED_INC
 
-LLVMCPluginSrc := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td))
+LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
+       $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
 
 TDFiles := $(LLVMCPluginSrc) \
        $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
@@ -1435,7 +1479,6 @@ $(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
 
 endif # LLVMC_BUILD_AUTOGENERATED_INC
 
-
 ###############################################################################
 # OTHER RULES: Other rules needed
 ###############################################################################