Checkin of autoconf-style object root.
[oota-llvm.git] / Makefile.rules
index 45a25edb0ab4916908277737a97eaa8b75928a5d..99556b46b9a54ebbeba3a3e83a1e5abfad7e0886 100644 (file)
 #===-----------------------------------------------------------------------====
 
 #
-# Configuration file to set paths specific to local installation of LLVM
-# 
-ifdef LLVM_SRC_ROOT
-include $(LLVM_SRC_ROOT)/Makefile.config
-else
-include $(LEVEL)/Makefile.config
-endif
-
-###########################################################################
-# Directory Configuration
-#      This section of the Makefile determines what is where.  To be
-#      specific, there are several locations that need to be defined:
-#
-#      o LLVM_SRC_ROOT  : The root directory of the LLVM source code.
-#      o LLVM_OBJ_ROOT  : The root directory containing the built LLVM code.
-#
-#      o BUILD_SRC_DIR  : The directory containing the code to build.
-#      o BUILD_SRC_ROOT : The root directory of the code to build.
-#
-#      o BUILD_OBJ_DIR  : The directory in which compiled code will be placed.
-#      o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
-#
-###########################################################################
-
-#
-# Set the source build directory.  That is almost always the current directory.
-#
-ifndef BUILD_SRC_DIR
-BUILD_SRC_DIR = $(shell pwd)
-endif
-
-#
-# Set the source root directory.
-#
-ifndef BUILD_SRC_ROOT
-BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
-endif
-
-#
-# Determine the path of the source tree relative from $HOME (the mythical
-# home directory).
-#
-HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
-
-#
-# Set the object build directory.  Its location depends upon the source path
-# and where object files should go.
+# Set the VPATH so that we can find source files.
+# Also set $SouceDir for backwards compatibility
 #
-ifndef BUILD_OBJ_DIR
-ifeq ($(OBJ_ROOT),.)
-BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
-else
-BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
-endif
-endif
-
-#
-# Set the root of the object directory.
-#
-ifndef BUILD_OBJ_ROOT
-ifeq ($(OBJ_ROOT),.)
-BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
-else
-BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
-endif
-endif
-
-#
-# Set the LLVM object directory.
-#
-ifndef LLVM_OBJ_ROOT
-ifdef LLVM_SRC_ROOT
-LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_DIR); cd $(LLVM_SRC_ROOT); pwd)
-else
-LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_ROOT); pwd)
-endif
-endif
-
-#
-# Set the LLVM source directory.
-# It is typically the root directory of what we're compiling now.
-#
-ifndef LLVM_SRC_ROOT
-LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
-endif
+VPATH=$(BUILD_SRC_DIR)
+SourceDir=$(BUILD_SRC_DIR)
 
 ###########################################################################
 # Default Targets:
@@ -165,7 +85,6 @@ bytecode::
 
 # Print out the directories used for building
 prdirs::
-       @echo "Home Offset      : " $(HOME_OBJ_ROOT)
        @echo "Build Source Root: " $(BUILD_SRC_ROOT)
        @echo "Build Source Dir : " $(BUILD_SRC_DIR)
        @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
@@ -282,7 +201,7 @@ PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
 #
 # Libtool is found in the current directory.
 #
-LIBTOOL := $(LLVM_SRC_ROOT)/mklib
+LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
 
 #
 # If we're not building a shared library, use the disable-shared tag with
@@ -343,7 +262,15 @@ LLVMAS  := $(LLVMTOOLCURRENT)/llvm-as
 # Include both the project headers and the LLVM headers for compilation and
 # dependency computation.
 #
-CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
+# BUILD_OBJ_DIR          : Files local to the particular object directory
+#                          (locallly generated header files).
+# BUILD_SRC_DIR          : Files local to the particular source directory.
+# BUILD_SRC_ROOT/include : Files global to the project.
+# LEVEL/include          : config.h files for the project
+# LLVM_SRC_ROOT/include  : Files global to LLVM.
+# LLVM_OBJ_ROOT/include  : config.h files generated by autoconf
+#
+CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include -I$(LLVM_SRC_ROOT)/include -I$(LLVM_OBJ_ROOT)/include 
 
 # By default, strip symbol information from executable
 ifndef KEEP_SYMBOLS
@@ -355,7 +282,7 @@ endif
 CPPFLAGS += -D_GNU_SOURCE
 
 CompileWarnings  := -Wall -W  -Wwrite-strings -Wno-unused
-CompileCommonOpts := $(CompileWarnings) -I$(LEVEL)/include -fshort-enums
+CompileCommonOpts := $(CompileWarnings) -fshort-enums
 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
 
 #
@@ -417,7 +344,7 @@ AR       = ${AR_PATH} cq
 # The local Makefile can list other Source files via ExtraSource = ...
 # 
 ifndef Source
-Source  := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
+Source  := $(ExtraSource) $(wildcard $(SourceDir)/*.cpp $(SourceDir)/*.c $(SourceDir)/*.y $(SourceDir)/*.l)
 endif
 
 #
@@ -620,7 +547,7 @@ endif
 
 ifdef ETAGS
 ifeq ($(LEVEL), .)
-SRCDIRS := $(wildcard include lib tools)
+SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
 
 tags:
        $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
@@ -714,39 +641,39 @@ endif
 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
 
 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
-$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
+$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)/%.cpp $(BUILD_OBJ_DIR)/Release/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileO) $< -o $@
 
-$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
+$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)/%.c $(BUILD_OBJ_DIR)/Release/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileCO) $< -o $@
 
-$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
+$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)/%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileP) $< -o $@
 
-$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
+$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)/%.c $(BUILD_OBJ_DIR)/Profile/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileCP) $< -o $@
 
-$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
+$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)/%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
        @echo "Compiling $<"
        $(VERB) $(CompileG) $< -o $@
 
-$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir 
+$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)/%.c $(BUILD_OBJ_DIR)/Debug/.dir 
        @echo "Compiling $<"
        $(VERB) $(CompileCG) $< -o $@
 
-$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
+$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)/%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
        @echo "Compiling $< to bytecode"
        $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
 
-$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
+$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)/%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
        @echo "Compiling $< to bytecode"
        $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
 
-$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
+$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)/%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
        @echo "Compiling $< to bytecode"
        $(VERB) $(LLVMAS) $< -f -o $@
 
@@ -785,7 +712,7 @@ YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
 %.h: %.y     # Cancel built-in rules for yacc
 %.cpp %.h : %.y
        @echo Bison\'ing $<...
-       $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
+       $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) $*.y
        $(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...
@@ -805,6 +732,13 @@ else
        ${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 $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
@@ -824,18 +758,16 @@ ifndef DISABLE_AUTO_DEPENDENCIES
 # If dependencies were generated for the file that included this file,
 # include the dependencies now...
 #
-SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
+SourceBaseNames := $(basename $(notdir $(filter-out $(SourceDir)/$(CONFIGURATION)/%, $(Source))))
 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
 
 # Create dependencies for the *.cpp files...
-$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
+$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)/%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
        $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
-       $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.cpp||' | $(SED) 's|[^\]$$|&::|' >> $@
 
 # Create dependencies for the *.c files...
-$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
+$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)/%.c $(BUILD_OBJ_DIR)/Depend/.dir
        $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
-       $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.c||' | $(SED) 's|[^\]$$|&::|' >> $@
 
 #
 # Include dependencies generated from C/C++ source files, but not if we