Skip to content
Makefile.rules 38.1 KiB
Newer Older
#===-- 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.
# 
#===------------------------------------------------------------------------===#
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

# Set the VPATH so that we can find source files.
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
#--------------------------------------------------------------------
RECURSIVE_TARGETS := all clean check install uninstall
Reid Spencer's avatar
Reid Spencer committed
LOCAL_TARGETS     := all-local clean-local check-local install-local \
	             printvars uninstall-local
Reid Spencer's avatar
Reid Spencer committed
TOPLEV_TARGETS    := dist dist-check dist-clean tags
Reid Spencer's avatar
Reid Spencer committed
USER_TARGETS      := $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOPLEV_TARGETS)
Reid Spencer's avatar
Reid Spencer committed
INTERNAL_TARGETS  := preconditions \
  install-config-dir install-shared-library install-bytecode-library \
  install-archive-library install-relinked-library install-tool \
  uninstall-config-dir uninstall-shared-library uninstall-bytecode-library \
  uninstall-archive-library uninstall-relinked-library uninstall-tool
Reid Spencer's avatar
Reid Spencer committed
###############################################################################
# INITIALIZATION: Basic things the makefile needs
###############################################################################

#--------------------------------------------------------------------
# Reset the list of suffixes we know how to build
#--------------------------------------------------------------------
.SUFFIXES:
.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)

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

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

SRCMKFILES    := $(wildcard $(BUILD_SRC_DIR)/Makefile*)
OBJMKFILES    := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SRCMKFILES))
CONFIGURE     := $(LLVM_SRC_ROOT)/configure
CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
MAKE_CONFIG_IN:= $(LLVM_SRC_ROOT)/Makefile.config.in
MAKE_CONFIG   := $(LLVM_OBJ_ROOT)/Makefile.config
PRECONDITIONS := $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILES)

preconditions : $(PRECONDITIONS)

#------------------------------------------------------------------------
# Make sure the BUILT_SOURCES are built first
#------------------------------------------------------------------------
$(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)

clean-local::
ifneq ($(strip $(BUILT_SOURCES)),)
	$(VERB) $(RM) -f $(BUILT_SOURCES)
endif

#------------------------------------------------------------------------
# Make sure we're not using a stale configuration
#------------------------------------------------------------------------
.PRECIOUS: $(CONFIG_STATUS)
$(CONFIG_STATUS): $(CONFIGURE)
	@$(ECHO) Reconfiguring with $<
	$(VERB) $(CONFIG_STATUS) --recheck $(CONFIGUREFLAGS)

#------------------------------------------------------------------------
# Make sure the configuration makefile is up to date
#------------------------------------------------------------------------
$(MAKE_CONFIG): $(MAKE_CONFIG_IN) $(CONFIG_STATUS)
	@$(ECHO) Regenerating $@
	$(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config

#------------------------------------------------------------------------
# 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
#------------------------------------------------------------------------
ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))

$(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
	@$(ECHO) "Updating Makefile"
	$(VERB) $(MKDIR) $(@D)
	$(VERB) cp -f $< $@
	$(VERB) $(MAKE) $(MAKECMDGOALS)

# 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.
ifneq ($(BUILD_OBJ_DIR),$(BUILD_OBJ_ROOT))
$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
	@$(ECHO) "Updating $(@F)"
	$(VERB) $(MKDIR) $(@D)
	$(VERB) cp -f $< $@
	$(VERB) $(MAKE) $(MAKECMDGOALS)
endif
endif
Reid Spencer's avatar
Reid Spencer committed
#------------------------------------------------------------------------
# Set up the basic dependencies
#------------------------------------------------------------------------
$(USER_TARGETS):: $(PRECONDITIONS)

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

###############################################################################
# VARIABLES: Set up various variables based on configuration data
###############################################################################
Chris Lattner's avatar
Chris Lattner committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Variables derived from configuration we are building
Chris Lattner's avatar
Chris Lattner committed
#--------------------------------------------------------------------

ifdef ENABLE_PROFILING
  CONFIGURATION := Profile
  CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
  CFLAGS   += -O3 -DNDEBUG -pg
  LDFLAGS  += -O3 -DNDEBUG -pg 
else
  ifdef ENABLE_OPTIMIZED
    CONFIGURATION := Release
    CXXFLAGS  += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
    CFLAGS    += -O3 -DNDEBUG -fomit-frame-pointer
    LDFLAGS   += -O3 -DNDEBUG 
    CXXFLAGS += -g -D_DEBUG 
    CFLAGS   += -g -D_DEBUG
    LDFLAGS  += -g -D_DEBUG 
    KEEP_SYMBOLS := 1
Reid Spencer's avatar
Reid Spencer committed

#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
OBJDIR      := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
LIBDIR      := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
TOOLDIR     := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
LLVMLIBDIR  := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
# Full Paths To Compiled Tools and Utilities
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
LLVMAS   := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
BURG     := $(LLVMTOOLDIR)/burg$(EXEEXT)
TBLGEN   := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
GCCLD    := $(LLVMTOOLDIR)/gccld$(EXEEXT)
LLVMGCC  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
LLVMGXX  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++

# Need a better way to compute this.
LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/

Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
#--------------------------------------------------------------------
Reid Spencer's avatar
Reid Spencer committed
# Adjust LIBTOOL options for shared libraries, or not.
  LIBTOOL += --tag=disable-shared
else
  LDFLAGS += -rpath $(LIBDIR)
Reid Spencer's avatar
Reid Spencer committed
# Adjust settings for verbose mode
Loading
Loading full blame...