blob: 2b30928248b71ae8e4537c247ef7f17033a36062 [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#--------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +000038VPATH=$(PROJ_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 Spencer11fde542005-01-16 02:20:54 +000064 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66ConfigureScript := $(PROJ_SRC_ROOT)/configure
67ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
71MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
72PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
73ifneq ($(MakefileCommonIn),)
74PreConditions += $(MakefileCommon)
75endif
76ifneq ($(MakefileConfigIn),)
77PreConditions += $(MakefileConfig)
78endif
Reid Spencer9411c642004-10-26 22:26:33 +000079
Reid Spencercc2d1e22004-10-30 09:19:36 +000080preconditions : $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +000081
82#------------------------------------------------------------------------
83# Make sure the BUILT_SOURCES are built first
84#------------------------------------------------------------------------
Reid Spencer07a549a2004-12-16 07:15:16 +000085$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000086
87clean-local::
88ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +000089 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000090endif
91
Reid Spencer11fde542005-01-16 02:20:54 +000092ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer31f95242004-12-16 08:00:46 +000093spotless:
Reid Spencer31f95242004-12-16 08:00:46 +000094 $(Verb) if test -x config.status ; then \
Reid Spencer11fde542005-01-16 02:20:54 +000095 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +000096 $(MKDIR) .spotless.save ; \
97 $(MV) config.status .spotless.save ; \
98 $(MV) mklib .spotless.save ; \
99 $(MV) projects .spotless.save ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000100 $(RM) -rf * ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000101 $(MV) .spotless.save/config.status . ; \
102 $(MV) .spotless.save/mklib . ; \
103 $(MV) .spotless.save/projects . ; \
104 $(RM) -rf .spotless.save ; \
Reid Spencer11fde542005-01-16 02:20:54 +0000105 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000106 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
107 $(ConfigStatusScript) ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000108 else \
Reid Spencer11fde542005-01-16 02:20:54 +0000109 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer31f95242004-12-16 08:00:46 +0000110 fi
111endif
112
Reid Spencercc2d1e22004-10-30 09:19:36 +0000113$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +0000114
Reid Spencer9411c642004-10-26 22:26:33 +0000115#------------------------------------------------------------------------
116# Make sure we're not using a stale configuration
117#------------------------------------------------------------------------
Reid Spencerc3719842004-12-16 18:26:53 +0000118reconfigure:
Reid Spencer11fde542005-01-16 02:20:54 +0000119 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
120 $(Verb) cd $(PROJ_OBJ_ROOT) && \
121 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
122 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer32924e02004-12-24 03:36:31 +0000123 fi ; \
Reid Spencerc3719842004-12-16 18:26:53 +0000124 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
125 $(ConfigStatusScript)
126
Reid Spencercc2d1e22004-10-30 09:19:36 +0000127.PRECIOUS: $(ConfigStatusScript)
128$(ConfigStatusScript): $(ConfigureScript)
129 $(Echo) Reconfiguring with $<
Reid Spencer11fde542005-01-16 02:20:54 +0000130 $(Verb) cd $(PROJ_OBJ_ROOT) && \
131 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
132 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer32924e02004-12-24 03:36:31 +0000133 fi ; \
Reid Spencer7d277002004-11-29 12:37:44 +0000134 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
135 $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +0000136
137#------------------------------------------------------------------------
138# Make sure the configuration makefile is up to date
139#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +0000140ifneq ($(MakefileConfigIn),)
141$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000142 $(Echo) Regenerating $@
Reid Spencer11fde542005-01-16 02:20:54 +0000143 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
144endif
145
146ifneq ($(MakefileCommonIn),)
147$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
148 $(Echo) Regenerating $@
149 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
150endif
Reid Spencer9411c642004-10-26 22:26:33 +0000151
152#------------------------------------------------------------------------
153# If the Makefile in the source tree has been updated, copy it over into the
154# build tree. But, only do this if the source and object makefiles differ
155#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +0000156ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer9411c642004-10-26 22:26:33 +0000157
Reid Spencer11fde542005-01-16 02:20:54 +0000158Makefile: $(PROJ_SRC_DIR)/Makefile
Reid Spencercc2d1e22004-10-30 09:19:36 +0000159 $(Echo) "Updating Makefile"
160 $(Verb) $(MKDIR) $(@D)
Reid Spencerc3719842004-12-16 18:26:53 +0000161 $(Verb) $(CP) -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000162
163# Copy the Makefile.* files unless we're in the root directory which avoids
164# the copying of Makefile.config.in or other things that should be explicitly
165# taken care of.
Reid Spencer11fde542005-01-16 02:20:54 +0000166$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
Reid Spencer86606782004-10-26 23:10:00 +0000167 @case '$?' in \
168 *Makefile.rules) ;; \
169 *.in) ;; \
Reid Spencercc2d1e22004-10-30 09:19:36 +0000170 *) $(Echo) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000171 $(MKDIR) $(@D) ; \
Reid Spencerc3719842004-12-16 18:26:53 +0000172 $(CP) -f $< $@ ;; \
Reid Spencer86606782004-10-26 23:10:00 +0000173 esac
174
Reid Spencer9411c642004-10-26 22:26:33 +0000175endif
176
177#------------------------------------------------------------------------
178# Set up the basic dependencies
179#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000180$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000181
182all:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000183clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000184clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000185install:: install-local
186uninstall:: uninstall-local
Reid Spencer9411c642004-10-26 22:26:33 +0000187install-local:: all-local
Reid Spencer44cb1b32004-12-03 20:08:48 +0000188install-bytecode:: install-bytecode-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000189
190###############################################################################
191# VARIABLES: Set up various variables based on configuration data
192###############################################################################
193
194#--------------------------------------------------------------------
195# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000196#--------------------------------------------------------------------
197
Reid Spencer325a87e2005-01-02 17:43:20 +0000198
Chris Lattner760da062003-03-14 20:25:22 +0000199ifdef ENABLE_PROFILING
Reid Spencer9af3b292004-11-01 07:50:27 +0000200 BuildMode := Profile
Reid Spencer519799e2004-12-08 04:34:51 +0000201 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
Reid Spencercc2d1e22004-10-30 09:19:36 +0000202 C.Flags := -O3 -DNDEBUG -pg
203 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000204else
205 ifdef ENABLE_OPTIMIZED
Reid Spencer9af3b292004-11-01 07:50:27 +0000206 BuildMode := Release
Reid Spencer325a87e2005-01-02 17:43:20 +0000207 # Don't use -fomit-frame-pointer on FreeBSD
208 ifneq ($(OS),FreeBSD)
209 OmitFramePointer := -fomit-frame-pointer
210 endif
211 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
212 $(OmitFramePointer)
213 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000214 LD.Flags := -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000215 else
Reid Spencer9af3b292004-11-01 07:50:27 +0000216 BuildMode := Debug
Reid Spencer519799e2004-12-08 04:34:51 +0000217 CXX.Flags := -g -D_DEBUG
Reid Spencercc2d1e22004-10-30 09:19:36 +0000218 C.Flags := -g -D_DEBUG
219 LD.Flags := -g -D_DEBUG
Reid Spencer4d71b662004-10-22 21:01:56 +0000220 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000221 endif
222endif
223
Reid Spencercc2d1e22004-10-30 09:19:36 +0000224CXX.Flags += $(CXXFLAGS)
225C.Flags += $(CFLAGS)
226CPP.Flags += $(CPPFLAGS)
227LD.Flags += $(LDFLAGS)
228AR.Flags := cru
229LibTool.Flags := --tag=CXX
Reid Spencer3a561f52004-10-23 20:04:14 +0000230
231#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000232# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000233#--------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +0000234ObjDir := $(PROJ_OBJ_DIR)/$(BuildMode)
235LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
236ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
237ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer815cbcf2004-11-18 10:03:46 +0000238LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer9a5acaf2004-11-18 20:04:39 +0000239LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer775bf892004-12-28 07:59:22 +0000240LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer2f138e72004-12-22 05:57:21 +0000241CFERuntimeLibDir := $(LLVMGCCDIR)/lib
John Criswell7a73b802003-06-30 21:59:07 +0000242
Reid Spencer3a561f52004-10-23 20:04:14 +0000243#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000244# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000245#--------------------------------------------------------------------
Reid Spencer3ca6d8b2005-01-14 16:33:36 +0000246EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
247Echo = @$(EchoCmd)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000248ifndef LIBTOOL
Reid Spencer4d71b662004-10-22 21:01:56 +0000249LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencercc2d1e22004-10-30 09:19:36 +0000250endif
251ifndef LLVMAS
252LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
253endif
254ifndef BURG
255BURG := $(LLVMToolDir)/burg$(EXEEXT)
256endif
257ifndef TBLGEN
258TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
259endif
Chris Lattner478b3b42004-11-29 19:47:58 +0000260ifndef GCCAS
261GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
262endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000263ifndef GCCLD
264GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
265endif
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000266ifndef LDIS
267LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
268endif
269ifndef LLI
270LLI := $(LLVMToolDir)/lli$(EXEEXT)
271endif
272ifndef LOPT
Alkis Evlogimenos20d793a2004-12-13 18:08:29 +0000273LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000274endif
John Criswellf5629d02005-01-03 17:42:57 +0000275LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
276LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000277
Reid Spencer3a561f52004-10-23 20:04:14 +0000278#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000279# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000280#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000281
Reid Spencer492c2932005-01-11 04:31:07 +0000282# Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
283# to be built. Note that if LOADABLE_MODULE is specified then the resulting
284# shared library can be opened with dlopen
285ifdef SHARED_LIBRARY
Reid Spencercc2d1e22004-10-30 09:19:36 +0000286 LD.Flags += -rpath $(LibDir)
Reid Spencer492c2932005-01-11 04:31:07 +0000287 ifdef LOADABLE_MODULE
288 LD.Flags += -module
289 endif
290else
291 LibTool.Flags += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000292endif
293
Reid Spencercceed9f2004-11-08 17:32:12 +0000294ifdef TOOL_VERBOSE
295 C.Flags += -v
296 CXX.Flags += -v
297 LD.Flags += -v
Reid Spencercceed9f2004-11-08 17:32:12 +0000298 VERBOSE := 1
299endif
300
Reid Spencer3a561f52004-10-23 20:04:14 +0000301# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000302ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000303 Verb := @
304 LibTool.Flags += --silent
305 AR.Flags += >/dev/null 2>/dev/null
Reid Spencer11fde542005-01-16 02:20:54 +0000306 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000307else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000308 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000309endif
310
Vikram S. Advefeeae582002-09-18 11:55:13 +0000311# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000312ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000313 Strip := $(PLATFORMSTRIPOPTS)
314 StripWarnMsg := "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000315endif
316
Reid Spencer3a561f52004-10-23 20:04:14 +0000317# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000318ifdef TOOLNAME
Reid Spencer815cbcf2004-11-18 10:03:46 +0000319ifdef EXAMPLE_TOOL
320 LD.Flags += -rpath $(ExmplDir) -export-dynamic
321else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000322 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000323endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000324endif
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000325
Reid Spencer3a561f52004-10-23 20:04:14 +0000326#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000327# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000328#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000329
330CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
331
Reid Spencerf8f57402005-01-28 19:52:32 +0000332LD.Flags += -L$(LibDir) -L$(LLVMLibDir) $(LIBS)
Reid Spencer11fde542005-01-16 02:20:54 +0000333CPP.Flags += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
334 -I$(PROJ_OBJ_ROOT)/include \
335 -I$(PROJ_SRC_ROOT)/include \
336 -I$(LLVM_OBJ_ROOT)/include \
337 -I$(LLVM_SRC_ROOT)/include \
338 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencer4d71b662004-10-22 21:01:56 +0000339
Reid Spencercc2d1e22004-10-30 09:19:36 +0000340Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
341LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
Reid Spencer2f138e72004-12-22 05:57:21 +0000342BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
343 $(C.Flags) -c
Reid Spencercc2d1e22004-10-30 09:19:36 +0000344Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
345LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
Reid Spencerbc52ad72004-12-24 14:47:34 +0000346BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
347 $(CXX.Flags) -c
Reid Spencercc2d1e22004-10-30 09:19:36 +0000348Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
349 $(CompileCommonOpts) $(LD.Flags) $(Strip)
350Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencera69b1ea2004-10-28 09:15:28 +0000351 $(CompileCommonOpts)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000352LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
Reid Spencer11fde542005-01-16 02:20:54 +0000353Burg = $(BURG) -I $(PROJ_SRC_DIR)
354TableGen = $(TBLGEN) -I $(PROJ_SRC_DIR)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000355Archive = $(AR) $(AR.Flags)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000356LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000357ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000358Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000359else
Reid Spencer3a561f52004-10-23 20:04:14 +0000360Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000361endif
362
Chris Lattner00950542001-06-06 20:29:01 +0000363#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000364# Get the list of source files and compute object file
365# names from them.
Reid Spencer3a561f52004-10-23 20:04:14 +0000366#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000367ifdef FAKE_SOURCES
368 Sources :=
369 FakeSources := $(FAKE_SOURCES)
370 ifdef BUILT_SOURCES
371 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
372 endif
373 BaseNameSources := $(sort $(basename $(FakeSources)))
374 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
375 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
376 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000377else
Reid Spencer345235ca2004-12-04 22:34:09 +0000378 ifndef SOURCES
Reid Spencer11fde542005-01-16 02:20:54 +0000379 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
380 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
381 $(PROJ_SRC_DIR)/*.l))
Reid Spencer345235ca2004-12-04 22:34:09 +0000382 else
383 Sources := $(SOURCES)
384 endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000385
Reid Spencer345235ca2004-12-04 22:34:09 +0000386 ifdef BUILT_SOURCES
387 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
388 endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000389
Reid Spencer345235ca2004-12-04 22:34:09 +0000390 BaseNameSources := $(sort $(basename $(Sources)))
391 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
392 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
393 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
394endif
Reid Spencer3a561f52004-10-23 20:04:14 +0000395
396###############################################################################
397# DIRECTORIES: Handle recursive descent of directory structure
398###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000399
Chris Lattner00950542001-06-06 20:29:01 +0000400#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000401# Provide rules to make install dirs. This must be early
402# in the file so they get built before dependencies
403#---------------------------------------------------------
404
Reid Spencer11fde542005-01-16 02:20:54 +0000405$(PROJ_bindir):
406 $(Verb) $(MKDIR) $(PROJ_bindir)
Chris Lattnere4cb90f2004-11-01 06:14:59 +0000407
Reid Spencer11fde542005-01-16 02:20:54 +0000408$(PROJ_libdir):
409 $(Verb) $(MKDIR) $(PROJ_libdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000410
Reid Spencer11fde542005-01-16 02:20:54 +0000411$(PROJ_includedir):
412 $(Verb) $(MKDIR) $(PROJ_includedir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000413
Reid Spencer11fde542005-01-16 02:20:54 +0000414$(PROJ_etcdir):
415 $(Verb) $(MKDIR) $(PROJ_etcdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000416
Reid Spencercc2d1e22004-10-30 09:19:36 +0000417# To create other directories, as needed, and timestamp their creation
418%/.dir:
419 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfbbf3072004-11-29 05:00:33 +0000420 $(Verb) $(DATE) > $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000421
Reid Spencer815cbcf2004-11-18 10:03:46 +0000422.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
423.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000424
425#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000426# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000427#---------------------------------------------------------
428
Reid Spencercc2d1e22004-10-30 09:19:36 +0000429SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000430ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000431SubDirs += $(DIRS)
432$(RecursiveTargets)::
433 $(Verb) for dir in $(DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000434 if [ ! -f $$dir/Makefile ]; then \
435 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000436 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000437 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000438 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
439 ($(MAKE) -C $$dir $@ ) || exit 1; \
440 fi ; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000441 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000442endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000443
Reid Spencer3a561f52004-10-23 20:04:14 +0000444#---------------------------------------------------------
445# Handle the EXPERIMENTAL_DIRS options ensuring success
446# after each directory is built.
447#---------------------------------------------------------
448ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000449$(RecursiveTargets)::
450 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer3a561f52004-10-23 20:04:14 +0000451 if [ ! -f $$dir/Makefile ]; then \
452 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000453 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000454 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000455 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
456 ($(MAKE) -C $$dir $@ ) || exit 0; \
457 fi ; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000458 done
459endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000460
Reid Spencer3a561f52004-10-23 20:04:14 +0000461#---------------------------------------------------------
462# Handle the PARALLEL_DIRS options for parallel construction
463#---------------------------------------------------------
464ifdef PARALLEL_DIRS
465
Reid Spencercc2d1e22004-10-30 09:19:36 +0000466SubDirs += $(PARALLEL_DIRS)
467
Reid Spencer44cb1b32004-12-03 20:08:48 +0000468# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencercc2d1e22004-10-30 09:19:36 +0000469all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
470clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000471clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000472install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000473uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencer44cb1b32004-12-03 20:08:48 +0000474install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000475
Reid Spencer345235ca2004-12-04 22:34:09 +0000476ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000477
Reid Spencer345235ca2004-12-04 22:34:09 +0000478$(ParallelTargets) :
Reid Spencercc2d1e22004-10-30 09:19:36 +0000479 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000480 $(MKDIR) $(@D); \
Reid Spencer11fde542005-01-16 02:20:54 +0000481 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000482 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000483 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
484 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
485 fi
Chris Lattner00950542001-06-06 20:29:01 +0000486endif
487
Reid Spencer3a561f52004-10-23 20:04:14 +0000488#---------------------------------------------------------
489# Handle the OPTIONAL_DIRS options for directores that may
490# or may not exist.
491#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000492ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000493
Reid Spencercc2d1e22004-10-30 09:19:36 +0000494SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000495
Reid Spencercc2d1e22004-10-30 09:19:36 +0000496$(RecursiveTargets)::
497 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000498 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Reid Spencer4d71b662004-10-22 21:01:56 +0000499 if [ ! -f $$dir/Makefile ]; then \
500 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000501 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000502 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000503 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
504 ($(MAKE) -C$$dir $@ ) || exit 1; \
505 fi ; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000506 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000507 done
508endif
509
Reid Spencerfc945082004-08-20 09:20:05 +0000510#---------------------------------------------------------
511# Handle the CONFIG_FILES options
512#---------------------------------------------------------
513ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000514
Reid Spencer11fde542005-01-16 02:20:54 +0000515install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
516 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000517 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000518 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
519 $(INSTALL) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
520 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
521 $(INSTALL) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencer1b426ab2004-11-23 05:59:53 +0000522 else \
523 $(ECHO) Error: cannot find config file $${file}. ; \
524 fi \
Reid Spencerfc945082004-08-20 09:20:05 +0000525 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000526
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000527uninstall-local::
Reid Spencer11fde542005-01-16 02:20:54 +0000528 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000529 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000530 $(RM) -f $(PROJ_etcdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000531 done
532
Reid Spencerfc945082004-08-20 09:20:05 +0000533endif
534
Reid Spencer3a561f52004-10-23 20:04:14 +0000535###############################################################################
536# Library Build Rules: Four ways to build a library
537###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000538
Reid Spencer7980ea42004-12-05 05:17:22 +0000539#---------------------------------------------------------
540# Bytecode Module Targets:
541# If the user set MODULE_NAME then they want to build a
542# bytecode module from the sources. We compile all the
543# sources and link it together into a single bytecode
544# module.
545#---------------------------------------------------------
546
547ifdef MODULE_NAME
548
549Module := $(LibDir)/$(MODULE_NAME).bc
Reid Spencer2f138e72004-12-22 05:57:21 +0000550LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
Reid Spencer7980ea42004-12-05 05:17:22 +0000551
552ifdef EXPORTED_SYMBOL_FILE
Reid Spencerf8f57402005-01-28 19:52:32 +0000553LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer7980ea42004-12-05 05:17:22 +0000554endif
555
556$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
557 $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
558 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
559
560all-local:: $(Module)
561
562clean-local::
563ifneq ($(strip $(Module)),)
564 -$(Verb) $(RM) -f $(Module)
565endif
566
Reid Spencerab3690b2004-12-13 07:38:07 +0000567ifdef BYTECODE_DESTINATION
568ModuleDestDir := $(BYTECODE_DESTINATION)
569else
Reid Spencer11fde542005-01-16 02:20:54 +0000570ModuleDestDir := $(PROJ_libdir)
Reid Spencerab3690b2004-12-13 07:38:07 +0000571endif
Reid Spencer7980ea42004-12-05 05:17:22 +0000572
Reid Spencerab3690b2004-12-13 07:38:07 +0000573DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
574
575install-module:: $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +0000576install-local:: $(DestModule)
577
Reid Spencerab3690b2004-12-13 07:38:07 +0000578$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencer7980ea42004-12-05 05:17:22 +0000579 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
580 $(Verb) $(INSTALL) $(Module) $@
581
582uninstall-local::
583 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
584 -$(Verb) $(RM) -f $(DestModule)
585
586endif
Brian Gaeke8abff792004-01-22 22:53:48 +0000587
Reid Spencer3a561f52004-10-23 20:04:14 +0000588# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000589ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000590
Chris Lattner2a548c52002-09-16 22:36:42 +0000591# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000592LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer492c2932005-01-11 04:31:07 +0000593ifdef LOADABLE_MODULE
594LibName.LA := $(LibDir)/$(LIBRARYNAME).la
595else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000596LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
Reid Spencer492c2932005-01-11 04:31:07 +0000597endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000598LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
599LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer9a2f1372004-12-02 09:28:21 +0000600LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000601
Reid Spencer3a561f52004-10-23 20:04:14 +0000602#---------------------------------------------------------
603# Shared Library Targets:
604# If the user asked for a shared library to be built
605# with the SHARED_LIBRARY variable, then we provide
606# targets for building them.
607#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000608ifdef SHARED_LIBRARY
609
Reid Spencercc2d1e22004-10-30 09:19:36 +0000610all-local:: $(LibName.LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000611
Reid Spencerf2ac1892004-12-16 07:36:08 +0000612$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000613 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000614 $(Verb) $(Link) -o $@ $(ObjectsLO)
615 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencer3a561f52004-10-23 20:04:14 +0000616
617clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000618ifneq ($(strip $(LibName.LA)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000619 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000620endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000621
Reid Spencer11fde542005-01-16 02:20:54 +0000622DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000623
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000624install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000625
Reid Spencer11fde542005-01-16 02:20:54 +0000626$(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
Reid Spencer9af3b292004-11-01 07:50:27 +0000627 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000628 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
Reid Spencer11fde542005-01-16 02:20:54 +0000629 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000630
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000631uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000632 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencer11fde542005-01-16 02:20:54 +0000633 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
Reid Spencere5487ba2004-10-24 07:53:21 +0000634
Reid Spencer4d71b662004-10-22 21:01:56 +0000635endif
636
Reid Spencer3a561f52004-10-23 20:04:14 +0000637#---------------------------------------------------------
638# Bytecode Library Targets:
639# If the user asked for a bytecode library to be built
640# with the BYTECODE_LIBRARY variable, then we provide
641# targets for building them.
642#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000643ifdef BYTECODE_LIBRARY
644
Reid Spencer776b8052004-12-03 06:04:35 +0000645# make the C and C++ compilers strip debug info out of bytecode libraries.
646BCCompile.C += -Wa,-strip-debug
647BCCompile.CXX += -Wa,-strip-debug
648
Reid Spencer9a2f1372004-12-02 09:28:21 +0000649all-local:: $(LibName.BCA)
650
651ifdef EXPORTED_SYMBOL_FILE
Reid Spencer2f138e72004-12-22 05:57:21 +0000652BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
Reid Spencer9a2f1372004-12-02 09:28:21 +0000653 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
654
Reid Spencerf2ac1892004-12-16 07:36:08 +0000655$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000656 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000657 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
658 "(internalize)"
Chris Lattnerb0ea8642004-12-02 21:23:43 +0000659 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000660 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000661 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
Reid Spencer4d71b662004-10-22 21:01:56 +0000662else
Reid Spencerf2ac1892004-12-16 07:36:08 +0000663$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000664 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000665 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000666 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000667 $(Verb) $(LArchive) $@ $(ObjectsBC)
668
Reid Spencer4d71b662004-10-22 21:01:56 +0000669endif
670
Reid Spencer3a561f52004-10-23 20:04:14 +0000671clean-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000672ifneq ($(strip $(LibName.BCA)),)
673 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000674endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000675
Reid Spencer8f094f32004-12-13 07:28:21 +0000676ifdef BYTECODE_DESTINATION
677BytecodeDestDir := $(BYTECODE_DESTINATION)
678else
Reid Spencer11fde542005-01-16 02:20:54 +0000679BytecodeDestDir := $(PROJ_libdir)
Reid Spencer8f094f32004-12-13 07:28:21 +0000680endif
681
682DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
Reid Spencer9a2f1372004-12-02 09:28:21 +0000683
Reid Spencer44cb1b32004-12-03 20:08:48 +0000684install-bytecode-local:: $(DestBytecodeLib)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000685
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000686install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000687
Reid Spencer8f094f32004-12-13 07:28:21 +0000688$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000689 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
690 $(Verb) $(INSTALL) $(LibName.BCA) $@
Reid Spencere5487ba2004-10-24 07:53:21 +0000691
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000692uninstall-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000693 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000694 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000695
696endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000697
Reid Spencercc2d1e22004-10-30 09:19:36 +0000698#---------------------------------------------------------
699# ReLinked Library Targets:
700# If the user didn't explicitly forbid building a
701# relinked then we provide targets for building them.
702#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000703ifndef DONT_BUILD_RELINKED
Reid Spencer4d71b662004-10-22 21:01:56 +0000704
Reid Spencercc2d1e22004-10-30 09:19:36 +0000705all-local:: $(LibName.O)
706
Reid Spencerf2ac1892004-12-16 07:36:08 +0000707$(LibName.O): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000708 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000709 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencer4d71b662004-10-22 21:01:56 +0000710
Reid Spencer3a561f52004-10-23 20:04:14 +0000711clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000712ifneq ($(strip $(LibName.O)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000713 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000714endif
715
Reid Spencer11fde542005-01-16 02:20:54 +0000716DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
Reid Spencere5487ba2004-10-24 07:53:21 +0000717
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000718install-local:: $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000719
Reid Spencer11fde542005-01-16 02:20:54 +0000720$(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
Reid Spencer9af3b292004-11-01 07:50:27 +0000721 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000722 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000723
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000724uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000725 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000726 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000727
Chris Lattnere62dbe92002-07-23 17:56:16 +0000728endif
Chris Lattner760da062003-03-14 20:25:22 +0000729
Reid Spencercc2d1e22004-10-30 09:19:36 +0000730#---------------------------------------------------------
731# Archive Library Targets:
732# If the user wanted a regular archive library built,
733# then we provide targets for building them.
734#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000735ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +0000736
Reid Spencercc2d1e22004-10-30 09:19:36 +0000737all-local:: $(LibName.A)
738
Reid Spencerf2ac1892004-12-16 07:36:08 +0000739$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000740 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000741 -$(Verb) $(RM) -f $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000742 $(Verb) $(Archive) $@ $(ObjectsO)
743 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000744
Reid Spencer3a561f52004-10-23 20:04:14 +0000745clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000746ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000747 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +0000748endif
749
Reid Spencer11fde542005-01-16 02:20:54 +0000750DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencere5487ba2004-10-24 07:53:21 +0000751
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000752install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000753
Reid Spencer11fde542005-01-16 02:20:54 +0000754$(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
Reid Spencer9af3b292004-11-01 07:50:27 +0000755 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer11fde542005-01-16 02:20:54 +0000756 $(Verb) $(MKDIR) $(PROJ_libdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000757 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000758
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000759uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000760 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000761 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000762
763endif
764
765# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000766endif
767
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000768###############################################################################
769# Tool Build Rules: Build executable tool based on TOOLNAME option
770###############################################################################
771
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000772ifdef TOOLNAME
773
Reid Spencercc2d1e22004-10-30 09:19:36 +0000774#---------------------------------------------------------
Reid Spencer7c787c92004-11-29 07:17:07 +0000775# Handle the special "JIT" value for LLVM_LIBS which is a
776# shorthand for a bunch of libraries that get the correct
777# JIT support for a tool that runs JIT.
778#---------------------------------------------------------
779ifeq ($(LLVMLIBS),JIT)
780
781# Make sure we can get our own symbols in the tool
782Link += -dlopen self
783
784# Generic JIT libraries
785JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
786
787# You can enable the X86 JIT on a non-X86 host by setting the flag
788# ENABLE_X86_JIT on the make command line. If not, it will still be
789# enabled automagically on an X86 host.
790ifeq ($(ARCH), x86)
791 ENABLE_X86_JIT = 1
792endif
793
794# What the X86 JIT requires
795ifdef ENABLE_X86_JIT
Chris Lattner85139f52005-01-07 07:51:11 +0000796 JIT_LIBS += LLVMX86 LLVMSelectionDAG
Reid Spencer7c787c92004-11-29 07:17:07 +0000797endif
798
799# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
800# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
801# enabled automagically on an SparcV9 host.
802ifeq ($(ARCH), Sparc)
803 ENABLE_SPARCV9_JIT = 1
804endif
805
806# What the Sparc JIT requires
807ifdef ENABLE_SPARCV9_JIT
808 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
809 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
810 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
811 LLVMDataStructure.a LLVMSparcV9RegAlloc
812endif
813
814# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
815# ENABLE_PPC_JIT on the make command line. If not, it will still be
816# enabled automagically on an PowerPC host.
817ifeq ($(ARCH), PowerPC)
818 ENABLE_PPC_JIT = 1
819endif
820
821# What the PowerPC JIT requires
822ifdef ENABLE_PPC_JIT
823 JIT_LIBS += LLVMPowerPC
824endif
825
826LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
827 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
828 LLVMSystem.a $(PLATFORMLIBDL)
829endif
830
831#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000832# Set up variables for building a tool.
833#---------------------------------------------------------
Reid Spencer815cbcf2004-11-18 10:03:46 +0000834ifdef EXAMPLE_TOOL
835ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
836else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000837ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000838endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000839ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
840ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
841LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
842LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
843ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
844LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
845ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
846LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000847
Reid Spencercc2d1e22004-10-30 09:19:36 +0000848#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000849# Tell make that we need to rebuild subdirectories before
850# we can link the tool. This affects things like LLI which
851# has library subdirectories.
852#---------------------------------------------------------
853$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000854
Reid Spencercc2d1e22004-10-30 09:19:36 +0000855#---------------------------------------------------------
856# Provide targets for building the tools
857#---------------------------------------------------------
858all-local:: $(ToolBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +0000859
Reid Spencer3a561f52004-10-23 20:04:14 +0000860clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000861ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000862 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +0000863endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000864
Reid Spencer815cbcf2004-11-18 10:03:46 +0000865ifdef EXAMPLE_TOOL
866$(ToolBuildPath): $(ExmplDir)/.dir
867else
868$(ToolBuildPath): $(ToolDir)/.dir
869endif
870
Reid Spencerf2ac1892004-12-16 07:36:08 +0000871$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +0000872 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000873 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
874 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
Reid Spencer9af3b292004-11-01 07:50:27 +0000875 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +0000876
Reid Spencer11fde542005-01-16 02:20:54 +0000877DestTool = $(PROJ_bindir)/$(TOOLNAME)
Reid Spencere5487ba2004-10-24 07:53:21 +0000878
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000879install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000880
Reid Spencer11fde542005-01-16 02:20:54 +0000881$(DestTool): $(PROJ_bindir) $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +0000882 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000883 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000884
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000885uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000886 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000887 -$(Verb) $(RM) -f $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000888
Reid Spencer4d71b662004-10-22 21:01:56 +0000889endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000890
Reid Spencercc2d1e22004-10-30 09:19:36 +0000891###############################################################################
892# Object Build Rules: Build object files based on sources
893###############################################################################
894
895# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000896ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000897
Reid Spencercc2d1e22004-10-30 09:19:36 +0000898#---------------------------------------------------------
899# Create .lo files in the ObjDir directory from the .cpp and .c files...
900#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000901ifdef SHARED_LIBRARY
902
Chris Lattner3c473472004-12-16 17:28:50 +0000903$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000904 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000905 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
906 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
907 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000908
Chris Lattner3c473472004-12-16 17:28:50 +0000909$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000910 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000911 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
912 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
913 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000914
Reid Spencercc2d1e22004-10-30 09:19:36 +0000915#---------------------------------------------------------
916# Create .o files in the ObjDir directory from the .cpp and .c files...
917#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000918else
Reid Spencer4d71b662004-10-22 21:01:56 +0000919
Chris Lattner3c473472004-12-16 17:28:50 +0000920$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000921 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000922 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
923 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
924 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000925
Chris Lattner3c473472004-12-16 17:28:50 +0000926$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000927 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000928 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
929 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
930 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000931
932endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000933
Reid Spencercc2d1e22004-10-30 09:19:36 +0000934#---------------------------------------------------------
935# Create .bc files in the ObjDir directory from .cpp and .c files...
936#---------------------------------------------------------
Chris Lattner3c473472004-12-16 17:28:50 +0000937$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000938 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000939 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
940 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
941 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000942
Chris Lattner3c473472004-12-16 17:28:50 +0000943$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000944 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000945 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
946 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
947 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000948
Reid Spencercc2d1e22004-10-30 09:19:36 +0000949# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000950else
951
Reid Spencer3a561f52004-10-23 20:04:14 +0000952ifdef SHARED_LIBRARY
953
Chris Lattner3c473472004-12-16 17:28:50 +0000954$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000955 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000956 $(LTCompile.CXX) $< -o $@
957
Chris Lattner3c473472004-12-16 17:28:50 +0000958$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerc3719842004-12-16 18:26:53 +0000959 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000960 $(LTCompile.C) $< -o $@
961
962else
Reid Spencer4d71b662004-10-22 21:01:56 +0000963
Chris Lattner3c473472004-12-16 17:28:50 +0000964$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000965 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000966 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000967
Chris Lattner3c473472004-12-16 17:28:50 +0000968$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerc3719842004-12-16 18:26:53 +0000969 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000970 $(Compile.C) $< -o $@
971endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000972
Chris Lattner3c473472004-12-16 17:28:50 +0000973$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000974 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000975 $(BCCompile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000976
Chris Lattner3c473472004-12-16 17:28:50 +0000977$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000978 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000979 $(BCCompile.C) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000980
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000981endif
982
Reid Spencercc2d1e22004-10-30 09:19:36 +0000983#---------------------------------------------------------
984# Provide rule to build .bc files from .ll sources,
985# regardless of dependencies
986#---------------------------------------------------------
987$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +0000988 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000989 $(Verb) $(LLVMAS) $< -f -o $@
990
991###############################################################################
992# TABLEGEN: Provide rules for running tblgen to produce *.inc files
993###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +0000994
Reid Spencer4d71b662004-10-22 21:01:56 +0000995ifdef TARGET
996
Reid Spencer11fde542005-01-16 02:20:54 +0000997TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000998INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner3c473472004-12-16 17:28:50 +0000999INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1000.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001001
Chris Lattner3c473472004-12-16 17:28:50 +00001002# All of these files depend on tblgen and the .td files.
1003$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001004
Chris Lattner23ee7952004-12-16 17:38:56 +00001005# INCFiles rule: All of the tblgen generated files are emitted to
1006# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1007# us to only "touch" the real file if the contents of it change. IOW, if
1008# tblgen is modified, all of the .inc.tmp files are regereated, but no
1009# dependencies of the .inc files are, unless the contents of the .inc file
1010# changes.
1011$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerc3719842004-12-16 18:26:53 +00001012 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner3c473472004-12-16 17:28:50 +00001013
1014$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1015$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001016 $(Echo) "Building $(<F) register names with tblgen"
1017 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001018
Chris Lattner3c473472004-12-16 17:28:50 +00001019$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1020$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001021 $(Echo) "Building $(<F) register information header with tblgen"
1022 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001023
Chris Lattner3c473472004-12-16 17:28:50 +00001024$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1025$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001026 $(Echo) "Building $(<F) register info implementation with tblgen"
1027 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001028
Chris Lattner3c473472004-12-16 17:28:50 +00001029$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1030$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001031 $(Echo) "Building $(<F) instruction names with tblgen"
1032 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001033
Chris Lattner3c473472004-12-16 17:28:50 +00001034$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1035$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001036 $(Echo) "Building $(<F) instruction information with tblgen"
1037 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001038
Chris Lattner3c473472004-12-16 17:28:50 +00001039$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1040$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001041 $(Echo) "Building $(<F) assembly writer with tblgen"
1042 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001043
Chris Lattner02a4f902004-12-16 17:34:04 +00001044$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1045$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1046 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Reid Spencercc2d1e22004-10-30 09:19:36 +00001047 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001048
Chris Lattner3c473472004-12-16 17:28:50 +00001049$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1050$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001051 $(Echo) "Building $(<F) code emitter with tblgen"
1052 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001053
Reid Spencer3a561f52004-10-23 20:04:14 +00001054clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001055 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001056
1057endif
Chris Lattner481cc7c2003-08-15 02:18:35 +00001058
Reid Spencercc2d1e22004-10-30 09:19:36 +00001059###############################################################################
1060# LEX AND YACC: Provide rules for generating sources with lex and yacc
1061###############################################################################
Chris Lattnere8996782003-01-16 22:44:19 +00001062
Reid Spencercc2d1e22004-10-30 09:19:36 +00001063#---------------------------------------------------------
1064# Provide rules for generating a .cpp source file from
1065# (f)lex input sources.
1066#---------------------------------------------------------
1067
Reid Spencer3d659492004-11-02 16:36:03 +00001068LexFiles := $(filter %.l,$(Sources))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001069
Reid Spencer3d659492004-11-02 16:36:03 +00001070ifneq ($(LexFiles),)
1071
1072LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001073
1074.PRECIOUS: $(LexOutput)
1075
1076# Note the extra sed filtering here, used to cut down on the warnings emited
1077# by GCC. The last line is a gross hack to work around flex aparently not
1078# being able to resize the buffer on a large token input. Currently, for
1079# uninitialized string buffers in LLVM we can generate very long tokens, so
1080# this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +00001081# FIXME. (f.e. char Buffer[10000] )
Chris Lattner00950542001-06-06 20:29:01 +00001082%.cpp: %.l
Reid Spencerc2ef8cd2004-12-10 19:44:16 +00001083 $(Echo) Flexing $*.l
Reid Spencercc2d1e22004-10-30 09:19:36 +00001084 $(Verb) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +00001085 $(SED) 's/void yyunput/inline void yyunput/' | \
1086 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1087 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer80f0ef72004-10-28 00:41:43 +00001088 > $@
Chris Lattner00950542001-06-06 20:29:01 +00001089
Reid Spencer9af3b292004-11-01 07:50:27 +00001090clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001091 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001092 $(Verb) $(RM) -f $(LexOutput)
Reid Spencer9af3b292004-11-01 07:50:27 +00001093
Reid Spencercc2d1e22004-10-30 09:19:36 +00001094endif
1095
1096#---------------------------------------------------------
1097# Provide rules for generating a .cpp and .h source files
1098# from yacc (bison) input sources.
1099#---------------------------------------------------------
1100
Reid Spencer3d659492004-11-02 16:36:03 +00001101YaccFiles := $(filter %.y,$(Sources))
1102ifneq ($(YaccFiles),)
1103YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001104
1105.PRECIOUS: $(YaccOutput)
1106
1107# Cancel built-in rules for yacc
1108%.c: %.y
1109%.cpp: %.y
1110%.h: %.y
1111
Chris Lattner00950542001-06-06 20:29:01 +00001112# Rule for building the bison parsers...
Chris Lattner00950542001-06-06 20:29:01 +00001113%.cpp %.h : %.y
Reid Spencercc2d1e22004-10-30 09:19:36 +00001114 $(Echo) "Bisoning $*.y"
1115 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1116 $(Verb) $(MV) -f $*.tab.c $*.cpp
1117 $(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +00001118
Reid Spencer9af3b292004-11-01 07:50:27 +00001119clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001120 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001121 $(Verb) $(RM) -f $(YaccOutput)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001122endif
Chris Lattner00950542001-06-06 20:29:01 +00001123
Reid Spencercc2d1e22004-10-30 09:19:36 +00001124###############################################################################
1125# OTHER RULES: Other rules needed
1126###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001127
Chris Lattner30440c62003-01-16 21:06:18 +00001128# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +00001129ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +00001130%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +00001131 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +00001132else
1133%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +00001134 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +00001135endif
Chris Lattner30440c62003-01-16 21:06:18 +00001136
John Criswell7f336952003-09-06 14:44:17 +00001137# This rules ensures that header files that are removed still have a rule for
1138# which they can be "generated." This allows make to ignore them and
1139# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +00001140%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +00001141
Reid Spencercc2d1e22004-10-30 09:19:36 +00001142# Define clean-local to clean the current directory. Note that this uses a
1143# very conservative approach ensuring that empty variables do not cause
1144# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +00001145clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001146ifneq ($(strip $(ObjDir)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001147 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencere5487ba2004-10-24 07:53:21 +00001148endif
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001149 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001150ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001151 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001152endif
John Criswell7a73b802003-06-30 21:59:07 +00001153
Reid Spencer3d659492004-11-02 16:36:03 +00001154clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001155 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +00001156
Reid Spencercc2d1e22004-10-30 09:19:36 +00001157# Build tags database for Emacs/Xemacs:
Reid Spencer12d79512004-11-12 02:27:36 +00001158tags:: TAGS CTAGS
1159
Reid Spencercc2d1e22004-10-30 09:19:36 +00001160TAGS:
Reid Spencer11fde542005-01-16 02:20:54 +00001161 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1162 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1163 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1164 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
Reid Spencer12d79512004-11-12 02:27:36 +00001165 -name '*.cpp' -o -name '*.h' | \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001166 $(ETAGS) $(ETAGSFLAGS) -
1167
Reid Spencer12d79512004-11-12 02:27:36 +00001168CTAGS:
Reid Spencer11fde542005-01-16 02:20:54 +00001169 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1170 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1171 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1172 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
Reid Spencer12d79512004-11-12 02:27:36 +00001173 \( -name '*.cpp' -o -name '*.h' \) -print | \
Reid Spencer11fde542005-01-16 02:20:54 +00001174 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
Reid Spencer12d79512004-11-12 02:27:36 +00001175
1176
Reid Spencer3a561f52004-10-23 20:04:14 +00001177###############################################################################
1178# DEPENDENCIES: Include the dependency files if we should
1179###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +00001180ifndef DISABLE_AUTO_DEPENDENCIES
1181
Reid Spencer3a561f52004-10-23 20:04:14 +00001182# If its not one of the cleaning targets
Reid Spencercc2d1e22004-10-30 09:19:36 +00001183ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +00001184
Reid Spencer3a561f52004-10-23 20:04:14 +00001185# Get the list of dependency files
Reid Spencercc2d1e22004-10-30 09:19:36 +00001186DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencer11fde542005-01-16 02:20:54 +00001187DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +00001188
Reid Spencer3a561f52004-10-23 20:04:14 +00001189-include /dev/null $(DependFiles)
1190
John Criswelld741bcf2003-08-12 18:51:51 +00001191endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +00001192
Reid Spencercc2d1e22004-10-30 09:19:36 +00001193endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001194
Reid Spencer151f8ba2004-10-25 08:27:37 +00001195###############################################################################
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001196# CHECK: Running the test suite
1197###############################################################################
1198
1199check::
Reid Spencer11fde542005-01-16 02:20:54 +00001200 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1201 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001202 $(EchoCmd) Running test suite ; \
Reid Spencer11fde542005-01-16 02:20:54 +00001203 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001204 TESTSUITE=$(TESTSUITE) ; \
1205 else \
1206 $(EchoCmd) No Makefile in test directory ; \
1207 fi ; \
1208 else \
1209 $(EchoCmd) No test directory ; \
1210 fi
1211
1212###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001213# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +00001214###############################################################################
1215
Reid Spencere45ebfa2004-10-26 07:09:33 +00001216#------------------------------------------------------------------------
1217# Define distribution related variables
1218#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00001219DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1220DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1221TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1222DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1223DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1224DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer151f8ba2004-10-25 08:27:37 +00001225DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1226 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001227 Makefile.config.in configure autoconf
1228DistOther := $(notdir $(wildcard \
Reid Spencer11fde542005-01-16 02:20:54 +00001229 $(PROJ_SRC_DIR)/*.h \
1230 $(PROJ_SRC_DIR)/*.td \
1231 $(PROJ_SRC_DIR)/*.def \
1232 $(PROJ_SRC_DIR)/*.ll \
1233 $(PROJ_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001234DistSubDirs := $(SubDirs)
Reid Spencerfbbf3072004-11-29 05:00:33 +00001235DistSources = $(Sources) $(EXTRA_DIST)
1236DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001237
Reid Spencere45ebfa2004-10-26 07:09:33 +00001238#------------------------------------------------------------------------
1239# We MUST build distribution with OBJ_DIR != SRC_DIR
1240#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00001241ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencere45ebfa2004-10-26 07:09:33 +00001242dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001243 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00001244
Reid Spencere45ebfa2004-10-26 07:09:33 +00001245else
1246
Reid Spencere45ebfa2004-10-26 07:09:33 +00001247#------------------------------------------------------------------------
Reid Spencere45ebfa2004-10-26 07:09:33 +00001248# Prevent attempt to run dist targets from anywhere but the top level
1249#------------------------------------------------------------------------
1250ifneq ($(LEVEL),.)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001251dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencer11fde542005-01-16 02:20:54 +00001252 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001253else
1254
1255#------------------------------------------------------------------------
1256# Provide the top level targets
1257#------------------------------------------------------------------------
1258
Reid Spencercc2d1e22004-10-30 09:19:36 +00001259dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001260
Reid Spencer345235ca2004-12-04 22:34:09 +00001261$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001262 $(Echo) Packing gzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00001263 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00001264 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00001265
Reid Spencercc2d1e22004-10-30 09:19:36 +00001266dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001267
Reid Spencer345235ca2004-12-04 22:34:09 +00001268$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001269 $(Echo) Packing bzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00001270 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00001271 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001272
Reid Spencercc2d1e22004-10-30 09:19:36 +00001273dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001274
Reid Spencer345235ca2004-12-04 22:34:09 +00001275$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001276 $(Echo) Packing zipped distribution file.
1277 $(Verb) rm -f $(DistZip)
Reid Spencer11fde542005-01-16 02:20:54 +00001278 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001279
1280dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001281 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001282
Reid Spencerf8f57402005-01-28 19:52:32 +00001283DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencere45ebfa2004-10-26 07:09:33 +00001284
Reid Spencer345235ca2004-12-04 22:34:09 +00001285dist-check:: $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001286 $(Echo) Checking distribution tar file.
1287 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001288 $(RM) -rf $(DistCheckDir) ; \
1289 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00001290 $(Verb) $(MKDIR) $(DistCheckDir)
1291 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001292 $(MKDIR) $(DistCheckDir)/build && \
1293 $(MKDIR) $(DistCheckDir)/install && \
1294 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1295 cd build && \
1296 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer32924e02004-12-24 03:36:31 +00001297 --srcdir=../$(DistName) && \
Reid Spencer345235ca2004-12-04 22:34:09 +00001298 $(MAKE) all && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001299 $(MAKE) check && \
1300 $(MAKE) install && \
1301 $(MAKE) uninstall && \
1302 $(MAKE) dist && \
1303 $(MAKE) clean && \
1304 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001305 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001306
1307dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001308 $(Echo) Cleaning distribution files
Reid Spencer345235ca2004-12-04 22:34:09 +00001309 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1310 $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001311
1312endif
1313
1314#------------------------------------------------------------------------
1315# Provide the recursive distdir target for building the distribution directory
1316#------------------------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +00001317distdir: $(DistDir)/.makedistdir
1318$(DistDir)/.makedistdir: $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001319 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001320 if test -d "$(DistDir)" ; then \
1321 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1322 exit 1 ; \
1323 fi ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001324 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001325 $(RM) -rf $(DistDir); \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001326 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001327 $(MAKE) all ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001328 fi
Reid Spencerfbbf3072004-11-29 05:00:33 +00001329 $(Echo) Building Distribution Directory $(DistDir)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001330 $(Verb) $(MKDIR) $(DistDir)
Reid Spencer11fde542005-01-16 02:20:54 +00001331 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1332 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001333 for file in $(DistFiles) ; do \
1334 case "$$file" in \
Reid Spencer11fde542005-01-16 02:20:54 +00001335 $(PROJ_SRC_DIR)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00001336 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1337 ;; \
Reid Spencer11fde542005-01-16 02:20:54 +00001338 $(PROJ_SRC_ROOT)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00001339 file=`echo "$$file" | \
1340 sed "s#^$$srcrootstrip/##"` \
1341 ;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001342 esac; \
Reid Spencer11fde542005-01-16 02:20:54 +00001343 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1344 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1345 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001346 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001347 from_dir=. ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001348 fi ; \
1349 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001350 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1351 to_dir="$(DistDir)/$$dir"; \
1352 $(MKDIR) "$$to_dir" ; \
1353 else \
1354 to_dir="$(DistDir)"; \
1355 fi; \
1356 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1357 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001358 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001359 fi ; \
1360 if test -d "$$from_dir/$$file"; then \
Reid Spencer11fde542005-01-16 02:20:54 +00001361 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1362 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1363 $(CP) -pR "$(PROJ_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001364 fi; \
Reid Spencerc3719842004-12-16 18:26:53 +00001365 $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001366 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00001367 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001368 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00001369 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001370 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer345235ca2004-12-04 22:34:09 +00001371 $(EchoCmd) "===== WARNING: Distribution Source " \
1372 "$$from_dir/$$file Not Found!" ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001373 elif test "$(Verb)" != '@' ; then \
1374 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001375 fi; \
1376 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00001377 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001378 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001379 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001380 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001381 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1382 exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001383 fi; \
1384 done
Reid Spencer345235ca2004-12-04 22:34:09 +00001385 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1386 $(EchoCmd) Eliminating CVS directories from distribution ; \
1387 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1388 $(MAKE) dist-hook ; \
1389 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1390 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1391 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1392 -o ! -type d ! -perm -444 -exec \
1393 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1394 || chmod -R a+r $(DistDir) ; \
1395 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +00001396
Reid Spencercc2d1e22004-10-30 09:19:36 +00001397# This is invoked by distdir target, define it as a no-op to avoid errors if not
1398# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00001399dist-hook::
1400
Reid Spencere53e3972004-10-22 23:06:30 +00001401endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001402
1403###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00001404# TOP LEVEL - targets only to apply at the top level directory
1405###############################################################################
1406
1407ifeq ($(LEVEL),.)
1408
1409#------------------------------------------------------------------------
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001410# Install support for the project's include files:
Reid Spencere5487ba2004-10-24 07:53:21 +00001411#------------------------------------------------------------------------
1412install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001413 $(Echo) Installing include files
Reid Spencer11fde542005-01-16 02:20:54 +00001414 $(Verb) $(MKDIR) $(PROJ_includedir)
1415 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1416 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencere5487ba2004-10-24 07:53:21 +00001417 find . -path '*/Internal' -prune -o '(' -type f \
1418 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
Reid Spencer11fde542005-01-16 02:20:54 +00001419 -print ')' | grep -v CVS | pax -rwdvpe $(PROJ_includedir) ; \
Reid Spencere5487ba2004-10-24 07:53:21 +00001420 fi
1421
1422uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001423 $(Echo) Uninstalling include files
Reid Spencer11fde542005-01-16 02:20:54 +00001424 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1425 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencere5487ba2004-10-24 07:53:21 +00001426 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1427 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
Reid Spencer11fde542005-01-16 02:20:54 +00001428 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
Reid Spencere5487ba2004-10-24 07:53:21 +00001429 fi
1430
Reid Spencere5487ba2004-10-24 07:53:21 +00001431endif
1432
Reid Spencer4d71b662004-10-22 21:01:56 +00001433#------------------------------------------------------------------------
1434# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00001435#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001436printvars::
Reid Spencer11fde542005-01-16 02:20:54 +00001437 $(Echo) "BuildMode : " '$(BuildMode)'
1438 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1439 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1440 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1441 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1442 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1443 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1444 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1445 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1446 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1447 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1448 $(Echo) "UserTargets : " '$(UserTargets)'
1449 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1450 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1451 $(Echo) "ObjDir : " '$(ObjDir)'
1452 $(Echo) "LibDir : " '$(LibDir)'
1453 $(Echo) "ToolDir : " '$(ToolDir)'
1454 $(Echo) "ExmplDir : " '$(ExmplDir)'
1455 $(Echo) "Sources : " '$(Sources)'
1456 $(Echo) "TDFiles : " '$(TDFiles)'
1457 $(Echo) "INCFiles : " '$(INCFiles)'
1458 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1459 $(Echo) "Preconditions: " '$(Preconditions)'
1460 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1461 $(Echo) "Compile.C : " '$(Compile.C)'
1462 $(Echo) "Archive : " '$(Archive)'
1463 $(Echo) "YaccFiles : " '$(YaccFiles)'
1464 $(Echo) "LexFiles : " '$(LexFiles)'
1465 $(Echo) "Module : " '$(Module)'