Skip to content
Makefile.rules 75.6 KiB
Newer Older
#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
#
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#===------------------------------------------------------------------------===#
Chris Lattner's avatar
Chris Lattner committed
#
Reid Spencer's avatar
Reid Spencer committed
# 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.
#===-----------------------------------------------------------------------====#
Chris Lattner's avatar
Chris Lattner committed

################################################################################
Reid Spencer's avatar
Reid Spencer committed
# TARGETS: Define standard targets that can be invoked
################################################################################
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Define the various target sets
#--------------------------------------------------------------------
RecursiveTargets := all clean clean-all install uninstall install-bytecode \
                    unitcheck
LocalTargets     := all-local clean-local clean-all-local check-local \
                    install-local printvars uninstall-local \
TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
InternalTargets  := preconditions distdir dist-hook
################################################################################
Reid Spencer's avatar
Reid Spencer committed
# INITIALIZATION: Basic things the makefile needs
################################################################################

#--------------------------------------------------------------------
# Set the VPATH so that we can find source files.
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
VPATH=$(PROJ_SRC_DIR)
Reid Spencer's avatar
Reid Spencer committed

#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Reset the list of suffixes we know how to build.
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
.SUFFIXES:
.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Mark all of these targets as phony to avoid implicit rule search
#--------------------------------------------------------------------
.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Make sure all the user-target rules are double colon rules and
Reid Spencer's avatar
Reid Spencer committed
# they are defined first.
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed

################################################################################
# PRECONDITIONS: that which must be built/checked first
################################################################################

SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
Reid Spencer's avatar
Reid Spencer committed
                      $(wildcard $(PROJ_SRC_DIR)/Makefile*))
ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
ConfigureScript    := $(PROJ_SRC_ROOT)/configure
ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
ifneq ($(MakefileCommonIn),)
PreConditions      += $(MakefileCommon)
endif
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(MakefileConfigIn),)
PreConditions      += $(MakefileConfig)
endif
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
preconditions: $(PreConditions)
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# Make sure the BUILT_SOURCES are built first
#------------------------------------------------------------------------
$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer's avatar
Reid Spencer committed
endif

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
spotless:
	$(Verb) if test -x config.status ; then \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
	  $(MKDIR) .spotless.save ; \
	  $(MV) config.status .spotless.save ; \
	  $(MV) mklib  .spotless.save ; \
	  $(MV) projects  .spotless.save ; \
	  $(MV) .spotless.save/config.status . ; \
	  $(MV) .spotless.save/mklib . ; \
	  $(MV) .spotless.save/projects . ; \
	  $(RM) -rf .spotless.save ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript) ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer's avatar
Reid Spencer committed
else
spotless:
	$(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer's avatar
Reid Spencer committed

Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
# Make sure we're not using a stale configuration
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
reconfigure:
Reid Spencer's avatar
Reid Spencer committed
	$(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
	$(Verb) cd $(PROJ_OBJ_ROOT) && \
	  if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
	    $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer's avatar
Reid Spencer committed
	  fi ; \
Reid Spencer's avatar
Reid Spencer committed
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript)

$(ConfigStatusScript): $(ConfigureScript)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) && \
	  if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
	    $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer's avatar
Reid Spencer committed
	  fi ; \
	  $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
	  $(ConfigStatusScript)
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# Make sure the configuration makefile is up to date
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
ifneq ($(MakefileConfigIn),)
$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
	$(Echo) Regenerating $@
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
endif

ifneq ($(MakefileCommonIn),)
$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
endif
Reid Spencer's avatar
Reid Spencer committed

#------------------------------------------------------------------------
# If the Makefile in the source tree has been updated, copy it over into the
# build tree. But, only do this if the source and object makefiles differ
#------------------------------------------------------------------------
ifndef PROJ_MAKEFILE
PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
endif

Reid Spencer's avatar
Reid Spencer committed
ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer's avatar
Reid Spencer committed

Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
	$(Echo) "Updating Makefile"
	$(Verb) $(MKDIR) $(@D)
Reid Spencer's avatar
Reid Spencer committed
	$(Verb) $(CP) -f $< $@
Reid Spencer's avatar
Reid Spencer committed

# Copy the Makefile.* files unless we're in the root directory which avoids
# the copying of Makefile.config.in or other things that should be explicitly
# taken care of.
$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
	@case '$?' in \
          *Makefile.rules) ;; \
          *.in) ;; \
          *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencer's avatar
Reid Spencer committed
	     $(CP) -f $< $@ ;; \
Reid Spencer's avatar
Reid Spencer committed
endif
Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
# Set up the basic dependencies
#------------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed

all:: all-local
clean-all:: clean-local clean-all-local
Reid Spencer's avatar
Reid Spencer committed
install:: install-local
uninstall:: uninstall-local
install-local:: all-local
install-bytecode:: install-bytecode-local
Reid Spencer's avatar
Reid Spencer committed

###############################################################################
# LLVMC: Provide rules for compiling llvmc-based driver
Loading
Loading full blame...