Skip to content
Makefile.rules 49.5 KiB
Newer Older
$(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 $@ $<
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 $@ $<
$(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 $@ $<
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),)

LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))

.PRECIOUS: $(LexOutput)

# 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] )
Chris Lattner's avatar
Chris Lattner committed
%.cpp: %.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
	  > $@
Chris Lattner's avatar
Chris Lattner committed

	$(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),)
YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)

.PRECIOUS: $(YaccOutput)

# Cancel built-in rules for yacc
%.c: %.y 
%.cpp: %.y
%.h: %.y

Chris Lattner's avatar
Chris Lattner committed
# Rule for building the bison parsers...
%.cpp %.h : %.y
	$(Echo) "Bisoning $*.y"
	$(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
	$(Verb) $(MV) -f $*.tab.c $*.cpp
	$(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner's avatar
Chris Lattner 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::
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
# Build tags database for Emacs/Xemacs:
	find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
          $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
          $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
          $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
        -name '*.cpp' -o -name '*.h' | \
CTAGS:
	find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
          $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
          $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
          $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
          \( -name '*.cpp' -o -name '*.h' \) -print | \
          ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -


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 := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Reid Spencer's avatar
Reid Spencer committed

-include /dev/null $(DependFiles)
###############################################################################
# CHECK: Running the test suite
###############################################################################

check::
	$(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
	  if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
	    $(EchoCmd) Running test suite ; \
	    $(MAKE) -C $(BUILD_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
#------------------------------------------------------------------------
DistName    := $(LLVM_TARBALL_NAME)
DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
DistTarBZ2  := $(BUILD_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 \
               $(BUILD_SRC_DIR)/*.h \
               $(BUILD_SRC_DIR)/*.td \
               $(BUILD_SRC_DIR)/*.def \
               $(BUILD_SRC_DIR)/*.ll \
               $(BUILD_SRC_DIR)/*.in))
DistSources  = $(Sources) $(EXTRA_DIST)
DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
#------------------------------------------------------------------------
# We MUST build distribution with OBJ_DIR != SRC_DIR
#------------------------------------------------------------------------
ifeq ($(BUILD_SRC_DIR),$(BUILD_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 catastrophic remove
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifeq ($(LLVM_TARBALL_NAME),)
Chris Lattner's avatar
Chris Lattner committed
$(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
#------------------------------------------------------------------------
# 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 ::
	$(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
#------------------------------------------------------------------------
# Provide the top level targets
#------------------------------------------------------------------------

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

dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
	$(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
DistCheckDir := $(LLVM_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" \
Reid Spencer's avatar
Reid Spencer committed
	    --srcdir=../$(DistName) && \
	  $(MAKE) all && \
	  $(MAKE) check && \
	  $(MAKE) install && \
	  $(MAKE) uninstall && \
	  $(MAKE) dist && \
	  $(MAKE) clean && \
	  $(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) all ; \
	$(Echo) Building Distribution Directory $(DistDir)
	$(Verb) $(MKDIR) $(DistDir) 
	$(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
Reid Spencer's avatar
Reid Spencer committed
	srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
	for file in $(DistFiles) ; do \
	  case "$$file" in \
	    $(BUILD_SRC_DIR)/*) \
	      file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
	      ;; \
	    $(BUILD_SRC_ROOT)/*) \
	      file=`echo "$$file" | \
		sed "s#^$$srcrootstrip/##"` \
	      ;; \
Reid Spencer's avatar
Reid Spencer committed
	  esac; \
	  if test -f "$(BUILD_SRC_DIR)/$$file" || \
	     test -d "$(BUILD_SRC_DIR)/$$file" ; then \
	    from_dir="$(BUILD_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 \
	    if test -d "$(BUILD_SRC_DIR)/$$file" && \
	       test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
Reid Spencer's avatar
Reid Spencer committed
	      $(CP) -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	    fi; \
Reid Spencer's avatar
Reid Spencer committed
	    $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	  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) DistDir="$$new_distdir" distdir ) || \
	    exit 1; \
Reid Spencer's avatar
Reid Spencer committed
	  fi; \
	done
	$(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
	  $(EchoCmd) Eliminating CVS directories from distribution ; \
	  $(RM) -rf `find $(TopDistDir) -type d -name CVS -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
#------------------------------------------------------------------------
install-local::
	$(Echo) Installing include files
	$(Verb) $(MKDIR) $(includedir)
	$(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencer's avatar
Reid Spencer committed
	  cd $(BUILD_SRC_ROOT)/include && \
	    find . -path '*/Internal' -prune -o '(' -type f \
	      '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
	      -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
	fi

uninstall-local::
	$(Echo) Uninstalling include files
	$(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencer's avatar
Reid Spencer committed
	  cd $(BUILD_SRC_ROOT)/include && \
	    $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
	      '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
	      -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
	fi 

endif

#------------------------------------------------------------------------
# Print out the directories used for building
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
printvars::
	$(Echo) "BuildMode      : " '$(BuildMode)'
	$(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
	$(Echo) "BUILD_SRC_DIR  : " '$(BUILD_SRC_DIR)'
	$(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
	$(Echo) "BUILD_OBJ_DIR  : " '$(BUILD_OBJ_DIR)'
	$(Echo) "LLVM_SRC_ROOT  : " '$(LLVM_SRC_ROOT)'
	$(Echo) "LLVM_OBJ_ROOT  : " '$(LLVM_OBJ_ROOT)'
	$(Echo) "libdir         : " '$(libdir)'
	$(Echo) "bindir         : " '$(bindir)'
	$(Echo) "sysconfdir     : " '$(sysconfdir)'
	$(Echo) "UserTargets    : " '$(UserTargets)'
	$(Echo) "ObjMakefiles   : " '$(ObjMakefiles)'
	$(Echo) "SrcMakefiles   : " '$(SrcMakefiles)'
	$(Echo) "ObjDir         : " '$(ObjDir)'
	$(Echo) "LibDir         : " '$(LibDir)'
	$(Echo) "ToolDir        : " '$(ToolDir)'
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) "ExmplDir       : " '$(ExmplDir)'
	$(Echo) "Sources        : " '$(Sources)'
	$(Echo) "TDFiles        : " '$(TDFiles)'
	$(Echo) "INCFiles       : " '$(INCFiles)'
	$(Echo) "INCTMPFiles    : " '$(INCTMPFiles)'
	$(Echo) "Compile.CXX    : " '$(Compile.CXX)'
	$(Echo) "Compile.C      : " '$(Compile.C)'
	$(Echo) "Archive        : " '$(Archive)'
	$(Echo) "YaccFiles      : " '$(YaccFiles)'
	$(Echo) "LexFiles       : " '$(LexFiles)'
	$(Echo) "Module         : " '$(Module)'