Formatting improvements.
[oota-llvm.git] / Makefile.rules
index cebf2d8d38c8b5dea8f57b752ec66e2f78702113..685569a702d8d94d5b0572fe6abfb92bef6b6a88 100644 (file)
@@ -2,8 +2,8 @@
 #
 #                     The LLVM Compiler Infrastructure
 #
-# This file was developed by the LLVM research group and is distributed under
-# the University of Illinois Open Source License. See LICENSE.TXT for details.
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
 # 
 #===------------------------------------------------------------------------===#
 #
@@ -23,7 +23,7 @@ RecursiveTargets := all clean clean-all install uninstall install-bytecode
 LocalTargets     := all-local clean-local clean-all-local check-local \
                     install-local printvars uninstall-local \
                    install-bytecode-local
-TopLevelTargets  := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
+TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
                     dist-zip
 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
 InternalTargets  := preconditions distdir dist-hook
@@ -175,7 +175,7 @@ $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
             $(MKDIR) $(@D) ; \
             $(CP) -f $< $@ ;; \
        esac
-         
+
 endif
 
 #------------------------------------------------------------------------
@@ -210,9 +210,9 @@ endif
 
 ifdef ENABLE_PROFILING
   BuildMode := Profile
-  CXX.Flags := $(OPTIMIZE_OPTION) -pg -g
-  C.Flags   := $(OPTIMIZE_OPTION) -pg -g
-  LD.Flags  := $(OPTIMIZE_OPTION) -pg -g
+  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)
@@ -229,14 +229,14 @@ else
       EXTRA_OPTIONS += -fstrict-aliasing
     endif
 
-    CXX.Flags := $(OPTIMIZE_OPTION) $(OmitFramePointer)
-    C.Flags   := $(OPTIMIZE_OPTION) $(OmitFramePointer)
-    LD.Flags  := $(OPTIMIZE_OPTION)
+    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
+    CXX.Flags += -g
+    C.Flags   += -g
+    LD.Flags  += -g
     KEEP_SYMBOLS := 1
   endif
 endif
@@ -454,12 +454,11 @@ endif
 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir) 
 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
 # All -I flags should go here, so that they don't confuse llvm-config.
-CPP.Flags     += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
-                -I$(PROJ_OBJ_ROOT)/include \
-                -I$(PROJ_SRC_ROOT)/include \
-                -I$(LLVM_OBJ_ROOT)/include \
-                -I$(LLVM_SRC_ROOT)/include \
-                $(CPP.BaseFlags)
+CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
+                $(patsubst %,-I%/include,\
+                $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
+                $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
+                $(CPP.BaseFlags)
 
 Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
@@ -483,8 +482,14 @@ LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
 ScriptInstall = $(INSTALL) -m 0755 
 DataInstall   = $(INSTALL) -m 0644
-TableGen      = $(TBLGEN) -I $(PROJ_SRC_DIR) -I$(PROJ_SRC_ROOT)/include \
-                -I $(PROJ_SRC_ROOT)/lib/Target      
+
+# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
+# paths. In this case, the SYSPATH function (defined in
+# Makefile.config) transforms Unix paths into Windows paths.
+TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
+                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
+                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
+
 Archive       = $(AR) $(AR.Flags)
 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
 ifdef RANLIB
@@ -696,7 +701,7 @@ ifdef LINK_COMPONENTS
 $(LLVM_CONFIG):
        @echo "*** llvm-config doesn't exist - rebuilding it."
        @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
-        
+
 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
 
 ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
@@ -723,7 +728,7 @@ $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
 else
 
 Module     := $(LibDir)/$(MODULE_NAME).bc
-LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir)
+LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
 
 
 ifdef EXPORTED_SYMBOL_FILE
@@ -800,7 +805,7 @@ SharedLibKindMessage := "Loadable Module"
 else
 SharedLibKindMessage := "Shared Library"
 endif
-$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
+$(LibName.LA): $(ObjectsLO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
        $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
          $(LIBRARYNAME)$(SHLIBEXT)
        $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
@@ -1079,23 +1084,28 @@ ifndef DISABLE_AUTO_DEPENDENCIES
 # Create .lo files in the ObjDir directory from the .cpp and .c files...
 #---------------------------------------------------------
 
+DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
+         -MT "$(ObjDir)/$*.lo" -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
+
+# If the build succeeded, move the dependency file over.  If it failed, put an
+# empty file there.
+DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
+                  else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
+
 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
        $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
-       $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
-         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
-         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
+       $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
+               $(DEPEND_MOVEFILE)
 
 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
        $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
-       $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
-       then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
-       else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
+       $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
+               $(DEPEND_MOVEFILE)
 
 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
        $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
-       $(Verb) if $(MAYBE_PIC_Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
-       then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
-       else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
+       $(Verb) if $(MAYBE_PIC_Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
+               $(DEPEND_MOVEFILE)
 
 #---------------------------------------------------------
 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
@@ -1243,57 +1253,57 @@ $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) register names with tblgen"
-       $(Verb) $(TableGen) -gen-register-enums -o $@ $<
+       $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) register information header with tblgen"
-       $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
+       $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) register info implementation with tblgen"
-       $(Verb) $(TableGen) -gen-register-desc -o $@ $<
+       $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) instruction names with tblgen"
-       $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
+       $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) instruction information with tblgen"
-       $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
+       $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) assembly writer with tblgen"
-       $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
+       $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) assembly writer #1 with tblgen"
-       $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
+       $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $< 
 
 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) code emitter with tblgen"
-       $(Verb) $(TableGen) -gen-emitter -o $@ $<
+       $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) instruction selector implementation with tblgen"
-       $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
+       $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) subtarget information with tblgen"
-       $(Verb) $(TableGen) -gen-subtarget -o $@ $<
+       $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) calling convention information with tblgen"
-       $(Verb) $(TableGen) -gen-callingconv -o $@ $<
+       $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
 
 clean-local::
        -$(Verb) $(RM) -f $(INCFiles)
@@ -1332,8 +1342,8 @@ $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
        $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
        $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
          > $(PROJ_SRC_DIR)/$*.cpp
-    
-# IFF the .l file has changed since it was last checked into CVS, copy the .l
+
+# IFF the .l file has changed since it was last checked into SVN, copy the .l
 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
 # so that people without flex can build LLVM by copying the .cvs files to the 
 # source location and building them.
@@ -1375,7 +1385,7 @@ $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
        $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
        $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
 
-# IFF the .y file has changed since it was last checked into CVS, copy the .y
+# IFF the .y file has changed since it was last checked into SVN, copy the .y
 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
 # mechanism so that people without flex can build LLVM by copying the .cvs files
 # to the source location and building them.
@@ -1439,25 +1449,6 @@ endif
 clean-all-local::
        -$(Verb) $(RM) -rf Debug Release Profile
 
-# Build tags database for Emacs/Xemacs:
-tags:: TAGS CTAGS
-
-TAGS: 
-       find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
-          $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
-          $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
-          $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
-        -name '*.cpp' -o -name '*.h' | \
-        $(ETAGS) $(ETAGSFLAGS) -
-
-CTAGS:
-       find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
-          $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
-          $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
-          $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
-          \( -name '*.cpp' -o -name '*.h' \) -print | \
-          ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
-
 
 ###############################################################################
 # DEPENDENCIES: Include the dependency files if we should
@@ -1465,7 +1456,7 @@ CTAGS:
 ifndef DISABLE_AUTO_DEPENDENCIES
 
 # If its not one of the cleaning targets
-ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS)))),)
+ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
 
 # Get the list of dependency files
 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))