Implement BR_CC and BRTWOWAY_CC. This allows the removal of a rather nasty
[oota-llvm.git] / Makefile.rules
index 724554272a97d3063c90a1f3969156e96f75ce88..53bfa6dbd8a1409ccd4cd9b0da98e8aab6df3c1a 100644 (file)
@@ -275,6 +275,9 @@ endif
 ifndef LLI
 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
 endif
+ifndef LLC
+LLC      := $(LLVMToolDir)/llc$(EXEEXT)
+endif
 ifndef LOPT
 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
 endif
@@ -322,6 +325,7 @@ endif
 ifndef KEEP_SYMBOLS
   Strip := $(PLATFORMSTRIPOPTS)
   StripWarnMsg := "(without symbols)"
+  Install.StripFlag += -s
 endif
 
 # Adjust linker flags for building an executable
@@ -339,7 +343,11 @@ endif
 
 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
 
-LD.Flags  += -L$(LibDir) -L$(LLVMLibDir) $(LIBS)
+ifeq ($(OS),HP-UX)
+  CompileCommonOpts += -D_REENTRANT -D_HPUX_SOURCE
+endif
+
+LD.Flags  += -L$(LibDir) -L$(LLVMLibDir) 
 CPP.Flags += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
             -I$(PROJ_OBJ_ROOT)/include \
             -I$(PROJ_SRC_ROOT)/include \
@@ -359,7 +367,10 @@ Link          = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
                $(CompileCommonOpts) $(LD.Flags) $(Strip)
 Relink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
                 $(CompileCommonOpts)
-LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
+LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
+               $(Install.Flags)
+ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
+DataInstall   = $(INSTALL) -m 0644
 Burg          = $(BURG) -I $(PROJ_SRC_DIR)
 TableGen      = $(TBLGEN) -I $(PROJ_SRC_DIR)
 Archive       = $(AR) $(AR.Flags)
@@ -412,17 +423,10 @@ endif
 # in the file so they get built before dependencies
 #---------------------------------------------------------
 
-$(PROJ_bindir):
-       $(Verb) $(MKDIR) $(PROJ_bindir)
-
-$(PROJ_libdir):
-       $(Verb) $(MKDIR) $(PROJ_libdir)
-
-$(PROJ_includedir):
-       $(Verb) $(MKDIR) $(PROJ_includedir)
-
-$(PROJ_etcdir):
-       $(Verb) $(MKDIR) $(PROJ_etcdir)
+$(PROJ_bindir): $(PROJ_bindir)/.dir
+$(PROJ_libdir): $(PROJ_libdir)/.dir
+$(PROJ_includedir): $(PROJ_includedir)/.dir
+$(PROJ_etcdir): $(PROJ_etcdir)/.dir
 
 # To create other directories, as needed, and timestamp their creation
 %/.dir:
@@ -526,9 +530,9 @@ install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
        $(Echo) Installing Configuration Files To $(PROJ_etcdir)
        $(Verb)for file in $(CONFIG_FILES); do \
           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
-            $(INSTALL) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
+            $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
-            $(INSTALL) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
+            $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
           else \
             $(ECHO) Error: cannot find config file $${file}. ; \
           fi \
@@ -542,6 +546,100 @@ uninstall-local::
 
 endif
 
+###############################################################################
+# Set up variables for building libararies
+###############################################################################
+
+#---------------------------------------------------------
+# Handle the special "JIT" value for LLVM_LIBS which is a
+# shorthand for a bunch of libraries that get the correct
+# JIT support for a library or a tool that runs JIT.
+#---------------------------------------------------------
+ifeq ($(LLVMLIBS),JIT)
+
+# Make sure we can get our own symbols in the tool
+Link += -dlopen self
+
+# Generic JIT libraries
+JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
+
+# You can enable the X86 JIT on a non-X86 host by setting the flag
+# ENABLE_X86_JIT on the make command line. If not, it will still be
+# enabled automagically on an X86 host.
+ifeq ($(ARCH), x86)
+  ENABLE_X86_JIT = 1
+endif
+
+# What the X86 JIT requires
+ifdef ENABLE_X86_JIT
+  JIT_LIBS += LLVMX86 LLVMSelectionDAG
+endif
+
+# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
+# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
+# enabled automagically on an SparcV9 host.
+ifeq ($(ARCH), Sparc)
+  ENABLE_SPARCV9_JIT = 1
+endif
+
+# What the Sparc JIT requires
+ifdef ENABLE_SPARCV9_JIT
+  JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
+              LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
+              LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
+              LLVMDataStructure.a LLVMSparcV9RegAlloc
+endif
+
+# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
+# ENABLE_PPC_JIT on the make command line. If not, it will still be
+# enabled automagically on an PowerPC host.
+ifeq ($(ARCH), PowerPC)
+  ENABLE_PPC_JIT = 1
+endif
+
+# What the PowerPC JIT requires
+ifdef ENABLE_PPC_JIT
+  JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
+endif
+
+# You can enable the Alpha JIT on a non-Alpha host by setting the flag
+# ENABLE_ALPHA_JIT on the make command line. If not, it will still be
+# enabled automagically on an Alpha host.
+ifeq ($(ARCH), Alpha)
+  ENABLE_ALPHA_JIT = 1
+endif
+
+# What the Alpha JIT requires
+ifdef ENABLE_ALPHA_JIT
+  JIT_LIBS += LLVMAlpha LLVMSelectionDAG
+endif
+
+LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
+            LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
+            LLVMSystem.a $(PLATFORMLIBDL)
+endif
+
+#---------------------------------------------------------
+# Define various command line options pertaining to the
+# libraries needed when linking. There are "Proj" libs 
+# (defined by the user's project) and "LLVM" libs (defined 
+# by the # LLVM project).
+#---------------------------------------------------------
+#some versions of gcc on alpha produce to many symbols, so use a .a file
+ifeq ($(ARCH),Alpha)
+USEDLIBS :=  $(subst LLVMCore, LLVMCore.a, $(USEDLIBS))
+LLVMLIBS := $(subst LLVMCore, LLVMCore.a, $(LLVMLIBS))
+endif
+
+ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
+ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
+LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
+LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
+ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
+LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
+ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
+LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
+
 ###############################################################################
 # Library Build Rules: Four ways to build a library
 ###############################################################################
