llvm-6502/Makefile.rules

795 lines
27 KiB
Makefile
Raw Normal View History

#===-- 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. This file defines common
# rules to do things like compile a .cpp file or generate dependency info.
# These are platform dependent, so this is the file used to specify these
# system dependent operations.
#
# The following functionality can be set by setting incoming variables.
# The variable $(LEVEL) *must* be set:
#
# 1. LEVEL - The level of the current subdirectory from the top of the
# MagicStats view. This level should be expressed as a path, for
# example, ../.. for two levels deep.
#
# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
# so that each of the targets "all", "install", and "clean" each build
# the subdirectories before the local target. DIRS are guaranteed to be
# built in order.
#
# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
# built in any order. All DIRS are built in order before PARALLEL_DIRS are
# built, which are then built in any order.
#
# 4. Source - If specified, this sets the source code filenames. If this
# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
# in the current directory. Also, if you want to build files in addition
# to the local files, you can use the BUILT_SOURCES variable
#
# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
#
# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
# and usually the source code too (unless SourceDir is set).
#
# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
#
# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
#
# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
# placed.
#
# For building,
# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
#
#===-----------------------------------------------------------------------====
#
# Set the VPATH so that we can find source files.
#
VPATH=$(BUILD_SRC_DIR)
###########################################################################
# Default Targets:
# The following targets are the standard top level targets for
# building.
###########################################################################
# Ensure all preconditions are met
all:: preconditions
# Make sure all the user-target rules are double colon rules
all :: preconditions
clean:: preconditions
install :: preconditions
uninstall :: preconditions
check:: preconditions
dist:: preconditions
distcheck:: preconditions
distclean:: preconditions
###########################################################################
# Suffixes and implicit rules:
# Empty out the list of suffixes, generate a list that is only
# used by this Makefile, and cancel useless implicit rules. This
# will hopefully speed up compilation a little bit.
###########################################################################
.SUFFIXES:
.SUFFIXES: .c .cpp .h .hpp .y .l
.SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
.SUFFIXES: .ps .dot .d
#
# Mark all of these targets as phony. This will hopefully speed up builds
# slightly since GNU Make will not try to find implicit rules for targets
# which are marked as Phony.
#
ALL_TARGETS= all dynamic bytecodelib install-bytecode-library clean distclean install test bytecode prdirs
.PHONY: $(ALL_TARGETS) preconditions
###########################################################################
# Miscellaneous paths and commands:
# This section defines various configuration macros, such as where
# to find burg, tblgen, and libtool.
###########################################################################
#--------------------------------------------------------------------
# Variables derived from configuration options...
#--------------------------------------------------------------------
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
else
CONFIGURATION := Debug
CXXFLAGS += -g -D_DEBUG
CFLAGS += -g -D_DEBUG
LDFLAGS += -g -D_DEBUG
KEEP_SYMBOLS := 1
endif
endif
ARFLAGS := cru
#------------------------------------------------------------------------------
# Directory locations
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)
#------------------------------------------------------------------------------
# Full Paths To Compiled Tools and Utilities
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))/
#------------------------------------------------------------------------------
# Adjust to user's request
ifndef SHARED_LIBRARY
LIBTOOL += --tag=disable-shared
else
LDFLAGS += -rpath $(LIBDIR)
endif
#
# Verbosity levels
#
ifndef VERBOSE
VERB := @
LIBTOOL += --silent
AR += >/dev/null 2>/dev/null
endif
# By default, strip symbol information from executable
ifndef KEEP_SYMBOLS
STRIP = $(PLATFORMSTRIPOPTS)
STRIP_WARN_MSG = "(without symbols)"
endif
ifdef TOOLNAME
LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
endif
# TOOLLINKOPTSB to pass options to the linker like library search path etc
# Note that this is different from TOOLLINKOPTS, these options
# are passed to the linker *before* the USEDLIBS options are passed.
# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
ifdef TOOLLINKOPTSB
LDFLAGS += $(TOOLLINKOPTSB)
endif
LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
#------------------------------------------------------------------------------
# Options To Invoke Tools
CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
CPPFLAGS += -I$(BUILD_OBJ_DIR) \
-I$(BUILD_SRC_DIR) \
-I$(BUILD_SRC_ROOT)/include \
-I$(BUILD_OBJ_ROOT)/include \
-I$(LLVM_OBJ_ROOT)/include \
-I$(LLVM_SRC_ROOT)/include \
-D_GNU_SOURCE -D__STDC_LIMIT_MACROS
CXXCompile := $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
LTCXXCompile := $(LIBTOOL) --tag=CXX --mode=compile $(CXXCompile)
CCompile := $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
LTCCompile := $(LIBTOOL) --mode=compile $(CCompile)
BCCXXCompile := $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
BCCCompile := $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
Link := $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
Relink := $(LIBTOOL) --tag=CXX --mode=link $(CXX)
BCLinkLib := $(LLVMGCC) -shared -nostdlib
Burg := $(BURG) -I $(BUILD_SRC_DIR)
TableGen := $(TBLGEN) -I $(BUILD_SRC_DIR)
Archive := $(AR) $(ARFLAGS)
ifdef RANLIB
Ranlib := $(RANLIB)
else
Ranlib := ranlib
endif
#----------------------------------------------------------
# Source includes all of the cpp files, and objects are derived from the
# source files...
# The local Makefile can list other Source files via BUILT_SOURCES = ...
#
ifndef Source
Source := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
$(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
$(BUILD_SRC_DIR)/*.l))
endif
ifdef BUILT_SOURCES
Source += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
endif
#
# Libtool Objects
#
Srcs := $(sort $(basename $(Source)))
ObjectsO := $(Srcs:%=$(OBJDIR)/%.o)
ObjectsLO := $(Srcs:%=$(OBJDIR)/%.lo)
ObjectsBC := $(Srcs:%=$(OBJDIR)/%.bc)
#---------------------------------------------------------
# Handle the DIRS and PARALLEL_DIRS options
#---------------------------------------------------------
ifdef DIRS
$(ALL_TARGETS)::
$(VERB) for dir in $(DIRS); do \
if [ ! -f $$dir/Makefile ]; then \
$(MKDIR) $$dir; \
cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
fi; \
($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
done
endif
# Handle PARALLEL_DIRS
ifdef PARALLEL_DIRS
all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
install-bytecode :: $(addsuffix /.makeinstall-bytecode, $(PARALLEL_DIRS))
%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode %/.makeinstall-bytecode:
$(VERB) if [ ! -f $(@D)/Makefile ]; then \
$(MKDIR) $(@D); \
cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
fi; \
$(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
endif
# Handle directories that may or may not exist
ifdef OPTIONAL_DIRS
$(ALL_TARGETS)::
$(VERB) for dir in $(OPTIONAL_DIRS); do \
if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
if [ ! -f $$dir/Makefile ]; then \
$(MKDIR) $$dir; \
cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
fi; \
($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 0; \
fi \
done
endif
#---------------------------------------------------------
# Handle the CONFIG_FILES options
#---------------------------------------------------------
ifdef CONFIG_FILES
install:: install-config-files
$(sysconfdir):
$(MKDIR) $(sysconfdir)
install-config-files: $(sysconfdir) $(CONFIG_FILES)
$(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
$(VERB)for file in $(CONFIG_FILES); do \
$(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
done
endif
###########################################################################
# Library Build Rules:
#
#---------------------------------------------------------
# Handle the LIBRARYNAME option - used when building libs...
#---------------------------------------------------------
#
# When libraries are built, they are allowed to optionally define the
# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
# from being built for the library. This .o files may then be linked to by a
# tool if the tool does not need (or want) the semantics a .a file provides
# (linking in only object files that are "needed"). If a library is never to
# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
# BUILD_ARCHIVE instead.
#
# Some libraries must be built as .a files (libscalar for example) because if
# it's built as a .o file, then all of the constituent .o files in it will be
# linked into tools (for example gccas) even if they only use one of the parts
# of it. For this reason, sometimes it's useful to use libraries as .a files.
###########################################################################
# Install rule for making bytecode library directory if it does not exist.
# Trigger this by making libraries that need to be installed here depend on it.
$(DESTDIR)$(bytecode_libdir):
$(MKDIR) $@
ifdef LIBRARYNAME
# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
LIBRARYNAME := $(strip $(LIBRARYNAME))
LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
#-------------------------------------------------------------------------------
# Shared Library Targets
# Modify the top level targets to build the desired libraries.
#-------------------------------------------------------------------------------
# Does the library want a shared library version built?
ifdef SHARED_LIBRARY
all:: $(LIBNAME_LA)
$(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
@$(ECHO) Linking shared library $(notdir $@)
$(VERB) $(Link) -o $@ $(ObjectsLO)
$(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
@$(ECHO) Finished linking shared library $(LIBRARYNAME).la
clean::
$(VERB) $(RM) -f $(LIBNAME_LA)
install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
$(DESTDIR)/lib/lib$(LIBRARYNAME)$(SHLIBEXT): $(LIBNAME_LA)
@$(ECHO) Installing shared library $(notdir $@)
$(VERB) $(MKDIR) $(DESTDIR)
$(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
$(VERB) $(LIBTOOL) --finish $(DESTDIR)$(libdir)
endif
# Does the library want a bytecode version built?
ifdef BYTECODE_LIBRARY
ifdef EXPORTED_SYMBOL_LIST
BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
else
ifdef EXPORTED_SYMBOL_FILE
BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
else
BCLinkLib += -Xlinker -disable-internalize
endif
endif
all:: $(LIBNAME_BC)
$(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
@$(ECHO) Linking bytecode library $(notdir $@)
$(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
clean::
$(VERB) $(RM) -f $(LIBNAME_BC)
install:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
$(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
@$(ECHO) Installing bytecode library $(notdir $@)
$(VERB)$(INSTALL) $< $@
endif
# Does the library want a .o version built?
ifndef DONT_BUILD_RELINKED
all:: $(LIBNAME_O)
$(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
@$(ECHO) Linking object $(notdir $@)
$(VERB) $(Relink) -o $@ $(ObjectsO)
install:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
$(DESTDIR)$(libdir)/$(LIBRARYNAME).o: $(LIBNAME_O)
@$(ECHO) Installing object library $(notdir $@)
$(VERB) $(MKDIR) $(DESTDIR)$(libdir)
$(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
clean::
$(VERB) $(RM) -f $(LIBNAME_O)
endif
# Does the library want an archive version built?
ifdef BUILD_ARCHIVE
all:: $(LIBNAME_A)
$(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
@$(ECHO) Linking archive $(notdir $@) library
$(VERB)$(RM) -f $@
$(VERB) $(Archive) $@ $(ObjectsO)
$(VERB) $(Ranlib) $@
clean::
$(VERB) $(RM) -f $(LIBNAME_A)
install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
$(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a: $(LIBNAME_A)
$(MKDIR) $(DESTDIR)$(libdir)
$(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
endif
# if LIBRARYNAME
endif
#------------------------------------------------------------------------
# Handle the TOOLNAME option - used when building tool executables...
#------------------------------------------------------------------------
#
# The TOOLNAME option should be used with a USEDLIBS variable that tells the
# libraries (and the order of the libs) that should be linked to the
# tool. USEDLIBS should contain a list of library names (some with .a extension)
# that are automatically linked in as .o files unless the .a suffix is added.
#
ifdef TOOLNAME
# TOOLLINKOPTSB to pass options to the linker like library search path etc
# Note that this is different from TOOLLINKOPTS, these options
# are passed to the linker *before* the USEDLIBS options are passed.
# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
ifdef TOOLLINKOPTSB
Link += $(TOOLLINKOPTSB)
endif
# TOOLEXENAME* - These compute the output filenames to generate...
TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
#
# Libtool link options:
# Ensure that all binaries have their symbols exported so that they can
# by dlsym'ed.
#
# Handle compression libraries automatically
ifeq ($(HAVE_BZIP2),1)
LIBS += -lbz2
endif
ifeq ($(HAVE_ZLIB),1)
LIBS += -lz
endif
# Tell make that we need to rebuild subdirectories before we can link the tool.
# This affects things like LLI which has library subdirectories.
$(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
all:: $(TOOLEXENAME)
clean::
$(VERB) $(RM) -f $(TOOLEXENAME)
$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
@$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
$(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
@$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
install:: $(TOOLEXENAME)
@$(ECHO) Installing $(TOOLNAME)
$(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
endif
ifndef DISABLE_AUTO_DEPENDENCIES
# Create .lo files in the OBJDIR directory from the .cpp and .c files...
$(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
$(VERB) if $(LTCXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
$(VERB) if $(CXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
$(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
$(VERB) if $(LTCCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
$(VERB) if $(CCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
# Create .bc files in the OBJDIR directory from .cpp and .c files...
$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
$(VERB) if $(BCCXXCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
$(VERB) if $(BCCCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Tpo"; exit 1; fi
else
$(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
$(LTCXXCompile) $< -o $@
$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
$(CXXCompile) $< -o $@
$(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
$(LTCCompile) $< -o $@
$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
$(CCompile) $< -o $@
# Create .bc files in the OBJDIR directory from .cpp and .c files...
$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
$(BCCompileCPP) $< -o $@
$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
@$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
$(BCCompileC) $< -o $@
endif
$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
@$(ECHO) "Compiling $*.ll To Bytecode"
$(VERB) $(LLVMAS) $< -f -o $@
ifdef TARGET
TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
$(BUILT_SOURCES): $(TDFILES)
%GenRegisterNames.inc : %.td
@echo "Building $(<F) register names with tblgen"
$(VERB) $(TableGen) -gen-register-enums -o $@ $<
%GenRegisterInfo.h.inc : %.td
@echo "Building $(<F) register information header with tblgen"
$(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
%GenRegisterInfo.inc : %.td
@echo "Building $(<F) register info implementation with tblgen"
$(VERB) $(TableGen) -gen-register-desc -o $@ $<
%GenInstrNames.inc : %.td
@echo "Building $(<F) instruction names with tblgen"
$(VERB) $(TableGen) -gen-instr-enums -o $@ $<
%GenInstrInfo.inc : %.td
@echo "Building $(<F) instruction information with tblgen"
$(VERB) $(TableGen) -gen-instr-desc -o $@ $<
%GenAsmWriter.inc : %.td
@echo "Building $(<F) assembly writer with tblgen"
$(VERB) $(TableGen) -gen-asm-writer -o $@ $<
%GenATTAsmWriter.inc : %.td
@echo "Building $(<F) AT&T assembly writer with tblgen"
$(VERB) $(TableGen) -gen-asm-writer -o $@ $<
%GenIntelAsmWriter.inc : %.td
@echo "Building $(<F) Intel assembly writer with tblgen"
$(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
%GenInstrSelector.inc: %.td
@echo "Building $(<F) instruction selector with tblgen"
$(VERB) $(TableGen) -gen-instr-selector -o $@ $<
%GenCodeEmitter.inc:: %.td
@echo "Building $(<F) code emitter with tblgen"
$(VERB) $(TableGen) -gen-emitter -o $@ $<
clean::
$(VERB) rm -f *.inc
endif
#
# Rules for building lex/yacc files
#
LEX_FILES = $(filter %.l, $(Source))
LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
YACC_FILES = $(filter %.y, $(Source))
YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
# Create a .cpp source file from a flex input file... this uses sed 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] )
#
%.cpp: %.l
@$(ECHO) Flexing $<
$(VERB) $(FLEX) -t $< | \
$(SED) '/^find_rule/d' | \
$(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)/' \
> $@.tmp
$(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
@# remove the output of flex if it didn't get moved over...
@rm -f $@.tmp
# Rule for building the bison parsers...
%.c: %.y # Cancel built-in rules for yacc
%.h: %.y # Cancel built-in rules for yacc
%.cpp %.h : %.y
@$(ECHO) "Bisoning $*.y"
$(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
$(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
$(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
@# If the files were not updated, don't leave them lying around...
@rm -f $*.tab.c $*.tab.h
# To create the directories...
%/.dir:
$(VERB) $(MKDIR) $* > /dev/null
@$(DATE) > $@
.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
.PRECIOUS: $(LLVMTOOLDIR)/.dir
# 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:: ;
# 'make clean' nukes the tree
clean::
$(VERB) $(RM) -rf $(OBJDIR)
$(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
$(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
###########################################################################
# C/C++ Dependencies
# Define variables and rules that generate header file dependencies
# from C/C++ source files.
###########################################################################
ifndef DISABLE_AUTO_DEPENDENCIES
# If dependencies were generated for the file that included this file,
# include the dependencies now...
#
SourceBaseNames := $(basename $(Source))
SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d)
#
# Include dependencies generated from C/C++ source files, but not if we
# are cleaning (this example taken from the GNU Make Manual).
#
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include /dev/null $(SourceDepend)
endif
endif
endif # ifndef DISABLE_AUTO_DEPENDENCIES
###############################################################################
# PRECONDITIONS - that which must be built/checked first
###############################################################################
OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
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
#------------------------------------------------------------------------
# List of the preconditions
preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
all dist distcheck install:: $(BUILT_SOURCES)
clean::
$(VERB) $(RM) -f $(BUILT_SOURCES)
#------------------------------------------------------------------------
# Make sure we're not using a stale configuration
.PRECIOUS: $(CONFIG_STATUS)
$(CONFIG_STATUS): $(CONFIGURE)
@$(ECHO) Reconfiguring with $@
$(VERB) $(CONFIG_STATUS) --recheck
#------------------------------------------------------------------------
# Make sure the configuration makefile is up to date
$(MAKE_CONFIG): $(MAKE_CONFIG_IN)
@$(ECHO) Regenerating $@
$(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
$(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
@exit 0;
#------------------------------------------------------------------------
# If the Makefile in the source tree has been updated, copy it over into the
# build tree.
ifneq ($(OBJMKFILE),$(SRCMKFILE))
.PRECIOUS: $(OBJMKFILE)
$(OBJMKFILE): $(SRCMKFILE)
@$(ECHO) "Updating Makefile from : $(dir $<)"
$(VERB) $(MKDIR) $(@D)
$(VERB) cp -f $< $@
$(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
@exit 0;
endif
###############################################################################
# MISCELLANEOUS - utility targets
###############################################################################
#------------------------------------------------------------------------
# Print out the directories used for building
printvars:
@$(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) "CONFIGURATION : " $(CONFIGURATION)
@$(ECHO) "OBJDIR: " $(OBJDIR)
@$(ECHO) "LIBDIR: " $(LIBDIR)
@$(ECHO) "TOOLDIR: " $(TOOLDIR)
@$(ECHO) "TDFILES:" '$(TDFILES)'
@$(ECHO) "CXXCompile: " '$(CXXCompile)'
@$(ECHO) "CCompile: " '$(CCompile)'