blob: 9beed809efb6139e5219193c95391ed0262d4073 [file] [log] [blame]
#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
#
# 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 included by all of the LLVM makefiles. For details on how to use
# it properly, please see the document MakefileGuide.html in the docs directory.
#
#===-----------------------------------------------------------------------====#
include $(LLVM_TOP)/support/make/Makefile.common
###############################################################################
# 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
ifndef DISABLE_AUTO_DEPENDENCIES
#---------------------------------------------------------
# Create .lo files in the ObjDir directory from the .cpp and .c files...
#---------------------------------------------------------
$(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
$(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
$(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
#---------------------------------------------------------
# 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)"
$(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)"
$(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)"
$(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
else
$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
$(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
$(MAYBE_PIC_Compile.CXX) $< -o $@
$(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)"
$(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)"
$(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)"
$(BCCompile.C) $< -o $@ -S -emit-llvm
$(call UPGRADE_MSG,@)
$(call UPGRADE_LL,@)
endif
## 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
# make the C and C++ compilers strip debug info out of bytecode libraries.
ifdef DEBUG_RUNTIME
$(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
else
$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
$(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
$(Verb) $(LLVMAS) $< -o - | \
$(LOPT) -std-compile-opts -strip-debug -o $@ -f
endif
#---------------------------------------------------------
# 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
###############################################################################
ifdef TARGET
TDFiles := $(strip $(wildcard $(SRC_DIR)/*.td) \
$(LLVM_TOP)/llvm/lib/Target/Target.td \
$(LLVM_TOP)/llvm/lib/Target/TargetCallingConv.td \
$(LLVM_TOP)/llvm/lib/Target/TargetSelectionDAG.td \
$(LLVM_TOP)/llvm/include/llvm/CodeGen/ValueTypes.td) \
$(wildcard $(LLVM_TOP)/llvm/include/llvm/Intrinsics*.td)
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
# 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
$(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 $@ $<
$(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 $@ $<
$(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 $@ $<
$(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 $@ $<
$(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 $@ $<
$(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 $@ $<
$(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 $@ $<
$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
$(Echo) "Building $(<F) code emitter with tblgen"
$(Verb) $(TableGen) -gen-emitter -o $@ $<
$(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 $@ $<
$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
$(Echo) "Building $(<F) subtarget information with tblgen"
$(Verb) $(TableGen) -gen-subtarget -o $@ $<
$(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 $@ $<
clean-local::
-$(Verb) $(RM) -f $(INCFiles)
endif
###############################################################################
# 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),)
# Cancel built-in rules for lex
%.c: %.l
%.cpp: %.l
all:: $(LexFiles:%.l=$(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] )
$(SRC_DIR)/%.cpp: $(SRC_DIR)/%.l
$(Echo) Flexing $*.l
$(Verb) $(FLEX) -t $(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)/' \
> $(SRC_DIR)/$*.cpp
# IFF the .l file has changed since it was last checked into CVS, 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=$(SRC_DIR)/%.cpp.cvs): \
$(SRC_DIR)/%.cpp.cvs: $(SRC_DIR)/%.cpp
$(Verb) $(CMP) -s $(SRC_DIR)/$*.l $(SRC_DIR)/$*.l.cvs || \
($(CP) $< $@; $(CP) $(SRC_DIR)/$*.l $(SRC_DIR)/$*.l.cvs)
$(LexFiles:%.l=$(ObjDir)/%.o) : \
$(ObjDir)/%.o : $(SRC_DIR)/%.cpp
clean-local::
-$(Verb) $(RM) -f $(LexOutput)
endif
#---------------------------------------------------------
# Provide rules for generating a .cpp and .h source files
# from yacc (bison) input sources.
#---------------------------------------------------------
YaccFiles := $(filter %.y,$(Sources))
ifneq ($(YaccFiles),)
.PRECIOUS: $(YaccOutput)
all:: $(YaccFiles:%.y=$(SRC_DIR)/%.cpp.cvs)
# Cancel built-in rules for yacc
%.c: %.y
%.cpp: %.y
%.h: %.y
# Rule for building the bison based parsers...
ifneq ($(BISON),)
$(SRC_DIR)/%.cpp $(SRC_DIR)/%.h : $(SRC_DIR)/%.y
$(Echo) "Bisoning $*.y"
$(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
$(Verb) $(MV) -f $*.tab.c $(SRC_DIR)/$*.cpp
$(Verb) $(MV) -f $*.tab.h $(SRC_DIR)/$*.h
# IFF the .y file has changed since it was last checked into CVS, 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=$(SRC_DIR)/%.cpp.cvs): \
$(SRC_DIR)/%.cpp.cvs: $(SRC_DIR)/%.cpp
$(Verb) $(CMP) -s $(SRC_DIR)/$*.y $(SRC_DIR)/$*.y.cvs || \
($(CP) $< $@; \
$(CP) $(SRC_DIR)/$*.y $(SRC_DIR)/$*.y.cvs; \
$(CP) $(SRC_DIR)/$*.h $(SRC_DIR)/$*.h.cvs)
else
$(SRC_DIR)/%.cpp : $(SRC_DIR)/%.cpp.cvs
$(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .cpp.cvs"
$(Verb)$(CP) $(SRC_DIR)/$*.cpp.cvs $(SRC_DIR)/$*.cpp
$(SRC_DIR)/%.h : $(SRC_DIR)/%.h.cvs
$(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .h.cvs"
$(Verb)$(CP) $(SRC_DIR)/$*.h.cvs $(SRC_DIR)/$*.h
endif
$(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(SRC_DIR)/%.cpp
YaccOutput := $(YaccFiles:%.y=%.output)
clean-local::
-$(Verb) $(RM) -f $(YaccOutput)
endif
###############################################################################
# OTHER RULES: Other rules needed
###############################################################################
# To create postscript files from dot files...
ifneq ($(DOT),false)
%.ps: %.dot
$(DOT) -Tps < $< > $@
else
%.ps: %.dot
$(Echo) "Cannot build $@: The program dot is not installed"
endif
# 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.
%.h:: ;
%.hpp:: ;
# 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.
clean-local::
ifneq ($(strip $(ObjDir)),)
-$(Verb) $(RM) -rf $(ObjDir)
endif
-$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
-$(Verb) $(RM) -f *$(SHLIBEXT)
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
###############################################################################
ifndef DISABLE_AUTO_DEPENDENCIES
# If its not one of the cleaning targets
ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS)))),)
# Get the list of dependency files
DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
-include /dev/null $(DependFiles)
endif
endif