Skip to content
Makefile.rules 62.8 KiB
Newer Older
	$(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
#---------------------------------------------------------
# Archive Library Targets:
#   If the user wanted a regular archive library built, 
#   then we provide targets for building them.
#---------------------------------------------------------
$(LibName.A): $(ObjectsO) $(LibDir)/.dir
	$(Echo) Building $(BuildMode) Archive Library $(notdir $@)
	$(Verb) $(Archive) $@ $(ObjectsO)
	$(Verb) $(Ranlib) $@
Reid Spencer's avatar
Reid Spencer committed
clean-local::
ifdef NO_INSTALL
install-local::
	$(Echo) Install circumvented with NO_INSTALL
uninstall-local::
	$(Echo) Uninstall circumvented with NO_INSTALL
else
Reid Spencer's avatar
Reid Spencer committed
DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
install-local:: $(DestArchiveLib)
Reid Spencer's avatar
Reid Spencer committed
$(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
	$(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(MKDIR) $(PROJ_libdir)
	$(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
	$(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Chris Lattner's avatar
Chris Lattner committed
endif

Reid Spencer's avatar
Reid Spencer committed
# endif LIBRARYNAME
###############################################################################
# Tool Build Rules: Build executable tool based on TOOLNAME option
###############################################################################

#---------------------------------------------------------
# Set up variables for building a tool.
#---------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifdef EXAMPLE_TOOL
ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer's avatar
Reid Spencer committed
else
ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer's avatar
Reid Spencer committed
endif
#---------------------------------------------------------
# Provide targets for building the tools
#---------------------------------------------------------
all-local:: $(ToolBuildPath)
Reid Spencer's avatar
Reid Spencer committed
clean-local::
Reid Spencer's avatar
Reid Spencer committed
endif
Reid Spencer's avatar
Reid Spencer committed
ifdef EXAMPLE_TOOL
$(ToolBuildPath): $(ExmplDir)/.dir
else
$(ToolBuildPath): $(ToolDir)/.dir
endif

Chris Lattner's avatar
Chris Lattner committed
$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
	$(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
	$(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattner's avatar
Chris Lattner committed
	$(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
          $(StripWarnMsg) 
ifdef NO_INSTALL
install-local::
	$(Echo) Install circumvented with NO_INSTALL
uninstall-local::
	$(Echo) Uninstall circumvented with NO_INSTALL
else
Reid Spencer's avatar
Reid Spencer committed
DestTool = $(PROJ_bindir)/$(TOOLNAME)
Reid Spencer's avatar
Reid Spencer committed
$(DestTool): $(PROJ_bindir) $(ToolBuildPath)
	$(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
	$(Echo) Uninstalling $(BuildMode) $(DestTool)
###############################################################################
# Object Build Rules: Build object files based on sources 
###############################################################################

# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
ifeq ($(OS),HP-UX)
  DISABLE_AUTO_DEPENDENCIES=1
endif

ifdef SHARED_LIBRARY
PIC_FLAG = "(PIC)"
MAYBE_PIC_Compile.CXX = $(LTCompile.CXX)
MAYBE_PIC_Compile.C = $(LTCompile.C)
else
MAYBE_PIC_Compile.CXX = $(Compile.CXX)
MAYBE_PIC_Compile.C = $(Compile.C)
endif

# Provide rule sets for when dependency generation is enabled
#---------------------------------------------------------
# Create .lo files in the ObjDir directory from the .cpp and .c files...
#---------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed

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) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
	        $(DEPEND_MOVEFILE)
Reid Spencer's avatar
Reid Spencer committed

$(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
	$(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) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
	        $(DEPEND_MOVEFILE)
Reid Spencer's avatar
Reid Spencer committed

#---------------------------------------------------------
# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
#---------------------------------------------------------
$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
	$(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
                              $< -o $@ -S -emit-llvm ; \
	then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
	else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
	$(call UPGRADE_MSG,$@) 
	$(call UPGRADE_LL,$@)
$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
	$(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
                              $< -o $@ -S -emit-llvm ; \
	then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
	else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
	$(call UPGRADE_MSG,$@) 
	$(call UPGRADE_LL,$@)
$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
	$(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
                            $< -o $@ -S -emit-llvm ; \
	then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
	else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
	$(call UPGRADE_MSG,$@) 
	$(call UPGRADE_LL,$@)

# Provide alternate rule sets if dependencies are disabled
$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.CXX) $< -o $@ 
Reid Spencer's avatar
Reid Spencer committed

$(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.CXX) $< -o $@ 
$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.C) $< -o $@ 
$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
	$(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(BCCompile.CXX) $< -o $@ -S -emit-llvm
	$(call UPGRADE_MSG,$@) 
	$(call UPGRADE_LL,$@)
$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
	$(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(BCCompile.CXX) $< -o $@ -S -emit-llvm
	$(call UPGRADE_MSG,$@) 
	$(call UPGRADE_LL,$@)
$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
	$(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattner's avatar
Chris Lattner committed
	$(BCCompile.C) $< -o $@ -S -emit-llvm
	$(call UPGRADE_MSG,@) 
	$(call UPGRADE_LL,@)

## Rules for building preprocessed (.i/.ii) outputs.
$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
	$(Verb) $(Preprocess.CXX) $< -o $@

$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
	$(Verb) $(Preprocess.CXX) $< -o $@

$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
	$(Verb) $(Preprocess.C) $< -o $@


$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.CXX) $< -o $@ -S

$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.CXX) $< -o $@ -S

$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
	$(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
	$(MAYBE_PIC_Compile.C) $< -o $@ -S

Chris Lattner's avatar
Chris Lattner committed
# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer's avatar
Reid Spencer committed
$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
	$(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
	$(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
Reid Spencer's avatar
Reid Spencer committed
$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
Chris Lattner's avatar
Chris Lattner committed
	$(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(LLVMAS) $< -o - | \
	   $(LOPT) -std-compile-opts -strip-debug -o $@ -f
#---------------------------------------------------------
# Provide rule to build .bc files from .ll sources,
# regardless of dependencies
#---------------------------------------------------------
$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
	$(Echo) "Compiling $*.ll for $(BuildMode) build"
	$(Verb) $(LLVMAS) $< -f -o $@

###############################################################################
# TABLEGEN: Provide rules for running tblgen to produce *.inc files
###############################################################################
Chris Lattner's avatar
Chris Lattner committed

Chris Lattner's avatar
Chris Lattner committed
TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
           $(LLVM_SRC_ROOT)/lib/Target/Target.td \
Chris Lattner's avatar
Chris Lattner committed
           $(LLVM_SRC_ROOT)/lib/Target/TargetCallingConv.td \
           $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td \
           $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
           $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
INCFiles := $(filter %.inc,$(BUILT_SOURCES))
INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Chris Lattner's avatar
Chris Lattner committed

# All of these files depend on tblgen and the .td files.
$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Chris Lattner's avatar
Chris Lattner committed

# 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
# tblgen is modified, all of the .inc.tmp files are regereated, but no
# dependencies of the .inc files are, unless the contents of the .inc file
# changes.
$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(CMP) -s $@ $< || $(CP) $< $@

$(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 $(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 $(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 $(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 $(call SYSPATH, $@) $<
Chris Lattner's avatar
Chris Lattner committed

$(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 $(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 $(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 $(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 $(call SYSPATH, $@) $<
$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
	$(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
	$(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
	$(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
	$(Verb) $(TableGen) -gen-fast-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 $(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 $(call SYSPATH, $@) $<
Reid Spencer's avatar
Reid Spencer committed
clean-local::
###############################################################################
# LEX AND YACC: Provide rules for generating sources with lex and yacc
###############################################################################

#---------------------------------------------------------
# Provide rules for generating a .cpp source file from 
# (f)lex input sources. 
#---------------------------------------------------------

LexFiles  := $(filter %.l,$(Sources))
ifneq ($(LexFiles),)

Reid Spencer's avatar
Reid Spencer committed
# Cancel built-in rules for lex
%.c: %.l
%.cpp: %.l
all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)

# Note the extra sed filtering here, used to cut down on the warnings emited 
# by GCC.  The last line is a gross hack to work around flex aparently not 
# being able to resize the buffer on a large token input.  Currently, for 
# uninitialized string buffers in LLVM we can generate very long tokens, so 
# this is a hack around it.
# FIXME.  (f.e. char Buffer[10000] )
Reid Spencer's avatar
Reid Spencer committed
$(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
	$(SED) 's/void yyunput/inline void yyunput/' | \
	$(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
	$(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer's avatar
Reid Spencer committed
	  > $(PROJ_SRC_DIR)/$*.cpp

# 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.
$(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
$(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
	$(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs || \
      ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)

$(LexFiles:%.l=$(ObjDir)/%.o) : \
$(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
Chris Lattner's avatar
Chris Lattner committed

endif

#---------------------------------------------------------
# Provide rules for generating a .cpp and .h source files 
# from yacc (bison) input sources.
#---------------------------------------------------------

YaccFiles  := $(filter %.y,$(Sources))
ifneq ($(YaccFiles),)
Chris Lattner's avatar
Chris Lattner committed
all:: $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs)
# Cancel built-in rules for yacc
%.c: %.y 
%.cpp: %.y
%.h: %.y

Reid Spencer's avatar
Reid Spencer committed
# Rule for building the bison based parsers...
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(BISON),)
$(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
	$(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
	$(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
Chris Lattner's avatar
Chris Lattner committed

# 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.
$(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
$(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
	$(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs || \
Chris Lattner's avatar
Chris Lattner committed
       $(CP) $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs; \
       $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)

else
$(PROJ_SRC_DIR)/%.cpp : $(PROJ_SRC_DIR)/%.cpp.cvs
	$(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .cpp.cvs"
	$(Verb)$(CP) $(PROJ_SRC_DIR)/$*.cpp.cvs $(PROJ_SRC_DIR)/$*.cpp

$(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.h.cvs
	$(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .h.cvs"
	$(Verb)$(CP) $(PROJ_SRC_DIR)/$*.h.cvs $(PROJ_SRC_DIR)/$*.h
endif


$(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
YaccOutput := $(YaccFiles:%.y=%.output)
Reid Spencer's avatar
Reid Spencer committed
	-$(Verb) $(RM) -f $(YaccOutput)
Chris Lattner's avatar
Chris Lattner committed

###############################################################################
# OTHER RULES: Other rules needed
###############################################################################
Chris Lattner's avatar
Chris Lattner committed
# To create postscript files from dot files...
Chris Lattner's avatar
Chris Lattner committed
%.ps: %.dot
	$(Echo) "Cannot build $@: The program dot is not installed"
Chris Lattner's avatar
Chris Lattner committed

# This rules ensures that header files that are removed still have a rule for
# which they can be "generated."  This allows make to ignore them and
# reproduce the dependency lists.
# Define clean-local to clean the current directory. Note that this uses a
# very conservative approach ensuring that empty variables do not cause 
# errors or disastrous removal.
Reid Spencer's avatar
Reid Spencer committed
clean-local::
ifneq ($(strip $(ObjRootDir)),)
	-$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencer's avatar
Reid Spencer committed
endif
	-$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
clean-all-local::
	-$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# DEPENDENCIES: Include the dependency files if we should
###############################################################################
ifndef DISABLE_AUTO_DEPENDENCIES

Reid Spencer's avatar
Reid Spencer committed
# If its not one of the cleaning targets
ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencer's avatar
Reid Spencer committed
# Get the list of dependency files
DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
Reid Spencer's avatar
Reid Spencer committed

-include $(DependFiles) ""
###############################################################################
# CHECK: Running the test suite
###############################################################################

check::
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
	  if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
	    $(EchoCmd) Running test suite ; \
Reid Spencer's avatar
Reid Spencer committed
	    $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
	      TESTSUITE=$(TESTSUITE) ; \
	  else \
	    $(EchoCmd) No Makefile in test directory ; \
	  fi ; \
	else \
	  $(EchoCmd) No test directory ; \
	fi

Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer's avatar
Reid Spencer committed
###############################################################################

#------------------------------------------------------------------------
# Define distribution related variables
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
	       ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
	       Makefile.config.in configure autoconf
DistOther   := $(notdir $(wildcard \
Reid Spencer's avatar
Reid Spencer committed
               $(PROJ_SRC_DIR)/*.h \
               $(PROJ_SRC_DIR)/*.td \
               $(PROJ_SRC_DIR)/*.def \
               $(PROJ_SRC_DIR)/*.ll \
               $(PROJ_SRC_DIR)/*.in))
DistSources  = $(Sources) $(EXTRA_DIST)
DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
#------------------------------------------------------------------------
# We MUST build distribution with OBJ_DIR != SRC_DIR
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencer's avatar
Reid Spencer committed
dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
	$(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
#------------------------------------------------------------------------
# Prevent attempt to run dist targets from anywhere but the top level
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(LEVEL),.)
dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
#------------------------------------------------------------------------
# Provide the top level targets
#------------------------------------------------------------------------

$(DistTarGZip) : $(TopDistDir)/.makedistdir
	$(Echo) Packing gzipped distribution tar file.
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
	  $(GZIP) -c > "$(DistTarGZip)"
$(DistTarBZ2) : $(TopDistDir)/.makedistdir
	$(Echo) Packing bzipped distribution tar file.
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
	  $(BZIP2) -c >$(DistTarBZ2)
$(DistZip) : $(TopDistDir)/.makedistdir
	$(Echo) Packing zipped distribution file.
	$(Verb) rm -f $(DistZip)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)

dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
	$(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
dist-check:: $(DistTarGZip)
	$(Echo) Checking distribution tar file.
	$(Verb) if test -d $(DistCheckDir) ; then \
	$(Verb) $(MKDIR) $(DistCheckDir)
	$(Verb) cd $(DistCheckDir) && \
	  $(MKDIR) $(DistCheckDir)/build && \
	  $(MKDIR) $(DistCheckDir)/install && \
	  gunzip -c $(DistTarGZip) | $(TAR) xf - && \
	  cd build && \
	  ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
	    --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
	  $(MAKE) all && \
	  $(MAKE) check && \
	  $(MAKE) install && \
	  $(MAKE) uninstall && \
	  $(MAKE) dist-clean && \
	  $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer's avatar
Reid Spencer committed

dist-clean::
	$(Echo) Cleaning distribution files
	-$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
	  $(DistCheckDir)
#------------------------------------------------------------------------
# Provide the recursive distdir target for building the distribution directory
#------------------------------------------------------------------------
distdir: $(DistDir)/.makedistdir
$(DistDir)/.makedistdir: $(DistSources)
	$(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
	  if test -d "$(DistDir)" ; then \
	    find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
	      exit 1 ; \
	  fi ; \
	  $(EchoCmd) Removing old $(DistDir) ; \
	  $(EchoCmd) Making 'all' to verify build ; \
	  $(MAKE) ENABLE_OPTIMIZED=1 all ; \
	$(Echo) Building Distribution Directory $(DistDir)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
	srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer's avatar
Reid Spencer committed
	for file in $(DistFiles) ; do \
	  case "$$file" in \
Reid Spencer's avatar
Reid Spencer committed
	    $(PROJ_SRC_DIR)/*) \
	      file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
	      ;; \
Reid Spencer's avatar
Reid Spencer committed
	    $(PROJ_SRC_ROOT)/*) \
	      file=`echo "$$file" | \
		sed "s#^$$srcrootstrip/##"` \
	      ;; \
Reid Spencer's avatar
Reid Spencer committed
	  esac; \
Reid Spencer's avatar
Reid Spencer committed
	  if test -f "$(PROJ_SRC_DIR)/$$file" || \
	     test -d "$(PROJ_SRC_DIR)/$$file" ; then \
	    from_dir="$(PROJ_SRC_DIR)" ; \
	  elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer's avatar
Reid Spencer committed
	    from_dir=. ; \
	  fi ; \
	  to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer's avatar
Reid Spencer committed
	  if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
	    to_dir="$(DistDir)/$$dir"; \
	    $(MKDIR) "$$to_dir" ; \
	  else \
	    to_dir="$(DistDir)"; \
	  fi; \
	  mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
	  if test -n "$$mid_dir" ; then \
            $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
          fi ; \
	  if test -d "$$from_dir/$$file"; then \
Reid Spencer's avatar
Reid Spencer committed
	    if test -d "$(PROJ_SRC_DIR)/$$file" && \
	       test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
	       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) ; \
Reid Spencer's avatar
Reid Spencer committed
	    fi; \
	  elif test -f "$$from_dir/$$file" ; then \
Reid Spencer's avatar
Reid Spencer committed
	    $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	  elif test -L "$$from_dir/$$file" ; then \
Reid Spencer's avatar
Reid Spencer committed
	    $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	  elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
	    $(EchoCmd) "===== WARNING: Distribution Source " \
	      "$$from_dir/$$file Not Found!" ; \
	  elif test "$(Verb)" != '@' ; then \
	    $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer's avatar
Reid Spencer committed
	  fi; \
	done
	$(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer's avatar
Reid Spencer committed
	  if test "$$subdir" \!= "." ; then \
	    new_distdir="$(DistDir)/$$subdir" ; \
	    test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
	    ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencer's avatar
Reid Spencer committed
	      DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	  fi; \
	done
	$(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
	  $(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 {} \; \
	    -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
	    -o ! -type d ! -perm -444 -exec \
	      $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
	    || chmod -R a+r $(DistDir) ; \
	fi
# This is invoked by distdir target, define it as a no-op to avoid errors if not
# defined by user.
Reid Spencer's avatar
Reid Spencer committed
dist-hook::

endif

###############################################################################
# TOP LEVEL - targets only to apply at the top level directory
###############################################################################

ifeq ($(LEVEL),.)
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# Install support for the project's include files:
Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
ifdef NO_INSTALL
install-local::
	$(Echo) Install circumvented with NO_INSTALL
uninstall-local::
	$(Echo) Uninstall circumvented with NO_INSTALL
else
Reid Spencer's avatar
Reid Spencer committed
install-local::
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(MKDIR) $(PROJ_includedir)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencer's avatar
Reid Spencer committed
	  cd $(PROJ_SRC_ROOT)/include && \
	  for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
	      -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
	      grep -v .svn` ; do \
Reid Spencer's avatar
Reid Spencer committed
	    instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
	    if test \! -d "$$instdir" ; then \
	      $(EchoCmd) Making install directory $$instdir ; \
	      $(MKDIR) $$instdir ;\
	    fi ; \
	    $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer's avatar
Reid Spencer committed
	  for hdr in `find . -type f -print | grep -v CVS` ; do \
Reid Spencer's avatar
Reid Spencer committed
	    $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer's avatar
Reid Spencer committed
endif
Reid Spencer's avatar
Reid Spencer committed

uninstall-local::
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
	  cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer's avatar
Reid Spencer committed
	    $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattner's avatar
Chris Lattner committed
	      '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
        -o -name '*.in' ')' -print ')' | \
        grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
	  cd $(PROJ_SRC_ROOT)/include && \
Chris Lattner's avatar
Chris Lattner committed
	    $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
      -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
	@echo searching for overlength lines in files: $(Sources)
	@echo
	@echo
	egrep -n '.{81}' $(Sources) /dev/null
	@echo searching for tabs in files: $(Sources)
	@echo
	@echo
	egrep -n '	' $(Sources) /dev/null
check-footprint:
	@ls -l $(LibDir) | awk '\
	  BEGIN { sum = 0; } \
	        { sum += $$5; } \
	  END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
	@ls -l $(ToolDir) | awk '\
	  BEGIN { sum = 0; } \
	        { sum += $$5; } \
	  END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
#------------------------------------------------------------------------
# Print out the directories used for building
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
printvars::
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "BuildMode    : " '$(BuildMode)'
	$(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
	$(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
	$(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
	$(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
	$(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
	$(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
	$(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
	$(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
	$(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
	$(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
	$(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "UserTargets  : " '$(UserTargets)'
	$(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
	$(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
	$(Echo) "ObjDir       : " '$(ObjDir)'
	$(Echo) "LibDir       : " '$(LibDir)'
	$(Echo) "ToolDir      : " '$(ToolDir)'
	$(Echo) "ExmplDir     : " '$(ExmplDir)'
	$(Echo) "Sources      : " '$(Sources)'
	$(Echo) "TDFiles      : " '$(TDFiles)'
	$(Echo) "INCFiles     : " '$(INCFiles)'
	$(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
	$(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "Compile.CXX  : " '$(Compile.CXX)'
	$(Echo) "Compile.C    : " '$(Compile.C)'
	$(Echo) "Archive      : " '$(Archive)'
	$(Echo) "YaccFiles    : " '$(YaccFiles)'
	$(Echo) "LexFiles     : " '$(LexFiles)'
	$(Echo) "Module       : " '$(Module)'
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
	$(Echo) "SubDirs      : " '$(SubDirs)'
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
	$(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'