@@ -555,6 +653,9 @@ endif
 #---------------------------------------------------------
 
 ifdef MODULE_NAME
+ifeq ($(strip $(LLVMGCC)),)
+$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
+else
 
 Module     := $(LibDir)/$(MODULE_NAME).bc
 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
@@ -564,7 +665,7 @@ LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
 endif
 
 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
-       $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
+       $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
        $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
 
 all-local:: $(Module)
@@ -587,13 +688,14 @@ install-local:: $(DestModule)
 
 $(DestModule): $(ModuleDestDir) $(Module) 
        $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
-       $(Verb) $(INSTALL) $(Module) $@
+       $(Verb) $(DataInstall) $(Module) $(DestModule)
 
 uninstall-local::
        $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
        -$(Verb) $(RM) -f $(DestModule)
 
 endif
+endif
 
 # if we're building a library ...
 ifdef LIBRARYNAME
@@ -619,10 +721,18 @@ ifdef SHARED_LIBRARY
 
 all-local:: $(LibName.LA)
 
+ifdef LINK_LIBS_IN_SHARED
+$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
+       $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
+       $(Verb) $(Link) -o $@ $(ObjectsLO) \
+         $(ProjLibsOptions) $(LLVMLibsOptions)
+       $(Verb) $(LTInstall) $@ $(LibDir)
+else
 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
        $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
        $(Verb) $(Link) -o $@ $(ObjectsLO)
        $(Verb) $(LTInstall) $@ $(LibDir)
+endif
 
 clean-local::
 ifneq ($(strip $(LibName.LA)),)
@@ -651,6 +761,9 @@ endif
 #   targets for building them.
 #---------------------------------------------------------
 ifdef BYTECODE_LIBRARY
+ifeq ($(strip $(LLVMGCC)),)
+$(warning Bytecode libraries require llvm-gcc which could not be found ****)
+else
 
 # make the C and C++ compilers strip debug info out of bytecode libraries.
 BCCompile.C += -Wa,-strip-debug
@@ -697,13 +810,14 @@ install-local:: $(DestBytecodeLib)
 
 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
        $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
-       $(Verb) $(INSTALL) $(LibName.BCA) $@
+       $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
 
 uninstall-local::
        $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
        -$(Verb) $(RM) -f $(DestBytecodeLib)
 
 endif
+endif
 
 #---------------------------------------------------------
 # ReLinked Library Targets:
@@ -781,79 +895,14 @@ endif
 
 ifdef TOOLNAME
 
-#---------------------------------------------------------
-# Handle the special "JIT" value for LLVM_LIBS which is a
-# shorthand for a bunch of libraries that get the correct
-# JIT support for a tool that runs JIT.
-#---------------------------------------------------------
-ifeq ($(LLVMLIBS),JIT)
-
-# Make sure we can get our own symbols in the tool
-Link += -dlopen self
-
-# Generic JIT libraries
-JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
-
-# You can enable the X86 JIT on a non-X86 host by setting the flag
-# ENABLE_X86_JIT on the make command line. If not, it will still be
-# enabled automagically on an X86 host.
-ifeq ($(ARCH), x86)
-  ENABLE_X86_JIT = 1
-endif
-
-# What the X86 JIT requires
-ifdef ENABLE_X86_JIT
-  JIT_LIBS  += LLVMX86 LLVMSelectionDAG
-endif
-
-# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
-# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
-# enabled automagically on an SparcV9 host.
-ifeq ($(ARCH), Sparc)
-  ENABLE_SPARCV9_JIT = 1
-endif
-
-# What the Sparc JIT requires
-ifdef ENABLE_SPARCV9_JIT
-  JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
-              LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
-             LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
-             LLVMDataStructure.a LLVMSparcV9RegAlloc
-endif
-
-# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
-# ENABLE_PPC_JIT on the make command line. If not, it will still be
-# enabled automagically on an PowerPC host.
-ifeq ($(ARCH), PowerPC)
-  ENABLE_PPC_JIT = 1
-endif
-
-# What the PowerPC JIT requires
-ifdef ENABLE_PPC_JIT
-  JIT_LIBS  += LLVMPowerPC
-endif
-
-LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
-             LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
-            LLVMSystem.a $(PLATFORMLIBDL)
-endif
-
 #---------------------------------------------------------
 # Set up variables for building a tool.
 #---------------------------------------------------------
 ifdef EXAMPLE_TOOL
