blob: d929ae8974f84d9bf9d504cdcc6fff66a77c2c99 [file] [log] [blame]
Misha Brukman6d5ab862004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswelld8846c12003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
5# This file was developed by the LLVM research group and is distributed under
6# the University of Illinois Open Source License. See LICENSE.TXT for details.
7#
Misha Brukman6d5ab862004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner00950542001-06-06 20:29:01 +00009#
Reid Spencer3a561f52004-10-23 20:04:14 +000010# This file is included by all of the LLVM makefiles. For details on how to use
11# it properly, please see the document MakefileGuide.html in the docs directory.
Chris Lattneraf06a082003-08-15 03:02:52 +000012#
Vikram S. Adved60aede2002-07-09 12:04:21 +000013#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000014
Reid Spencercc2d1e22004-10-30 09:19:36 +000015################################################################################
Reid Spencer3a561f52004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencercc2d1e22004-10-30 09:19:36 +000017################################################################################
John Criswell7a73b802003-06-30 21:59:07 +000018
Chris Lattner00950542001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Reid Spencer3d659492004-11-02 16:36:03 +000022RecursiveTargets := all clean clean-all check install uninstall
23LocalTargets := all-local clean-local clean-all-local check-local \
24 install-local printvars uninstall-local
Reid Spencercc2d1e22004-10-30 09:19:36 +000025TopLevelTargets := dist dist-check dist-clean tags dist-gzip dist-bzip2 \
26 dist-zip
27UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
28InternalTargets := preconditions distdir dist-hook
Reid Spencer3a561f52004-10-23 20:04:14 +000029
Reid Spencercc2d1e22004-10-30 09:19:36 +000030################################################################################
Reid Spencer9411c642004-10-26 22:26:33 +000031# INITIALIZATION: Basic things the makefile needs
Reid Spencercc2d1e22004-10-30 09:19:36 +000032################################################################################
33
34#--------------------------------------------------------------------
35# Set the VPATH so that we can find source files.
36#--------------------------------------------------------------------
37VPATH=$(BUILD_SRC_DIR)
Reid Spencer9411c642004-10-26 22:26:33 +000038
39#--------------------------------------------------------------------
40# Reset the list of suffixes we know how to build
41#--------------------------------------------------------------------
42.SUFFIXES:
Reid Spencercc2d1e22004-10-30 09:19:36 +000043.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
44.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer9411c642004-10-26 22:26:33 +000045
Reid Spencer3a561f52004-10-23 20:04:14 +000046#--------------------------------------------------------------------
47# Mark all of these targets as phony to avoid implicit rule search
48#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000049.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer3a561f52004-10-23 20:04:14 +000050
51#--------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +000052# Make sure all the user-target rules are double colon rules and
53# they are defined first.
Reid Spencer3a561f52004-10-23 20:04:14 +000054#--------------------------------------------------------------------
55
Reid Spencercc2d1e22004-10-30 09:19:36 +000056$(UserTargets)::
Reid Spencer151f8ba2004-10-25 08:27:37 +000057
Reid Spencer9411c642004-10-26 22:26:33 +000058################################################################################
59# PRECONDITIONS: that which must be built/checked first
60################################################################################
61
Reid Spencer023c4462004-11-17 19:08:44 +000062SrcMakefiles := $(filter %Makefile %Makefile.tests %Makefile.JIT,\
63 $(wildcard $(BUILD_SRC_DIR)/Makefile*))
Reid Spencercc2d1e22004-10-30 09:19:36 +000064ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
65ConfigureScript := $(LLVM_SRC_ROOT)/configure
66ConfigStatusScript := $(LLVM_OBJ_ROOT)/config.status
67MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
68MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
69PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
Reid Spencer9411c642004-10-26 22:26:33 +000070
Reid Spencercc2d1e22004-10-30 09:19:36 +000071preconditions : $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +000072
73#------------------------------------------------------------------------
74# Make sure the BUILT_SOURCES are built first
75#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000076$(filter-out clean clean-local,UserTargets):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000077
78clean-local::
79ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +000080 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000081endif
82
Reid Spencercc2d1e22004-10-30 09:19:36 +000083$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +000084
Reid Spencer9411c642004-10-26 22:26:33 +000085#------------------------------------------------------------------------
86# Make sure we're not using a stale configuration
87#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000088.PRECIOUS: $(ConfigStatusScript)
89$(ConfigStatusScript): $(ConfigureScript)
90 $(Echo) Reconfiguring with $<
91 $(Verb) $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS)
92 $(Verb) $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +000093
94#------------------------------------------------------------------------
95# Make sure the configuration makefile is up to date
96#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000097$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
98 $(Echo) Regenerating $@
99 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
Reid Spencer9411c642004-10-26 22:26:33 +0000100
101#------------------------------------------------------------------------
102# If the Makefile in the source tree has been updated, copy it over into the
103# build tree. But, only do this if the source and object makefiles differ
104#------------------------------------------------------------------------
105ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
106
Reid Spencer023c4462004-11-17 19:08:44 +0000107Makefile: $(BUILD_SRC_DIR)/Makefile
Reid Spencercc2d1e22004-10-30 09:19:36 +0000108 $(Echo) "Updating Makefile"
109 $(Verb) $(MKDIR) $(@D)
110 $(Verb) cp -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000111
112# Copy the Makefile.* files unless we're in the root directory which avoids
113# the copying of Makefile.config.in or other things that should be explicitly
114# taken care of.
Reid Spencer9411c642004-10-26 22:26:33 +0000115$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
Reid Spencer86606782004-10-26 23:10:00 +0000116 @case '$?' in \
117 *Makefile.rules) ;; \
118 *.in) ;; \
Reid Spencercc2d1e22004-10-30 09:19:36 +0000119 *) $(Echo) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000120 $(MKDIR) $(@D) ; \
121 cp -f $< $@ ;; \
122 esac
123
Reid Spencer9411c642004-10-26 22:26:33 +0000124endif
125
126#------------------------------------------------------------------------
127# Set up the basic dependencies
128#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000129$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000130
131all:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000132check:: check-local
133clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000134clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000135install:: install-local
136uninstall:: uninstall-local
137check-local:: all-local
138install-local:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000139
140###############################################################################
141# VARIABLES: Set up various variables based on configuration data
142###############################################################################
143
144#--------------------------------------------------------------------
145# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000146#--------------------------------------------------------------------
147
Chris Lattner760da062003-03-14 20:25:22 +0000148ifdef ENABLE_PROFILING
Reid Spencer9af3b292004-11-01 07:50:27 +0000149 BuildMode := Profile
Reid Spencercc2d1e22004-10-30 09:19:36 +0000150 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
151 C.Flags := -O3 -DNDEBUG -pg
152 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000153else
154 ifdef ENABLE_OPTIMIZED
Reid Spencer9af3b292004-11-01 07:50:27 +0000155 BuildMode := Release
Reid Spencercc2d1e22004-10-30 09:19:36 +0000156 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
157 C.Flags := -O3 -DNDEBUG -fomit-frame-pointer
158 LD.Flags := -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000159 else
Reid Spencer9af3b292004-11-01 07:50:27 +0000160 BuildMode := Debug
Reid Spencercc2d1e22004-10-30 09:19:36 +0000161 CXX.Flags := -g -D_DEBUG
162 C.Flags := -g -D_DEBUG
163 LD.Flags := -g -D_DEBUG
Reid Spencer4d71b662004-10-22 21:01:56 +0000164 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000165 endif
166endif
167
Reid Spencercc2d1e22004-10-30 09:19:36 +0000168CXX.Flags += $(CXXFLAGS)
169C.Flags += $(CFLAGS)
170CPP.Flags += $(CPPFLAGS)
171LD.Flags += $(LDFLAGS)
172AR.Flags := cru
173LibTool.Flags := --tag=CXX
Reid Spencer3a561f52004-10-23 20:04:14 +0000174
175#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000176# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000177#--------------------------------------------------------------------
Reid Spencer9af3b292004-11-01 07:50:27 +0000178ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000179LibDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
180ToolDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/tools
181ExmplDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
182LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
183LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/tools
184LExmplDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell7a73b802003-06-30 21:59:07 +0000185
Reid Spencer3a561f52004-10-23 20:04:14 +0000186#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000187# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000188#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000189EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
190Echo := @$(EchoCmd)
191ifndef LIBTOOL
Reid Spencer4d71b662004-10-22 21:01:56 +0000192LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencercc2d1e22004-10-30 09:19:36 +0000193endif
194ifndef LLVMAS
195LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
196endif
197ifndef BURG
198BURG := $(LLVMToolDir)/burg$(EXEEXT)
199endif
200ifndef TBLGEN
201TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
202endif
203ifndef GCCLD
204GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
205endif
206ifndef LLVMGCC
207LLVMGCC := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
208endif
209ifndef LLVMGXX
210LLVMGXX := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
211endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000212
Reid Spencer4d71b662004-10-22 21:01:56 +0000213# Need a better way to compute this.
Reid Spencercc2d1e22004-10-30 09:19:36 +0000214LLVMGCCLibDir := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000215
Reid Spencer3a561f52004-10-23 20:04:14 +0000216#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000217# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000218#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000219
Reid Spencercc2d1e22004-10-30 09:19:36 +0000220# Adjust LIBTOOL flags for shared libraries, or not.
John Criswell82f4a5a2003-07-31 20:58:51 +0000221ifndef SHARED_LIBRARY
Reid Spencercc2d1e22004-10-30 09:19:36 +0000222 LibTool.Flags += --tag=disable-shared
Reid Spencer4d71b662004-10-22 21:01:56 +0000223else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000224 LD.Flags += -rpath $(LibDir)
John Criswell82f4a5a2003-07-31 20:58:51 +0000225endif
226
Reid Spencercceed9f2004-11-08 17:32:12 +0000227ifdef TOOL_VERBOSE
228 C.Flags += -v
229 CXX.Flags += -v
230 LD.Flags += -v
231 BCLinkLib.Flags += -v
232 VERBOSE := 1
233endif
234
Reid Spencer3a561f52004-10-23 20:04:14 +0000235# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000236ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000237 Verb := @
238 LibTool.Flags += --silent
239 AR.Flags += >/dev/null 2>/dev/null
240 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000241else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000242 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000243endif
244
Vikram S. Advefeeae582002-09-18 11:55:13 +0000245# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000246ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000247 Strip := $(PLATFORMSTRIPOPTS)
248 StripWarnMsg := "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000249endif
250
Reid Spencer3a561f52004-10-23 20:04:14 +0000251# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000252ifdef TOOLNAME
Reid Spencer815cbcf2004-11-18 10:03:46 +0000253ifdef EXAMPLE_TOOL
254 LD.Flags += -rpath $(ExmplDir) -export-dynamic
255else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000256 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000257endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000258endif
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000259
Reid Spencer3a561f52004-10-23 20:04:14 +0000260#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000261# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000262#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000263
264CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
265
Reid Spencercc2d1e22004-10-30 09:19:36 +0000266LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
267CPP.Flags += -I$(BUILD_OBJ_DIR) \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000268 -I$(BUILD_SRC_DIR) \
269 -I$(BUILD_SRC_ROOT)/include \
270 -I$(BUILD_OBJ_ROOT)/include \
271 -I$(LLVM_OBJ_ROOT)/include \
272 -I$(LLVM_SRC_ROOT)/include \
273 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencer4d71b662004-10-22 21:01:56 +0000274
Reid Spencercc2d1e22004-10-30 09:19:36 +0000275Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
276LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
277BCCompile.C = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
278Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
279LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
280BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
281Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
282 $(CompileCommonOpts) $(LD.Flags) $(Strip)
283Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencera69b1ea2004-10-28 09:15:28 +0000284 $(CompileCommonOpts)
Reid Spencercceed9f2004-11-08 17:32:12 +0000285BCLinkLib = $(LLVMGCC) -shared -nostdlib $(BCLinkLib.Flags)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000286LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
Reid Spencer3a561f52004-10-23 20:04:14 +0000287Burg = $(BURG) -I $(BUILD_SRC_DIR)
288TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000289Archive = $(AR) $(AR.Flags)
Reid Spencer5991dcb2004-11-14 21:46:55 +0000290LArchive = $(ToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000291ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000292Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000293else
Reid Spencer3a561f52004-10-23 20:04:14 +0000294Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000295endif
296
Chris Lattner00950542001-06-06 20:29:01 +0000297#----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000298# Get the list of source files
299#----------------------------------------------------------
300ifndef SOURCES
Reid Spencercc2d1e22004-10-30 09:19:36 +0000301 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
302 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
303 $(BUILD_SRC_DIR)/*.l))
304else
305 Sources := $(SOURCES)
Reid Spencer4d71b662004-10-22 21:01:56 +0000306endif
307
308ifdef BUILT_SOURCES
Reid Spencercc2d1e22004-10-30 09:19:36 +0000309Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000310endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000311
Reid Spencer3a561f52004-10-23 20:04:14 +0000312#----------------------------------------------------------
313# Types of objects that can be built from sources
314#----------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000315BaseNameSources := $(sort $(basename $(Sources)))
316ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
317ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
318ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencer3a561f52004-10-23 20:04:14 +0000319
320###############################################################################
321# DIRECTORIES: Handle recursive descent of directory structure
322###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000323
Chris Lattner00950542001-06-06 20:29:01 +0000324#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000325# Provide rules to make install dirs. This must be early
326# in the file so they get built before dependencies
327#---------------------------------------------------------
328
329$(bindir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000330 $(Verb) $(MKDIR) $(bindir)
Chris Lattnere4cb90f2004-11-01 06:14:59 +0000331
Reid Spencera69b1ea2004-10-28 09:15:28 +0000332$(libdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000333 $(Verb) $(MKDIR) $(libdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000334
335$(bytecode_libdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000336 $(Verb) $(MKDIR) $(bytecode_libdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000337
338$(sysconfdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000339 $(Verb) $(MKDIR) $(sysconfdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000340
Reid Spencercc2d1e22004-10-30 09:19:36 +0000341# To create other directories, as needed, and timestamp their creation
342%/.dir:
343 $(Verb) $(MKDIR) $* > /dev/null
344 @$(DATE) > $@
345
Reid Spencer815cbcf2004-11-18 10:03:46 +0000346.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
347.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000348
349#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000350# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000351#---------------------------------------------------------
352
Reid Spencercc2d1e22004-10-30 09:19:36 +0000353SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000354ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000355SubDirs += $(DIRS)
356$(RecursiveTargets)::
357 $(Verb) for dir in $(DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000358 if [ ! -f $$dir/Makefile ]; then \
359 $(MKDIR) $$dir; \
360 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
361 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000362 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000363 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000364endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000365
Reid Spencer3a561f52004-10-23 20:04:14 +0000366#---------------------------------------------------------
367# Handle the EXPERIMENTAL_DIRS options ensuring success
368# after each directory is built.
369#---------------------------------------------------------
370ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000371$(RecursiveTargets)::
372 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer3a561f52004-10-23 20:04:14 +0000373 if [ ! -f $$dir/Makefile ]; then \
374 $(MKDIR) $$dir; \
375 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
376 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000377 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000378 done
379endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000380
Reid Spencer3a561f52004-10-23 20:04:14 +0000381#---------------------------------------------------------
382# Handle the PARALLEL_DIRS options for parallel construction
383#---------------------------------------------------------
384ifdef PARALLEL_DIRS
385
Reid Spencercc2d1e22004-10-30 09:19:36 +0000386SubDirs += $(PARALLEL_DIRS)
387
Reid Spencer3a561f52004-10-23 20:04:14 +0000388# Unfortunately, this list must be maintained if new
389# recursive targets are added.
Reid Spencercc2d1e22004-10-30 09:19:36 +0000390all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
391clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000392clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000393check :: $(addsuffix /.makecheck ,$(PARALLEL_DIRS))
394install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000395uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
396
Reid Spencercc2d1e22004-10-30 09:19:36 +0000397Parallel_Targets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000398
399$(Parallel_Targets) :
Reid Spencercc2d1e22004-10-30 09:19:36 +0000400 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000401 $(MKDIR) $(@D); \
402 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000403 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000404 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000405endif
406
Reid Spencer3a561f52004-10-23 20:04:14 +0000407#---------------------------------------------------------
408# Handle the OPTIONAL_DIRS options for directores that may
409# or may not exist.
410#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000411ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000412
Reid Spencercc2d1e22004-10-30 09:19:36 +0000413SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000414
Reid Spencercc2d1e22004-10-30 09:19:36 +0000415$(RecursiveTargets)::
416 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000417 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
418 if [ ! -f $$dir/Makefile ]; then \
419 $(MKDIR) $$dir; \
420 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
421 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000422 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000423 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000424 done
425endif
426
Reid Spencerfc945082004-08-20 09:20:05 +0000427#---------------------------------------------------------
428# Handle the CONFIG_FILES options
429#---------------------------------------------------------
430ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000431
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000432install-local:: $(sysconfdir) $(CONFIG_FILES)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000433 $(Echo) Installing Configuration Files To $(sysconfdir)
434 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000435 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
Reid Spencerfc945082004-08-20 09:20:05 +0000436 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000437
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000438uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000439 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
440 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000441 $(RM) -f $(sysconfdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000442 done
443
Reid Spencerfc945082004-08-20 09:20:05 +0000444endif
445
Reid Spencer3a561f52004-10-23 20:04:14 +0000446###############################################################################
447# Library Build Rules: Four ways to build a library
448###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000449
Brian Gaeke8abff792004-01-22 22:53:48 +0000450
Reid Spencer3a561f52004-10-23 20:04:14 +0000451# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000452ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000453
Chris Lattner2a548c52002-09-16 22:36:42 +0000454# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000455LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000456LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
457LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
458LibName.O := $(LibDir)/$(LIBRARYNAME).o
459LibName.BC := $(LibDir)/lib$(LIBRARYNAME).bc
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000460
Reid Spencer3a561f52004-10-23 20:04:14 +0000461#---------------------------------------------------------
462# Shared Library Targets:
463# If the user asked for a shared library to be built
464# with the SHARED_LIBRARY variable, then we provide
465# targets for building them.
466#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000467ifdef SHARED_LIBRARY
468
Reid Spencercc2d1e22004-10-30 09:19:36 +0000469all-local:: $(LibName.LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000470
Reid Spencercc2d1e22004-10-30 09:19:36 +0000471$(LibName.LA): $(BUILT_SOURCES) $(ObjectsLO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000472 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000473 $(Verb) $(Link) -o $@ $(ObjectsLO)
474 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencer3a561f52004-10-23 20:04:14 +0000475
476clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000477ifneq ($(strip $(LibName.LA)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000478 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000479endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000480
Reid Spencere5487ba2004-10-24 07:53:21 +0000481DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000482
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000483install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000484
Reid Spencercc2d1e22004-10-30 09:19:36 +0000485$(DestSharedLib): $(libdir) $(LibName.LA)
Reid Spencer9af3b292004-11-01 07:50:27 +0000486 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000487 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
488 $(Verb) $(LIBTOOL) --finish $(libdir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000489
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000490uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000491 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencer12d79512004-11-12 02:27:36 +0000492 -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
Reid Spencere5487ba2004-10-24 07:53:21 +0000493
Reid Spencer4d71b662004-10-22 21:01:56 +0000494endif
495
Reid Spencer3a561f52004-10-23 20:04:14 +0000496#---------------------------------------------------------
497# Bytecode Library Targets:
498# If the user asked for a bytecode library to be built
499# with the BYTECODE_LIBRARY variable, then we provide
500# targets for building them.
501#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000502ifdef BYTECODE_LIBRARY
503
504ifdef EXPORTED_SYMBOL_LIST
505 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
506else
507 ifdef EXPORTED_SYMBOL_FILE
508 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
509 else
510 BCLinkLib += -Xlinker -disable-internalize
511 endif
512endif
513
Reid Spencercc2d1e22004-10-30 09:19:36 +0000514all-local:: $(LibName.BC)
Reid Spencer4d71b662004-10-22 21:01:56 +0000515
Reid Spencercc2d1e22004-10-30 09:19:36 +0000516$(LibName.BC): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000517 $(Echo) Linking $(BuildMode) Bytecode Library $(notdir $@)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000518 $(Verb) $(BCLinkLib) -o $@ $(ObjectsBC)
Reid Spencer4d71b662004-10-22 21:01:56 +0000519
Reid Spencer3a561f52004-10-23 20:04:14 +0000520clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000521ifneq ($(strip $(LibName.BC)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000522 -$(Verb) $(RM) -f $(LibName.BC)
Reid Spencere5487ba2004-10-24 07:53:21 +0000523endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000524
Reid Spencere5487ba2004-10-24 07:53:21 +0000525DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
Reid Spencere45ebfa2004-10-26 07:09:33 +0000526
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000527install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000528
Reid Spencercc2d1e22004-10-30 09:19:36 +0000529$(DestBytecodeLib): $(bytecode_libdir) $(LibName.BC)
Reid Spencer9af3b292004-11-01 07:50:27 +0000530 $(Echo) Installing $(BuildMode) Bytecode Library $(DestBytecodeLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000531 $(Verb) $(INSTALL) $(LibName.BC) $@
Reid Spencere5487ba2004-10-24 07:53:21 +0000532
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000533uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000534 $(Echo) Uninstalling $(BuildMode) Bytecode Library $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000535 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000536
537endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000538
Reid Spencercc2d1e22004-10-30 09:19:36 +0000539#---------------------------------------------------------
540# ReLinked Library Targets:
541# If the user didn't explicitly forbid building a
542# relinked then we provide targets for building them.
543#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000544ifndef DONT_BUILD_RELINKED
Reid Spencer4d71b662004-10-22 21:01:56 +0000545
Reid Spencercc2d1e22004-10-30 09:19:36 +0000546all-local:: $(LibName.O)
547
548$(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000549 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000550 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencer4d71b662004-10-22 21:01:56 +0000551
Reid Spencer3a561f52004-10-23 20:04:14 +0000552clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000553ifneq ($(strip $(LibName.O)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000554 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000555endif
556
557DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
558
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000559install-local:: $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000560
Reid Spencercc2d1e22004-10-30 09:19:36 +0000561$(DestRelinkedLib): $(libdir) $(LibName.O)
Reid Spencer9af3b292004-11-01 07:50:27 +0000562 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000563 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000564
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000565uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000566 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000567 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000568
Chris Lattnere62dbe92002-07-23 17:56:16 +0000569endif
Chris Lattner760da062003-03-14 20:25:22 +0000570
Reid Spencercc2d1e22004-10-30 09:19:36 +0000571#---------------------------------------------------------
572# Archive Library Targets:
573# If the user wanted a regular archive library built,
574# then we provide targets for building them.
575#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000576ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +0000577
Reid Spencercc2d1e22004-10-30 09:19:36 +0000578all-local:: $(LibName.A)
579
580$(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000581 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000582 -$(Verb) $(RM) -f $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000583 $(Verb) $(Archive) $@ $(ObjectsO)
584 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000585
Reid Spencer3a561f52004-10-23 20:04:14 +0000586clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000587ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000588 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +0000589endif
590
Reid Spencere5487ba2004-10-24 07:53:21 +0000591DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
592
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000593install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000594
Reid Spencercc2d1e22004-10-30 09:19:36 +0000595$(DestArchiveLib): $(libdir) $(LibName.A)
Reid Spencer9af3b292004-11-01 07:50:27 +0000596 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000597 $(Verb) $(MKDIR) $(libdir)
598 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000599
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000600uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000601 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000602 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000603
604endif
605
606# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000607endif
608
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000609###############################################################################
610# Tool Build Rules: Build executable tool based on TOOLNAME option
611###############################################################################
612
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000613ifdef TOOLNAME
614
Reid Spencercc2d1e22004-10-30 09:19:36 +0000615#---------------------------------------------------------
616# Set up variables for building a tool.
617#---------------------------------------------------------
Reid Spencer815cbcf2004-11-18 10:03:46 +0000618ifdef EXAMPLE_TOOL
619ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
620else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000621ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000622endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000623ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
624ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
625LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
626LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
627ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
628LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
629ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
630LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000631
Reid Spencercc2d1e22004-10-30 09:19:36 +0000632#---------------------------------------------------------
633# Handle optional compression libraries automatically
634#---------------------------------------------------------
635ExtraLibs := $(LIBS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000636ifeq ($(HAVE_BZIP2),1)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000637ExtraLibs += -lbz2
Reid Spencer4d71b662004-10-22 21:01:56 +0000638endif
639ifeq ($(HAVE_ZLIB),1)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000640ExtraLibs += -lz
Reid Spencer4d71b662004-10-22 21:01:56 +0000641endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000642
Reid Spencercc2d1e22004-10-30 09:19:36 +0000643#---------------------------------------------------------
644# Tell make that we need to rebuild subdirectories before
645# we can link the tool. This affects things like LLI which
646# has library subdirectories.
647#---------------------------------------------------------
648$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000649
Reid Spencercc2d1e22004-10-30 09:19:36 +0000650#---------------------------------------------------------
651# Provide targets for building the tools
652#---------------------------------------------------------
653all-local:: $(ToolBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +0000654
Reid Spencer3a561f52004-10-23 20:04:14 +0000655clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000656ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000657 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +0000658endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000659
Reid Spencer815cbcf2004-11-18 10:03:46 +0000660ifdef EXAMPLE_TOOL
661$(ToolBuildPath): $(ExmplDir)/.dir
662else
663$(ToolBuildPath): $(ToolDir)/.dir
664endif
665
666$(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +0000667 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000668 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
669 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
Reid Spencer9af3b292004-11-01 07:50:27 +0000670 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +0000671
672DestTool = $(bindir)/$(TOOLNAME)
673
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000674install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000675
Reid Spencercc2d1e22004-10-30 09:19:36 +0000676$(DestTool): $(bindir) $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +0000677 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000678 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000679
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000680uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000681 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000682 -$(Verb) $(RM) -f $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000683
Reid Spencer4d71b662004-10-22 21:01:56 +0000684endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000685
Reid Spencercc2d1e22004-10-30 09:19:36 +0000686###############################################################################
687# Object Build Rules: Build object files based on sources
688###############################################################################
689
690# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000691ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000692
Reid Spencercc2d1e22004-10-30 09:19:36 +0000693#---------------------------------------------------------
694# Create .lo files in the ObjDir directory from the .cpp and .c files...
695#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000696ifdef SHARED_LIBRARY
697
Reid Spencercc2d1e22004-10-30 09:19:36 +0000698$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000699 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000700 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
701 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
702 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000703
Reid Spencercc2d1e22004-10-30 09:19:36 +0000704$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000705 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000706 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
707 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
708 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000709
Reid Spencercc2d1e22004-10-30 09:19:36 +0000710#---------------------------------------------------------
711# Create .o files in the ObjDir directory from the .cpp and .c files...
712#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000713else
Reid Spencer4d71b662004-10-22 21:01:56 +0000714
Reid Spencercc2d1e22004-10-30 09:19:36 +0000715$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000716 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000717 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
718 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
719 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000720
Reid Spencercc2d1e22004-10-30 09:19:36 +0000721$(ObjDir)/%.o: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000722 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000723 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
724 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
725 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000726
727endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000728
Reid Spencercc2d1e22004-10-30 09:19:36 +0000729#---------------------------------------------------------
730# Create .bc files in the ObjDir directory from .cpp and .c files...
731#---------------------------------------------------------
732$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000733 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000734 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
735 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
736 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000737
Reid Spencercc2d1e22004-10-30 09:19:36 +0000738$(ObjDir)/%.bc: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000739 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000740 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
741 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
742 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000743
Reid Spencercc2d1e22004-10-30 09:19:36 +0000744# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000745else
746
Reid Spencer3a561f52004-10-23 20:04:14 +0000747ifdef SHARED_LIBRARY
748
Reid Spencercc2d1e22004-10-30 09:19:36 +0000749$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000750 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000751 $(LTCompile.CXX) $< -o $@
752
Reid Spencercc2d1e22004-10-30 09:19:36 +0000753$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000754 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000755 $(LTCompile.C) $< -o $@
756
757else
Reid Spencer4d71b662004-10-22 21:01:56 +0000758
Reid Spencercc2d1e22004-10-30 09:19:36 +0000759$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000760 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000761 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000762
Reid Spencercc2d1e22004-10-30 09:19:36 +0000763$(ObjDir)/%.o: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000764 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000765 $(Compile.C) $< -o $@
766endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000767
Reid Spencercc2d1e22004-10-30 09:19:36 +0000768$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000769 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000770 $(BCCompile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000771
Reid Spencercc2d1e22004-10-30 09:19:36 +0000772$(ObjDir)/%.bc: %.c $(ObjDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000773 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000774 $(BCCompile.C) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000775
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000776endif
777
Reid Spencercc2d1e22004-10-30 09:19:36 +0000778#---------------------------------------------------------
779# Provide rule to build .bc files from .ll sources,
780# regardless of dependencies
781#---------------------------------------------------------
782$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +0000783 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000784 $(Verb) $(LLVMAS) $< -f -o $@
785
786###############################################################################
787# TABLEGEN: Provide rules for running tblgen to produce *.inc files
788###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +0000789
Reid Spencer4d71b662004-10-22 21:01:56 +0000790ifdef TARGET
791
Reid Spencercc2d1e22004-10-30 09:19:36 +0000792TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
793INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Reid Spencer4d71b662004-10-22 21:01:56 +0000794
Reid Spencercc2d1e22004-10-30 09:19:36 +0000795$(INCFiles) : $(TBLGEN) $(TDFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000796
Reid Spencer16544482004-10-27 04:34:35 +0000797%GenRegisterNames.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000798 $(Echo) "Building $(<F) register names with tblgen"
799 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000800
Reid Spencer16544482004-10-27 04:34:35 +0000801%GenRegisterInfo.h.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000802 $(Echo) "Building $(<F) register information header with tblgen"
803 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000804
805%GenRegisterInfo.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000806 $(Echo) "Building $(<F) register info implementation with tblgen"
807 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000808
809%GenInstrNames.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000810 $(Echo) "Building $(<F) instruction names with tblgen"
811 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000812
813%GenInstrInfo.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000814 $(Echo) "Building $(<F) instruction information with tblgen"
815 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000816
817%GenAsmWriter.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000818 $(Echo) "Building $(<F) assembly writer with tblgen"
819 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000820
821%GenATTAsmWriter.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000822 $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
823 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000824
825%GenIntelAsmWriter.inc : %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000826 $(Echo) "Building $(<F) Intel assembly writer with tblgen"
827 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000828
829%GenInstrSelector.inc: %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000830 $(Echo) "Building $(<F) instruction selector with tblgen"
831 $(Verb) $(TableGen) -gen-instr-selector -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000832
833%GenCodeEmitter.inc:: %.td
Reid Spencercc2d1e22004-10-30 09:19:36 +0000834 $(Echo) "Building $(<F) code emitter with tblgen"
835 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000836
Reid Spencer3a561f52004-10-23 20:04:14 +0000837clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000838 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000839
840endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000841
Reid Spencercc2d1e22004-10-30 09:19:36 +0000842###############################################################################
843# LEX AND YACC: Provide rules for generating sources with lex and yacc
844###############################################################################
Chris Lattnere8996782003-01-16 22:44:19 +0000845
Reid Spencercc2d1e22004-10-30 09:19:36 +0000846#---------------------------------------------------------
847# Provide rules for generating a .cpp source file from
848# (f)lex input sources.
849#---------------------------------------------------------
850
Reid Spencer3d659492004-11-02 16:36:03 +0000851LexFiles := $(filter %.l,$(Sources))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000852
Reid Spencer3d659492004-11-02 16:36:03 +0000853ifneq ($(LexFiles),)
854
855LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000856
857.PRECIOUS: $(LexOutput)
858
859# Note the extra sed filtering here, used to cut down on the warnings emited
860# by GCC. The last line is a gross hack to work around flex aparently not
861# being able to resize the buffer on a large token input. Currently, for
862# uninitialized string buffers in LLVM we can generate very long tokens, so
863# this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000864# FIXME. (f.e. char Buffer[10000] )
Chris Lattner00950542001-06-06 20:29:01 +0000865%.cpp: %.l
Reid Spencercc2d1e22004-10-30 09:19:36 +0000866 $(Echo) Flexing $<
867 $(Verb) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000868 $(SED) 's/void yyunput/inline void yyunput/' | \
869 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
870 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer80f0ef72004-10-28 00:41:43 +0000871 > $@
Chris Lattner00950542001-06-06 20:29:01 +0000872
Reid Spencer9af3b292004-11-01 07:50:27 +0000873clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000874 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencer3d659492004-11-02 16:36:03 +0000875 $(Verb) $(RM) -f $(LexOutput)
Reid Spencer9af3b292004-11-01 07:50:27 +0000876
Reid Spencercc2d1e22004-10-30 09:19:36 +0000877endif
878
879#---------------------------------------------------------
880# Provide rules for generating a .cpp and .h source files
881# from yacc (bison) input sources.
882#---------------------------------------------------------
883
Reid Spencer3d659492004-11-02 16:36:03 +0000884YaccFiles := $(filter %.y,$(Sources))
885ifneq ($(YaccFiles),)
886YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000887
888.PRECIOUS: $(YaccOutput)
889
890# Cancel built-in rules for yacc
891%.c: %.y
892%.cpp: %.y
893%.h: %.y
894
Chris Lattner00950542001-06-06 20:29:01 +0000895# Rule for building the bison parsers...
Chris Lattner00950542001-06-06 20:29:01 +0000896%.cpp %.h : %.y
Reid Spencercc2d1e22004-10-30 09:19:36 +0000897 $(Echo) "Bisoning $*.y"
898 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
899 $(Verb) $(MV) -f $*.tab.c $*.cpp
900 $(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000901
Reid Spencer9af3b292004-11-01 07:50:27 +0000902clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000903 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencer3d659492004-11-02 16:36:03 +0000904 $(Verb) $(RM) -f $(YaccOutput)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000905endif
Chris Lattner00950542001-06-06 20:29:01 +0000906
Reid Spencercc2d1e22004-10-30 09:19:36 +0000907###############################################################################
908# OTHER RULES: Other rules needed
909###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000910
Chris Lattner30440c62003-01-16 21:06:18 +0000911# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000912ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000913%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000914 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000915else
916%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +0000917 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000918endif
Chris Lattner30440c62003-01-16 21:06:18 +0000919
John Criswell7f336952003-09-06 14:44:17 +0000920# This rules ensures that header files that are removed still have a rule for
921# which they can be "generated." This allows make to ignore them and
922# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +0000923%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000924
Reid Spencercc2d1e22004-10-30 09:19:36 +0000925# Define clean-local to clean the current directory. Note that this uses a
926# very conservative approach ensuring that empty variables do not cause
927# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +0000928clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000929ifneq ($(strip $(ObjDir)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000930 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000931endif
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000932 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000933ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000934 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000935endif
John Criswell7a73b802003-06-30 21:59:07 +0000936
Reid Spencer3d659492004-11-02 16:36:03 +0000937clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000938 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +0000939
Reid Spencercc2d1e22004-10-30 09:19:36 +0000940# Build tags database for Emacs/Xemacs:
Reid Spencer12d79512004-11-12 02:27:36 +0000941tags:: TAGS CTAGS
942
Reid Spencercc2d1e22004-10-30 09:19:36 +0000943TAGS:
Reid Spencer12d79512004-11-12 02:27:36 +0000944 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
945 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
946 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
947 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
948 -name '*.cpp' -o -name '*.h' | \
Reid Spencercc2d1e22004-10-30 09:19:36 +0000949 $(ETAGS) $(ETAGSFLAGS) -
950
Reid Spencer12d79512004-11-12 02:27:36 +0000951CTAGS:
952 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
953 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
954 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
955 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
956 \( -name '*.cpp' -o -name '*.h' \) -print | \
957 ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
958
959
Reid Spencer3a561f52004-10-23 20:04:14 +0000960###############################################################################
961# DEPENDENCIES: Include the dependency files if we should
962###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +0000963ifndef DISABLE_AUTO_DEPENDENCIES
964
Reid Spencer3a561f52004-10-23 20:04:14 +0000965# If its not one of the cleaning targets
Reid Spencercc2d1e22004-10-30 09:19:36 +0000966ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000967
Reid Spencer3a561f52004-10-23 20:04:14 +0000968# Get the list of dependency files
Reid Spencercc2d1e22004-10-30 09:19:36 +0000969DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencer9af3b292004-11-01 07:50:27 +0000970DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000971
Reid Spencer3a561f52004-10-23 20:04:14 +0000972-include /dev/null $(DependFiles)
973
John Criswelld741bcf2003-08-12 18:51:51 +0000974endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000975
Reid Spencercc2d1e22004-10-30 09:19:36 +0000976endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000977
Reid Spencer151f8ba2004-10-25 08:27:37 +0000978###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +0000979# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +0000980###############################################################################
981
Reid Spencere45ebfa2004-10-26 07:09:33 +0000982#------------------------------------------------------------------------
983# Define distribution related variables
984#------------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +0000985DistName := $(LLVM_TARBALL_NAME)
986DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000987TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000988DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
989DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
990DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
991DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
992 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +0000993 Makefile.config.in configure autoconf
994DistOther := $(notdir $(wildcard \
995 $(BUILD_SRC_DIR)/*.h \
996 $(BUILD_SRC_DIR)/*.td \
997 $(BUILD_SRC_DIR)/*.def \
998 $(BUILD_SRC_DIR)/*.ll \
999 $(BUILD_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001000DistSources := $(Sources) $(EXTRA_DIST)
1001DistSubDirs := $(SubDirs)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001002DistFiles := $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001003
Reid Spencere45ebfa2004-10-26 07:09:33 +00001004#------------------------------------------------------------------------
1005# We MUST build distribution with OBJ_DIR != SRC_DIR
1006#------------------------------------------------------------------------
1007ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1008dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001009 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00001010
1011DistCheckTop :=
1012else
1013
1014DistCheckTop := check
Reid Spencercc2d1e22004-10-30 09:19:36 +00001015
Reid Spencere45ebfa2004-10-26 07:09:33 +00001016#------------------------------------------------------------------------
1017# Prevent catastrophic remove
1018#------------------------------------------------------------------------
1019ifeq ($(LLVM_TARBALL_NAME),)
1020$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
1021endif
1022
1023#------------------------------------------------------------------------
1024# Prevent attempt to run dist targets from anywhere but the top level
1025#------------------------------------------------------------------------
1026ifneq ($(LEVEL),.)
1027
1028dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001029 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001030
1031else
1032
1033#------------------------------------------------------------------------
1034# Provide the top level targets
1035#------------------------------------------------------------------------
1036
Reid Spencercc2d1e22004-10-30 09:19:36 +00001037dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001038
1039$(DistTarGZip) : distdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001040 $(Echo) Packing gzipped distribution tar file.
1041 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00001042
Reid Spencercc2d1e22004-10-30 09:19:36 +00001043dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001044
1045$(DistTarBZ2) : distdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001046 $(Echo) Packing bzipped distribution tar file.
1047 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001048
Reid Spencercc2d1e22004-10-30 09:19:36 +00001049dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001050
1051$(DistZip) : distdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001052 $(Echo) Packing zipped distribution file.
1053 $(Verb) rm -f $(DistZip)
1054 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001055
1056dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001057 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001058
1059DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1060
Reid Spencer9411c642004-10-26 22:26:33 +00001061dist-check:: $(DistCheckTop) $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001062 $(Echo) Checking distribution tar file.
1063 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001064 $(RM) -rf $(DistCheckDir) ; \
1065 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00001066 $(Verb) $(MKDIR) $(DistCheckDir)
1067 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001068 $(MKDIR) $(DistCheckDir)/build && \
1069 $(MKDIR) $(DistCheckDir)/install && \
1070 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1071 cd build && \
1072 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1073 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1074 $(MAKE) check && \
1075 $(MAKE) install && \
1076 $(MAKE) uninstall && \
1077 $(MAKE) dist && \
1078 $(MAKE) clean && \
1079 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001080 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001081
1082dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001083 $(Echo) Cleaning distribution files
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001084 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001085
1086endif
1087
1088#------------------------------------------------------------------------
1089# Provide the recursive distdir target for building the distribution directory
1090#------------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +00001091distdir : $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001092 $(Echo) Building Distribution Directory $(DistDir)
1093 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001094 if test -d "$(DistDir)" ; then \
1095 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1096 exit 1 ; \
1097 fi ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001098 $(EchoCmd) Removing $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001099 $(RM) -rf $(DistDir); \
1100 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00001101 $(Verb) $(MKDIR) $(DistDir)
1102 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001103 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1104 for file in $(DistFiles) ; do \
1105 case "$$file" in \
1106 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001107 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001108 esac; \
1109 if test -f "$$file" || test -d "$$file" ; then \
1110 from_dir=. ; \
1111 else \
1112 from_dir=$(BUILD_SRC_DIR); \
1113 fi; \
1114 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1115 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1116 to_dir="$(DistDir)/$$dir"; \
1117 $(MKDIR) "$$to_dir" ; \
1118 else \
1119 to_dir="$(DistDir)"; \
1120 fi; \
1121 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1122 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001123 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001124 fi ; \
1125 if test -d "$$from_dir/$$file"; then \
1126 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1127 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1128 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1129 fi; \
1130 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1131 elif test -f "$$from_dir/$$file" ; then \
1132 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1133 elif test -L "$$from_dir/$$file" ; then \
1134 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1135 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001136 $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1137 elif test "$(Verb)" != '@' ; then \
1138 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001139 fi; \
1140 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00001141 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001142 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001143 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001144 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1145 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001146 fi; \
1147 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00001148 $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1149 -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001150 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1151 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1152 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1153 || chmod -R a+r $(DistDir)
1154
Reid Spencercc2d1e22004-10-30 09:19:36 +00001155# This is invoked by distdir target, define it as a no-op to avoid errors if not
1156# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00001157dist-hook::
1158
Reid Spencere53e3972004-10-22 23:06:30 +00001159endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001160
1161###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00001162# TOP LEVEL - targets only to apply at the top level directory
1163###############################################################################
1164
1165ifeq ($(LEVEL),.)
1166
1167#------------------------------------------------------------------------
Reid Spencere5487ba2004-10-24 07:53:21 +00001168# Install support for project's include files:
1169#------------------------------------------------------------------------
1170install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001171 $(Echo) Installing include files
1172 $(Verb) $(MKDIR) $(includedir)
1173 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001174 cd $(BUILD_SRC_ROOT)/include && \
1175 find . -path '*/Internal' -prune -o '(' -type f \
1176 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1177 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1178 fi
1179
1180uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001181 $(Echo) Uninstalling include files
1182 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001183 cd $(BUILD_SRC_ROOT)/include && \
1184 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1185 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1186 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1187 fi
1188
Reid Spencere5487ba2004-10-24 07:53:21 +00001189endif
1190
Reid Spencer4d71b662004-10-22 21:01:56 +00001191#------------------------------------------------------------------------
1192# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00001193#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001194printvars::
Reid Spencer9af3b292004-11-01 07:50:27 +00001195 $(Echo) "BuildMode : " '$(BuildMode)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001196 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1197 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1198 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1199 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1200 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1201 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1202 $(Echo) "libdir : " '$(libdir)'
1203 $(Echo) "bindir : " '$(bindir)'
1204 $(Echo) "sysconfdir : " '$(sysconfdir)'
1205 $(Echo) "bytecode_libdir: " '$(bytecode_libdir)'
1206 $(Echo) "UserTargets : " '$(UserTargets)'
1207 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1208 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1209 $(Echo) "ObjDir : " '$(ObjDir)'
1210 $(Echo) "LibDir : " '$(LibDir)'
1211 $(Echo) "ToolDir : " '$(ToolDir)'
Reid Spencer815cbcf2004-11-18 10:03:46 +00001212 $(Echo) "ExmplDir : " '$(ExmplDir)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001213 $(Echo) "TDFiles : " '$(TDFiles)'
1214 $(Echo) "INCFiles : " '$(INCFiles)'
1215 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1216 $(Echo) "Compile.C : " '$(Compile.C)'
1217 $(Echo) "Archive : " '$(Archive)'
Reid Spencer3d659492004-11-02 16:36:03 +00001218 $(Echo) "YaccFiles : " '$(YaccFiles)'
1219 $(Echo) "LexFiles : " '$(LexFiles)'