blob: 39c741a8838c196a294dbe5529bf000c352fe815 [file] [log] [blame]
Misha Brukman7426c892004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswell23e43fb2003-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 Brukman7426c892004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner2f7c9632001-06-06 20:29:01 +00009#
Reid Spencer81cd0492004-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 Lattner2e9fc94a2003-08-15 03:02:52 +000012#
Vikram S. Adve24132e82002-07-09 12:04:21 +000013#===-----------------------------------------------------------------------====
Chris Lattner2f7c9632001-06-06 20:29:01 +000014
Reid Spencerf88808a2004-10-30 09:19:36 +000015################################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencerf88808a2004-10-30 09:19:36 +000017################################################################################
John Criswell3ef61af2003-06-30 21:59:07 +000018
Chris Lattner2f7c9632001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Chris Lattner661a7142004-12-03 21:05:57 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode
Reid Spencer8b5ebe52004-12-06 05:35:13 +000023LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencerd4bd3752004-12-03 20:08:48 +000024 install-local printvars uninstall-local \
25 install-bytecode-local
Reid Spencer8b5ebe52004-12-06 05:35:13 +000026TopLevelTargets := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
Reid Spencerf88808a2004-10-30 09:19:36 +000027 dist-zip
28UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29InternalTargets := preconditions distdir dist-hook
Reid Spencer81cd0492004-10-23 20:04:14 +000030
Reid Spencerf88808a2004-10-30 09:19:36 +000031################################################################################
Reid Spencer77a46d22004-10-26 22:26:33 +000032# INITIALIZATION: Basic things the makefile needs
Reid Spencerf88808a2004-10-30 09:19:36 +000033################################################################################
34
35#--------------------------------------------------------------------
36# Set the VPATH so that we can find source files.
37#--------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +000038VPATH=$(PROJ_SRC_DIR)
Reid Spencer77a46d22004-10-26 22:26:33 +000039
40#--------------------------------------------------------------------
41# Reset the list of suffixes we know how to build
42#--------------------------------------------------------------------
43.SUFFIXES:
Chris Lattnerf60c1702005-02-04 21:28:50 +000044.SUFFIXES: .c .cpp .cc .h .hpp .y .l .lo .o .a .bc .td .ps .dot
Reid Spencerf88808a2004-10-30 09:19:36 +000045.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer77a46d22004-10-26 22:26:33 +000046
Reid Spencer81cd0492004-10-23 20:04:14 +000047#--------------------------------------------------------------------
48# Mark all of these targets as phony to avoid implicit rule search
49#--------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +000050.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer81cd0492004-10-23 20:04:14 +000051
52#--------------------------------------------------------------------
Reid Spencer77a46d22004-10-26 22:26:33 +000053# Make sure all the user-target rules are double colon rules and
54# they are defined first.
Reid Spencer81cd0492004-10-23 20:04:14 +000055#--------------------------------------------------------------------
56
Reid Spencerf88808a2004-10-30 09:19:36 +000057$(UserTargets)::
Reid Spencer100080c2004-10-25 08:27:37 +000058
Reid Spencer77a46d22004-10-26 22:26:33 +000059################################################################################
60# PRECONDITIONS: that which must be built/checked first
61################################################################################
62
Reid Spencerd4bd3752004-12-03 20:08:48 +000063SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencerba6a3db2005-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 Spencer77a46d22004-10-26 22:26:33 +000079
Reid Spencer53846bc2005-08-25 04:59:49 +000080preconditions: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +000081
82#------------------------------------------------------------------------
83# Make sure the BUILT_SOURCES are built first
84#------------------------------------------------------------------------
Reid Spencer97e40f12004-12-16 07:15:16 +000085$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000086
87clean-local::
88ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +000089 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000090endif
91
Reid Spencerba6a3db2005-01-16 02:20:54 +000092ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer55814372004-12-16 08:00:46 +000093spotless:
Reid Spencer55814372004-12-16 08:00:46 +000094 $(Verb) if test -x config.status ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +000095 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-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 Spencer55814372004-12-16 08:00:46 +0000100 $(RM) -rf * ; \
Reid Spencer7ef8e662004-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 Spencerba6a3db2005-01-16 02:20:54 +0000105 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000106 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
107 $(ConfigStatusScript) ; \
Reid Spencer55814372004-12-16 08:00:46 +0000108 else \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000109 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer55814372004-12-16 08:00:46 +0000110 fi
Reid Spencerc49a8632005-12-21 23:17:06 +0000111else
112spotless:
113 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer55814372004-12-16 08:00:46 +0000114endif
115
Reid Spencerf88808a2004-10-30 09:19:36 +0000116$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencerb7f710a2004-10-28 00:41:43 +0000117
Reid Spencer77a46d22004-10-26 22:26:33 +0000118#------------------------------------------------------------------------
119# Make sure we're not using a stale configuration
120#------------------------------------------------------------------------
Reid Spencerafdc82c2004-12-16 18:26:53 +0000121reconfigure:
Reid Spencerba6a3db2005-01-16 02:20:54 +0000122 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
123 $(Verb) cd $(PROJ_OBJ_ROOT) && \
124 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
125 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000126 fi ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000127 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
128 $(ConfigStatusScript)
129
Reid Spencerf88808a2004-10-30 09:19:36 +0000130.PRECIOUS: $(ConfigStatusScript)
131$(ConfigStatusScript): $(ConfigureScript)
132 $(Echo) Reconfiguring with $<
Reid Spencerba6a3db2005-01-16 02:20:54 +0000133 $(Verb) cd $(PROJ_OBJ_ROOT) && \
134 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
135 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000136 fi ; \
Reid Spencer50f34872004-11-29 12:37:44 +0000137 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
138 $(ConfigStatusScript)
Reid Spencer77a46d22004-10-26 22:26:33 +0000139
Reid Spencer83bde552005-08-25 04:44:18 +0000140#------------------------------------------------------------------------
Reid Spencer77a46d22004-10-26 22:26:33 +0000141# Make sure the configuration makefile is up to date
142#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000143ifneq ($(MakefileConfigIn),)
144$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000145 $(Echo) Regenerating $@
Reid Spencerba6a3db2005-01-16 02:20:54 +0000146 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
147endif
148
149ifneq ($(MakefileCommonIn),)
150$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
151 $(Echo) Regenerating $@
152 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
153endif
Reid Spencer77a46d22004-10-26 22:26:33 +0000154
155#------------------------------------------------------------------------
156# If the Makefile in the source tree has been updated, copy it over into the
157# build tree. But, only do this if the source and object makefiles differ
158#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000159ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer77a46d22004-10-26 22:26:33 +0000160
Reid Spencerba6a3db2005-01-16 02:20:54 +0000161Makefile: $(PROJ_SRC_DIR)/Makefile
Reid Spencerf88808a2004-10-30 09:19:36 +0000162 $(Echo) "Updating Makefile"
163 $(Verb) $(MKDIR) $(@D)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000164 $(Verb) $(CP) -f $< $@
Reid Spencer77a46d22004-10-26 22:26:33 +0000165
166# Copy the Makefile.* files unless we're in the root directory which avoids
167# the copying of Makefile.config.in or other things that should be explicitly
168# taken care of.
Reid Spencerba6a3db2005-01-16 02:20:54 +0000169$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
Reid Spencerd94bb332004-10-26 23:10:00 +0000170 @case '$?' in \
171 *Makefile.rules) ;; \
172 *.in) ;; \
Reid Spencerf88808a2004-10-30 09:19:36 +0000173 *) $(Echo) "Updating $(@F)" ; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000174 $(MKDIR) $(@D) ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000175 $(CP) -f $< $@ ;; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000176 esac
177
Reid Spencer77a46d22004-10-26 22:26:33 +0000178endif
179
180#------------------------------------------------------------------------
181# Set up the basic dependencies
182#------------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000183$(UserTargets):: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +0000184
185all:: all-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000186clean:: clean-local
Reid Spencer9d0c1e02004-11-02 16:36:03 +0000187clean-all:: clean-local clean-all-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000188install:: install-local
189uninstall:: uninstall-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000190install-local:: all-local
Reid Spencerd4bd3752004-12-03 20:08:48 +0000191install-bytecode:: install-bytecode-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000192
193###############################################################################
194# VARIABLES: Set up various variables based on configuration data
195###############################################################################
196
197#--------------------------------------------------------------------
198# Variables derived from configuration we are building
Chris Lattner2f7c9632001-06-06 20:29:01 +0000199#--------------------------------------------------------------------
200
Reid Spencer34982d82005-01-02 17:43:20 +0000201
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000202ifdef ENABLE_PROFILING
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000203 BuildMode := Profile
Reid Spencercd7d6cf2004-12-08 04:34:51 +0000204 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
Reid Spencerf88808a2004-10-30 09:19:36 +0000205 C.Flags := -O3 -DNDEBUG -pg
206 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000207else
208 ifdef ENABLE_OPTIMIZED
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000209 BuildMode := Release
Reid Spencer34982d82005-01-02 17:43:20 +0000210 # Don't use -fomit-frame-pointer on FreeBSD
211 ifneq ($(OS),FreeBSD)
212 OmitFramePointer := -fomit-frame-pointer
213 endif
214 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
215 $(OmitFramePointer)
216 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
Reid Spencerf88808a2004-10-30 09:19:36 +0000217 LD.Flags := -O3 -DNDEBUG
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000218 else
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000219 BuildMode := Debug
Reid Spencercd7d6cf2004-12-08 04:34:51 +0000220 CXX.Flags := -g -D_DEBUG
Reid Spencerf88808a2004-10-30 09:19:36 +0000221 C.Flags := -g -D_DEBUG
222 LD.Flags := -g -D_DEBUG
Reid Spencerf206bd72004-10-22 21:01:56 +0000223 KEEP_SYMBOLS := 1
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000224 endif
225endif
226
Jeff Cohen8b7b47c2005-10-23 04:51:22 +0000227CXX.Flags += $(CXXFLAGS)
Reid Spencerf88808a2004-10-30 09:19:36 +0000228C.Flags += $(CFLAGS)
229CPP.Flags += $(CPPFLAGS)
230LD.Flags += $(LDFLAGS)
231AR.Flags := cru
232LibTool.Flags := --tag=CXX
Reid Spencer81cd0492004-10-23 20:04:14 +0000233
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000234#Make Floating point ieee complient on alpha
235ifeq ($(ARCH),Alpha)
236 CXX.Flags += -mieee
237 CPP.Flags += -mieee
238endif
239
Reid Spencer81cd0492004-10-23 20:04:14 +0000240#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000241# Directory locations
Reid Spencer81cd0492004-10-23 20:04:14 +0000242#--------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000243ObjDir := $(PROJ_OBJ_DIR)/$(BuildMode)
244LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
245ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
246ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000247LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer0dbf1012004-11-18 20:04:39 +0000248LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencerb9f8de62004-12-28 07:59:22 +0000249LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer2bba41c2004-12-22 05:57:21 +0000250CFERuntimeLibDir := $(LLVMGCCDIR)/lib
John Criswell3ef61af2003-06-30 21:59:07 +0000251
Reid Spencer81cd0492004-10-23 20:04:14 +0000252#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000253# Full Paths To Compiled Tools and Utilities
Reid Spencer81cd0492004-10-23 20:04:14 +0000254#--------------------------------------------------------------------
Reid Spencerb12e2902005-01-14 16:33:36 +0000255EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
256Echo = @$(EchoCmd)
Reid Spencerf88808a2004-10-30 09:19:36 +0000257ifndef LIBTOOL
Reid Spencerf206bd72004-10-22 21:01:56 +0000258LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencerf88808a2004-10-30 09:19:36 +0000259endif
260ifndef LLVMAS
261LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
262endif
263ifndef BURG
264BURG := $(LLVMToolDir)/burg$(EXEEXT)
265endif
266ifndef TBLGEN
267TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
268endif
Chris Lattner0ea40c92004-11-29 19:47:58 +0000269ifndef GCCAS
270GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
271endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000272ifndef GCCLD
273GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
274endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000275ifndef LDIS
276LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
277endif
278ifndef LLI
279LLI := $(LLVMToolDir)/lli$(EXEEXT)
280endif
Alkis Evlogimenos24340582005-02-27 10:21:37 +0000281ifndef LLC
282LLC := $(LLVMToolDir)/llc$(EXEEXT)
283endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000284ifndef LOPT
Alkis Evlogimenos7c7705d2004-12-13 18:08:29 +0000285LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000286endif
Alkis Evlogimenos7c04a3d2005-02-02 00:40:15 +0000287ifndef LBUGPOINT
288LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
289endif
290
John Criswelldc665012005-01-03 17:42:57 +0000291LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
292LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000293
Reid Spencer81cd0492004-10-23 20:04:14 +0000294#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000295# Adjust to user's request
Reid Spencer81cd0492004-10-23 20:04:14 +0000296#--------------------------------------------------------------------
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000297
Reid Spencer87e645c2005-01-11 04:31:07 +0000298# Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
299# to be built. Note that if LOADABLE_MODULE is specified then the resulting
300# shared library can be opened with dlopen
301ifdef SHARED_LIBRARY
Reid Spencerf88808a2004-10-30 09:19:36 +0000302 LD.Flags += -rpath $(LibDir)
Reid Spencer87e645c2005-01-11 04:31:07 +0000303 ifdef LOADABLE_MODULE
304 LD.Flags += -module
305 endif
306else
307 LibTool.Flags += --tag=disable-shared
John Criswell3601f372003-07-31 20:58:51 +0000308endif
309
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000310ifdef TOOL_VERBOSE
311 C.Flags += -v
312 CXX.Flags += -v
313 LD.Flags += -v
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000314 VERBOSE := 1
315endif
316
Reid Spencer81cd0492004-10-23 20:04:14 +0000317# Adjust settings for verbose mode
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000318ifndef VERBOSE
Reid Spencerf88808a2004-10-30 09:19:36 +0000319 Verb := @
320 LibTool.Flags += --silent
321 AR.Flags += >/dev/null 2>/dev/null
Reid Spencerba6a3db2005-01-16 02:20:54 +0000322 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer100080c2004-10-25 08:27:37 +0000323else
Reid Spencerf88808a2004-10-30 09:19:36 +0000324 ConfigureScriptFLAGS :=
Misha Brukman1326a7c2002-09-12 16:05:39 +0000325endif
326
Vikram S. Adved141c282002-09-18 11:55:13 +0000327# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000328ifndef KEEP_SYMBOLS
Reid Spencerf88808a2004-10-30 09:19:36 +0000329 Strip := $(PLATFORMSTRIPOPTS)
330 StripWarnMsg := "(without symbols)"
Reid Spencer247a10e2005-02-24 07:12:43 +0000331 Install.StripFlag += -s
Vikram S. Adved141c282002-09-18 11:55:13 +0000332endif
333
Reid Spencer81cd0492004-10-23 20:04:14 +0000334# Adjust linker flags for building an executable
Reid Spencerf206bd72004-10-22 21:01:56 +0000335ifdef TOOLNAME
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000336ifdef EXAMPLE_TOOL
337 LD.Flags += -rpath $(ExmplDir) -export-dynamic
338else
Reid Spencerf88808a2004-10-30 09:19:36 +0000339 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000340endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000341endif
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000342
Reid Spencer81cd0492004-10-23 20:04:14 +0000343#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000344# Options To Invoke Tools
Reid Spencer81cd0492004-10-23 20:04:14 +0000345#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000346
347CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
348
Duraid Madina60c9a3c2005-05-16 06:38:09 +0000349ifeq ($(OS),HP-UX)
350 CompileCommonOpts += -D_REENTRANT -D_HPUX_SOURCE
351endif
352
Reid Spencere9fa5442005-02-14 21:54:08 +0000353LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Reid Spencerba6a3db2005-01-16 02:20:54 +0000354CPP.Flags += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
355 -I$(PROJ_OBJ_ROOT)/include \
356 -I$(PROJ_SRC_ROOT)/include \
357 -I$(LLVM_OBJ_ROOT)/include \
358 -I$(LLVM_SRC_ROOT)/include \
359 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencerf206bd72004-10-22 21:01:56 +0000360
Reid Spencerf88808a2004-10-30 09:19:36 +0000361Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
362LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
Reid Spencer2bba41c2004-12-22 05:57:21 +0000363BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
364 $(C.Flags) -c
Chris Lattnerbb087952005-10-05 00:28:41 +0000365Preprocess.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -E $(C.Flags)
366
Reid Spencerf88808a2004-10-30 09:19:36 +0000367Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
368LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
Reid Spencerc005fba2004-12-24 14:47:34 +0000369BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
370 $(CXX.Flags) -c
Chris Lattnerbb087952005-10-05 00:28:41 +0000371Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
Reid Spencerf88808a2004-10-30 09:19:36 +0000372Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
373 $(CompileCommonOpts) $(LD.Flags) $(Strip)
374Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000375 $(CompileCommonOpts)
Reid Spencerfe0a01e2005-02-16 16:13:02 +0000376LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
377 $(Install.Flags)
Reid Spencer247a10e2005-02-24 07:12:43 +0000378ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
379DataInstall = $(INSTALL) -m 0644
Reid Spencerba6a3db2005-01-16 02:20:54 +0000380Burg = $(BURG) -I $(PROJ_SRC_DIR)
381TableGen = $(TBLGEN) -I $(PROJ_SRC_DIR)
Reid Spencerf88808a2004-10-30 09:19:36 +0000382Archive = $(AR) $(AR.Flags)
Reid Spencer32f7e422004-12-02 09:28:21 +0000383LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencerf206bd72004-10-22 21:01:56 +0000384ifdef RANLIB
Reid Spencer81cd0492004-10-23 20:04:14 +0000385Ranlib = $(RANLIB)
Reid Spencerf206bd72004-10-22 21:01:56 +0000386else
Reid Spencer81cd0492004-10-23 20:04:14 +0000387Ranlib = ranlib
John Criswell3ef61af2003-06-30 21:59:07 +0000388endif
389
Chris Lattner2f7c9632001-06-06 20:29:01 +0000390#----------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +0000391# Get the list of source files and compute object file
392# names from them.
Reid Spencer81cd0492004-10-23 20:04:14 +0000393#----------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +0000394ifdef FAKE_SOURCES
395 Sources :=
396 FakeSources := $(FAKE_SOURCES)
397 ifdef BUILT_SOURCES
398 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
399 endif
400 BaseNameSources := $(sort $(basename $(FakeSources)))
401 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
402 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
403 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencerf88808a2004-10-30 09:19:36 +0000404else
Reid Spencer81546582004-12-04 22:34:09 +0000405 ifndef SOURCES
Reid Spencerba6a3db2005-01-16 02:20:54 +0000406 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
407 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
408 $(PROJ_SRC_DIR)/*.l))
Reid Spencer81546582004-12-04 22:34:09 +0000409 else
410 Sources := $(SOURCES)
411 endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000412
Reid Spencer81546582004-12-04 22:34:09 +0000413 ifdef BUILT_SOURCES
414 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
415 endif
Vikram S. Advefe346892001-07-15 13:16:47 +0000416
Reid Spencer81546582004-12-04 22:34:09 +0000417 BaseNameSources := $(sort $(basename $(Sources)))
418 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
419 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
420 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
421endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000422
423###############################################################################
424# DIRECTORIES: Handle recursive descent of directory structure
425###############################################################################
John Criswell3601f372003-07-31 20:58:51 +0000426
Chris Lattner2f7c9632001-06-06 20:29:01 +0000427#---------------------------------------------------------
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000428# Provide rules to make install dirs. This must be early
429# in the file so they get built before dependencies
430#---------------------------------------------------------
431
Reid Spencer90b689d2005-05-19 20:26:14 +0000432$(PROJ_bindir): $(PROJ_bindir)/.dir
433$(PROJ_libdir): $(PROJ_libdir)/.dir
434$(PROJ_includedir): $(PROJ_includedir)/.dir
435$(PROJ_etcdir): $(PROJ_etcdir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000436
Reid Spencerf88808a2004-10-30 09:19:36 +0000437# To create other directories, as needed, and timestamp their creation
438%/.dir:
439 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfc66af42004-11-29 05:00:33 +0000440 $(Verb) $(DATE) > $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000441
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000442.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
443.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000444
445#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000446# Handle the DIRS options for sequential construction
Chris Lattner2f7c9632001-06-06 20:29:01 +0000447#---------------------------------------------------------
448
Reid Spencerf88808a2004-10-30 09:19:36 +0000449SubDirs :=
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000450ifdef DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000451SubDirs += $(DIRS)
452$(RecursiveTargets)::
453 $(Verb) for dir in $(DIRS); do \
Reid Spencerf206bd72004-10-22 21:01:56 +0000454 if [ ! -f $$dir/Makefile ]; then \
455 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000456 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000457 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000458 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
459 ($(MAKE) -C $$dir $@ ) || exit 1; \
460 fi ; \
Chris Lattner539a23c2002-09-17 23:35:02 +0000461 done
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000462endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000463
Reid Spencer81cd0492004-10-23 20:04:14 +0000464#---------------------------------------------------------
465# Handle the EXPERIMENTAL_DIRS options ensuring success
466# after each directory is built.
467#---------------------------------------------------------
468ifdef EXPERIMENTAL_DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000469$(RecursiveTargets)::
470 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer81cd0492004-10-23 20:04:14 +0000471 if [ ! -f $$dir/Makefile ]; then \
472 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000473 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000474 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000475 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
476 ($(MAKE) -C $$dir $@ ) || exit 0; \
477 fi ; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000478 done
479endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000480
Reid Spencerc49a8632005-12-21 23:17:06 +0000481#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000482# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencerc49a8632005-12-21 23:17:06 +0000483#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000484ifdef PARALLEL_DIRS
485
Reid Spencerf88808a2004-10-30 09:19:36 +0000486SubDirs += $(PARALLEL_DIRS)
487
Reid Spencerd4bd3752004-12-03 20:08:48 +0000488# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencerf88808a2004-10-30 09:19:36 +0000489all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
490clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000491clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencerf88808a2004-10-30 09:19:36 +0000492install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000493uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencerd4bd3752004-12-03 20:08:48 +0000494install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000495
Reid Spencer81546582004-12-04 22:34:09 +0000496ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer81cd0492004-10-23 20:04:14 +0000497
Reid Spencer81546582004-12-04 22:34:09 +0000498$(ParallelTargets) :
Reid Spencerf88808a2004-10-30 09:19:36 +0000499 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000500 $(MKDIR) $(@D); \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000501 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswell6df35dd2003-11-25 19:32:22 +0000502 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000503 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
504 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
505 fi
Chris Lattner2f7c9632001-06-06 20:29:01 +0000506endif
507
Reid Spencer81cd0492004-10-23 20:04:14 +0000508#---------------------------------------------------------
509# Handle the OPTIONAL_DIRS options for directores that may
510# or may not exist.
511#---------------------------------------------------------
John Criswell8224df92003-06-27 16:58:44 +0000512ifdef OPTIONAL_DIRS
Reid Spencer100080c2004-10-25 08:27:37 +0000513
Reid Spencerf88808a2004-10-30 09:19:36 +0000514SubDirs += $(OPTIONAL_DIRS)
Reid Spencer100080c2004-10-25 08:27:37 +0000515
Reid Spencerf88808a2004-10-30 09:19:36 +0000516$(RecursiveTargets)::
517 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000518 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Reid Spencerf206bd72004-10-22 21:01:56 +0000519 if [ ! -f $$dir/Makefile ]; then \
520 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000521 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000522 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000523 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
524 ($(MAKE) -C$$dir $@ ) || exit 1; \
525 fi ; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000526 fi \
John Criswell8224df92003-06-27 16:58:44 +0000527 done
528endif
529
Reid Spencercc51e7b2004-08-20 09:20:05 +0000530#---------------------------------------------------------
531# Handle the CONFIG_FILES options
532#---------------------------------------------------------
533ifdef CONFIG_FILES
Reid Spencercc51e7b2004-08-20 09:20:05 +0000534
Reid Spencerba6a3db2005-01-16 02:20:54 +0000535install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
536 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000537 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000538 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000539 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000540 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000541 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencer39d6a612004-11-23 05:59:53 +0000542 else \
543 $(ECHO) Error: cannot find config file $${file}. ; \
544 fi \
Reid Spencercc51e7b2004-08-20 09:20:05 +0000545 done
Reid Spencer81cd0492004-10-23 20:04:14 +0000546
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000547uninstall-local::
Reid Spencerba6a3db2005-01-16 02:20:54 +0000548 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000549 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000550 $(RM) -f $(PROJ_etcdir)/$${file} ; \
Reid Spencer12a3a052004-10-24 07:53:21 +0000551 done
552
Reid Spencercc51e7b2004-08-20 09:20:05 +0000553endif
554
Reid Spencer81cd0492004-10-23 20:04:14 +0000555###############################################################################
Reid Spencera80f1672005-05-19 00:37:31 +0000556# Set up variables for building libararies
557###############################################################################
558
559#---------------------------------------------------------
560# Handle the special "JIT" value for LLVM_LIBS which is a
561# shorthand for a bunch of libraries that get the correct
562# JIT support for a library or a tool that runs JIT.
563#---------------------------------------------------------
564ifeq ($(LLVMLIBS),JIT)
565
566# Make sure we can get our own symbols in the tool
567Link += -dlopen self
568
569# Generic JIT libraries
570JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
571
572# You can enable the X86 JIT on a non-X86 host by setting the flag
573# ENABLE_X86_JIT on the make command line. If not, it will still be
574# enabled automagically on an X86 host.
575ifeq ($(ARCH), x86)
576 ENABLE_X86_JIT = 1
577endif
578
579# What the X86 JIT requires
580ifdef ENABLE_X86_JIT
581 JIT_LIBS += LLVMX86 LLVMSelectionDAG
582endif
583
584# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
585# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
586# enabled automagically on an SparcV9 host.
587ifeq ($(ARCH), Sparc)
588 ENABLE_SPARCV9_JIT = 1
589endif
590
591# What the Sparc JIT requires
592ifdef ENABLE_SPARCV9_JIT
593 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
John Criswell94b7bea2005-10-26 20:35:13 +0000594 LLVMSparcV9LiveVar LLVMInstrumentation.a \
Reid Spencera80f1672005-05-19 00:37:31 +0000595 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
John Criswell94b7bea2005-10-26 20:35:13 +0000596 LLVMDataStructure LLVMSparcV9RegAlloc
Reid Spencera80f1672005-05-19 00:37:31 +0000597endif
598
599# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
600# ENABLE_PPC_JIT on the make command line. If not, it will still be
601# enabled automagically on an PowerPC host.
602ifeq ($(ARCH), PowerPC)
603 ENABLE_PPC_JIT = 1
604endif
605
606# What the PowerPC JIT requires
607ifdef ENABLE_PPC_JIT
608 JIT_LIBS += LLVMPowerPC LLVMSelectionDAG
609endif
610
Andrew Lenharthc7fe0f52005-07-22 20:54:01 +0000611# You can enable the Alpha JIT on a non-Alpha host by setting the flag
612# ENABLE_ALPHA_JIT on the make command line. If not, it will still be
Misha Brukman08c36452005-07-22 22:43:40 +0000613# enabled automagically on an Alpha host.
Andrew Lenharthc7fe0f52005-07-22 20:54:01 +0000614ifeq ($(ARCH), Alpha)
615 ENABLE_ALPHA_JIT = 1
616endif
617
Andrew Lenharth99007012005-07-22 22:00:24 +0000618# What the Alpha JIT requires
Andrew Lenharthc7fe0f52005-07-22 20:54:01 +0000619ifdef ENABLE_ALPHA_JIT
620 JIT_LIBS += LLVMAlpha LLVMSelectionDAG
621endif
622
John Criswellfe5f33b2005-10-27 15:54:34 +0000623LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts.a LLVMTransformUtils.a LLVMAnalysis.a \
Reid Spencera80f1672005-05-19 00:37:31 +0000624 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
625 LLVMSystem.a $(PLATFORMLIBDL)
626endif
627
628#---------------------------------------------------------
629# Define various command line options pertaining to the
630# libraries needed when linking. There are "Proj" libs
631# (defined by the user's project) and "LLVM" libs (defined
632# by the # LLVM project).
633#---------------------------------------------------------
Misha Brukman5fbf58a2005-08-17 02:38:56 +0000634# Some versions of gcc on Alpha produce too many symbols, so use a .a file
Andrew Lenharth6b62b472005-08-13 05:09:50 +0000635ifeq ($(ARCH),Alpha)
636USEDLIBS := $(subst LLVMCore, LLVMCore.a, $(USEDLIBS))
637LLVMLIBS := $(subst LLVMCore, LLVMCore.a, $(LLVMLIBS))
638endif
639
Reid Spencera80f1672005-05-19 00:37:31 +0000640ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
641ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
642LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
643LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
644ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
645LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
646ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
647LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
648
649###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000650# Library Build Rules: Four ways to build a library
651###############################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000652
Reid Spencerd78077d2004-12-05 05:17:22 +0000653#---------------------------------------------------------
654# Bytecode Module Targets:
655# If the user set MODULE_NAME then they want to build a
656# bytecode module from the sources. We compile all the
657# sources and link it together into a single bytecode
658# module.
659#---------------------------------------------------------
660
661ifdef MODULE_NAME
Reid Spencere9fa5442005-02-14 21:54:08 +0000662ifeq ($(strip $(LLVMGCC)),)
Reid Spencer83745dd2005-05-13 18:32:54 +0000663$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +0000664else
Reid Spencerd78077d2004-12-05 05:17:22 +0000665
666Module := $(LibDir)/$(MODULE_NAME).bc
Reid Spencer2bba41c2004-12-22 05:57:21 +0000667LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
Reid Spencerd78077d2004-12-05 05:17:22 +0000668
669ifdef EXPORTED_SYMBOL_FILE
Reid Spencer3a468752005-01-28 19:52:32 +0000670LinkModule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencerd78077d2004-12-05 05:17:22 +0000671endif
672
673$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
Reid Spencer83745dd2005-05-13 18:32:54 +0000674 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencerd78077d2004-12-05 05:17:22 +0000675 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
676
677all-local:: $(Module)
678
679clean-local::
680ifneq ($(strip $(Module)),)
681 -$(Verb) $(RM) -f $(Module)
682endif
683
Reid Spencerefe3a822004-12-13 07:38:07 +0000684ifdef BYTECODE_DESTINATION
685ModuleDestDir := $(BYTECODE_DESTINATION)
686else
Reid Spencerba6a3db2005-01-16 02:20:54 +0000687ModuleDestDir := $(PROJ_libdir)
Reid Spencerefe3a822004-12-13 07:38:07 +0000688endif
Reid Spencerd78077d2004-12-05 05:17:22 +0000689
Reid Spencerefe3a822004-12-13 07:38:07 +0000690DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
691
692install-module:: $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +0000693install-local:: $(DestModule)
694
Reid Spencerefe3a822004-12-13 07:38:07 +0000695$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencerd78077d2004-12-05 05:17:22 +0000696 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencerd77a4c02005-02-24 21:30:37 +0000697 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +0000698
699uninstall-local::
700 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
701 -$(Verb) $(RM) -f $(DestModule)
702
703endif
Reid Spencere9fa5442005-02-14 21:54:08 +0000704endif
Brian Gaekeecc92bf2004-01-22 22:53:48 +0000705
Reid Spencer81cd0492004-10-23 20:04:14 +0000706# if we're building a library ...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000707ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000708
Chris Lattner0100eab2002-09-16 22:36:42 +0000709# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000710LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer87e645c2005-01-11 04:31:07 +0000711ifdef LOADABLE_MODULE
712LibName.LA := $(LibDir)/$(LIBRARYNAME).la
713else
Reid Spencerf88808a2004-10-30 09:19:36 +0000714LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
Reid Spencer87e645c2005-01-11 04:31:07 +0000715endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000716LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
717LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer32f7e422004-12-02 09:28:21 +0000718LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000719
Reid Spencer81cd0492004-10-23 20:04:14 +0000720#---------------------------------------------------------
721# Shared Library Targets:
722# If the user asked for a shared library to be built
723# with the SHARED_LIBRARY variable, then we provide
724# targets for building them.
725#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000726ifdef SHARED_LIBRARY
727
Reid Spencerf88808a2004-10-30 09:19:36 +0000728all-local:: $(LibName.LA)
Reid Spencerf206bd72004-10-22 21:01:56 +0000729
Reid Spencera80f1672005-05-19 00:37:31 +0000730ifdef LINK_LIBS_IN_SHARED
731$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
732 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
733 $(Verb) $(Link) -o $@ $(ObjectsLO) \
734 $(ProjLibsOptions) $(LLVMLibsOptions)
735 $(Verb) $(LTInstall) $@ $(LibDir)
736else
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000737$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000738 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf88808a2004-10-30 09:19:36 +0000739 $(Verb) $(Link) -o $@ $(ObjectsLO)
740 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencera80f1672005-05-19 00:37:31 +0000741endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000742
743clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000744ifneq ($(strip $(LibName.LA)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000745 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencer12a3a052004-10-24 07:53:21 +0000746endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000747
Reid Spencerba6a3db2005-01-16 02:20:54 +0000748DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf206bd72004-10-22 21:01:56 +0000749
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000750install-local:: $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000751
Reid Spencerba6a3db2005-01-16 02:20:54 +0000752$(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000753 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencerf88808a2004-10-30 09:19:36 +0000754 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +0000755 $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
Reid Spencer12a3a052004-10-24 07:53:21 +0000756
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000757uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000758 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +0000759 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
Reid Spencer12a3a052004-10-24 07:53:21 +0000760
Reid Spencerf206bd72004-10-22 21:01:56 +0000761endif
762
Reid Spencer81cd0492004-10-23 20:04:14 +0000763#---------------------------------------------------------
764# Bytecode Library Targets:
765# If the user asked for a bytecode library to be built
766# with the BYTECODE_LIBRARY variable, then we provide
767# targets for building them.
768#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000769ifdef BYTECODE_LIBRARY
Reid Spencere9fa5442005-02-14 21:54:08 +0000770ifeq ($(strip $(LLVMGCC)),)
Reid Spencer83745dd2005-05-13 18:32:54 +0000771$(warning Bytecode libraries require llvm-gcc which could not be found ****)
Reid Spencere9fa5442005-02-14 21:54:08 +0000772else
Reid Spencerf206bd72004-10-22 21:01:56 +0000773
Reid Spencer2b1b83a2004-12-03 06:04:35 +0000774# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer3f31cc42005-12-21 03:31:53 +0000775ifndef DEBUG_RUNTIME
Reid Spencer2b1b83a2004-12-03 06:04:35 +0000776BCCompile.C += -Wa,-strip-debug
777BCCompile.CXX += -Wa,-strip-debug
Reid Spencer3f31cc42005-12-21 03:31:53 +0000778endif
Reid Spencer2b1b83a2004-12-03 06:04:35 +0000779
Reid Spencer32f7e422004-12-02 09:28:21 +0000780all-local:: $(LibName.BCA)
781
782ifdef EXPORTED_SYMBOL_FILE
Reid Spencer2bba41c2004-12-22 05:57:21 +0000783BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
Reid Spencer32f7e422004-12-02 09:28:21 +0000784 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
785
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000786$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +0000787 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +0000788 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
789 "(internalize)"
Chris Lattnere3d98f12004-12-02 21:23:43 +0000790 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
Reid Spencer85d55ad2004-12-13 03:59:35 +0000791 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +0000792 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
Reid Spencerf206bd72004-10-22 21:01:56 +0000793else
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000794$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +0000795 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +0000796 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencer85d55ad2004-12-13 03:59:35 +0000797 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +0000798 $(Verb) $(LArchive) $@ $(ObjectsBC)
799
Reid Spencerf206bd72004-10-22 21:01:56 +0000800endif
801
Reid Spencer81cd0492004-10-23 20:04:14 +0000802clean-local::
Reid Spencer32f7e422004-12-02 09:28:21 +0000803ifneq ($(strip $(LibName.BCA)),)
804 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencer12a3a052004-10-24 07:53:21 +0000805endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000806
Reid Spencer65086be2004-12-13 07:28:21 +0000807ifdef BYTECODE_DESTINATION
808BytecodeDestDir := $(BYTECODE_DESTINATION)
809else
Reid Spencerba6a3db2005-01-16 02:20:54 +0000810BytecodeDestDir := $(PROJ_libdir)
Reid Spencer65086be2004-12-13 07:28:21 +0000811endif
812
813DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
Reid Spencer32f7e422004-12-02 09:28:21 +0000814
Reid Spencerd4bd3752004-12-03 20:08:48 +0000815install-bytecode-local:: $(DestBytecodeLib)
Reid Spencer8da1b5d2004-10-26 07:09:33 +0000816
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000817install-local:: $(DestBytecodeLib)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000818
Reid Spencer65086be2004-12-13 07:28:21 +0000819$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
Reid Spencer32f7e422004-12-02 09:28:21 +0000820 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerdcc53752005-02-24 21:36:32 +0000821 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000822
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000823uninstall-local::
Reid Spencer32f7e422004-12-02 09:28:21 +0000824 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000825 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencerf206bd72004-10-22 21:01:56 +0000826
827endif
Reid Spencere9fa5442005-02-14 21:54:08 +0000828endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000829
Reid Spencerf88808a2004-10-30 09:19:36 +0000830#---------------------------------------------------------
831# ReLinked Library Targets:
Chris Lattner1b91cbd2005-10-24 02:21:45 +0000832# If the user explicitly requests a relinked library with
833# BUILD_RELINKED, provide it. Otherwise, if they specify
834# neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
835# them one.
Reid Spencerf88808a2004-10-30 09:19:36 +0000836#---------------------------------------------------------
Chris Lattner1b91cbd2005-10-24 02:21:45 +0000837ifndef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +0000838ifndef DONT_BUILD_RELINKED
Chris Lattner1b91cbd2005-10-24 02:21:45 +0000839BUILD_RELINKED = 1
840endif
841endif
842
843ifdef BUILD_RELINKED
Reid Spencerf206bd72004-10-22 21:01:56 +0000844
Reid Spencerf88808a2004-10-30 09:19:36 +0000845all-local:: $(LibName.O)
846
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000847$(LibName.O): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000848 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencerf88808a2004-10-30 09:19:36 +0000849 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencerf206bd72004-10-22 21:01:56 +0000850
Reid Spencer81cd0492004-10-23 20:04:14 +0000851clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000852ifneq ($(strip $(LibName.O)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000853 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencer12a3a052004-10-24 07:53:21 +0000854endif
855
Reid Spencerba6a3db2005-01-16 02:20:54 +0000856DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
Reid Spencer12a3a052004-10-24 07:53:21 +0000857
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000858install-local:: $(DestRelinkedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000859
Reid Spencerba6a3db2005-01-16 02:20:54 +0000860$(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000861 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerf88808a2004-10-30 09:19:36 +0000862 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000863
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000864uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000865 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000866 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencerf206bd72004-10-22 21:01:56 +0000867
Chris Lattner76d98ba2002-07-23 17:56:16 +0000868endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000869
Reid Spencerf88808a2004-10-30 09:19:36 +0000870#---------------------------------------------------------
871# Archive Library Targets:
872# If the user wanted a regular archive library built,
873# then we provide targets for building them.
874#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +0000875ifdef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +0000876
Reid Spencerf88808a2004-10-30 09:19:36 +0000877all-local:: $(LibName.A)
878
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000879$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000880 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000881 -$(Verb) $(RM) -f $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000882 $(Verb) $(Archive) $@ $(ObjectsO)
883 $(Verb) $(Ranlib) $@
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000884
Reid Spencer81cd0492004-10-23 20:04:14 +0000885clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000886ifneq ($(strip $(LibName.A)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000887 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000888endif
889
Reid Spencerba6a3db2005-01-16 02:20:54 +0000890DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencer12a3a052004-10-24 07:53:21 +0000891
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000892install-local:: $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000893
Reid Spencerba6a3db2005-01-16 02:20:54 +0000894$(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000895 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +0000896 $(Verb) $(MKDIR) $(PROJ_libdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000897 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000898
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000899uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000900 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000901 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000902
903endif
904
905# endif LIBRARYNAME
Reid Spencerf206bd72004-10-22 21:01:56 +0000906endif
907
Reid Spencerdcba7782004-10-24 08:21:04 +0000908###############################################################################
909# Tool Build Rules: Build executable tool based on TOOLNAME option
910###############################################################################
911
Chris Lattner07c7c192001-09-07 22:57:58 +0000912ifdef TOOLNAME
913
Reid Spencerf88808a2004-10-30 09:19:36 +0000914#---------------------------------------------------------
915# Set up variables for building a tool.
916#---------------------------------------------------------
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000917ifdef EXAMPLE_TOOL
Reid Spencer98a2d982005-05-19 21:03:11 +0000918ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000919else
Reid Spencer98a2d982005-05-19 21:03:11 +0000920ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000921endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000922
Reid Spencerf88808a2004-10-30 09:19:36 +0000923#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000924# Tell make that we need to rebuild subdirectories before
925# we can link the tool. This affects things like LLI which
926# has library subdirectories.
927#---------------------------------------------------------
928$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner3ecb7762003-01-22 16:13:31 +0000929
Reid Spencerf88808a2004-10-30 09:19:36 +0000930#---------------------------------------------------------
931# Provide targets for building the tools
932#---------------------------------------------------------
933all-local:: $(ToolBuildPath)
John Criswell8224df92003-06-27 16:58:44 +0000934
Reid Spencer81cd0492004-10-23 20:04:14 +0000935clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000936ifneq ($(strip $(ToolBuildPath)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000937 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencer12a3a052004-10-24 07:53:21 +0000938endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000939
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000940ifdef EXAMPLE_TOOL
941$(ToolBuildPath): $(ExmplDir)/.dir
942else
943$(ToolBuildPath): $(ToolDir)/.dir
944endif
945
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000946$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000947 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencerf88808a2004-10-30 09:19:36 +0000948 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencere9fa5442005-02-14 21:54:08 +0000949 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000950 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencer12a3a052004-10-24 07:53:21 +0000951
Reid Spencerba6a3db2005-01-16 02:20:54 +0000952DestTool = $(PROJ_bindir)/$(TOOLNAME)
Reid Spencer12a3a052004-10-24 07:53:21 +0000953
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000954install-local:: $(DestTool)
Reid Spencer8da1b5d2004-10-26 07:09:33 +0000955
Reid Spencerba6a3db2005-01-16 02:20:54 +0000956$(DestTool): $(PROJ_bindir) $(ToolBuildPath)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000957 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencerc43b1d42005-02-24 03:56:32 +0000958 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +0000959
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000960uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000961 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000962 -$(Verb) $(RM) -f $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +0000963
Reid Spencerf206bd72004-10-22 21:01:56 +0000964endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000965
Reid Spencerf88808a2004-10-30 09:19:36 +0000966###############################################################################
967# Object Build Rules: Build object files based on sources
968###############################################################################
969
970# Provide rule sets for when dependency generation is enabled
Reid Spencerf206bd72004-10-22 21:01:56 +0000971ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000972
Reid Spencerf88808a2004-10-30 09:19:36 +0000973#---------------------------------------------------------
974# Create .lo files in the ObjDir directory from the .cpp and .c files...
975#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000976ifdef SHARED_LIBRARY
977
Chris Lattner2a023902004-12-16 17:28:50 +0000978$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000979 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000980 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
981 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
982 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +0000983
Chris Lattnerf60c1702005-02-04 21:28:50 +0000984$(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
985 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
986 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
987 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
988 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
989
Chris Lattner2a023902004-12-16 17:28:50 +0000990$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000991 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000992 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
993 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
994 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +0000995
Reid Spencerf88808a2004-10-30 09:19:36 +0000996#---------------------------------------------------------
997# Create .o files in the ObjDir directory from the .cpp and .c files...
998#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000999else
Reid Spencerf206bd72004-10-22 21:01:56 +00001000
Chris Lattner2a023902004-12-16 17:28:50 +00001001$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001002 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001003 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
1004 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
1005 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +00001006
Chris Lattnerf60c1702005-02-04 21:28:50 +00001007$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1008 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1009 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
1010 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
1011 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
1012
Chris Lattner2a023902004-12-16 17:28:50 +00001013$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001014 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001015 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
1016 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
1017 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +00001018
1019endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001020
Chris Lattnerbb087952005-10-05 00:28:41 +00001021## Rules for building preprocessed (.i/.ii) outputs.
1022$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1023 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1024 $(Verb) $(Preprocess.CXX) $< -o $@
1025
1026$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1027 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1028 $(Verb) $(Preprocess.CXX) $< -o $@
1029
1030 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1031 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1032 $(Verb) $(Preprocess.C) $< -o $@
1033
1034
Reid Spencerf88808a2004-10-30 09:19:36 +00001035#---------------------------------------------------------
Chris Lattnerf60c1702005-02-04 21:28:50 +00001036# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001037#---------------------------------------------------------
Chris Lattner2a023902004-12-16 17:28:50 +00001038$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001039 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencerf88808a2004-10-30 09:19:36 +00001040 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1041 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1042 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +00001043
Chris Lattnerf60c1702005-02-04 21:28:50 +00001044$(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1045 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1046 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
1047 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1048 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1049
Chris Lattner2a023902004-12-16 17:28:50 +00001050$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001051 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencerf88808a2004-10-30 09:19:36 +00001052 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
1053 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1054 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +00001055
Reid Spencerf88808a2004-10-30 09:19:36 +00001056# Provide alternate rule sets if dependencies are disabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001057else
1058
Reid Spencer81cd0492004-10-23 20:04:14 +00001059ifdef SHARED_LIBRARY
1060
Chris Lattner2a023902004-12-16 17:28:50 +00001061$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001062 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer81cd0492004-10-23 20:04:14 +00001063 $(LTCompile.CXX) $< -o $@
1064
Chris Lattnerf60c1702005-02-04 21:28:50 +00001065$(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1066 $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1067 $(LTCompile.CXX) $< -o $@
1068
Chris Lattner2a023902004-12-16 17:28:50 +00001069$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerafdc82c2004-12-16 18:26:53 +00001070 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencer81cd0492004-10-23 20:04:14 +00001071 $(LTCompile.C) $< -o $@
1072
1073else
Reid Spencerf206bd72004-10-22 21:01:56 +00001074
Chris Lattner2a023902004-12-16 17:28:50 +00001075$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001076 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer81cd0492004-10-23 20:04:14 +00001077 $(Compile.CXX) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +00001078
Chris Lattnerf60c1702005-02-04 21:28:50 +00001079$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1080 $(Echo) "Compiling $*.cc for $(BuildMode) build"
1081 $(Compile.CXX) $< -o $@
1082
Chris Lattner2a023902004-12-16 17:28:50 +00001083$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerafdc82c2004-12-16 18:26:53 +00001084 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencer81cd0492004-10-23 20:04:14 +00001085 $(Compile.C) $< -o $@
1086endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001087
Chris Lattner2a023902004-12-16 17:28:50 +00001088$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001089 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer991f66a2004-10-31 18:52:15 +00001090 $(BCCompile.CXX) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +00001091
Chris Lattnerf60c1702005-02-04 21:28:50 +00001092$(ObjDir)/%.bc: %.cc $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
1093 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1094 $(BCCompile.CXX) $< -o $@
1095
Chris Lattner2a023902004-12-16 17:28:50 +00001096$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001097 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer991f66a2004-10-31 18:52:15 +00001098 $(BCCompile.C) $< -o $@
Brian Gaeke0f148bc2003-12-10 00:26:28 +00001099
Chris Lattner07c7c192001-09-07 22:57:58 +00001100endif
1101
Reid Spencerf88808a2004-10-30 09:19:36 +00001102#---------------------------------------------------------
1103# Provide rule to build .bc files from .ll sources,
1104# regardless of dependencies
1105#---------------------------------------------------------
1106$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001107 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001108 $(Verb) $(LLVMAS) $< -f -o $@
1109
1110###############################################################################
1111# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1112###############################################################################
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001113
Reid Spencerf206bd72004-10-22 21:01:56 +00001114ifdef TARGET
1115
Chris Lattner95866d32005-10-14 06:31:58 +00001116TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td)
Reid Spencerf88808a2004-10-30 09:19:36 +00001117INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner2a023902004-12-16 17:28:50 +00001118INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1119.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001120
Chris Lattner2a023902004-12-16 17:28:50 +00001121# All of these files depend on tblgen and the .td files.
1122$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001123
Chris Lattnerf86914d2004-12-16 17:38:56 +00001124# INCFiles rule: All of the tblgen generated files are emitted to
1125# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1126# us to only "touch" the real file if the contents of it change. IOW, if
1127# tblgen is modified, all of the .inc.tmp files are regereated, but no
1128# dependencies of the .inc files are, unless the contents of the .inc file
1129# changes.
1130$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerafdc82c2004-12-16 18:26:53 +00001131 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner2a023902004-12-16 17:28:50 +00001132
1133$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1134$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001135 $(Echo) "Building $(<F) register names with tblgen"
1136 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001137
Chris Lattner2a023902004-12-16 17:28:50 +00001138$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1139$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001140 $(Echo) "Building $(<F) register information header with tblgen"
1141 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001142
Chris Lattner2a023902004-12-16 17:28:50 +00001143$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1144$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001145 $(Echo) "Building $(<F) register info implementation with tblgen"
1146 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001147
Chris Lattner2a023902004-12-16 17:28:50 +00001148$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1149$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001150 $(Echo) "Building $(<F) instruction names with tblgen"
1151 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001152
Chris Lattner2a023902004-12-16 17:28:50 +00001153$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1154$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001155 $(Echo) "Building $(<F) instruction information with tblgen"
1156 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001157
Chris Lattner2a023902004-12-16 17:28:50 +00001158$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1159$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001160 $(Echo) "Building $(<F) assembly writer with tblgen"
1161 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001162
Chris Lattner22f937a2004-12-16 17:34:04 +00001163$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1164$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1165 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Reid Spencerf88808a2004-10-30 09:19:36 +00001166 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001167
Chris Lattner2a023902004-12-16 17:28:50 +00001168$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1169$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001170 $(Echo) "Building $(<F) code emitter with tblgen"
1171 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001172
Chris Lattner33f98bd2005-09-03 01:15:25 +00001173$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1174$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1175 $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1176 $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1177
Jim Laskey9ed90322005-10-21 19:05:19 +00001178$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1179$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1180 $(Echo) "Building $(<F) subtarget information with tblgen"
1181 $(Verb) $(TableGen) -gen-subtarget -o $@ $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001182
Reid Spencer81cd0492004-10-23 20:04:14 +00001183clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001184 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001185
1186endif
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001187
Reid Spencerf88808a2004-10-30 09:19:36 +00001188###############################################################################
1189# LEX AND YACC: Provide rules for generating sources with lex and yacc
1190###############################################################################
Chris Lattnerdb644dd2003-01-16 22:44:19 +00001191
Reid Spencerf88808a2004-10-30 09:19:36 +00001192#---------------------------------------------------------
1193# Provide rules for generating a .cpp source file from
1194# (f)lex input sources.
1195#---------------------------------------------------------
1196
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001197LexFiles := $(filter %.l,$(Sources))
Reid Spencerf88808a2004-10-30 09:19:36 +00001198
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001199ifneq ($(LexFiles),)
1200
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001201# Cancel built-in rules for lex
1202%.c: %.l
1203%.cpp: %.l
Reid Spencerf88808a2004-10-30 09:19:36 +00001204
1205# Note the extra sed filtering here, used to cut down on the warnings emited
1206# by GCC. The last line is a gross hack to work around flex aparently not
1207# being able to resize the buffer on a large token input. Currently, for
1208# uninitialized string buffers in LLVM we can generate very long tokens, so
1209# this is a hack around it.
Chris Lattner92fc9b02003-08-15 20:00:47 +00001210# FIXME. (f.e. char Buffer[10000] )
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001211$(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
Reid Spencer993b95e2004-12-10 19:44:16 +00001212 $(Echo) Flexing $*.l
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001213 $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
Reid Spencerf206bd72004-10-22 21:01:56 +00001214 $(SED) 's/void yyunput/inline void yyunput/' | \
1215 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1216 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001217 > $(PROJ_SRC_DIR)/$*.cpp
1218 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp (generated file)"
1219
1220LexObjs := $(patsubst %.l,$(ObjDir)/%.o,$(LexFiles))
1221$(LexObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
Chris Lattner2f7c9632001-06-06 20:29:01 +00001222
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001223clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001224 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001225
Reid Spencerf88808a2004-10-30 09:19:36 +00001226endif
1227
1228#---------------------------------------------------------
1229# Provide rules for generating a .cpp and .h source files
1230# from yacc (bison) input sources.
1231#---------------------------------------------------------
1232
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001233YaccFiles := $(filter %.y,$(Sources))
1234ifneq ($(YaccFiles),)
Reid Spencerf88808a2004-10-30 09:19:36 +00001235
1236.PRECIOUS: $(YaccOutput)
1237
1238# Cancel built-in rules for yacc
1239%.c: %.y
1240%.cpp: %.y
1241%.h: %.y
1242
Reid Spencerc49a8632005-12-21 23:17:06 +00001243# Rule for building the bison based parsers...
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001244$(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
Reid Spencerf88808a2004-10-30 09:19:36 +00001245 $(Echo) "Bisoning $*.y"
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001246 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1247 $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1248 $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1249 $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp and $*.h (generated files)"
Chris Lattner2f7c9632001-06-06 20:29:01 +00001250
Reid Spencerc49a8632005-12-21 23:17:06 +00001251YaccObjs := $(patsubst %.y,$(ObjDir)/%.o,$(YaccFiles))
1252$(YaccObjs): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1253
1254YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.output)
1255
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001256clean-local::
Reid Spencerc49a8632005-12-21 23:17:06 +00001257 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencerf88808a2004-10-30 09:19:36 +00001258endif
Chris Lattner2f7c9632001-06-06 20:29:01 +00001259
Reid Spencerf88808a2004-10-30 09:19:36 +00001260###############################################################################
1261# OTHER RULES: Other rules needed
1262###############################################################################
Reid Spencerf206bd72004-10-22 21:01:56 +00001263
Chris Lattner23d47392003-01-16 21:06:18 +00001264# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +00001265ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +00001266%.ps: %.dot
Reid Spencerf206bd72004-10-22 21:01:56 +00001267 $(DOT) -Tps < $< > $@
John Criswell3ef61af2003-06-30 21:59:07 +00001268else
1269%.ps: %.dot
Reid Spencerf88808a2004-10-30 09:19:36 +00001270 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell3ef61af2003-06-30 21:59:07 +00001271endif
Chris Lattner23d47392003-01-16 21:06:18 +00001272
John Criswell0a6e6aa2003-09-06 14:44:17 +00001273# This rules ensures that header files that are removed still have a rule for
1274# which they can be "generated." This allows make to ignore them and
1275# reproduce the dependency lists.
John Criswella8391af2003-09-18 18:37:08 +00001276%.h:: ;
Chris Lattnerf60c1702005-02-04 21:28:50 +00001277%.hpp:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +00001278
Reid Spencerf88808a2004-10-30 09:19:36 +00001279# Define clean-local to clean the current directory. Note that this uses a
1280# very conservative approach ensuring that empty variables do not cause
1281# errors or disastrous removal.
Reid Spencer81cd0492004-10-23 20:04:14 +00001282clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001283ifneq ($(strip $(ObjDir)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001284 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencer12a3a052004-10-24 07:53:21 +00001285endif
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001286 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke8625f682004-01-21 19:53:11 +00001287ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001288 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke8625f682004-01-21 19:53:11 +00001289endif
John Criswell3ef61af2003-06-30 21:59:07 +00001290
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001291clean-all-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001292 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001293
Reid Spencerf88808a2004-10-30 09:19:36 +00001294# Build tags database for Emacs/Xemacs:
Reid Spenceraee67e62004-11-12 02:27:36 +00001295tags:: TAGS CTAGS
1296
Reid Spencerf88808a2004-10-30 09:19:36 +00001297TAGS:
Reid Spencerba6a3db2005-01-16 02:20:54 +00001298 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1299 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1300 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1301 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
Reid Spenceraee67e62004-11-12 02:27:36 +00001302 -name '*.cpp' -o -name '*.h' | \
Reid Spencerf88808a2004-10-30 09:19:36 +00001303 $(ETAGS) $(ETAGSFLAGS) -
1304
Reid Spenceraee67e62004-11-12 02:27:36 +00001305CTAGS:
Reid Spencerba6a3db2005-01-16 02:20:54 +00001306 find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1307 $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1308 $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1309 $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
Reid Spenceraee67e62004-11-12 02:27:36 +00001310 \( -name '*.cpp' -o -name '*.h' \) -print | \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001311 ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
Reid Spenceraee67e62004-11-12 02:27:36 +00001312
1313
Reid Spencer81cd0492004-10-23 20:04:14 +00001314###############################################################################
1315# DEPENDENCIES: Include the dependency files if we should
1316###############################################################################
Chris Lattnere9d7d702003-08-22 14:10:16 +00001317ifndef DISABLE_AUTO_DEPENDENCIES
1318
Reid Spencer81cd0492004-10-23 20:04:14 +00001319# If its not one of the cleaning targets
Reid Spencerf88808a2004-10-30 09:19:36 +00001320ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencerf206bd72004-10-22 21:01:56 +00001321
Reid Spencer81cd0492004-10-23 20:04:14 +00001322# Get the list of dependency files
Reid Spencerf88808a2004-10-30 09:19:36 +00001323DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencerba6a3db2005-01-16 02:20:54 +00001324DependFiles := $(patsubst %,$(PROJ_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukmanb891ffb2003-11-09 21:36:19 +00001325
Reid Spencer81cd0492004-10-23 20:04:14 +00001326-include /dev/null $(DependFiles)
1327
John Criswell48ecca62003-08-12 18:51:51 +00001328endif
Chris Lattner598222b2003-08-18 17:27:40 +00001329
Reid Spencerf88808a2004-10-30 09:19:36 +00001330endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001331
Reid Spencer100080c2004-10-25 08:27:37 +00001332###############################################################################
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001333# CHECK: Running the test suite
1334###############################################################################
1335
1336check::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001337 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1338 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001339 $(EchoCmd) Running test suite ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001340 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001341 TESTSUITE=$(TESTSUITE) ; \
1342 else \
1343 $(EchoCmd) No Makefile in test directory ; \
1344 fi ; \
1345 else \
1346 $(EchoCmd) No test directory ; \
1347 fi
1348
1349###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001350# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer100080c2004-10-25 08:27:37 +00001351###############################################################################
1352
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001353#------------------------------------------------------------------------
1354# Define distribution related variables
1355#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001356DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1357DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1358TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1359DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1360DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1361DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer100080c2004-10-25 08:27:37 +00001362DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1363 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001364 Makefile.config.in configure autoconf
1365DistOther := $(notdir $(wildcard \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001366 $(PROJ_SRC_DIR)/*.h \
1367 $(PROJ_SRC_DIR)/*.td \
1368 $(PROJ_SRC_DIR)/*.def \
1369 $(PROJ_SRC_DIR)/*.ll \
1370 $(PROJ_SRC_DIR)/*.in))
Reid Spencerf88808a2004-10-30 09:19:36 +00001371DistSubDirs := $(SubDirs)
Reid Spencerfc66af42004-11-29 05:00:33 +00001372DistSources = $(Sources) $(EXTRA_DIST)
1373DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer100080c2004-10-25 08:27:37 +00001374
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001375#------------------------------------------------------------------------
1376# We MUST build distribution with OBJ_DIR != SRC_DIR
1377#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001378ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001379dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001380 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001381
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001382else
1383
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001384#------------------------------------------------------------------------
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001385# Prevent attempt to run dist targets from anywhere but the top level
1386#------------------------------------------------------------------------
1387ifneq ($(LEVEL),.)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001388dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001389 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001390else
1391
1392#------------------------------------------------------------------------
1393# Provide the top level targets
1394#------------------------------------------------------------------------
1395
Reid Spencerf88808a2004-10-30 09:19:36 +00001396dist-gzip:: $(DistTarGZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001397
Reid Spencer81546582004-12-04 22:34:09 +00001398$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001399 $(Echo) Packing gzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001400 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001401 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001402
Reid Spencerf88808a2004-10-30 09:19:36 +00001403dist-bzip2:: $(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001404
Reid Spencer81546582004-12-04 22:34:09 +00001405$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001406 $(Echo) Packing bzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001407 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001408 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001409
Reid Spencerf88808a2004-10-30 09:19:36 +00001410dist-zip:: $(DistZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001411
Reid Spencer81546582004-12-04 22:34:09 +00001412$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001413 $(Echo) Packing zipped distribution file.
1414 $(Verb) rm -f $(DistZip)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001415 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001416
1417dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001418 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001419
Reid Spencer3a468752005-01-28 19:52:32 +00001420DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001421
Reid Spencer81546582004-12-04 22:34:09 +00001422dist-check:: $(DistTarGZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001423 $(Echo) Checking distribution tar file.
1424 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001425 $(RM) -rf $(DistCheckDir) ; \
1426 fi
Reid Spencerf88808a2004-10-30 09:19:36 +00001427 $(Verb) $(MKDIR) $(DistCheckDir)
1428 $(Verb) cd $(DistCheckDir) && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001429 $(MKDIR) $(DistCheckDir)/build && \
1430 $(MKDIR) $(DistCheckDir)/install && \
1431 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1432 cd build && \
1433 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer13f51932005-05-24 02:33:20 +00001434 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer81546582004-12-04 22:34:09 +00001435 $(MAKE) all && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001436 $(MAKE) check && \
1437 $(MAKE) install && \
1438 $(MAKE) uninstall && \
1439 $(MAKE) dist && \
1440 $(MAKE) clean && \
1441 $(MAKE) dist-clean && \
Reid Spencerf88808a2004-10-30 09:19:36 +00001442 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001443
1444dist-clean::
Reid Spencerf88808a2004-10-30 09:19:36 +00001445 $(Echo) Cleaning distribution files
Reid Spencer81546582004-12-04 22:34:09 +00001446 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1447 $(DistCheckDir)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001448
1449endif
1450
1451#------------------------------------------------------------------------
1452# Provide the recursive distdir target for building the distribution directory
1453#------------------------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +00001454distdir: $(DistDir)/.makedistdir
1455$(DistDir)/.makedistdir: $(DistSources)
Reid Spencerf88808a2004-10-30 09:19:36 +00001456 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001457 if test -d "$(DistDir)" ; then \
1458 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1459 exit 1 ; \
1460 fi ; \
Reid Spencer81546582004-12-04 22:34:09 +00001461 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001462 $(RM) -rf $(DistDir); \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001463 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer81546582004-12-04 22:34:09 +00001464 $(MAKE) all ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001465 fi
Reid Spencerfc66af42004-11-29 05:00:33 +00001466 $(Echo) Building Distribution Directory $(DistDir)
Reid Spencerf88808a2004-10-30 09:19:36 +00001467 $(Verb) $(MKDIR) $(DistDir)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001468 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1469 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer100080c2004-10-25 08:27:37 +00001470 for file in $(DistFiles) ; do \
1471 case "$$file" in \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001472 $(PROJ_SRC_DIR)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001473 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1474 ;; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001475 $(PROJ_SRC_ROOT)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001476 file=`echo "$$file" | \
1477 sed "s#^$$srcrootstrip/##"` \
1478 ;; \
Reid Spencer100080c2004-10-25 08:27:37 +00001479 esac; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001480 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1481 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1482 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer81546582004-12-04 22:34:09 +00001483 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001484 from_dir=. ; \
Reid Spencer81546582004-12-04 22:34:09 +00001485 fi ; \
1486 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001487 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1488 to_dir="$(DistDir)/$$dir"; \
1489 $(MKDIR) "$$to_dir" ; \
1490 else \
1491 to_dir="$(DistDir)"; \
1492 fi; \
1493 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1494 if test -n "$$mid_dir" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001495 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001496 fi ; \
1497 if test -d "$$from_dir/$$file"; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001498 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1499 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001500 cd $(PROJ_SRC_DIR) ; \
1501 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1502 ( cd $$to_dir ; $(TAR) xf - ) ; \
1503 cd $(PROJ_OBJ_DIR) ; \
1504 else \
1505 cd $$from_dir ; \
1506 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1507 ( cd $$to_dir ; $(TAR) xf - ) ; \
1508 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001509 fi; \
Reid Spencer100080c2004-10-25 08:27:37 +00001510 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001511 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001512 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001513 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001514 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer81546582004-12-04 22:34:09 +00001515 $(EchoCmd) "===== WARNING: Distribution Source " \
1516 "$$from_dir/$$file Not Found!" ; \
Reid Spencerf88808a2004-10-30 09:19:36 +00001517 elif test "$(Verb)" != '@' ; then \
1518 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001519 fi; \
1520 done
Reid Spencerf88808a2004-10-30 09:19:36 +00001521 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer100080c2004-10-25 08:27:37 +00001522 if test "$$subdir" \!= "." ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001523 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001524 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer81546582004-12-04 22:34:09 +00001525 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1526 exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001527 fi; \
1528 done
Reid Spencer81546582004-12-04 22:34:09 +00001529 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001530 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1531 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o -name .svn \) -print` ;\
Reid Spencer81546582004-12-04 22:34:09 +00001532 $(MAKE) dist-hook ; \
1533 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1534 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1535 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1536 -o ! -type d ! -perm -444 -exec \
1537 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1538 || chmod -R a+r $(DistDir) ; \
1539 fi
Reid Spencer100080c2004-10-25 08:27:37 +00001540
Reid Spencerf88808a2004-10-30 09:19:36 +00001541# This is invoked by distdir target, define it as a no-op to avoid errors if not
1542# defined by user.
Reid Spencer100080c2004-10-25 08:27:37 +00001543dist-hook::
1544
Reid Spencer23a70372004-10-22 23:06:30 +00001545endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001546
1547###############################################################################
Reid Spencer12a3a052004-10-24 07:53:21 +00001548# TOP LEVEL - targets only to apply at the top level directory
1549###############################################################################
1550
1551ifeq ($(LEVEL),.)
1552
1553#------------------------------------------------------------------------
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001554# Install support for the project's include files:
Reid Spencer12a3a052004-10-24 07:53:21 +00001555#------------------------------------------------------------------------
1556install-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001557 $(Echo) Installing include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001558 $(Verb) $(MKDIR) $(PROJ_includedir)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001559 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001560 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer48a82f42005-02-16 15:54:03 +00001561 for hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1562 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001563 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1564 if test \! -d "$$instdir" ; then \
1565 $(EchoCmd) Making install directory $$instdir ; \
1566 $(MKDIR) $$instdir ;\
1567 fi ; \
1568 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001569 done ; \
Reid Spencer12a3a052004-10-24 07:53:21 +00001570 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001571ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerc43b1d42005-02-24 03:56:32 +00001572 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer48a82f42005-02-16 15:54:03 +00001573 cd $(PROJ_OBJ_ROOT)/include && \
Reid Spencer528c9802005-12-23 22:27:56 +00001574 for hdr in `find . -type f -print | grep -v CVS` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001575 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001576 done ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001577 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001578endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001579
1580uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001581 $(Echo) Uninstalling include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001582 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1583 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer12a3a052004-10-24 07:53:21 +00001584 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001585 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' -o -name '*.in' ')' \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001586 -print ')' | grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001587 cd $(PROJ_SRC_ROOT)/include && \
1588 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' -print ')' \
1589 | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1590 fi
Reid Spencer12a3a052004-10-24 07:53:21 +00001591
Reid Spencer12a3a052004-10-24 07:53:21 +00001592endif
1593
Reid Spencerf206bd72004-10-22 21:01:56 +00001594#------------------------------------------------------------------------
1595# Print out the directories used for building
Reid Spencerf88808a2004-10-30 09:19:36 +00001596#------------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001597printvars::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001598 $(Echo) "BuildMode : " '$(BuildMode)'
1599 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1600 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1601 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1602 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1603 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1604 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1605 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1606 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1607 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1608 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencerfe0a01e2005-02-16 16:13:02 +00001609 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00001610 $(Echo) "UserTargets : " '$(UserTargets)'
1611 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1612 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1613 $(Echo) "ObjDir : " '$(ObjDir)'
1614 $(Echo) "LibDir : " '$(LibDir)'
1615 $(Echo) "ToolDir : " '$(ToolDir)'
1616 $(Echo) "ExmplDir : " '$(ExmplDir)'
1617 $(Echo) "Sources : " '$(Sources)'
1618 $(Echo) "TDFiles : " '$(TDFiles)'
1619 $(Echo) "INCFiles : " '$(INCFiles)'
1620 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencerfefb9ea2005-03-01 16:27:06 +00001621 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00001622 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1623 $(Echo) "Compile.C : " '$(Compile.C)'
1624 $(Echo) "Archive : " '$(Archive)'
1625 $(Echo) "YaccFiles : " '$(YaccFiles)'
1626 $(Echo) "LexFiles : " '$(LexFiles)'
1627 $(Echo) "Module : " '$(Module)'
Reid Spencerb48e3f82005-08-24 10:43:10 +00001628 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'