-ToolBuildPath   := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
+ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
 else
-ToolBuildPath   := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
+ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
 endif
-ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
-ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
-LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
-LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
-ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
-LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
-ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
-LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
 
 #---------------------------------------------------------
 # Tell make that we need to rebuild subdirectories before 
@@ -881,7 +930,7 @@ endif
 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
        $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
        $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
-          $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
+          $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
        $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg) 
 
 DestTool = $(PROJ_bindir)/$(TOOLNAME)
@@ -890,7 +939,7 @@ install-local:: $(DestTool)
 
 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
        $(Echo) Installing $(BuildMode) $(DestTool)
-       $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
+       $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
 
 uninstall-local::
        $(Echo) Uninstalling $(BuildMode) $(DestTool)
@@ -1335,7 +1384,7 @@ dist-check:: $(DistTarGZip)
          gunzip -c $(DistTarGZip) | $(TAR) xf - && \
          cd build && \
          ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
-           --srcdir=../$(DistName) && \
+           --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
          $(MAKE) all && \
          $(MAKE) check && \
          $(MAKE) install && \
@@ -1401,9 +1450,16 @@ $(DistDir)/.makedistdir: $(DistSources)
          if test -d "$$from_dir/$$file"; then \
            if test -d "$(PROJ_SRC_DIR)/$$file" && \
               test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
-             $(CP) -pR "$(PROJ_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
+              cd $(PROJ_SRC_DIR) ; \
+              $(TAR) cf - $$file --exclude .svn --exclude CVS | \
+                ( cd $$to_dir ; $(TAR) xf - ) ; \
+              cd $(PROJ_OBJ_DIR) ; \
+           else \
+              cd $$from_dir ; \
+              $(TAR) cf - $$file --exclude .svn --exclude CVS | \
+                ( cd $$to_dir ; $(TAR) xf - ) ; \
+              cd $(PROJ_OBJ_DIR) ; \
            fi; \
-           $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
          elif test -f "$$from_dir/$$file" ; then \
            $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
          elif test -L "$$from_dir/$$file" ; then \
@@ -1424,8 +1480,8 @@ $(DistDir)/.makedistdir: $(DistSources)
          fi; \
        done
        $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
-         $(EchoCmd) Eliminating CVS directories from distribution ; \
-         $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
+         $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
+         $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o -name .svn \) -print` ;\
          $(MAKE) dist-hook ; \
          $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
            -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
@@ -1453,16 +1509,23 @@ ifeq ($(LEVEL),.)
 install-local::
        $(Echo) Installing include files
        $(Verb) $(MKDIR) $(PROJ_includedir)
-       $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
+       $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
          cd $(PROJ_SRC_ROOT)/include && \
-           find . -path '*/Internal' -prune -o '(' -type f \
-             '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
-             -print ')' | grep -v CVS | pax -rwdvpe $(PROJ_includedir) ; \
+         for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
+             -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
+           instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
+           if test \! -d "$$instdir" ; then \
+             $(EchoCmd) Making install directory $$instdir ; \
+             $(MKDIR) $$instdir ;\
+           fi ; \
+           $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
+         done ; \
        fi
-       $(Verb) if [ -d "$(PROJ_OBJ_ROOT)/include" ] ; then \
-         cd $(PROJ_OBJ_ROOT)/include && ( cd $(PROJ_SRC_ROOT)/include && \
-           find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' ) \
-           | sed 's#.in$$##' | pax -rwdvpe $(PROJ_includedir) ; \
+       $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
+         cd $(PROJ_OBJ_ROOT)/include && \
+         for hdr in `find . -type f -print` ; do \
+           $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
+         done ; \
        fi
 
 uninstall-local::
@@ -1494,6 +1557,7 @@ printvars::
        $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
        $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
        $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
+       $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
        $(Echo) "UserTargets  : " '$(UserTargets)'
        $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
        $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
@@ -1505,7 +1569,7 @@ printvars::
        $(Echo) "TDFiles      : " '$(TDFiles)'
        $(Echo) "INCFiles     : " '$(INCFiles)'
        $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
-       $(Echo) "Preconditions: " '$(Preconditions)'
+       $(Echo) "PreConditions: " '$(PreConditions)'
        $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
        $(Echo) "Compile.C    : " '$(Compile.C)'
        $(Echo) "Archive      : " '$(Archive)'