blob: 4f4fb452a12c2d86ca6502609d5248a49dd5db87 [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#--------------------------------------------------------------------
Chris Lattner7dc02822004-12-03 21:05:57 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode
Reid Spencer9e8d54a2004-12-06 05:35:13 +000023LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencer44cb1b32004-12-03 20:08:48 +000024 install-local printvars uninstall-local \
25 install-bytecode-local
Reid Spencer9e8d54a2004-12-06 05:35:13 +000026TopLevelTargets := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
Reid Spencercc2d1e22004-10-30 09:19:36 +000027 dist-zip
28UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29InternalTargets := preconditions distdir dist-hook
Reid Spencer3a561f52004-10-23 20:04:14 +000030
Reid Spencercc2d1e22004-10-30 09:19:36 +000031################################################################################
Reid Spencer9411c642004-10-26 22:26:33 +000032# INITIALIZATION: Basic things the makefile needs
Reid Spencercc2d1e22004-10-30 09:19:36 +000033################################################################################
34
35#--------------------------------------------------------------------
36# Set the VPATH so that we can find source files.
37#--------------------------------------------------------------------
38VPATH=$(BUILD_SRC_DIR)
Reid Spencer9411c642004-10-26 22:26:33 +000039
40#--------------------------------------------------------------------
41# Reset the list of suffixes we know how to build
42#--------------------------------------------------------------------
43.SUFFIXES:
Reid Spencercc2d1e22004-10-30 09:19:36 +000044.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
45.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer9411c642004-10-26 22:26:33 +000046
Reid Spencer3a561f52004-10-23 20:04:14 +000047#--------------------------------------------------------------------
48# Mark all of these targets as phony to avoid implicit rule search
49#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000050.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer3a561f52004-10-23 20:04:14 +000051
52#--------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +000053# Make sure all the user-target rules are double colon rules and
54# they are defined first.
Reid Spencer3a561f52004-10-23 20:04:14 +000055#--------------------------------------------------------------------
56
Reid Spencercc2d1e22004-10-30 09:19:36 +000057$(UserTargets)::
Reid Spencer151f8ba2004-10-25 08:27:37 +000058
Reid Spencer9411c642004-10-26 22:26:33 +000059################################################################################
60# PRECONDITIONS: that which must be built/checked first
61################################################################################
62
Reid Spencer44cb1b32004-12-03 20:08:48 +000063SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencer023c4462004-11-17 19:08:44 +000064 $(wildcard $(BUILD_SRC_DIR)/Makefile*))
Reid Spencercc2d1e22004-10-30 09:19:36 +000065ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
66ConfigureScript := $(LLVM_SRC_ROOT)/configure
67ConfigStatusScript := $(LLVM_OBJ_ROOT)/config.status
68MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
69MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
70PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
Reid Spencer9411c642004-10-26 22:26:33 +000071
Reid Spencercc2d1e22004-10-30 09:19:36 +000072preconditions : $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +000073
74#------------------------------------------------------------------------
75# Make sure the BUILT_SOURCES are built first
76#------------------------------------------------------------------------
Reid Spencer07a549a2004-12-16 07:15:16 +000077$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000078
79clean-local::
80ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +000081 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000082endif
83
Reid Spencer31f95242004-12-16 08:00:46 +000084ifneq ($(BUILD_OBJ_ROOT),$(BUILD_SRC_ROOT))
85spotless:
86 $(Echo) Wiping out $(BUILD_OBJ_ROOT) and rebuilding configuration.
87 $(Verb) if test -x config.status ; then \
88 $(MV) config.status .. ; \
89 $(MV) mklib .. ; \
90 $(RM) -rf * ; \
91 $(MV) ../config.status . ; \
92 $(MV) ../mklib . ; \
93 ./config.status ; \
94 else \
95 $(EchoCmd) "make spotless" can only be run from $(BUILD_OBJ_ROOT); \
96 fi
97endif
98
Reid Spencercc2d1e22004-10-30 09:19:36 +000099$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +0000100
Reid Spencer9411c642004-10-26 22:26:33 +0000101#------------------------------------------------------------------------
102# Make sure we're not using a stale configuration
103#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000104.PRECIOUS: $(ConfigStatusScript)
105$(ConfigStatusScript): $(ConfigureScript)
106 $(Echo) Reconfiguring with $<
Reid Spencer7d277002004-11-29 12:37:44 +0000107 $(Verb) cd $(BUILD_OBJ_ROOT) && \
108 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
109 $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +0000110
111#------------------------------------------------------------------------
112# Make sure the configuration makefile is up to date
113#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000114$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
115 $(Echo) Regenerating $@
116 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
Reid Spencer9411c642004-10-26 22:26:33 +0000117
118#------------------------------------------------------------------------
119# If the Makefile in the source tree has been updated, copy it over into the
120# build tree. But, only do this if the source and object makefiles differ
121#------------------------------------------------------------------------
122ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
123
Reid Spencer023c4462004-11-17 19:08:44 +0000124Makefile: $(BUILD_SRC_DIR)/Makefile
Reid Spencercc2d1e22004-10-30 09:19:36 +0000125 $(Echo) "Updating Makefile"
126 $(Verb) $(MKDIR) $(@D)
127 $(Verb) cp -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000128
129# Copy the Makefile.* files unless we're in the root directory which avoids
130# the copying of Makefile.config.in or other things that should be explicitly
131# taken care of.
Reid Spencer9411c642004-10-26 22:26:33 +0000132$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
Reid Spencer86606782004-10-26 23:10:00 +0000133 @case '$?' in \
134 *Makefile.rules) ;; \
135 *.in) ;; \
Reid Spencercc2d1e22004-10-30 09:19:36 +0000136 *) $(Echo) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000137 $(MKDIR) $(@D) ; \
138 cp -f $< $@ ;; \
139 esac
140
Reid Spencer9411c642004-10-26 22:26:33 +0000141endif
142
143#------------------------------------------------------------------------
144# Set up the basic dependencies
145#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000146$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000147
148all:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000149clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000150clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000151install:: install-local
152uninstall:: uninstall-local
Reid Spencer9411c642004-10-26 22:26:33 +0000153install-local:: all-local
Reid Spencer44cb1b32004-12-03 20:08:48 +0000154install-bytecode:: install-bytecode-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000155
156###############################################################################
157# VARIABLES: Set up various variables based on configuration data
158###############################################################################
159
160#--------------------------------------------------------------------
161# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000162#--------------------------------------------------------------------
163
Chris Lattner760da062003-03-14 20:25:22 +0000164ifdef ENABLE_PROFILING
Reid Spencer9af3b292004-11-01 07:50:27 +0000165 BuildMode := Profile
Reid Spencer519799e2004-12-08 04:34:51 +0000166 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
Reid Spencercc2d1e22004-10-30 09:19:36 +0000167 C.Flags := -O3 -DNDEBUG -pg
168 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000169else
170 ifdef ENABLE_OPTIMIZED
Reid Spencer9af3b292004-11-01 07:50:27 +0000171 BuildMode := Release
Reid Spencer519799e2004-12-08 04:34:51 +0000172 CXX.Flags := -O3 -DNDEBUG -finline-functions \
Reid Spencer2e2035b2004-12-08 04:26:23 +0000173 -felide-constructors -fomit-frame-pointer
Reid Spencercc2d1e22004-10-30 09:19:36 +0000174 C.Flags := -O3 -DNDEBUG -fomit-frame-pointer
175 LD.Flags := -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000176 else
Reid Spencer9af3b292004-11-01 07:50:27 +0000177 BuildMode := Debug
Reid Spencer519799e2004-12-08 04:34:51 +0000178 CXX.Flags := -g -D_DEBUG
Reid Spencercc2d1e22004-10-30 09:19:36 +0000179 C.Flags := -g -D_DEBUG
180 LD.Flags := -g -D_DEBUG
Reid Spencer4d71b662004-10-22 21:01:56 +0000181 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000182 endif
183endif
184
Reid Spencercc2d1e22004-10-30 09:19:36 +0000185CXX.Flags += $(CXXFLAGS)
186C.Flags += $(CFLAGS)
187CPP.Flags += $(CPPFLAGS)
188LD.Flags += $(LDFLAGS)
189AR.Flags := cru
190LibTool.Flags := --tag=CXX
Reid Spencer3a561f52004-10-23 20:04:14 +0000191
192#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000193# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000194#--------------------------------------------------------------------
Reid Spencer9af3b292004-11-01 07:50:27 +0000195ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000196LibDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer9a5acaf2004-11-18 20:04:39 +0000197ToolDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer815cbcf2004-11-18 10:03:46 +0000198ExmplDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
199LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer9a5acaf2004-11-18 20:04:39 +0000200LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer815cbcf2004-11-18 10:03:46 +0000201LExmplDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell7a73b802003-06-30 21:59:07 +0000202
Reid Spencer3a561f52004-10-23 20:04:14 +0000203#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000204# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000205#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000206EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
207Echo := @$(EchoCmd)
208ifndef LIBTOOL
Reid Spencer4d71b662004-10-22 21:01:56 +0000209LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencercc2d1e22004-10-30 09:19:36 +0000210endif
211ifndef LLVMAS
212LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
213endif
214ifndef BURG
215BURG := $(LLVMToolDir)/burg$(EXEEXT)
216endif
217ifndef TBLGEN
218TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
219endif
Chris Lattner478b3b42004-11-29 19:47:58 +0000220ifndef GCCAS
221GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
222endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000223ifndef GCCLD
224GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
225endif
226ifndef LLVMGCC
227LLVMGCC := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
228endif
229ifndef LLVMGXX
230LLVMGXX := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
231endif
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000232ifndef LDIS
233LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
234endif
235ifndef LLI
236LLI := $(LLVMToolDir)/lli$(EXEEXT)
237endif
238ifndef LOPT
Alkis Evlogimenos20d793a2004-12-13 18:08:29 +0000239LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000240endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000241
Reid Spencer3a561f52004-10-23 20:04:14 +0000242#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000243# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000244#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000245
Reid Spencercc2d1e22004-10-30 09:19:36 +0000246# Adjust LIBTOOL flags for shared libraries, or not.
John Criswell82f4a5a2003-07-31 20:58:51 +0000247ifndef SHARED_LIBRARY
Reid Spencercc2d1e22004-10-30 09:19:36 +0000248 LibTool.Flags += --tag=disable-shared
Reid Spencer4d71b662004-10-22 21:01:56 +0000249else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000250 LD.Flags += -rpath $(LibDir)
John Criswell82f4a5a2003-07-31 20:58:51 +0000251endif
252
Reid Spencercceed9f2004-11-08 17:32:12 +0000253ifdef TOOL_VERBOSE
254 C.Flags += -v
255 CXX.Flags += -v
256 LD.Flags += -v
Reid Spencercceed9f2004-11-08 17:32:12 +0000257 VERBOSE := 1
258endif
259
Reid Spencer3a561f52004-10-23 20:04:14 +0000260# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000261ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000262 Verb := @
263 LibTool.Flags += --silent
264 AR.Flags += >/dev/null 2>/dev/null
265 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000266else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000267 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000268endif
269
Vikram S. Advefeeae582002-09-18 11:55:13 +0000270# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000271ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000272 Strip := $(PLATFORMSTRIPOPTS)
273 StripWarnMsg := "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000274endif
275
Reid Spencer3a561f52004-10-23 20:04:14 +0000276# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000277ifdef TOOLNAME
Reid Spencer815cbcf2004-11-18 10:03:46 +0000278ifdef EXAMPLE_TOOL
279 LD.Flags += -rpath $(ExmplDir) -export-dynamic
280else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000281 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000282endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000283endif
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000284
Reid Spencer3a561f52004-10-23 20:04:14 +0000285#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000286# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000287#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000288
289CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
290
Reid Spencercc2d1e22004-10-30 09:19:36 +0000291LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
292CPP.Flags += -I$(BUILD_OBJ_DIR) \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000293 -I$(BUILD_SRC_DIR) \
294 -I$(BUILD_SRC_ROOT)/include \
295 -I$(BUILD_OBJ_ROOT)/include \
296 -I$(LLVM_OBJ_ROOT)/include \
297 -I$(LLVM_SRC_ROOT)/include \
298 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencer4d71b662004-10-22 21:01:56 +0000299
Reid Spencercc2d1e22004-10-30 09:19:36 +0000300Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
301LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
302BCCompile.C = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
303Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
304LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
305BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
306Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
307 $(CompileCommonOpts) $(LD.Flags) $(Strip)
308Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencera69b1ea2004-10-28 09:15:28 +0000309 $(CompileCommonOpts)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000310LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
Reid Spencer3a561f52004-10-23 20:04:14 +0000311Burg = $(BURG) -I $(BUILD_SRC_DIR)
312TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000313Archive = $(AR) $(AR.Flags)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000314LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000315ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000316Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000317else
Reid Spencer3a561f52004-10-23 20:04:14 +0000318Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000319endif
320
Chris Lattner00950542001-06-06 20:29:01 +0000321#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000322# Get the list of source files and compute object file
323# names from them.
Reid Spencer3a561f52004-10-23 20:04:14 +0000324#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000325ifdef FAKE_SOURCES
326 Sources :=
327 FakeSources := $(FAKE_SOURCES)
328 ifdef BUILT_SOURCES
329 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
330 endif
331 BaseNameSources := $(sort $(basename $(FakeSources)))
332 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
333 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
334 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000335else
Reid Spencer345235ca2004-12-04 22:34:09 +0000336 ifndef SOURCES
337 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
338 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
339 $(BUILD_SRC_DIR)/*.l))
340 else
341 Sources := $(SOURCES)
342 endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000343
Reid Spencer345235ca2004-12-04 22:34:09 +0000344 ifdef BUILT_SOURCES
345 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
346 endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000347
Reid Spencer345235ca2004-12-04 22:34:09 +0000348 BaseNameSources := $(sort $(basename $(Sources)))
349 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
350 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
351 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
352endif
Reid Spencer3a561f52004-10-23 20:04:14 +0000353
354###############################################################################
355# DIRECTORIES: Handle recursive descent of directory structure
356###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000357
Chris Lattner00950542001-06-06 20:29:01 +0000358#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000359# Provide rules to make install dirs. This must be early
360# in the file so they get built before dependencies
361#---------------------------------------------------------
362
363$(bindir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000364 $(Verb) $(MKDIR) $(bindir)
Chris Lattnere4cb90f2004-11-01 06:14:59 +0000365
Reid Spencera69b1ea2004-10-28 09:15:28 +0000366$(libdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000367 $(Verb) $(MKDIR) $(libdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000368
Reid Spencerab3690b2004-12-13 07:38:07 +0000369$(includedir):
370 $(Verb) $(MKDIR) $(includedir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000371
372$(sysconfdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000373 $(Verb) $(MKDIR) $(sysconfdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000374
Reid Spencercc2d1e22004-10-30 09:19:36 +0000375# To create other directories, as needed, and timestamp their creation
376%/.dir:
377 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfbbf3072004-11-29 05:00:33 +0000378 $(Verb) $(DATE) > $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000379
Reid Spencer815cbcf2004-11-18 10:03:46 +0000380.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
381.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000382
383#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000384# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000385#---------------------------------------------------------
386
Reid Spencercc2d1e22004-10-30 09:19:36 +0000387SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000388ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000389SubDirs += $(DIRS)
390$(RecursiveTargets)::
391 $(Verb) for dir in $(DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000392 if [ ! -f $$dir/Makefile ]; then \
393 $(MKDIR) $$dir; \
394 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
395 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000396 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
397 ($(MAKE) -C $$dir $@ ) || exit 1; \
398 fi ; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000399 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000400endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000401
Reid Spencer3a561f52004-10-23 20:04:14 +0000402#---------------------------------------------------------
403# Handle the EXPERIMENTAL_DIRS options ensuring success
404# after each directory is built.
405#---------------------------------------------------------
406ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000407$(RecursiveTargets)::
408 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer3a561f52004-10-23 20:04:14 +0000409 if [ ! -f $$dir/Makefile ]; then \
410 $(MKDIR) $$dir; \
411 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
412 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000413 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
414 ($(MAKE) -C $$dir $@ ) || exit 0; \
415 fi ; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000416 done
417endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000418
Reid Spencer3a561f52004-10-23 20:04:14 +0000419#---------------------------------------------------------
420# Handle the PARALLEL_DIRS options for parallel construction
421#---------------------------------------------------------
422ifdef PARALLEL_DIRS
423
Reid Spencercc2d1e22004-10-30 09:19:36 +0000424SubDirs += $(PARALLEL_DIRS)
425
Reid Spencer44cb1b32004-12-03 20:08:48 +0000426# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencercc2d1e22004-10-30 09:19:36 +0000427all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
428clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000429clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000430install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000431uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencer44cb1b32004-12-03 20:08:48 +0000432install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000433
Reid Spencer345235ca2004-12-04 22:34:09 +0000434ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000435
Reid Spencer345235ca2004-12-04 22:34:09 +0000436$(ParallelTargets) :
Reid Spencercc2d1e22004-10-30 09:19:36 +0000437 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000438 $(MKDIR) $(@D); \
439 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000440 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000441 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
442 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
443 fi
Chris Lattner00950542001-06-06 20:29:01 +0000444endif
445
Reid Spencer3a561f52004-10-23 20:04:14 +0000446#---------------------------------------------------------
447# Handle the OPTIONAL_DIRS options for directores that may
448# or may not exist.
449#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000450ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000451
Reid Spencercc2d1e22004-10-30 09:19:36 +0000452SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000453
Reid Spencercc2d1e22004-10-30 09:19:36 +0000454$(RecursiveTargets)::
455 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000456 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
457 if [ ! -f $$dir/Makefile ]; then \
458 $(MKDIR) $$dir; \
459 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
460 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000461 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
462 ($(MAKE) -C$$dir $@ ) || exit 1; \
463 fi ; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000464 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000465 done
466endif
467
Reid Spencerfc945082004-08-20 09:20:05 +0000468#---------------------------------------------------------
469# Handle the CONFIG_FILES options
470#---------------------------------------------------------
471ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000472
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000473install-local:: $(sysconfdir) $(CONFIG_FILES)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000474 $(Echo) Installing Configuration Files To $(sysconfdir)
475 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer1b426ab2004-11-23 05:59:53 +0000476 if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
477 $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
478 elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
479 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
480 else \
481 $(ECHO) Error: cannot find config file $${file}. ; \
482 fi \
Reid Spencerfc945082004-08-20 09:20:05 +0000483 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000484
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000485uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000486 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
487 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000488 $(RM) -f $(sysconfdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000489 done
490
Reid Spencerfc945082004-08-20 09:20:05 +0000491endif
492
Reid Spencer3a561f52004-10-23 20:04:14 +0000493###############################################################################
494# Library Build Rules: Four ways to build a library
495###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000496
Reid Spencer7980ea42004-12-05 05:17:22 +0000497#---------------------------------------------------------
498# Bytecode Module Targets:
499# If the user set MODULE_NAME then they want to build a
500# bytecode module from the sources. We compile all the
501# sources and link it together into a single bytecode
502# module.
503#---------------------------------------------------------
504
505ifdef MODULE_NAME
506
507Module := $(LibDir)/$(MODULE_NAME).bc
508LinkModule := $(LLVMGCC) -shared -nostdlib
509
510ifdef EXPORTED_SYMBOL_FILE
511LinkMOdule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
512endif
513
514$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
515 $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
516 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
517
518all-local:: $(Module)
519
520clean-local::
521ifneq ($(strip $(Module)),)
522 -$(Verb) $(RM) -f $(Module)
523endif
524
Reid Spencerab3690b2004-12-13 07:38:07 +0000525ifdef BYTECODE_DESTINATION
526ModuleDestDir := $(BYTECODE_DESTINATION)
527else
Reid Spencer18d3b982004-12-14 22:44:05 +0000528ModuleDestDir := $(libdir)
Reid Spencerab3690b2004-12-13 07:38:07 +0000529endif
Reid Spencer7980ea42004-12-05 05:17:22 +0000530
Reid Spencerab3690b2004-12-13 07:38:07 +0000531DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
532
533install-module:: $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +0000534install-local:: $(DestModule)
535
Reid Spencerab3690b2004-12-13 07:38:07 +0000536$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencer7980ea42004-12-05 05:17:22 +0000537 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
538 $(Verb) $(INSTALL) $(Module) $@
539
540uninstall-local::
541 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
542 -$(Verb) $(RM) -f $(DestModule)
543
544endif
Brian Gaeke8abff792004-01-22 22:53:48 +0000545
Reid Spencer3a561f52004-10-23 20:04:14 +0000546# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000547ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000548
Chris Lattner2a548c52002-09-16 22:36:42 +0000549# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000550LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000551LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
552LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
553LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer9a2f1372004-12-02 09:28:21 +0000554LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000555
Reid Spencer3a561f52004-10-23 20:04:14 +0000556#---------------------------------------------------------
557# Shared Library Targets:
558# If the user asked for a shared library to be built
559# with the SHARED_LIBRARY variable, then we provide
560# targets for building them.
561#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000562ifdef SHARED_LIBRARY
563
Reid Spencercc2d1e22004-10-30 09:19:36 +0000564all-local:: $(LibName.LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000565
Reid Spencerf2ac1892004-12-16 07:36:08 +0000566$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000567 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000568 $(Verb) $(Link) -o $@ $(ObjectsLO)
569 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencer3a561f52004-10-23 20:04:14 +0000570
571clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000572ifneq ($(strip $(LibName.LA)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000573 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000574endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000575
Reid Spencere5487ba2004-10-24 07:53:21 +0000576DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000577
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000578install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000579
Reid Spencercc2d1e22004-10-30 09:19:36 +0000580$(DestSharedLib): $(libdir) $(LibName.LA)
Reid Spencer9af3b292004-11-01 07:50:27 +0000581 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000582 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
583 $(Verb) $(LIBTOOL) --finish $(libdir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000584
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000585uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000586 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencer12d79512004-11-12 02:27:36 +0000587 -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
Reid Spencere5487ba2004-10-24 07:53:21 +0000588
Reid Spencer4d71b662004-10-22 21:01:56 +0000589endif
590
Reid Spencer3a561f52004-10-23 20:04:14 +0000591#---------------------------------------------------------
592# Bytecode Library Targets:
593# If the user asked for a bytecode library to be built
594# with the BYTECODE_LIBRARY variable, then we provide
595# targets for building them.
596#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000597ifdef BYTECODE_LIBRARY
598
Reid Spencer776b8052004-12-03 06:04:35 +0000599# make the C and C++ compilers strip debug info out of bytecode libraries.
600BCCompile.C += -Wa,-strip-debug
601BCCompile.CXX += -Wa,-strip-debug
602
Reid Spencer9a2f1372004-12-02 09:28:21 +0000603all-local:: $(LibName.BCA)
604
605ifdef EXPORTED_SYMBOL_FILE
606BCLinkLib = $(LLVMGCC) -shared -nostdlib -Xlinker \
607 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
608
Reid Spencerf2ac1892004-12-16 07:36:08 +0000609$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000610 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000611 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
612 "(internalize)"
Chris Lattnerb0ea8642004-12-02 21:23:43 +0000613 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000614 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000615 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
Reid Spencer4d71b662004-10-22 21:01:56 +0000616else
Reid Spencerf2ac1892004-12-16 07:36:08 +0000617$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000618 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000619 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000620 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000621 $(Verb) $(LArchive) $@ $(ObjectsBC)
622
Reid Spencer4d71b662004-10-22 21:01:56 +0000623endif
624
Reid Spencer3a561f52004-10-23 20:04:14 +0000625clean-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000626ifneq ($(strip $(LibName.BCA)),)
627 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000628endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000629
Reid Spencer8f094f32004-12-13 07:28:21 +0000630ifdef BYTECODE_DESTINATION
631BytecodeDestDir := $(BYTECODE_DESTINATION)
632else
633BytecodeDestDir := $(libdir)
634endif
635
636DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
Reid Spencer9a2f1372004-12-02 09:28:21 +0000637
Reid Spencer44cb1b32004-12-03 20:08:48 +0000638install-bytecode-local:: $(DestBytecodeLib)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000639
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000640install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000641
Reid Spencer8f094f32004-12-13 07:28:21 +0000642$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000643 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
644 $(Verb) $(INSTALL) $(LibName.BCA) $@
Reid Spencere5487ba2004-10-24 07:53:21 +0000645
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000646uninstall-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000647 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000648 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000649
650endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000651
Reid Spencercc2d1e22004-10-30 09:19:36 +0000652#---------------------------------------------------------
653# ReLinked Library Targets:
654# If the user didn't explicitly forbid building a
655# relinked then we provide targets for building them.
656#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000657ifndef DONT_BUILD_RELINKED
Reid Spencer4d71b662004-10-22 21:01:56 +0000658
Reid Spencercc2d1e22004-10-30 09:19:36 +0000659all-local:: $(LibName.O)
660
Reid Spencerf2ac1892004-12-16 07:36:08 +0000661$(LibName.O): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000662 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000663 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencer4d71b662004-10-22 21:01:56 +0000664
Reid Spencer3a561f52004-10-23 20:04:14 +0000665clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000666ifneq ($(strip $(LibName.O)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000667 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000668endif
669
670DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
671
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000672install-local:: $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000673
Reid Spencercc2d1e22004-10-30 09:19:36 +0000674$(DestRelinkedLib): $(libdir) $(LibName.O)
Reid Spencer9af3b292004-11-01 07:50:27 +0000675 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000676 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000677
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000678uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000679 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000680 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000681
Chris Lattnere62dbe92002-07-23 17:56:16 +0000682endif
Chris Lattner760da062003-03-14 20:25:22 +0000683
Reid Spencercc2d1e22004-10-30 09:19:36 +0000684#---------------------------------------------------------
685# Archive Library Targets:
686# If the user wanted a regular archive library built,
687# then we provide targets for building them.
688#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000689ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +0000690
Reid Spencercc2d1e22004-10-30 09:19:36 +0000691all-local:: $(LibName.A)
692
Reid Spencerf2ac1892004-12-16 07:36:08 +0000693$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000694 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000695 -$(Verb) $(RM) -f $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000696 $(Verb) $(Archive) $@ $(ObjectsO)
697 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000698
Reid Spencer3a561f52004-10-23 20:04:14 +0000699clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000700ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000701 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +0000702endif
703
Reid Spencere5487ba2004-10-24 07:53:21 +0000704DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
705
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000706install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000707
Reid Spencercc2d1e22004-10-30 09:19:36 +0000708$(DestArchiveLib): $(libdir) $(LibName.A)
Reid Spencer9af3b292004-11-01 07:50:27 +0000709 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000710 $(Verb) $(MKDIR) $(libdir)
711 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000712
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000713uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000714 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000715 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000716
717endif
718
719# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000720endif
721
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000722###############################################################################
723# Tool Build Rules: Build executable tool based on TOOLNAME option
724###############################################################################
725
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000726ifdef TOOLNAME
727
Reid Spencercc2d1e22004-10-30 09:19:36 +0000728#---------------------------------------------------------
Reid Spencer7c787c92004-11-29 07:17:07 +0000729# Handle the special "JIT" value for LLVM_LIBS which is a
730# shorthand for a bunch of libraries that get the correct
731# JIT support for a tool that runs JIT.
732#---------------------------------------------------------
733ifeq ($(LLVMLIBS),JIT)
734
735# Make sure we can get our own symbols in the tool
736Link += -dlopen self
737
738# Generic JIT libraries
739JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
740
741# You can enable the X86 JIT on a non-X86 host by setting the flag
742# ENABLE_X86_JIT on the make command line. If not, it will still be
743# enabled automagically on an X86 host.
744ifeq ($(ARCH), x86)
745 ENABLE_X86_JIT = 1
746endif
747
748# What the X86 JIT requires
749ifdef ENABLE_X86_JIT
750 JIT_LIBS += LLVMX86 LLVMSelectionDAG
751endif
752
753# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
754# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
755# enabled automagically on an SparcV9 host.
756ifeq ($(ARCH), Sparc)
757 ENABLE_SPARCV9_JIT = 1
758endif
759
760# What the Sparc JIT requires
761ifdef ENABLE_SPARCV9_JIT
762 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
763 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
764 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
765 LLVMDataStructure.a LLVMSparcV9RegAlloc
766endif
767
768# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
769# ENABLE_PPC_JIT on the make command line. If not, it will still be
770# enabled automagically on an PowerPC host.
771ifeq ($(ARCH), PowerPC)
772 ENABLE_PPC_JIT = 1
773endif
774
775# What the PowerPC JIT requires
776ifdef ENABLE_PPC_JIT
777 JIT_LIBS += LLVMPowerPC
778endif
779
780LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
781 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
782 LLVMSystem.a $(PLATFORMLIBDL)
783endif
784
785#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000786# Set up variables for building a tool.
787#---------------------------------------------------------
Reid Spencer815cbcf2004-11-18 10:03:46 +0000788ifdef EXAMPLE_TOOL
789ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
790else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000791ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000792endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000793ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
794ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
795LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
796LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
797ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
798LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
799ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
800LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000801
Reid Spencercc2d1e22004-10-30 09:19:36 +0000802#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000803# Tell make that we need to rebuild subdirectories before
804# we can link the tool. This affects things like LLI which
805# has library subdirectories.
806#---------------------------------------------------------
807$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000808
Reid Spencercc2d1e22004-10-30 09:19:36 +0000809#---------------------------------------------------------
810# Provide targets for building the tools
811#---------------------------------------------------------
812all-local:: $(ToolBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +0000813
Reid Spencer3a561f52004-10-23 20:04:14 +0000814clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000815ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000816 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +0000817endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000818
Reid Spencer815cbcf2004-11-18 10:03:46 +0000819ifdef EXAMPLE_TOOL
820$(ToolBuildPath): $(ExmplDir)/.dir
821else
822$(ToolBuildPath): $(ToolDir)/.dir
823endif
824
Reid Spencerf2ac1892004-12-16 07:36:08 +0000825$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +0000826 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000827 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
828 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
Reid Spencer9af3b292004-11-01 07:50:27 +0000829 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +0000830
831DestTool = $(bindir)/$(TOOLNAME)
832
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000833install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000834
Reid Spencercc2d1e22004-10-30 09:19:36 +0000835$(DestTool): $(bindir) $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +0000836 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000837 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000838
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000839uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000840 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000841 -$(Verb) $(RM) -f $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000842
Reid Spencer4d71b662004-10-22 21:01:56 +0000843endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000844
Reid Spencercc2d1e22004-10-30 09:19:36 +0000845###############################################################################
846# Object Build Rules: Build object files based on sources
847###############################################################################
848
849# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000850ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000851
Reid Spencercc2d1e22004-10-30 09:19:36 +0000852#---------------------------------------------------------
853# Create .lo files in the ObjDir directory from the .cpp and .c files...
854#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000855ifdef SHARED_LIBRARY
856
Chris Lattner3c473472004-12-16 17:28:50 +0000857$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000858 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000859 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
860 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
861 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000862
Chris Lattner3c473472004-12-16 17:28:50 +0000863$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000864 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000865 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
866 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
867 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000868
Reid Spencercc2d1e22004-10-30 09:19:36 +0000869#---------------------------------------------------------
870# Create .o files in the ObjDir directory from the .cpp and .c files...
871#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000872else
Reid Spencer4d71b662004-10-22 21:01:56 +0000873
Chris Lattner3c473472004-12-16 17:28:50 +0000874$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000875 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000876 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
877 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
878 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000879
Chris Lattner3c473472004-12-16 17:28:50 +0000880$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000881 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000882 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
883 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
884 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000885
886endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000887
Reid Spencercc2d1e22004-10-30 09:19:36 +0000888#---------------------------------------------------------
889# Create .bc files in the ObjDir directory from .cpp and .c files...
890#---------------------------------------------------------
Chris Lattner3c473472004-12-16 17:28:50 +0000891$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000892 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000893 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
894 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
895 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000896
Chris Lattner3c473472004-12-16 17:28:50 +0000897$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000898 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000899 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
900 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
901 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000902
Reid Spencercc2d1e22004-10-30 09:19:36 +0000903# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000904else
905
Reid Spencer3a561f52004-10-23 20:04:14 +0000906ifdef SHARED_LIBRARY
907
Chris Lattner3c473472004-12-16 17:28:50 +0000908$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000909 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000910 $(LTCompile.CXX) $< -o $@
911
Chris Lattner3c473472004-12-16 17:28:50 +0000912$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000913 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000914 $(LTCompile.C) $< -o $@
915
916else
Reid Spencer4d71b662004-10-22 21:01:56 +0000917
Chris Lattner3c473472004-12-16 17:28:50 +0000918$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000919 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000920 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000921
Chris Lattner3c473472004-12-16 17:28:50 +0000922$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000923 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000924 $(Compile.C) $< -o $@
925endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000926
Chris Lattner3c473472004-12-16 17:28:50 +0000927$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000928 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000929 $(BCCompile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000930
Chris Lattner3c473472004-12-16 17:28:50 +0000931$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000932 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000933 $(BCCompile.C) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000934
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000935endif
936
Reid Spencercc2d1e22004-10-30 09:19:36 +0000937#---------------------------------------------------------
938# Provide rule to build .bc files from .ll sources,
939# regardless of dependencies
940#---------------------------------------------------------
941$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +0000942 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000943 $(Verb) $(LLVMAS) $< -f -o $@
944
945###############################################################################
946# TABLEGEN: Provide rules for running tblgen to produce *.inc files
947###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +0000948
Reid Spencer4d71b662004-10-22 21:01:56 +0000949ifdef TARGET
950
Reid Spencercc2d1e22004-10-30 09:19:36 +0000951TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
952INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner3c473472004-12-16 17:28:50 +0000953INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
954.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000955
Chris Lattner3c473472004-12-16 17:28:50 +0000956# All of these files depend on tblgen and the .td files.
957$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000958
Chris Lattner3c473472004-12-16 17:28:50 +0000959
960$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
961$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000962 $(Echo) "Building $(<F) register names with tblgen"
963 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000964
Chris Lattner3c473472004-12-16 17:28:50 +0000965$(TARGET:%=%GenRegisterNames.inc): \
966%GenRegisterNames.inc : $(ObjDir)/%GenRegisterNames.inc.tmp
967 $(Verb) cmp -s $@ $< || cp $< $@
968
969$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
970$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000971 $(Echo) "Building $(<F) register information header with tblgen"
972 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000973
Chris Lattner3c473472004-12-16 17:28:50 +0000974$(TARGET:%=%GenRegisterInfo.h.inc): \
975%GenRegisterInfo.h.inc : $(ObjDir)/%GenRegisterInfo.h.inc.tmp
976 $(Verb) cmp -s $@ $< || cp $< $@
977
978$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
979$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000980 $(Echo) "Building $(<F) register info implementation with tblgen"
981 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000982
Chris Lattner3c473472004-12-16 17:28:50 +0000983$(TARGET:%=%GenRegisterInfo.inc): \
984%GenRegisterInfo.inc : $(ObjDir)/%GenRegisterInfo.inc.tmp
985 $(Verb) cmp -s $@ $< || cp $< $@
986
987$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
988$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000989 $(Echo) "Building $(<F) instruction names with tblgen"
990 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000991
Chris Lattner3c473472004-12-16 17:28:50 +0000992$(TARGET:%=%GenInstrNames.inc): \
993%GenInstrNames.inc : $(ObjDir)/%GenInstrNames.inc.tmp
994 $(Verb) cmp -s $@ $< || cp $< $@
995
996$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
997$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000998 $(Echo) "Building $(<F) instruction information with tblgen"
999 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001000
Chris Lattner3c473472004-12-16 17:28:50 +00001001$(TARGET:%=%GenInstrInfo.inc): \
1002%GenInstrInfo.inc : $(ObjDir)/%GenInstrInfo.inc.tmp
1003 $(Verb) cmp -s $@ $< || cp $< $@
1004
1005$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1006$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001007 $(Echo) "Building $(<F) assembly writer with tblgen"
1008 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001009
Chris Lattner3c473472004-12-16 17:28:50 +00001010$(TARGET:%=%GenAsmWriter.inc): \
1011%GenAsmWriter.inc : $(ObjDir)/%GenAsmWriter.inc.tmp
1012 $(Verb) cmp -s $@ $< || cp $< $@
1013
1014$(TARGET:%=$(ObjDir)/%GenATTAsmWriter.inc.tmp): \
1015$(ObjDir)/%GenATTAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001016 $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
1017 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001018
Chris Lattner3c473472004-12-16 17:28:50 +00001019$(TARGET:%=%GenATTAsmWriter.inc): \
1020%GenATTAsmWriter.inc : $(ObjDir)/%GenATTAsmWriter.inc.tmp
1021 $(Verb) cmp -s $@ $< || cp $< $@
1022
1023$(TARGET:%=$(ObjDir)/%GenIntelAsmWriter.inc.tmp): \
1024$(ObjDir)/%GenIntelAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001025 $(Echo) "Building $(<F) Intel assembly writer with tblgen"
1026 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001027
Chris Lattner3c473472004-12-16 17:28:50 +00001028$(TARGET:%=%GenIntelAsmWriter.inc): \
1029%GenIntelAsmWriter.inc : $(ObjDir)/%GenIntelAsmWriter.inc.tmp
1030 $(Verb) cmp -s $@ $< || cp $< $@
1031
1032$(TARGET:%=$(ObjDir)/%GenInstrSelector.inc.tmp): \
1033$(ObjDir)/%GenInstrSelector.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001034 $(Echo) "Building $(<F) instruction selector with tblgen"
1035 $(Verb) $(TableGen) -gen-instr-selector -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001036
Chris Lattner3c473472004-12-16 17:28:50 +00001037$(TARGET:%=%GenInstrSelector.inc): \
1038%GenInstrSelector.inc : $(ObjDir)/%GenInstrSelector.inc.tmp
1039 $(Verb) cmp -s $@ $< || cp $< $@
1040
1041$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1042$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001043 $(Echo) "Building $(<F) code emitter with tblgen"
1044 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001045
Chris Lattner3c473472004-12-16 17:28:50 +00001046$(TARGET:%=%GenCodeEmitter.inc): \
1047%GenCodeEmitter.inc : $(ObjDir)/%GenCodeEmitter.inc.tmp
1048 $(Verb) cmp -s $@ $< || cp $< $@
1049
Reid Spencer3a561f52004-10-23 20:04:14 +00001050clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001051 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001052
1053endif
Chris Lattner481cc7c2003-08-15 02:18:35 +00001054
Reid Spencercc2d1e22004-10-30 09:19:36 +00001055###############################################################################
1056# LEX AND YACC: Provide rules for generating sources with lex and yacc
1057###############################################################################
Chris Lattnere8996782003-01-16 22:44:19 +00001058
Reid Spencercc2d1e22004-10-30 09:19:36 +00001059#---------------------------------------------------------
1060# Provide rules for generating a .cpp source file from
1061# (f)lex input sources.
1062#---------------------------------------------------------
1063
Reid Spencer3d659492004-11-02 16:36:03 +00001064LexFiles := $(filter %.l,$(Sources))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001065
Reid Spencer3d659492004-11-02 16:36:03 +00001066ifneq ($(LexFiles),)
1067
1068LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001069
1070.PRECIOUS: $(LexOutput)
1071
1072# Note the extra sed filtering here, used to cut down on the warnings emited
1073# by GCC. The last line is a gross hack to work around flex aparently not
1074# being able to resize the buffer on a large token input. Currently, for
1075# uninitialized string buffers in LLVM we can generate very long tokens, so
1076# this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +00001077# FIXME. (f.e. char Buffer[10000] )
Chris Lattner00950542001-06-06 20:29:01 +00001078%.cpp: %.l
Reid Spencerc2ef8cd2004-12-10 19:44:16 +00001079 $(Echo) Flexing $*.l
Reid Spencercc2d1e22004-10-30 09:19:36 +00001080 $(Verb) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +00001081 $(SED) 's/void yyunput/inline void yyunput/' | \
1082 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1083 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer80f0ef72004-10-28 00:41:43 +00001084 > $@
Chris Lattner00950542001-06-06 20:29:01 +00001085
Reid Spencer9af3b292004-11-01 07:50:27 +00001086clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001087 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001088 $(Verb) $(RM) -f $(LexOutput)
Reid Spencer9af3b292004-11-01 07:50:27 +00001089
Reid Spencercc2d1e22004-10-30 09:19:36 +00001090endif
1091
1092#---------------------------------------------------------
1093# Provide rules for generating a .cpp and .h source files
1094# from yacc (bison) input sources.
1095#---------------------------------------------------------
1096
Reid Spencer3d659492004-11-02 16:36:03 +00001097YaccFiles := $(filter %.y,$(Sources))
1098ifneq ($(YaccFiles),)
1099YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001100
1101.PRECIOUS: $(YaccOutput)
1102
1103# Cancel built-in rules for yacc
1104%.c: %.y
1105%.cpp: %.y
1106%.h: %.y
1107
Chris Lattner00950542001-06-06 20:29:01 +00001108# Rule for building the bison parsers...
Chris Lattner00950542001-06-06 20:29:01 +00001109%.cpp %.h : %.y
Reid Spencercc2d1e22004-10-30 09:19:36 +00001110 $(Echo) "Bisoning $*.y"
1111 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1112 $(Verb) $(MV) -f $*.tab.c $*.cpp
1113 $(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +00001114
Reid Spencer9af3b292004-11-01 07:50:27 +00001115clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001116 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001117 $(Verb) $(RM) -f $(YaccOutput)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001118endif
Chris Lattner00950542001-06-06 20:29:01 +00001119
Reid Spencercc2d1e22004-10-30 09:19:36 +00001120###############################################################################
1121# OTHER RULES: Other rules needed
1122###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001123
Chris Lattner30440c62003-01-16 21:06:18 +00001124# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +00001125ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +00001126%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +00001127 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +00001128else
1129%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +00001130 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +00001131endif
Chris Lattner30440c62003-01-16 21:06:18 +00001132
John Criswell7f336952003-09-06 14:44:17 +00001133# This rules ensures that header files that are removed still have a rule for
1134# which they can be "generated." This allows make to ignore them and
1135# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +00001136%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +00001137
Reid Spencercc2d1e22004-10-30 09:19:36 +00001138# Define clean-local to clean the current directory. Note that this uses a
1139# very conservative approach ensuring that empty variables do not cause
1140# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +00001141clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001142ifneq ($(strip $(ObjDir)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001143 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencere5487ba2004-10-24 07:53:21 +00001144endif
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001145 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001146ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001147 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001148endif
John Criswell7a73b802003-06-30 21:59:07 +00001149
Reid Spencer3d659492004-11-02 16:36:03 +00001150clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001151 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +00001152
Reid Spencercc2d1e22004-10-30 09:19:36 +00001153# Build tags database for Emacs/Xemacs:
Reid Spencer12d79512004-11-12 02:27:36 +00001154tags:: TAGS CTAGS
1155
Reid Spencercc2d1e22004-10-30 09:19:36 +00001156TAGS:
Reid Spencer12d79512004-11-12 02:27:36 +00001157 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1158 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1159 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1160 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1161 -name '*.cpp' -o -name '*.h' | \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001162 $(ETAGS) $(ETAGSFLAGS) -
1163
Reid Spencer12d79512004-11-12 02:27:36 +00001164CTAGS:
1165 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1166 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1167 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1168 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1169 \( -name '*.cpp' -o -name '*.h' \) -print | \
1170 ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1171
1172
Reid Spencer3a561f52004-10-23 20:04:14 +00001173###############################################################################
1174# DEPENDENCIES: Include the dependency files if we should
1175###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +00001176ifndef DISABLE_AUTO_DEPENDENCIES
1177
Reid Spencer3a561f52004-10-23 20:04:14 +00001178# If its not one of the cleaning targets
Reid Spencercc2d1e22004-10-30 09:19:36 +00001179ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +00001180
Reid Spencer3a561f52004-10-23 20:04:14 +00001181# Get the list of dependency files
Reid Spencercc2d1e22004-10-30 09:19:36 +00001182DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencer9af3b292004-11-01 07:50:27 +00001183DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +00001184
Reid Spencer3a561f52004-10-23 20:04:14 +00001185-include /dev/null $(DependFiles)
1186
John Criswelld741bcf2003-08-12 18:51:51 +00001187endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +00001188
Reid Spencercc2d1e22004-10-30 09:19:36 +00001189endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001190
Reid Spencer151f8ba2004-10-25 08:27:37 +00001191###############################################################################
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001192# CHECK: Running the test suite
1193###############################################################################
1194
1195check::
1196 $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1197 if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1198 $(EchoCmd) Running test suite ; \
1199 $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1200 TESTSUITE=$(TESTSUITE) ; \
1201 else \
1202 $(EchoCmd) No Makefile in test directory ; \
1203 fi ; \
1204 else \
1205 $(EchoCmd) No test directory ; \
1206 fi
1207
1208###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001209# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +00001210###############################################################################
1211
Reid Spencere45ebfa2004-10-26 07:09:33 +00001212#------------------------------------------------------------------------
1213# Define distribution related variables
1214#------------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +00001215DistName := $(LLVM_TARBALL_NAME)
1216DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001217TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001218DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1219DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
1220DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1221DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1222 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001223 Makefile.config.in configure autoconf
1224DistOther := $(notdir $(wildcard \
1225 $(BUILD_SRC_DIR)/*.h \
1226 $(BUILD_SRC_DIR)/*.td \
1227 $(BUILD_SRC_DIR)/*.def \
1228 $(BUILD_SRC_DIR)/*.ll \
1229 $(BUILD_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001230DistSubDirs := $(SubDirs)
Reid Spencerfbbf3072004-11-29 05:00:33 +00001231DistSources = $(Sources) $(EXTRA_DIST)
1232DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001233
Reid Spencere45ebfa2004-10-26 07:09:33 +00001234#------------------------------------------------------------------------
1235# We MUST build distribution with OBJ_DIR != SRC_DIR
1236#------------------------------------------------------------------------
1237ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1238dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001239 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00001240
Reid Spencere45ebfa2004-10-26 07:09:33 +00001241else
1242
Reid Spencere45ebfa2004-10-26 07:09:33 +00001243#------------------------------------------------------------------------
1244# Prevent catastrophic remove
1245#------------------------------------------------------------------------
1246ifeq ($(LLVM_TARBALL_NAME),)
1247$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
1248endif
1249
1250#------------------------------------------------------------------------
1251# Prevent attempt to run dist targets from anywhere but the top level
1252#------------------------------------------------------------------------
1253ifneq ($(LEVEL),.)
1254
1255dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001256 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001257
1258else
1259
1260#------------------------------------------------------------------------
1261# Provide the top level targets
1262#------------------------------------------------------------------------
1263
Reid Spencercc2d1e22004-10-30 09:19:36 +00001264dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001265
Reid Spencer345235ca2004-12-04 22:34:09 +00001266$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001267 $(Echo) Packing gzipped distribution tar file.
Reid Spencerfbbf3072004-11-29 05:00:33 +00001268 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1269 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00001270
Reid Spencercc2d1e22004-10-30 09:19:36 +00001271dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001272
Reid Spencer345235ca2004-12-04 22:34:09 +00001273$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001274 $(Echo) Packing bzipped distribution tar file.
Reid Spencerfbbf3072004-11-29 05:00:33 +00001275 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1276 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001277
Reid Spencercc2d1e22004-10-30 09:19:36 +00001278dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001279
Reid Spencer345235ca2004-12-04 22:34:09 +00001280$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001281 $(Echo) Packing zipped distribution file.
1282 $(Verb) rm -f $(DistZip)
1283 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001284
1285dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001286 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001287
1288DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1289
Reid Spencer345235ca2004-12-04 22:34:09 +00001290dist-check:: $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001291 $(Echo) Checking distribution tar file.
1292 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001293 $(RM) -rf $(DistCheckDir) ; \
1294 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00001295 $(Verb) $(MKDIR) $(DistCheckDir)
1296 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001297 $(MKDIR) $(DistCheckDir)/build && \
1298 $(MKDIR) $(DistCheckDir)/install && \
1299 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1300 cd build && \
1301 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1302 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
Reid Spencer345235ca2004-12-04 22:34:09 +00001303 $(MAKE) all && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001304 $(MAKE) check && \
1305 $(MAKE) install && \
1306 $(MAKE) uninstall && \
1307 $(MAKE) dist && \
1308 $(MAKE) clean && \
1309 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001310 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001311
1312dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001313 $(Echo) Cleaning distribution files
Reid Spencer345235ca2004-12-04 22:34:09 +00001314 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1315 $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001316
1317endif
1318
1319#------------------------------------------------------------------------
1320# Provide the recursive distdir target for building the distribution directory
1321#------------------------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +00001322distdir: $(DistDir)/.makedistdir
1323$(DistDir)/.makedistdir: $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001324 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001325 if test -d "$(DistDir)" ; then \
1326 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1327 exit 1 ; \
1328 fi ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001329 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001330 $(RM) -rf $(DistDir); \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001331 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001332 $(MAKE) all ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001333 fi
Reid Spencerfbbf3072004-11-29 05:00:33 +00001334 $(Echo) Building Distribution Directory $(DistDir)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001335 $(Verb) $(MKDIR) $(DistDir)
1336 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001337 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1338 for file in $(DistFiles) ; do \
1339 case "$$file" in \
Reid Spencer345235ca2004-12-04 22:34:09 +00001340 $(BUILD_SRC_DIR)/*) \
1341 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1342 ;; \
1343 $(BUILD_SRC_ROOT)/*) \
1344 file=`echo "$$file" | \
1345 sed "s#^$$srcrootstrip/##"` \
1346 ;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001347 esac; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001348 if test -f "$(BUILD_SRC_DIR)/$$file" || \
1349 test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1350 from_dir="$(BUILD_SRC_DIR)" ; \
1351 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001352 from_dir=. ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001353 fi ; \
1354 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001355 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1356 to_dir="$(DistDir)/$$dir"; \
1357 $(MKDIR) "$$to_dir" ; \
1358 else \
1359 to_dir="$(DistDir)"; \
1360 fi; \
1361 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1362 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001363 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001364 fi ; \
1365 if test -d "$$from_dir/$$file"; then \
1366 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1367 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1368 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1369 fi; \
1370 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1371 elif test -f "$$from_dir/$$file" ; then \
1372 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1373 elif test -L "$$from_dir/$$file" ; then \
1374 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1375 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer345235ca2004-12-04 22:34:09 +00001376 $(EchoCmd) "===== WARNING: Distribution Source " \
1377 "$$from_dir/$$file Not Found!" ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001378 elif test "$(Verb)" != '@' ; then \
1379 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001380 fi; \
1381 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00001382 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001383 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001384 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001385 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001386 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1387 exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001388 fi; \
1389 done
Reid Spencer345235ca2004-12-04 22:34:09 +00001390 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1391 $(EchoCmd) Eliminating CVS directories from distribution ; \
1392 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1393 $(MAKE) dist-hook ; \
1394 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1395 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1396 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1397 -o ! -type d ! -perm -444 -exec \
1398 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1399 || chmod -R a+r $(DistDir) ; \
1400 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +00001401
Reid Spencercc2d1e22004-10-30 09:19:36 +00001402# This is invoked by distdir target, define it as a no-op to avoid errors if not
1403# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00001404dist-hook::
1405
Reid Spencere53e3972004-10-22 23:06:30 +00001406endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001407
1408###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00001409# TOP LEVEL - targets only to apply at the top level directory
1410###############################################################################
1411
1412ifeq ($(LEVEL),.)
1413
1414#------------------------------------------------------------------------
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001415# Install support for the project's include files:
Reid Spencere5487ba2004-10-24 07:53:21 +00001416#------------------------------------------------------------------------
1417install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001418 $(Echo) Installing include files
1419 $(Verb) $(MKDIR) $(includedir)
1420 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001421 cd $(BUILD_SRC_ROOT)/include && \
1422 find . -path '*/Internal' -prune -o '(' -type f \
1423 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1424 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1425 fi
1426
1427uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001428 $(Echo) Uninstalling include files
1429 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001430 cd $(BUILD_SRC_ROOT)/include && \
1431 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1432 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1433 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1434 fi
1435
Reid Spencere5487ba2004-10-24 07:53:21 +00001436endif
1437
Reid Spencer4d71b662004-10-22 21:01:56 +00001438#------------------------------------------------------------------------
1439# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00001440#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001441printvars::
Reid Spencer9af3b292004-11-01 07:50:27 +00001442 $(Echo) "BuildMode : " '$(BuildMode)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001443 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1444 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1445 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1446 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1447 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1448 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1449 $(Echo) "libdir : " '$(libdir)'
1450 $(Echo) "bindir : " '$(bindir)'
1451 $(Echo) "sysconfdir : " '$(sysconfdir)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001452 $(Echo) "UserTargets : " '$(UserTargets)'
1453 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1454 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1455 $(Echo) "ObjDir : " '$(ObjDir)'
1456 $(Echo) "LibDir : " '$(LibDir)'
1457 $(Echo) "ToolDir : " '$(ToolDir)'
Reid Spencer815cbcf2004-11-18 10:03:46 +00001458 $(Echo) "ExmplDir : " '$(ExmplDir)'
Reid Spencer7980ea42004-12-05 05:17:22 +00001459 $(Echo) "Sources : " '$(Sources)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001460 $(Echo) "TDFiles : " '$(TDFiles)'
1461 $(Echo) "INCFiles : " '$(INCFiles)'
Chris Lattner3c473472004-12-16 17:28:50 +00001462 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001463 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1464 $(Echo) "Compile.C : " '$(Compile.C)'
1465 $(Echo) "Archive : " '$(Archive)'
Reid Spencer3d659492004-11-02 16:36:03 +00001466 $(Echo) "YaccFiles : " '$(YaccFiles)'
1467 $(Echo) "LexFiles : " '$(LexFiles)'
Reid Spencer7980ea42004-12-05 05:17:22 +00001468 $(Echo) "Module : " '$(Module)'