blob: 65790880be536c24cc1dbcba94b4201f7fbafc97 [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#--------------------------------------------------------------------
38VPATH=$(BUILD_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:
Reid Spencerf88808a2004-10-30 09:19:36 +000044.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
45.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid 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 Spencer91234ff2004-11-17 19:08:44 +000064 $(wildcard $(BUILD_SRC_DIR)/Makefile*))
Reid Spencerf88808a2004-10-30 09:19:36 +000065ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
Reid Spencerc4f0c732004-12-27 08:50:27 +000066ConfigureScript := $(BUILD_SRC_ROOT)/configure
67ConfigStatusScript := $(BUILD_OBJ_ROOT)/config.status
68LConfigStatusScript:= $(LLVM_OBJ_ROOT)/config.status
Reid Spencerf88808a2004-10-30 09:19:36 +000069MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
70MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
71PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
Reid Spencer77a46d22004-10-26 22:26:33 +000072
Reid Spencerf88808a2004-10-30 09:19:36 +000073preconditions : $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +000074
75#------------------------------------------------------------------------
76# Make sure the BUILT_SOURCES are built first
77#------------------------------------------------------------------------
Reid Spencer97e40f12004-12-16 07:15:16 +000078$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000079
80clean-local::
81ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +000082 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000083endif
84
Reid Spencer55814372004-12-16 08:00:46 +000085ifneq ($(BUILD_OBJ_ROOT),$(BUILD_SRC_ROOT))
86spotless:
Reid Spencer55814372004-12-16 08:00:46 +000087 $(Verb) if test -x config.status ; then \
Reid Spencer7ef8e662004-12-17 07:45:03 +000088 $(EchoCmd) Wiping out $(BUILD_OBJ_ROOT) ; \
89 $(MKDIR) .spotless.save ; \
90 $(MV) config.status .spotless.save ; \
91 $(MV) mklib .spotless.save ; \
92 $(MV) projects .spotless.save ; \
Reid Spencer55814372004-12-16 08:00:46 +000093 $(RM) -rf * ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +000094 $(MV) .spotless.save/config.status . ; \
95 $(MV) .spotless.save/mklib . ; \
96 $(MV) .spotless.save/projects . ; \
97 $(RM) -rf .spotless.save ; \
98 $(EchoCmd) Rebuilding configuration of $(BUILD_OBJ_ROOT) ; \
99 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
100 $(ConfigStatusScript) ; \
Reid Spencer55814372004-12-16 08:00:46 +0000101 else \
102 $(EchoCmd) "make spotless" can only be run from $(BUILD_OBJ_ROOT); \
103 fi
104endif
105
Reid Spencerf88808a2004-10-30 09:19:36 +0000106$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencerb7f710a2004-10-28 00:41:43 +0000107
Reid Spencer77a46d22004-10-26 22:26:33 +0000108#------------------------------------------------------------------------
109# Make sure we're not using a stale configuration
110#------------------------------------------------------------------------
Reid Spencerafdc82c2004-12-16 18:26:53 +0000111reconfigure:
112 $(Echo) Reconfiguring $(BUILD_OBJ_ROOT)
113 $(Verb) cd $(BUILD_OBJ_ROOT) && \
Reid Spencer35655d62004-12-24 03:36:31 +0000114 if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
115 $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
116 fi ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000117 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
118 $(ConfigStatusScript)
119
Reid Spencerf88808a2004-10-30 09:19:36 +0000120.PRECIOUS: $(ConfigStatusScript)
121$(ConfigStatusScript): $(ConfigureScript)
122 $(Echo) Reconfiguring with $<
Reid Spencer50f34872004-11-29 12:37:44 +0000123 $(Verb) cd $(BUILD_OBJ_ROOT) && \
Reid Spencer35655d62004-12-24 03:36:31 +0000124 if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
125 $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
126 fi ; \
Reid Spencer50f34872004-11-29 12:37:44 +0000127 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
128 $(ConfigStatusScript)
Reid Spencer77a46d22004-10-26 22:26:33 +0000129
130#------------------------------------------------------------------------
131# Make sure the configuration makefile is up to date
132#------------------------------------------------------------------------
Reid Spencerc4f0c732004-12-27 08:50:27 +0000133$(MakefileConfig): $(MakefileConfigIn) $(LConfigStatusScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000134 $(Echo) Regenerating $@
Reid Spencerc4f0c732004-12-27 08:50:27 +0000135 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(LConfigStatusScript) Makefile.config
Reid Spencer77a46d22004-10-26 22:26:33 +0000136
137#------------------------------------------------------------------------
138# If the Makefile in the source tree has been updated, copy it over into the
139# build tree. But, only do this if the source and object makefiles differ
140#------------------------------------------------------------------------
141ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
142
Reid Spencer91234ff2004-11-17 19:08:44 +0000143Makefile: $(BUILD_SRC_DIR)/Makefile
Reid Spencerf88808a2004-10-30 09:19:36 +0000144 $(Echo) "Updating Makefile"
145 $(Verb) $(MKDIR) $(@D)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000146 $(Verb) $(CP) -f $< $@
Reid Spencer77a46d22004-10-26 22:26:33 +0000147
148# Copy the Makefile.* files unless we're in the root directory which avoids
149# the copying of Makefile.config.in or other things that should be explicitly
150# taken care of.
Reid Spencer77a46d22004-10-26 22:26:33 +0000151$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
Reid Spencerd94bb332004-10-26 23:10:00 +0000152 @case '$?' in \
153 *Makefile.rules) ;; \
154 *.in) ;; \
Reid Spencerf88808a2004-10-30 09:19:36 +0000155 *) $(Echo) "Updating $(@F)" ; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000156 $(MKDIR) $(@D) ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000157 $(CP) -f $< $@ ;; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000158 esac
159
Reid Spencer77a46d22004-10-26 22:26:33 +0000160endif
161
162#------------------------------------------------------------------------
163# Set up the basic dependencies
164#------------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000165$(UserTargets):: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +0000166
167all:: all-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000168clean:: clean-local
Reid Spencer9d0c1e02004-11-02 16:36:03 +0000169clean-all:: clean-local clean-all-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000170install:: install-local
171uninstall:: uninstall-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000172install-local:: all-local
Reid Spencerd4bd3752004-12-03 20:08:48 +0000173install-bytecode:: install-bytecode-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000174
175###############################################################################
176# VARIABLES: Set up various variables based on configuration data
177###############################################################################
178
179#--------------------------------------------------------------------
180# Variables derived from configuration we are building
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181#--------------------------------------------------------------------
182
Reid Spencer34982d82005-01-02 17:43:20 +0000183
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000184ifdef ENABLE_PROFILING
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000185 BuildMode := Profile
Reid Spencercd7d6cf2004-12-08 04:34:51 +0000186 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
Reid Spencerf88808a2004-10-30 09:19:36 +0000187 C.Flags := -O3 -DNDEBUG -pg
188 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000189else
190 ifdef ENABLE_OPTIMIZED
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000191 BuildMode := Release
Reid Spencer34982d82005-01-02 17:43:20 +0000192 # Don't use -fomit-frame-pointer on FreeBSD
193 ifneq ($(OS),FreeBSD)
194 OmitFramePointer := -fomit-frame-pointer
195 endif
196 CXX.Flags := -O3 -DNDEBUG -finline-functions -felide-constructors \
197 $(OmitFramePointer)
198 C.Flags := -O3 -DNDEBUG $(OmitFramePointer)
Reid Spencerf88808a2004-10-30 09:19:36 +0000199 LD.Flags := -O3 -DNDEBUG
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000200 else
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000201 BuildMode := Debug
Reid Spencercd7d6cf2004-12-08 04:34:51 +0000202 CXX.Flags := -g -D_DEBUG
Reid Spencerf88808a2004-10-30 09:19:36 +0000203 C.Flags := -g -D_DEBUG
204 LD.Flags := -g -D_DEBUG
Reid Spencerf206bd72004-10-22 21:01:56 +0000205 KEEP_SYMBOLS := 1
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000206 endif
207endif
208
Reid Spencerf88808a2004-10-30 09:19:36 +0000209CXX.Flags += $(CXXFLAGS)
210C.Flags += $(CFLAGS)
211CPP.Flags += $(CPPFLAGS)
212LD.Flags += $(LDFLAGS)
213AR.Flags := cru
214LibTool.Flags := --tag=CXX
Reid Spencer81cd0492004-10-23 20:04:14 +0000215
216#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000217# Directory locations
Reid Spencer81cd0492004-10-23 20:04:14 +0000218#--------------------------------------------------------------------
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000219ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000220LibDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer0dbf1012004-11-18 20:04:39 +0000221ToolDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000222ExmplDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
223LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer0dbf1012004-11-18 20:04:39 +0000224LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencerb9f8de62004-12-28 07:59:22 +0000225LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer2bba41c2004-12-22 05:57:21 +0000226CFERuntimeLibDir := $(LLVMGCCDIR)/lib
John Criswell3ef61af2003-06-30 21:59:07 +0000227
Reid Spencer81cd0492004-10-23 20:04:14 +0000228#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000229# Full Paths To Compiled Tools and Utilities
Reid Spencer81cd0492004-10-23 20:04:14 +0000230#--------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000231EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
232Echo := @$(EchoCmd)
233ifndef LIBTOOL
Reid Spencerf206bd72004-10-22 21:01:56 +0000234LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencerf88808a2004-10-30 09:19:36 +0000235endif
236ifndef LLVMAS
237LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
238endif
239ifndef BURG
240BURG := $(LLVMToolDir)/burg$(EXEEXT)
241endif
242ifndef TBLGEN
243TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
244endif
Chris Lattner0ea40c92004-11-29 19:47:58 +0000245ifndef GCCAS
246GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
247endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000248ifndef GCCLD
249GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
250endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000251ifndef LDIS
252LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
253endif
254ifndef LLI
255LLI := $(LLVMToolDir)/lli$(EXEEXT)
256endif
257ifndef LOPT
Alkis Evlogimenos7c7705d2004-12-13 18:08:29 +0000258LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000259endif
John Criswelldc665012005-01-03 17:42:57 +0000260LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
261LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000262
Reid Spencer81cd0492004-10-23 20:04:14 +0000263#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000264# Adjust to user's request
Reid Spencer81cd0492004-10-23 20:04:14 +0000265#--------------------------------------------------------------------
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000266
Reid Spencerf88808a2004-10-30 09:19:36 +0000267# Adjust LIBTOOL flags for shared libraries, or not.
John Criswell3601f372003-07-31 20:58:51 +0000268ifndef SHARED_LIBRARY
Reid Spencerf88808a2004-10-30 09:19:36 +0000269 LibTool.Flags += --tag=disable-shared
Reid Spencerf206bd72004-10-22 21:01:56 +0000270else
Reid Spencerf88808a2004-10-30 09:19:36 +0000271 LD.Flags += -rpath $(LibDir)
John Criswell3601f372003-07-31 20:58:51 +0000272endif
273
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000274ifdef TOOL_VERBOSE
275 C.Flags += -v
276 CXX.Flags += -v
277 LD.Flags += -v
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000278 VERBOSE := 1
279endif
280
Reid Spencer81cd0492004-10-23 20:04:14 +0000281# Adjust settings for verbose mode
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000282ifndef VERBOSE
Reid Spencerf88808a2004-10-30 09:19:36 +0000283 Verb := @
284 LibTool.Flags += --silent
285 AR.Flags += >/dev/null 2>/dev/null
286 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
Reid Spencer100080c2004-10-25 08:27:37 +0000287else
Reid Spencerf88808a2004-10-30 09:19:36 +0000288 ConfigureScriptFLAGS :=
Misha Brukman1326a7c2002-09-12 16:05:39 +0000289endif
290
Vikram S. Adved141c282002-09-18 11:55:13 +0000291# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000292ifndef KEEP_SYMBOLS
Reid Spencerf88808a2004-10-30 09:19:36 +0000293 Strip := $(PLATFORMSTRIPOPTS)
294 StripWarnMsg := "(without symbols)"
Vikram S. Adved141c282002-09-18 11:55:13 +0000295endif
296
Reid Spencer81cd0492004-10-23 20:04:14 +0000297# Adjust linker flags for building an executable
Reid Spencerf206bd72004-10-22 21:01:56 +0000298ifdef TOOLNAME
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000299ifdef EXAMPLE_TOOL
300 LD.Flags += -rpath $(ExmplDir) -export-dynamic
301else
Reid Spencerf88808a2004-10-30 09:19:36 +0000302 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000303endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000304endif
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000305
Reid Spencer81cd0492004-10-23 20:04:14 +0000306#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000307# Options To Invoke Tools
Reid Spencer81cd0492004-10-23 20:04:14 +0000308#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000309
310CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
311
Reid Spencerf88808a2004-10-30 09:19:36 +0000312LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
313CPP.Flags += -I$(BUILD_OBJ_DIR) \
Reid Spencer100080c2004-10-25 08:27:37 +0000314 -I$(BUILD_SRC_DIR) \
315 -I$(BUILD_SRC_ROOT)/include \
316 -I$(BUILD_OBJ_ROOT)/include \
317 -I$(LLVM_OBJ_ROOT)/include \
318 -I$(LLVM_SRC_ROOT)/include \
319 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencerf206bd72004-10-22 21:01:56 +0000320
Reid Spencerf88808a2004-10-30 09:19:36 +0000321Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
322LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
Reid Spencer2bba41c2004-12-22 05:57:21 +0000323BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
324 $(C.Flags) -c
Reid Spencerf88808a2004-10-30 09:19:36 +0000325Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
326LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
Reid Spencerc005fba2004-12-24 14:47:34 +0000327BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
328 $(CXX.Flags) -c
Reid Spencerf88808a2004-10-30 09:19:36 +0000329Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
330 $(CompileCommonOpts) $(LD.Flags) $(Strip)
331Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000332 $(CompileCommonOpts)
Reid Spencerf88808a2004-10-30 09:19:36 +0000333LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
Reid Spencer81cd0492004-10-23 20:04:14 +0000334Burg = $(BURG) -I $(BUILD_SRC_DIR)
335TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
Reid Spencerf88808a2004-10-30 09:19:36 +0000336Archive = $(AR) $(AR.Flags)
Reid Spencer32f7e422004-12-02 09:28:21 +0000337LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencerf206bd72004-10-22 21:01:56 +0000338ifdef RANLIB
Reid Spencer81cd0492004-10-23 20:04:14 +0000339Ranlib = $(RANLIB)
Reid Spencerf206bd72004-10-22 21:01:56 +0000340else
Reid Spencer81cd0492004-10-23 20:04:14 +0000341Ranlib = ranlib
John Criswell3ef61af2003-06-30 21:59:07 +0000342endif
343
Chris Lattner2f7c9632001-06-06 20:29:01 +0000344#----------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +0000345# Get the list of source files and compute object file
346# names from them.
Reid Spencer81cd0492004-10-23 20:04:14 +0000347#----------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +0000348ifdef FAKE_SOURCES
349 Sources :=
350 FakeSources := $(FAKE_SOURCES)
351 ifdef BUILT_SOURCES
352 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
353 endif
354 BaseNameSources := $(sort $(basename $(FakeSources)))
355 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
356 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
357 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencerf88808a2004-10-30 09:19:36 +0000358else
Reid Spencer81546582004-12-04 22:34:09 +0000359 ifndef SOURCES
360 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
361 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
362 $(BUILD_SRC_DIR)/*.l))
363 else
364 Sources := $(SOURCES)
365 endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000366
Reid Spencer81546582004-12-04 22:34:09 +0000367 ifdef BUILT_SOURCES
368 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
369 endif
Vikram S. Advefe346892001-07-15 13:16:47 +0000370
Reid Spencer81546582004-12-04 22:34:09 +0000371 BaseNameSources := $(sort $(basename $(Sources)))
372 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
373 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
374 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
375endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000376
377###############################################################################
378# DIRECTORIES: Handle recursive descent of directory structure
379###############################################################################
John Criswell3601f372003-07-31 20:58:51 +0000380
Chris Lattner2f7c9632001-06-06 20:29:01 +0000381#---------------------------------------------------------
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000382# Provide rules to make install dirs. This must be early
383# in the file so they get built before dependencies
384#---------------------------------------------------------
385
386$(bindir):
Reid Spencerf88808a2004-10-30 09:19:36 +0000387 $(Verb) $(MKDIR) $(bindir)
Chris Lattner615e7fb2004-11-01 06:14:59 +0000388
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000389$(libdir):
Reid Spencerf88808a2004-10-30 09:19:36 +0000390 $(Verb) $(MKDIR) $(libdir)
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000391
Reid Spencerefe3a822004-12-13 07:38:07 +0000392$(includedir):
393 $(Verb) $(MKDIR) $(includedir)
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000394
395$(sysconfdir):
Reid Spencerf88808a2004-10-30 09:19:36 +0000396 $(Verb) $(MKDIR) $(sysconfdir)
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000397
Reid Spencerf88808a2004-10-30 09:19:36 +0000398# To create other directories, as needed, and timestamp their creation
399%/.dir:
400 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfc66af42004-11-29 05:00:33 +0000401 $(Verb) $(DATE) > $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000402
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000403.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
404.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000405
406#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000407# Handle the DIRS options for sequential construction
Chris Lattner2f7c9632001-06-06 20:29:01 +0000408#---------------------------------------------------------
409
Reid Spencerf88808a2004-10-30 09:19:36 +0000410SubDirs :=
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000411ifdef DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000412SubDirs += $(DIRS)
413$(RecursiveTargets)::
414 $(Verb) for dir in $(DIRS); do \
Reid Spencerf206bd72004-10-22 21:01:56 +0000415 if [ ! -f $$dir/Makefile ]; then \
416 $(MKDIR) $$dir; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000417 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000418 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000419 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
420 ($(MAKE) -C $$dir $@ ) || exit 1; \
421 fi ; \
Chris Lattner539a23c2002-09-17 23:35:02 +0000422 done
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000423endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000424
Reid Spencer81cd0492004-10-23 20:04:14 +0000425#---------------------------------------------------------
426# Handle the EXPERIMENTAL_DIRS options ensuring success
427# after each directory is built.
428#---------------------------------------------------------
429ifdef EXPERIMENTAL_DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000430$(RecursiveTargets)::
431 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer81cd0492004-10-23 20:04:14 +0000432 if [ ! -f $$dir/Makefile ]; then \
433 $(MKDIR) $$dir; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000434 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000435 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000436 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
437 ($(MAKE) -C $$dir $@ ) || exit 0; \
438 fi ; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000439 done
440endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000441
Reid Spencer81cd0492004-10-23 20:04:14 +0000442#---------------------------------------------------------
443# Handle the PARALLEL_DIRS options for parallel construction
444#---------------------------------------------------------
445ifdef PARALLEL_DIRS
446
Reid Spencerf88808a2004-10-30 09:19:36 +0000447SubDirs += $(PARALLEL_DIRS)
448
Reid Spencerd4bd3752004-12-03 20:08:48 +0000449# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencerf88808a2004-10-30 09:19:36 +0000450all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
451clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000452clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencerf88808a2004-10-30 09:19:36 +0000453install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000454uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencerd4bd3752004-12-03 20:08:48 +0000455install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000456
Reid Spencer81546582004-12-04 22:34:09 +0000457ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer81cd0492004-10-23 20:04:14 +0000458
Reid Spencer81546582004-12-04 22:34:09 +0000459$(ParallelTargets) :
Reid Spencerf88808a2004-10-30 09:19:36 +0000460 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000461 $(MKDIR) $(@D); \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000462 $(CP) $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswell6df35dd2003-11-25 19:32:22 +0000463 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000464 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
465 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
466 fi
Chris Lattner2f7c9632001-06-06 20:29:01 +0000467endif
468
Reid Spencer81cd0492004-10-23 20:04:14 +0000469#---------------------------------------------------------
470# Handle the OPTIONAL_DIRS options for directores that may
471# or may not exist.
472#---------------------------------------------------------
John Criswell8224df92003-06-27 16:58:44 +0000473ifdef OPTIONAL_DIRS
Reid Spencer100080c2004-10-25 08:27:37 +0000474
Reid Spencerf88808a2004-10-30 09:19:36 +0000475SubDirs += $(OPTIONAL_DIRS)
Reid Spencer100080c2004-10-25 08:27:37 +0000476
Reid Spencerf88808a2004-10-30 09:19:36 +0000477$(RecursiveTargets)::
478 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencerf206bd72004-10-22 21:01:56 +0000479 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
480 if [ ! -f $$dir/Makefile ]; then \
481 $(MKDIR) $$dir; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000482 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000483 fi; \
Reid Spencer4e197482004-12-08 22:58:34 +0000484 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
485 ($(MAKE) -C$$dir $@ ) || exit 1; \
486 fi ; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000487 fi \
John Criswell8224df92003-06-27 16:58:44 +0000488 done
489endif
490
Reid Spencercc51e7b2004-08-20 09:20:05 +0000491#---------------------------------------------------------
492# Handle the CONFIG_FILES options
493#---------------------------------------------------------
494ifdef CONFIG_FILES
Reid Spencercc51e7b2004-08-20 09:20:05 +0000495
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000496install-local:: $(sysconfdir) $(CONFIG_FILES)
Reid Spencerf88808a2004-10-30 09:19:36 +0000497 $(Echo) Installing Configuration Files To $(sysconfdir)
498 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer39d6a612004-11-23 05:59:53 +0000499 if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
500 $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
501 elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
502 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
503 else \
504 $(ECHO) Error: cannot find config file $${file}. ; \
505 fi \
Reid Spencercc51e7b2004-08-20 09:20:05 +0000506 done
Reid Spencer81cd0492004-10-23 20:04:14 +0000507
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000508uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000509 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
510 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer100080c2004-10-25 08:27:37 +0000511 $(RM) -f $(sysconfdir)/$${file} ; \
Reid Spencer12a3a052004-10-24 07:53:21 +0000512 done
513
Reid Spencercc51e7b2004-08-20 09:20:05 +0000514endif
515
Reid Spencer81cd0492004-10-23 20:04:14 +0000516###############################################################################
517# Library Build Rules: Four ways to build a library
518###############################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000519
Reid Spencerd78077d2004-12-05 05:17:22 +0000520#---------------------------------------------------------
521# Bytecode Module Targets:
522# If the user set MODULE_NAME then they want to build a
523# bytecode module from the sources. We compile all the
524# sources and link it together into a single bytecode
525# module.
526#---------------------------------------------------------
527
528ifdef MODULE_NAME
529
530Module := $(LibDir)/$(MODULE_NAME).bc
Reid Spencer2bba41c2004-12-22 05:57:21 +0000531LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
Reid Spencerd78077d2004-12-05 05:17:22 +0000532
533ifdef EXPORTED_SYMBOL_FILE
534LinkMOdule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
535endif
536
537$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
538 $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
539 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
540
541all-local:: $(Module)
542
543clean-local::
544ifneq ($(strip $(Module)),)
545 -$(Verb) $(RM) -f $(Module)
546endif
547
Reid Spencerefe3a822004-12-13 07:38:07 +0000548ifdef BYTECODE_DESTINATION
549ModuleDestDir := $(BYTECODE_DESTINATION)
550else
Reid Spencer05d4d602004-12-14 22:44:05 +0000551ModuleDestDir := $(libdir)
Reid Spencerefe3a822004-12-13 07:38:07 +0000552endif
Reid Spencerd78077d2004-12-05 05:17:22 +0000553
Reid Spencerefe3a822004-12-13 07:38:07 +0000554DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
555
556install-module:: $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +0000557install-local:: $(DestModule)
558
Reid Spencerefe3a822004-12-13 07:38:07 +0000559$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencerd78077d2004-12-05 05:17:22 +0000560 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
561 $(Verb) $(INSTALL) $(Module) $@
562
563uninstall-local::
564 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
565 -$(Verb) $(RM) -f $(DestModule)
566
567endif
Brian Gaekeecc92bf2004-01-22 22:53:48 +0000568
Reid Spencer81cd0492004-10-23 20:04:14 +0000569# if we're building a library ...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000570ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000571
Chris Lattner0100eab2002-09-16 22:36:42 +0000572# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000573LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencerf88808a2004-10-30 09:19:36 +0000574LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
575LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
576LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer32f7e422004-12-02 09:28:21 +0000577LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000578
Reid Spencer81cd0492004-10-23 20:04:14 +0000579#---------------------------------------------------------
580# Shared Library Targets:
581# If the user asked for a shared library to be built
582# with the SHARED_LIBRARY variable, then we provide
583# targets for building them.
584#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000585ifdef SHARED_LIBRARY
586
Reid Spencerf88808a2004-10-30 09:19:36 +0000587all-local:: $(LibName.LA)
Reid Spencerf206bd72004-10-22 21:01:56 +0000588
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000589$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000590 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf88808a2004-10-30 09:19:36 +0000591 $(Verb) $(Link) -o $@ $(ObjectsLO)
592 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencer81cd0492004-10-23 20:04:14 +0000593
594clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000595ifneq ($(strip $(LibName.LA)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000596 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencer12a3a052004-10-24 07:53:21 +0000597endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000598
Reid Spencer12a3a052004-10-24 07:53:21 +0000599DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf206bd72004-10-22 21:01:56 +0000600
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000601install-local:: $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000602
Reid Spencerf88808a2004-10-30 09:19:36 +0000603$(DestSharedLib): $(libdir) $(LibName.LA)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000604 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencerf88808a2004-10-30 09:19:36 +0000605 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
606 $(Verb) $(LIBTOOL) --finish $(libdir)
Reid Spencer12a3a052004-10-24 07:53:21 +0000607
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000608uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000609 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spenceraee67e62004-11-12 02:27:36 +0000610 -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
Reid Spencer12a3a052004-10-24 07:53:21 +0000611
Reid Spencerf206bd72004-10-22 21:01:56 +0000612endif
613
Reid Spencer81cd0492004-10-23 20:04:14 +0000614#---------------------------------------------------------
615# Bytecode Library Targets:
616# If the user asked for a bytecode library to be built
617# with the BYTECODE_LIBRARY variable, then we provide
618# targets for building them.
619#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000620ifdef BYTECODE_LIBRARY
621
Reid Spencer2b1b83a2004-12-03 06:04:35 +0000622# make the C and C++ compilers strip debug info out of bytecode libraries.
623BCCompile.C += -Wa,-strip-debug
624BCCompile.CXX += -Wa,-strip-debug
625
Reid Spencer32f7e422004-12-02 09:28:21 +0000626all-local:: $(LibName.BCA)
627
628ifdef EXPORTED_SYMBOL_FILE
Reid Spencer2bba41c2004-12-22 05:57:21 +0000629BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
Reid Spencer32f7e422004-12-02 09:28:21 +0000630 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
631
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000632$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +0000633 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +0000634 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
635 "(internalize)"
Chris Lattnere3d98f12004-12-02 21:23:43 +0000636 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
Reid Spencer85d55ad2004-12-13 03:59:35 +0000637 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +0000638 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
Reid Spencerf206bd72004-10-22 21:01:56 +0000639else
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000640$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +0000641 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +0000642 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencer85d55ad2004-12-13 03:59:35 +0000643 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +0000644 $(Verb) $(LArchive) $@ $(ObjectsBC)
645
Reid Spencerf206bd72004-10-22 21:01:56 +0000646endif
647
Reid Spencer81cd0492004-10-23 20:04:14 +0000648clean-local::
Reid Spencer32f7e422004-12-02 09:28:21 +0000649ifneq ($(strip $(LibName.BCA)),)
650 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencer12a3a052004-10-24 07:53:21 +0000651endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000652
Reid Spencer65086be2004-12-13 07:28:21 +0000653ifdef BYTECODE_DESTINATION
654BytecodeDestDir := $(BYTECODE_DESTINATION)
655else
656BytecodeDestDir := $(libdir)
657endif
658
659DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
Reid Spencer32f7e422004-12-02 09:28:21 +0000660
Reid Spencerd4bd3752004-12-03 20:08:48 +0000661install-bytecode-local:: $(DestBytecodeLib)
Reid Spencer8da1b5d2004-10-26 07:09:33 +0000662
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000663install-local:: $(DestBytecodeLib)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000664
Reid Spencer65086be2004-12-13 07:28:21 +0000665$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
Reid Spencer32f7e422004-12-02 09:28:21 +0000666 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
667 $(Verb) $(INSTALL) $(LibName.BCA) $@
Reid Spencer12a3a052004-10-24 07:53:21 +0000668
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000669uninstall-local::
Reid Spencer32f7e422004-12-02 09:28:21 +0000670 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000671 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencerf206bd72004-10-22 21:01:56 +0000672
673endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000674
Reid Spencerf88808a2004-10-30 09:19:36 +0000675#---------------------------------------------------------
676# ReLinked Library Targets:
677# If the user didn't explicitly forbid building a
678# relinked then we provide targets for building them.
679#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +0000680ifndef DONT_BUILD_RELINKED
Reid Spencerf206bd72004-10-22 21:01:56 +0000681
Reid Spencerf88808a2004-10-30 09:19:36 +0000682all-local:: $(LibName.O)
683
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000684$(LibName.O): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000685 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencerf88808a2004-10-30 09:19:36 +0000686 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencerf206bd72004-10-22 21:01:56 +0000687
Reid Spencer81cd0492004-10-23 20:04:14 +0000688clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000689ifneq ($(strip $(LibName.O)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000690 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencer12a3a052004-10-24 07:53:21 +0000691endif
692
693DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
694
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000695install-local:: $(DestRelinkedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000696
Reid Spencerf88808a2004-10-30 09:19:36 +0000697$(DestRelinkedLib): $(libdir) $(LibName.O)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000698 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerf88808a2004-10-30 09:19:36 +0000699 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000700
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000701uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000702 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000703 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencerf206bd72004-10-22 21:01:56 +0000704
Chris Lattner76d98ba2002-07-23 17:56:16 +0000705endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000706
Reid Spencerf88808a2004-10-30 09:19:36 +0000707#---------------------------------------------------------
708# Archive Library Targets:
709# If the user wanted a regular archive library built,
710# then we provide targets for building them.
711#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +0000712ifdef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +0000713
Reid Spencerf88808a2004-10-30 09:19:36 +0000714all-local:: $(LibName.A)
715
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000716$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000717 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000718 -$(Verb) $(RM) -f $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000719 $(Verb) $(Archive) $@ $(ObjectsO)
720 $(Verb) $(Ranlib) $@
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000721
Reid Spencer81cd0492004-10-23 20:04:14 +0000722clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000723ifneq ($(strip $(LibName.A)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000724 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000725endif
726
Reid Spencer12a3a052004-10-24 07:53:21 +0000727DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
728
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000729install-local:: $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000730
Reid Spencerf88808a2004-10-30 09:19:36 +0000731$(DestArchiveLib): $(libdir) $(LibName.A)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000732 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerf88808a2004-10-30 09:19:36 +0000733 $(Verb) $(MKDIR) $(libdir)
734 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000735
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000736uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000737 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000738 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +0000739
740endif
741
742# endif LIBRARYNAME
Reid Spencerf206bd72004-10-22 21:01:56 +0000743endif
744
Reid Spencerdcba7782004-10-24 08:21:04 +0000745###############################################################################
746# Tool Build Rules: Build executable tool based on TOOLNAME option
747###############################################################################
748
Chris Lattner07c7c192001-09-07 22:57:58 +0000749ifdef TOOLNAME
750
Reid Spencerf88808a2004-10-30 09:19:36 +0000751#---------------------------------------------------------
Reid Spenceraf4495a2004-11-29 07:17:07 +0000752# Handle the special "JIT" value for LLVM_LIBS which is a
753# shorthand for a bunch of libraries that get the correct
754# JIT support for a tool that runs JIT.
755#---------------------------------------------------------
756ifeq ($(LLVMLIBS),JIT)
757
758# Make sure we can get our own symbols in the tool
759Link += -dlopen self
760
761# Generic JIT libraries
762JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
763
764# You can enable the X86 JIT on a non-X86 host by setting the flag
765# ENABLE_X86_JIT on the make command line. If not, it will still be
766# enabled automagically on an X86 host.
767ifeq ($(ARCH), x86)
768 ENABLE_X86_JIT = 1
769endif
770
771# What the X86 JIT requires
772ifdef ENABLE_X86_JIT
Chris Lattner867783a2004-12-16 19:40:10 +0000773 JIT_LIBS += LLVMX86
Reid Spenceraf4495a2004-11-29 07:17:07 +0000774endif
775
776# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
777# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
778# enabled automagically on an SparcV9 host.
779ifeq ($(ARCH), Sparc)
780 ENABLE_SPARCV9_JIT = 1
781endif
782
783# What the Sparc JIT requires
784ifdef ENABLE_SPARCV9_JIT
785 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
786 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
787 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
788 LLVMDataStructure.a LLVMSparcV9RegAlloc
789endif
790
791# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
792# ENABLE_PPC_JIT on the make command line. If not, it will still be
793# enabled automagically on an PowerPC host.
794ifeq ($(ARCH), PowerPC)
795 ENABLE_PPC_JIT = 1
796endif
797
798# What the PowerPC JIT requires
799ifdef ENABLE_PPC_JIT
800 JIT_LIBS += LLVMPowerPC
801endif
802
803LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
804 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
805 LLVMSystem.a $(PLATFORMLIBDL)
806endif
807
808#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000809# Set up variables for building a tool.
810#---------------------------------------------------------
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000811ifdef EXAMPLE_TOOL
812ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
813else
Reid Spencerf88808a2004-10-30 09:19:36 +0000814ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000815endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000816ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
817ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
818LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
819LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
820ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
821LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
822ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
823LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattner07c7c192001-09-07 22:57:58 +0000824
Reid Spencerf88808a2004-10-30 09:19:36 +0000825#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000826# Tell make that we need to rebuild subdirectories before
827# we can link the tool. This affects things like LLI which
828# has library subdirectories.
829#---------------------------------------------------------
830$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner3ecb7762003-01-22 16:13:31 +0000831
Reid Spencerf88808a2004-10-30 09:19:36 +0000832#---------------------------------------------------------
833# Provide targets for building the tools
834#---------------------------------------------------------
835all-local:: $(ToolBuildPath)
John Criswell8224df92003-06-27 16:58:44 +0000836
Reid Spencer81cd0492004-10-23 20:04:14 +0000837clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +0000838ifneq ($(strip $(ToolBuildPath)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000839 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencer12a3a052004-10-24 07:53:21 +0000840endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000841
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000842ifdef EXAMPLE_TOOL
843$(ToolBuildPath): $(ExmplDir)/.dir
844else
845$(ToolBuildPath): $(ToolDir)/.dir
846endif
847
Reid Spenceraeea3cf2004-12-16 07:36:08 +0000848$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000849 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencerf88808a2004-10-30 09:19:36 +0000850 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
851 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000852 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencer12a3a052004-10-24 07:53:21 +0000853
854DestTool = $(bindir)/$(TOOLNAME)
855
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000856install-local:: $(DestTool)
Reid Spencer8da1b5d2004-10-26 07:09:33 +0000857
Reid Spencerf88808a2004-10-30 09:19:36 +0000858$(DestTool): $(bindir) $(ToolBuildPath)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000859 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencerf88808a2004-10-30 09:19:36 +0000860 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +0000861
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000862uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000863 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000864 -$(Verb) $(RM) -f $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +0000865
Reid Spencerf206bd72004-10-22 21:01:56 +0000866endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000867
Reid Spencerf88808a2004-10-30 09:19:36 +0000868###############################################################################
869# Object Build Rules: Build object files based on sources
870###############################################################################
871
872# Provide rule sets for when dependency generation is enabled
Reid Spencerf206bd72004-10-22 21:01:56 +0000873ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000874
Reid Spencerf88808a2004-10-30 09:19:36 +0000875#---------------------------------------------------------
876# Create .lo files in the ObjDir directory from the .cpp and .c files...
877#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000878ifdef SHARED_LIBRARY
879
Chris Lattner2a023902004-12-16 17:28:50 +0000880$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000881 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000882 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
883 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
884 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +0000885
Chris Lattner2a023902004-12-16 17:28:50 +0000886$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000887 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000888 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
889 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
890 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +0000891
Reid Spencerf88808a2004-10-30 09:19:36 +0000892#---------------------------------------------------------
893# Create .o files in the ObjDir directory from the .cpp and .c files...
894#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000895else
Reid Spencerf206bd72004-10-22 21:01:56 +0000896
Chris Lattner2a023902004-12-16 17:28:50 +0000897$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000898 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +0000899 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
900 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
901 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +0000902
Chris Lattner2a023902004-12-16 17:28:50 +0000903$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000904 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +0000905 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
906 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
907 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer81cd0492004-10-23 20:04:14 +0000908
909endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000910
Reid Spencerf88808a2004-10-30 09:19:36 +0000911#---------------------------------------------------------
912# Create .bc files in the ObjDir directory from .cpp and .c files...
913#---------------------------------------------------------
Chris Lattner2a023902004-12-16 17:28:50 +0000914$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000915 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000916 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
917 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
918 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +0000919
Chris Lattner2a023902004-12-16 17:28:50 +0000920$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000921 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencerf88808a2004-10-30 09:19:36 +0000922 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
923 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
924 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencerf206bd72004-10-22 21:01:56 +0000925
Reid Spencerf88808a2004-10-30 09:19:36 +0000926# Provide alternate rule sets if dependencies are disabled
Reid Spencerf206bd72004-10-22 21:01:56 +0000927else
928
Reid Spencer81cd0492004-10-23 20:04:14 +0000929ifdef SHARED_LIBRARY
930
Chris Lattner2a023902004-12-16 17:28:50 +0000931$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000932 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer81cd0492004-10-23 20:04:14 +0000933 $(LTCompile.CXX) $< -o $@
934
Chris Lattner2a023902004-12-16 17:28:50 +0000935$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000936 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencer81cd0492004-10-23 20:04:14 +0000937 $(LTCompile.C) $< -o $@
938
939else
Reid Spencerf206bd72004-10-22 21:01:56 +0000940
Chris Lattner2a023902004-12-16 17:28:50 +0000941$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000942 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer81cd0492004-10-23 20:04:14 +0000943 $(Compile.CXX) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +0000944
Chris Lattner2a023902004-12-16 17:28:50 +0000945$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000946 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencer81cd0492004-10-23 20:04:14 +0000947 $(Compile.C) $< -o $@
948endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000949
Chris Lattner2a023902004-12-16 17:28:50 +0000950$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000951 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer991f66a2004-10-31 18:52:15 +0000952 $(BCCompile.CXX) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +0000953
Chris Lattner2a023902004-12-16 17:28:50 +0000954$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000955 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer991f66a2004-10-31 18:52:15 +0000956 $(BCCompile.C) $< -o $@
Brian Gaeke0f148bc2003-12-10 00:26:28 +0000957
Chris Lattner07c7c192001-09-07 22:57:58 +0000958endif
959
Reid Spencerf88808a2004-10-30 09:19:36 +0000960#---------------------------------------------------------
961# Provide rule to build .bc files from .ll sources,
962# regardless of dependencies
963#---------------------------------------------------------
964$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +0000965 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +0000966 $(Verb) $(LLVMAS) $< -f -o $@
967
968###############################################################################
969# TABLEGEN: Provide rules for running tblgen to produce *.inc files
970###############################################################################
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000971
Reid Spencerf206bd72004-10-22 21:01:56 +0000972ifdef TARGET
973
Reid Spencerf88808a2004-10-30 09:19:36 +0000974TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
975INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner2a023902004-12-16 17:28:50 +0000976INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
977.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +0000978
Chris Lattner2a023902004-12-16 17:28:50 +0000979# All of these files depend on tblgen and the .td files.
980$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +0000981
Chris Lattnerf86914d2004-12-16 17:38:56 +0000982# INCFiles rule: All of the tblgen generated files are emitted to
983# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
984# us to only "touch" the real file if the contents of it change. IOW, if
985# tblgen is modified, all of the .inc.tmp files are regereated, but no
986# dependencies of the .inc files are, unless the contents of the .inc file
987# changes.
988$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerafdc82c2004-12-16 18:26:53 +0000989 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner2a023902004-12-16 17:28:50 +0000990
991$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
992$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +0000993 $(Echo) "Building $(<F) register names with tblgen"
994 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +0000995
Chris Lattner2a023902004-12-16 17:28:50 +0000996$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
997$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +0000998 $(Echo) "Building $(<F) register information header with tblgen"
999 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001000
Chris Lattner2a023902004-12-16 17:28:50 +00001001$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1002$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001003 $(Echo) "Building $(<F) register info implementation with tblgen"
1004 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001005
Chris Lattner2a023902004-12-16 17:28:50 +00001006$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1007$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001008 $(Echo) "Building $(<F) instruction names with tblgen"
1009 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001010
Chris Lattner2a023902004-12-16 17:28:50 +00001011$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1012$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001013 $(Echo) "Building $(<F) instruction information with tblgen"
1014 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001015
Chris Lattner2a023902004-12-16 17:28:50 +00001016$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1017$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001018 $(Echo) "Building $(<F) assembly writer with tblgen"
1019 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001020
Chris Lattner22f937a2004-12-16 17:34:04 +00001021$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1022$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1023 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Reid Spencerf88808a2004-10-30 09:19:36 +00001024 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001025
Chris Lattner2a023902004-12-16 17:28:50 +00001026$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1027$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001028 $(Echo) "Building $(<F) code emitter with tblgen"
1029 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001030
Reid Spencer81cd0492004-10-23 20:04:14 +00001031clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001032 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001033
1034endif
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001035
Reid Spencerf88808a2004-10-30 09:19:36 +00001036###############################################################################
1037# LEX AND YACC: Provide rules for generating sources with lex and yacc
1038###############################################################################
Chris Lattnerdb644dd2003-01-16 22:44:19 +00001039
Reid Spencerf88808a2004-10-30 09:19:36 +00001040#---------------------------------------------------------
1041# Provide rules for generating a .cpp source file from
1042# (f)lex input sources.
1043#---------------------------------------------------------
1044
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001045LexFiles := $(filter %.l,$(Sources))
Reid Spencerf88808a2004-10-30 09:19:36 +00001046
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001047ifneq ($(LexFiles),)
1048
1049LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
Reid Spencerf88808a2004-10-30 09:19:36 +00001050
1051.PRECIOUS: $(LexOutput)
1052
1053# Note the extra sed filtering here, used to cut down on the warnings emited
1054# by GCC. The last line is a gross hack to work around flex aparently not
1055# being able to resize the buffer on a large token input. Currently, for
1056# uninitialized string buffers in LLVM we can generate very long tokens, so
1057# this is a hack around it.
Chris Lattner92fc9b02003-08-15 20:00:47 +00001058# FIXME. (f.e. char Buffer[10000] )
Chris Lattner2f7c9632001-06-06 20:29:01 +00001059%.cpp: %.l
Reid Spencer993b95e2004-12-10 19:44:16 +00001060 $(Echo) Flexing $*.l
Reid Spencerf88808a2004-10-30 09:19:36 +00001061 $(Verb) $(FLEX) -t $< | \
Reid Spencerf206bd72004-10-22 21:01:56 +00001062 $(SED) 's/void yyunput/inline void yyunput/' | \
1063 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1064 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencerb7f710a2004-10-28 00:41:43 +00001065 > $@
Chris Lattner2f7c9632001-06-06 20:29:01 +00001066
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001067clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001068 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001069 $(Verb) $(RM) -f $(LexOutput)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001070
Reid Spencerf88808a2004-10-30 09:19:36 +00001071endif
1072
1073#---------------------------------------------------------
1074# Provide rules for generating a .cpp and .h source files
1075# from yacc (bison) input sources.
1076#---------------------------------------------------------
1077
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001078YaccFiles := $(filter %.y,$(Sources))
1079ifneq ($(YaccFiles),)
1080YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
Reid Spencerf88808a2004-10-30 09:19:36 +00001081
1082.PRECIOUS: $(YaccOutput)
1083
1084# Cancel built-in rules for yacc
1085%.c: %.y
1086%.cpp: %.y
1087%.h: %.y
1088
Chris Lattner2f7c9632001-06-06 20:29:01 +00001089# Rule for building the bison parsers...
Chris Lattner2f7c9632001-06-06 20:29:01 +00001090%.cpp %.h : %.y
Reid Spencerf88808a2004-10-30 09:19:36 +00001091 $(Echo) "Bisoning $*.y"
1092 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1093 $(Verb) $(MV) -f $*.tab.c $*.cpp
1094 $(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner2f7c9632001-06-06 20:29:01 +00001095
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001096clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001097 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001098 $(Verb) $(RM) -f $(YaccOutput)
Reid Spencerf88808a2004-10-30 09:19:36 +00001099endif
Chris Lattner2f7c9632001-06-06 20:29:01 +00001100
Reid Spencerf88808a2004-10-30 09:19:36 +00001101###############################################################################
1102# OTHER RULES: Other rules needed
1103###############################################################################
Reid Spencerf206bd72004-10-22 21:01:56 +00001104
Chris Lattner23d47392003-01-16 21:06:18 +00001105# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +00001106ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +00001107%.ps: %.dot
Reid Spencerf206bd72004-10-22 21:01:56 +00001108 $(DOT) -Tps < $< > $@
John Criswell3ef61af2003-06-30 21:59:07 +00001109else
1110%.ps: %.dot
Reid Spencerf88808a2004-10-30 09:19:36 +00001111 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell3ef61af2003-06-30 21:59:07 +00001112endif
Chris Lattner23d47392003-01-16 21:06:18 +00001113
John Criswell0a6e6aa2003-09-06 14:44:17 +00001114# This rules ensures that header files that are removed still have a rule for
1115# which they can be "generated." This allows make to ignore them and
1116# reproduce the dependency lists.
John Criswella8391af2003-09-18 18:37:08 +00001117%.h:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +00001118
Reid Spencerf88808a2004-10-30 09:19:36 +00001119# Define clean-local to clean the current directory. Note that this uses a
1120# very conservative approach ensuring that empty variables do not cause
1121# errors or disastrous removal.
Reid Spencer81cd0492004-10-23 20:04:14 +00001122clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001123ifneq ($(strip $(ObjDir)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001124 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencer12a3a052004-10-24 07:53:21 +00001125endif
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001126 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke8625f682004-01-21 19:53:11 +00001127ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001128 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke8625f682004-01-21 19:53:11 +00001129endif
John Criswell3ef61af2003-06-30 21:59:07 +00001130
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001131clean-all-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001132 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001133
Reid Spencerf88808a2004-10-30 09:19:36 +00001134# Build tags database for Emacs/Xemacs:
Reid Spenceraee67e62004-11-12 02:27:36 +00001135tags:: TAGS CTAGS
1136
Reid Spencerf88808a2004-10-30 09:19:36 +00001137TAGS:
Reid Spenceraee67e62004-11-12 02:27:36 +00001138 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1139 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1140 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1141 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1142 -name '*.cpp' -o -name '*.h' | \
Reid Spencerf88808a2004-10-30 09:19:36 +00001143 $(ETAGS) $(ETAGSFLAGS) -
1144
Reid Spenceraee67e62004-11-12 02:27:36 +00001145CTAGS:
1146 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1147 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1148 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1149 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1150 \( -name '*.cpp' -o -name '*.h' \) -print | \
1151 ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1152
1153
Reid Spencer81cd0492004-10-23 20:04:14 +00001154###############################################################################
1155# DEPENDENCIES: Include the dependency files if we should
1156###############################################################################
Chris Lattnere9d7d702003-08-22 14:10:16 +00001157ifndef DISABLE_AUTO_DEPENDENCIES
1158
Reid Spencer81cd0492004-10-23 20:04:14 +00001159# If its not one of the cleaning targets
Reid Spencerf88808a2004-10-30 09:19:36 +00001160ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencerf206bd72004-10-22 21:01:56 +00001161
Reid Spencer81cd0492004-10-23 20:04:14 +00001162# Get the list of dependency files
Reid Spencerf88808a2004-10-30 09:19:36 +00001163DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001164DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukmanb891ffb2003-11-09 21:36:19 +00001165
Reid Spencer81cd0492004-10-23 20:04:14 +00001166-include /dev/null $(DependFiles)
1167
John Criswell48ecca62003-08-12 18:51:51 +00001168endif
Chris Lattner598222b2003-08-18 17:27:40 +00001169
Reid Spencerf88808a2004-10-30 09:19:36 +00001170endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001171
Reid Spencer100080c2004-10-25 08:27:37 +00001172###############################################################################
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001173# CHECK: Running the test suite
1174###############################################################################
1175
1176check::
1177 $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1178 if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1179 $(EchoCmd) Running test suite ; \
1180 $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1181 TESTSUITE=$(TESTSUITE) ; \
1182 else \
1183 $(EchoCmd) No Makefile in test directory ; \
1184 fi ; \
1185 else \
1186 $(EchoCmd) No test directory ; \
1187 fi
1188
1189###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001190# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer100080c2004-10-25 08:27:37 +00001191###############################################################################
1192
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001193#------------------------------------------------------------------------
1194# Define distribution related variables
1195#------------------------------------------------------------------------
Reid Spencer100080c2004-10-25 08:27:37 +00001196DistName := $(LLVM_TARBALL_NAME)
1197DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001198TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer100080c2004-10-25 08:27:37 +00001199DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1200DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
1201DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1202DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1203 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001204 Makefile.config.in configure autoconf
1205DistOther := $(notdir $(wildcard \
1206 $(BUILD_SRC_DIR)/*.h \
1207 $(BUILD_SRC_DIR)/*.td \
1208 $(BUILD_SRC_DIR)/*.def \
1209 $(BUILD_SRC_DIR)/*.ll \
1210 $(BUILD_SRC_DIR)/*.in))
Reid Spencerf88808a2004-10-30 09:19:36 +00001211DistSubDirs := $(SubDirs)
Reid Spencerfc66af42004-11-29 05:00:33 +00001212DistSources = $(Sources) $(EXTRA_DIST)
1213DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer100080c2004-10-25 08:27:37 +00001214
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001215#------------------------------------------------------------------------
1216# We MUST build distribution with OBJ_DIR != SRC_DIR
1217#------------------------------------------------------------------------
1218ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1219dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001220 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001221
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001222else
1223
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001224#------------------------------------------------------------------------
1225# Prevent catastrophic remove
1226#------------------------------------------------------------------------
1227ifeq ($(LLVM_TARBALL_NAME),)
1228$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
1229endif
1230
1231#------------------------------------------------------------------------
1232# Prevent attempt to run dist targets from anywhere but the top level
1233#------------------------------------------------------------------------
1234ifneq ($(LEVEL),.)
1235
1236dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001237 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001238
1239else
1240
1241#------------------------------------------------------------------------
1242# Provide the top level targets
1243#------------------------------------------------------------------------
1244
Reid Spencerf88808a2004-10-30 09:19:36 +00001245dist-gzip:: $(DistTarGZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001246
Reid Spencer81546582004-12-04 22:34:09 +00001247$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001248 $(Echo) Packing gzipped distribution tar file.
Reid Spencerfc66af42004-11-29 05:00:33 +00001249 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1250 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001251
Reid Spencerf88808a2004-10-30 09:19:36 +00001252dist-bzip2:: $(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001253
Reid Spencer81546582004-12-04 22:34:09 +00001254$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001255 $(Echo) Packing bzipped distribution tar file.
Reid Spencerfc66af42004-11-29 05:00:33 +00001256 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1257 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001258
Reid Spencerf88808a2004-10-30 09:19:36 +00001259dist-zip:: $(DistZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001260
Reid Spencer81546582004-12-04 22:34:09 +00001261$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001262 $(Echo) Packing zipped distribution file.
1263 $(Verb) rm -f $(DistZip)
1264 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001265
1266dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001267 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001268
1269DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1270
Reid Spencer81546582004-12-04 22:34:09 +00001271dist-check:: $(DistTarGZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001272 $(Echo) Checking distribution tar file.
1273 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001274 $(RM) -rf $(DistCheckDir) ; \
1275 fi
Reid Spencerf88808a2004-10-30 09:19:36 +00001276 $(Verb) $(MKDIR) $(DistCheckDir)
1277 $(Verb) cd $(DistCheckDir) && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001278 $(MKDIR) $(DistCheckDir)/build && \
1279 $(MKDIR) $(DistCheckDir)/install && \
1280 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1281 cd build && \
1282 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer35655d62004-12-24 03:36:31 +00001283 --srcdir=../$(DistName) && \
Reid Spencer81546582004-12-04 22:34:09 +00001284 $(MAKE) all && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001285 $(MAKE) check && \
1286 $(MAKE) install && \
1287 $(MAKE) uninstall && \
1288 $(MAKE) dist && \
1289 $(MAKE) clean && \
1290 $(MAKE) dist-clean && \
Reid Spencerf88808a2004-10-30 09:19:36 +00001291 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001292
1293dist-clean::
Reid Spencerf88808a2004-10-30 09:19:36 +00001294 $(Echo) Cleaning distribution files
Reid Spencer81546582004-12-04 22:34:09 +00001295 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1296 $(DistCheckDir)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001297
1298endif
1299
1300#------------------------------------------------------------------------
1301# Provide the recursive distdir target for building the distribution directory
1302#------------------------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +00001303distdir: $(DistDir)/.makedistdir
1304$(DistDir)/.makedistdir: $(DistSources)
Reid Spencerf88808a2004-10-30 09:19:36 +00001305 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001306 if test -d "$(DistDir)" ; then \
1307 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1308 exit 1 ; \
1309 fi ; \
Reid Spencer81546582004-12-04 22:34:09 +00001310 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001311 $(RM) -rf $(DistDir); \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001312 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer81546582004-12-04 22:34:09 +00001313 $(MAKE) all ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001314 fi
Reid Spencerfc66af42004-11-29 05:00:33 +00001315 $(Echo) Building Distribution Directory $(DistDir)
Reid Spencerf88808a2004-10-30 09:19:36 +00001316 $(Verb) $(MKDIR) $(DistDir)
1317 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
Reid Spencer100080c2004-10-25 08:27:37 +00001318 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1319 for file in $(DistFiles) ; do \
1320 case "$$file" in \
Reid Spencer81546582004-12-04 22:34:09 +00001321 $(BUILD_SRC_DIR)/*) \
1322 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1323 ;; \
1324 $(BUILD_SRC_ROOT)/*) \
1325 file=`echo "$$file" | \
1326 sed "s#^$$srcrootstrip/##"` \
1327 ;; \
Reid Spencer100080c2004-10-25 08:27:37 +00001328 esac; \
Reid Spencer81546582004-12-04 22:34:09 +00001329 if test -f "$(BUILD_SRC_DIR)/$$file" || \
1330 test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1331 from_dir="$(BUILD_SRC_DIR)" ; \
1332 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001333 from_dir=. ; \
Reid Spencer81546582004-12-04 22:34:09 +00001334 fi ; \
1335 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001336 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1337 to_dir="$(DistDir)/$$dir"; \
1338 $(MKDIR) "$$to_dir" ; \
1339 else \
1340 to_dir="$(DistDir)"; \
1341 fi; \
1342 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1343 if test -n "$$mid_dir" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001344 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001345 fi ; \
1346 if test -d "$$from_dir/$$file"; then \
1347 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1348 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001349 $(CP) -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001350 fi; \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001351 $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001352 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001353 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001354 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001355 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001356 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer81546582004-12-04 22:34:09 +00001357 $(EchoCmd) "===== WARNING: Distribution Source " \
1358 "$$from_dir/$$file Not Found!" ; \
Reid Spencerf88808a2004-10-30 09:19:36 +00001359 elif test "$(Verb)" != '@' ; then \
1360 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001361 fi; \
1362 done
Reid Spencerf88808a2004-10-30 09:19:36 +00001363 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer100080c2004-10-25 08:27:37 +00001364 if test "$$subdir" \!= "." ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001365 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001366 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer81546582004-12-04 22:34:09 +00001367 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1368 exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001369 fi; \
1370 done
Reid Spencer81546582004-12-04 22:34:09 +00001371 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1372 $(EchoCmd) Eliminating CVS directories from distribution ; \
1373 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1374 $(MAKE) dist-hook ; \
1375 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1376 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1377 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1378 -o ! -type d ! -perm -444 -exec \
1379 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1380 || chmod -R a+r $(DistDir) ; \
1381 fi
Reid Spencer100080c2004-10-25 08:27:37 +00001382
Reid Spencerf88808a2004-10-30 09:19:36 +00001383# This is invoked by distdir target, define it as a no-op to avoid errors if not
1384# defined by user.
Reid Spencer100080c2004-10-25 08:27:37 +00001385dist-hook::
1386
Reid Spencer23a70372004-10-22 23:06:30 +00001387endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001388
1389###############################################################################
Reid Spencer12a3a052004-10-24 07:53:21 +00001390# TOP LEVEL - targets only to apply at the top level directory
1391###############################################################################
1392
1393ifeq ($(LEVEL),.)
1394
1395#------------------------------------------------------------------------
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001396# Install support for the project's include files:
Reid Spencer12a3a052004-10-24 07:53:21 +00001397#------------------------------------------------------------------------
1398install-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001399 $(Echo) Installing include files
1400 $(Verb) $(MKDIR) $(includedir)
1401 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencer12a3a052004-10-24 07:53:21 +00001402 cd $(BUILD_SRC_ROOT)/include && \
1403 find . -path '*/Internal' -prune -o '(' -type f \
1404 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1405 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1406 fi
1407
1408uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001409 $(Echo) Uninstalling include files
1410 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencer12a3a052004-10-24 07:53:21 +00001411 cd $(BUILD_SRC_ROOT)/include && \
1412 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1413 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1414 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1415 fi
1416
Reid Spencer12a3a052004-10-24 07:53:21 +00001417endif
1418
Reid Spencerf206bd72004-10-22 21:01:56 +00001419#------------------------------------------------------------------------
1420# Print out the directories used for building
Reid Spencerf88808a2004-10-30 09:19:36 +00001421#------------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001422printvars::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001423 $(Echo) "BuildMode : " '$(BuildMode)'
Reid Spencerf88808a2004-10-30 09:19:36 +00001424 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1425 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1426 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1427 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1428 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1429 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1430 $(Echo) "libdir : " '$(libdir)'
1431 $(Echo) "bindir : " '$(bindir)'
1432 $(Echo) "sysconfdir : " '$(sysconfdir)'
Reid Spencerf88808a2004-10-30 09:19:36 +00001433 $(Echo) "UserTargets : " '$(UserTargets)'
1434 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1435 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1436 $(Echo) "ObjDir : " '$(ObjDir)'
1437 $(Echo) "LibDir : " '$(LibDir)'
1438 $(Echo) "ToolDir : " '$(ToolDir)'
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001439 $(Echo) "ExmplDir : " '$(ExmplDir)'
Reid Spencerd78077d2004-12-05 05:17:22 +00001440 $(Echo) "Sources : " '$(Sources)'
Reid Spencerf88808a2004-10-30 09:19:36 +00001441 $(Echo) "TDFiles : " '$(TDFiles)'
1442 $(Echo) "INCFiles : " '$(INCFiles)'
Chris Lattner2a023902004-12-16 17:28:50 +00001443 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencerf88808a2004-10-30 09:19:36 +00001444 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1445 $(Echo) "Compile.C : " '$(Compile.C)'
1446 $(Echo) "Archive : " '$(Archive)'
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001447 $(Echo) "YaccFiles : " '$(YaccFiles)'
1448 $(Echo) "LexFiles : " '$(LexFiles)'
Reid Spencerd78077d2004-12-05 05:17:22 +00001449 $(Echo) "Module : " '$(Module)'