blob: 0e618e5d80487f8f9a19e1d06335f9a7a970ddd6 [file] [log] [blame]
Misha Brukman6d5ab862004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswelld8846c12003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
5# This file was developed by the LLVM research group and is distributed under
6# the University of Illinois Open Source License. See LICENSE.TXT for details.
7#
Misha Brukman6d5ab862004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner00950542001-06-06 20:29:01 +00009#
Reid Spencer3a561f52004-10-23 20:04:14 +000010# This file is included by all of the LLVM makefiles. For details on how to use
11# it properly, please see the document MakefileGuide.html in the docs directory.
Chris Lattneraf06a082003-08-15 03:02:52 +000012#
Vikram S. Adved60aede2002-07-09 12:04:21 +000013#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000014
Reid Spencercc2d1e22004-10-30 09:19:36 +000015################################################################################
Reid Spencer3a561f52004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencercc2d1e22004-10-30 09:19:36 +000017################################################################################
John Criswell7a73b802003-06-30 21:59:07 +000018
Chris Lattner00950542001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Chris Lattner7dc02822004-12-03 21:05:57 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode
Reid Spencer9e8d54a2004-12-06 05:35:13 +000023LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencer44cb1b32004-12-03 20:08:48 +000024 install-local printvars uninstall-local \
25 install-bytecode-local
Reid Spencer9e8d54a2004-12-06 05:35:13 +000026TopLevelTargets := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
Reid Spencercc2d1e22004-10-30 09:19:36 +000027 dist-zip
28UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29InternalTargets := preconditions distdir dist-hook
Reid Spencer3a561f52004-10-23 20:04:14 +000030
Reid Spencercc2d1e22004-10-30 09:19:36 +000031################################################################################
Reid Spencer9411c642004-10-26 22:26:33 +000032# INITIALIZATION: Basic things the makefile needs
Reid Spencercc2d1e22004-10-30 09:19:36 +000033################################################################################
34
35#--------------------------------------------------------------------
36# Set the VPATH so that we can find source files.
37#--------------------------------------------------------------------
38VPATH=$(BUILD_SRC_DIR)
Reid Spencer9411c642004-10-26 22:26:33 +000039
40#--------------------------------------------------------------------
41# Reset the list of suffixes we know how to build
42#--------------------------------------------------------------------
43.SUFFIXES:
Reid Spencercc2d1e22004-10-30 09:19:36 +000044.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot
45.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer9411c642004-10-26 22:26:33 +000046
Reid Spencer3a561f52004-10-23 20:04:14 +000047#--------------------------------------------------------------------
48# Mark all of these targets as phony to avoid implicit rule search
49#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000050.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer3a561f52004-10-23 20:04:14 +000051
52#--------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +000053# Make sure all the user-target rules are double colon rules and
54# they are defined first.
Reid Spencer3a561f52004-10-23 20:04:14 +000055#--------------------------------------------------------------------
56
Reid Spencercc2d1e22004-10-30 09:19:36 +000057$(UserTargets)::
Reid Spencer151f8ba2004-10-25 08:27:37 +000058
Reid Spencer9411c642004-10-26 22:26:33 +000059################################################################################
60# PRECONDITIONS: that which must be built/checked first
61################################################################################
62
Reid Spencer44cb1b32004-12-03 20:08:48 +000063SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencer023c4462004-11-17 19:08:44 +000064 $(wildcard $(BUILD_SRC_DIR)/Makefile*))
Reid Spencercc2d1e22004-10-30 09:19:36 +000065ObjMakefiles := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
66ConfigureScript := $(LLVM_SRC_ROOT)/configure
67ConfigStatusScript := $(LLVM_OBJ_ROOT)/config.status
68MakefileConfigIn := $(LLVM_SRC_ROOT)/Makefile.config.in
69MakefileConfig := $(LLVM_OBJ_ROOT)/Makefile.config
70PreConditions := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
Reid Spencer9411c642004-10-26 22:26:33 +000071
Reid Spencercc2d1e22004-10-30 09:19:36 +000072preconditions : $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +000073
74#------------------------------------------------------------------------
75# Make sure the BUILT_SOURCES are built first
76#------------------------------------------------------------------------
Reid Spencer07a549a2004-12-16 07:15:16 +000077$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000078
79clean-local::
80ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +000081 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +000082endif
83
Reid Spencer31f95242004-12-16 08:00:46 +000084ifneq ($(BUILD_OBJ_ROOT),$(BUILD_SRC_ROOT))
85spotless:
86 $(Echo) Wiping out $(BUILD_OBJ_ROOT) and rebuilding configuration.
87 $(Verb) if test -x config.status ; then \
88 $(MV) config.status .. ; \
89 $(MV) mklib .. ; \
90 $(RM) -rf * ; \
91 $(MV) ../config.status . ; \
92 $(MV) ../mklib . ; \
93 ./config.status ; \
94 else \
95 $(EchoCmd) "make spotless" can only be run from $(BUILD_OBJ_ROOT); \
96 fi
97endif
98
Reid Spencercc2d1e22004-10-30 09:19:36 +000099$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +0000100
Reid Spencer9411c642004-10-26 22:26:33 +0000101#------------------------------------------------------------------------
102# Make sure we're not using a stale configuration
103#------------------------------------------------------------------------
Reid Spencerc3719842004-12-16 18:26:53 +0000104reconfigure:
105 $(Echo) Reconfiguring $(BUILD_OBJ_ROOT)
106 $(Verb) cd $(BUILD_OBJ_ROOT) && \
107 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108 $(ConfigStatusScript)
109
Reid Spencercc2d1e22004-10-30 09:19:36 +0000110.PRECIOUS: $(ConfigStatusScript)
111$(ConfigStatusScript): $(ConfigureScript)
112 $(Echo) Reconfiguring with $<
Reid Spencer7d277002004-11-29 12:37:44 +0000113 $(Verb) cd $(BUILD_OBJ_ROOT) && \
114 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
115 $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +0000116
117#------------------------------------------------------------------------
118# Make sure the configuration makefile is up to date
119#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000120$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
121 $(Echo) Regenerating $@
122 $(Verb) cd $(LLVM_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
Reid Spencer9411c642004-10-26 22:26:33 +0000123
124#------------------------------------------------------------------------
125# If the Makefile in the source tree has been updated, copy it over into the
126# build tree. But, only do this if the source and object makefiles differ
127#------------------------------------------------------------------------
128ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
129
Reid Spencer023c4462004-11-17 19:08:44 +0000130Makefile: $(BUILD_SRC_DIR)/Makefile
Reid Spencercc2d1e22004-10-30 09:19:36 +0000131 $(Echo) "Updating Makefile"
132 $(Verb) $(MKDIR) $(@D)
Reid Spencerc3719842004-12-16 18:26:53 +0000133 $(Verb) $(CP) -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000134
135# Copy the Makefile.* files unless we're in the root directory which avoids
136# the copying of Makefile.config.in or other things that should be explicitly
137# taken care of.
Reid Spencer9411c642004-10-26 22:26:33 +0000138$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
Reid Spencer86606782004-10-26 23:10:00 +0000139 @case '$?' in \
140 *Makefile.rules) ;; \
141 *.in) ;; \
Reid Spencercc2d1e22004-10-30 09:19:36 +0000142 *) $(Echo) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000143 $(MKDIR) $(@D) ; \
Reid Spencerc3719842004-12-16 18:26:53 +0000144 $(CP) -f $< $@ ;; \
Reid Spencer86606782004-10-26 23:10:00 +0000145 esac
146
Reid Spencer9411c642004-10-26 22:26:33 +0000147endif
148
149#------------------------------------------------------------------------
150# Set up the basic dependencies
151#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000152$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000153
154all:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000155clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000156clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000157install:: install-local
158uninstall:: uninstall-local
Reid Spencer9411c642004-10-26 22:26:33 +0000159install-local:: all-local
Reid Spencer44cb1b32004-12-03 20:08:48 +0000160install-bytecode:: install-bytecode-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000161
162###############################################################################
163# VARIABLES: Set up various variables based on configuration data
164###############################################################################
165
166#--------------------------------------------------------------------
167# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000168#--------------------------------------------------------------------
169
Chris Lattner760da062003-03-14 20:25:22 +0000170ifdef ENABLE_PROFILING
Reid Spencer9af3b292004-11-01 07:50:27 +0000171 BuildMode := Profile
Reid Spencer519799e2004-12-08 04:34:51 +0000172 CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
Reid Spencercc2d1e22004-10-30 09:19:36 +0000173 C.Flags := -O3 -DNDEBUG -pg
174 LD.Flags := -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000175else
176 ifdef ENABLE_OPTIMIZED
Reid Spencer9af3b292004-11-01 07:50:27 +0000177 BuildMode := Release
Reid Spencer519799e2004-12-08 04:34:51 +0000178 CXX.Flags := -O3 -DNDEBUG -finline-functions \
Reid Spencer2e2035b2004-12-08 04:26:23 +0000179 -felide-constructors -fomit-frame-pointer
Reid Spencercc2d1e22004-10-30 09:19:36 +0000180 C.Flags := -O3 -DNDEBUG -fomit-frame-pointer
181 LD.Flags := -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000182 else
Reid Spencer9af3b292004-11-01 07:50:27 +0000183 BuildMode := Debug
Reid Spencer519799e2004-12-08 04:34:51 +0000184 CXX.Flags := -g -D_DEBUG
Reid Spencercc2d1e22004-10-30 09:19:36 +0000185 C.Flags := -g -D_DEBUG
186 LD.Flags := -g -D_DEBUG
Reid Spencer4d71b662004-10-22 21:01:56 +0000187 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000188 endif
189endif
190
Reid Spencercc2d1e22004-10-30 09:19:36 +0000191CXX.Flags += $(CXXFLAGS)
192C.Flags += $(CFLAGS)
193CPP.Flags += $(CPPFLAGS)
194LD.Flags += $(LDFLAGS)
195AR.Flags := cru
196LibTool.Flags := --tag=CXX
Reid Spencer3a561f52004-10-23 20:04:14 +0000197
198#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000199# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000200#--------------------------------------------------------------------
Reid Spencer9af3b292004-11-01 07:50:27 +0000201ObjDir := $(BUILD_OBJ_DIR)/$(BuildMode)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000202LibDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer9a5acaf2004-11-18 20:04:39 +0000203ToolDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer815cbcf2004-11-18 10:03:46 +0000204ExmplDir := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
205LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
Reid Spencer9a5acaf2004-11-18 20:04:39 +0000206LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
Reid Spencer815cbcf2004-11-18 10:03:46 +0000207LExmplDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell7a73b802003-06-30 21:59:07 +0000208
Reid Spencer3a561f52004-10-23 20:04:14 +0000209#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000210# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000211#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000212EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
213Echo := @$(EchoCmd)
214ifndef LIBTOOL
Reid Spencer4d71b662004-10-22 21:01:56 +0000215LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
Reid Spencercc2d1e22004-10-30 09:19:36 +0000216endif
217ifndef LLVMAS
218LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
219endif
220ifndef BURG
221BURG := $(LLVMToolDir)/burg$(EXEEXT)
222endif
223ifndef TBLGEN
224TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
225endif
Chris Lattner478b3b42004-11-29 19:47:58 +0000226ifndef GCCAS
227GCCAS := $(LLVMToolDir)/gccas$(EXEEXT)
228endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000229ifndef GCCLD
230GCCLD := $(LLVMToolDir)/gccld$(EXEEXT)
231endif
232ifndef LLVMGCC
233LLVMGCC := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
234endif
235ifndef LLVMGXX
236LLVMGXX := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
237endif
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000238ifndef LDIS
239LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
240endif
241ifndef LLI
242LLI := $(LLVMToolDir)/lli$(EXEEXT)
243endif
244ifndef LOPT
Alkis Evlogimenos20d793a2004-12-13 18:08:29 +0000245LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000246endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000247
Reid Spencer3a561f52004-10-23 20:04:14 +0000248#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000249# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000250#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000251
Reid Spencercc2d1e22004-10-30 09:19:36 +0000252# Adjust LIBTOOL flags for shared libraries, or not.
John Criswell82f4a5a2003-07-31 20:58:51 +0000253ifndef SHARED_LIBRARY
Reid Spencercc2d1e22004-10-30 09:19:36 +0000254 LibTool.Flags += --tag=disable-shared
Reid Spencer4d71b662004-10-22 21:01:56 +0000255else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000256 LD.Flags += -rpath $(LibDir)
John Criswell82f4a5a2003-07-31 20:58:51 +0000257endif
258
Reid Spencercceed9f2004-11-08 17:32:12 +0000259ifdef TOOL_VERBOSE
260 C.Flags += -v
261 CXX.Flags += -v
262 LD.Flags += -v
Reid Spencercceed9f2004-11-08 17:32:12 +0000263 VERBOSE := 1
264endif
265
Reid Spencer3a561f52004-10-23 20:04:14 +0000266# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000267ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000268 Verb := @
269 LibTool.Flags += --silent
270 AR.Flags += >/dev/null 2>/dev/null
271 ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000272else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000273 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000274endif
275
Vikram S. Advefeeae582002-09-18 11:55:13 +0000276# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000277ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000278 Strip := $(PLATFORMSTRIPOPTS)
279 StripWarnMsg := "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000280endif
281
Reid Spencer3a561f52004-10-23 20:04:14 +0000282# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000283ifdef TOOLNAME
Reid Spencer815cbcf2004-11-18 10:03:46 +0000284ifdef EXAMPLE_TOOL
285 LD.Flags += -rpath $(ExmplDir) -export-dynamic
286else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000287 LD.Flags += -rpath $(ToolDir) -export-dynamic
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000288endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000289endif
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000290
Reid Spencer3a561f52004-10-23 20:04:14 +0000291#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000292# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000293#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000294
295CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
296
Reid Spencercc2d1e22004-10-30 09:19:36 +0000297LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
298CPP.Flags += -I$(BUILD_OBJ_DIR) \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000299 -I$(BUILD_SRC_DIR) \
300 -I$(BUILD_SRC_ROOT)/include \
301 -I$(BUILD_OBJ_ROOT)/include \
302 -I$(LLVM_OBJ_ROOT)/include \
303 -I$(LLVM_SRC_ROOT)/include \
304 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencer4d71b662004-10-22 21:01:56 +0000305
Reid Spencercc2d1e22004-10-30 09:19:36 +0000306Compile.C = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
307LTCompile.C = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
308BCCompile.C = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
309Compile.CXX = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
310LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
311BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
312Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
313 $(CompileCommonOpts) $(LD.Flags) $(Strip)
314Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
Reid Spencera69b1ea2004-10-28 09:15:28 +0000315 $(CompileCommonOpts)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000316LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
Reid Spencer3a561f52004-10-23 20:04:14 +0000317Burg = $(BURG) -I $(BUILD_SRC_DIR)
318TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000319Archive = $(AR) $(AR.Flags)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000320LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000321ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000322Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000323else
Reid Spencer3a561f52004-10-23 20:04:14 +0000324Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000325endif
326
Chris Lattner00950542001-06-06 20:29:01 +0000327#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000328# Get the list of source files and compute object file
329# names from them.
Reid Spencer3a561f52004-10-23 20:04:14 +0000330#----------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +0000331ifdef FAKE_SOURCES
332 Sources :=
333 FakeSources := $(FAKE_SOURCES)
334 ifdef BUILT_SOURCES
335 FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
336 endif
337 BaseNameSources := $(sort $(basename $(FakeSources)))
338 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
339 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
340 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000341else
Reid Spencer345235ca2004-12-04 22:34:09 +0000342 ifndef SOURCES
343 Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
344 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
345 $(BUILD_SRC_DIR)/*.l))
346 else
347 Sources := $(SOURCES)
348 endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000349
Reid Spencer345235ca2004-12-04 22:34:09 +0000350 ifdef BUILT_SOURCES
351 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
352 endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000353
Reid Spencer345235ca2004-12-04 22:34:09 +0000354 BaseNameSources := $(sort $(basename $(Sources)))
355 ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
356 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
357 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
358endif
Reid Spencer3a561f52004-10-23 20:04:14 +0000359
360###############################################################################
361# DIRECTORIES: Handle recursive descent of directory structure
362###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000363
Chris Lattner00950542001-06-06 20:29:01 +0000364#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000365# Provide rules to make install dirs. This must be early
366# in the file so they get built before dependencies
367#---------------------------------------------------------
368
369$(bindir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000370 $(Verb) $(MKDIR) $(bindir)
Chris Lattnere4cb90f2004-11-01 06:14:59 +0000371
Reid Spencera69b1ea2004-10-28 09:15:28 +0000372$(libdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000373 $(Verb) $(MKDIR) $(libdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000374
Reid Spencerab3690b2004-12-13 07:38:07 +0000375$(includedir):
376 $(Verb) $(MKDIR) $(includedir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000377
378$(sysconfdir):
Reid Spencercc2d1e22004-10-30 09:19:36 +0000379 $(Verb) $(MKDIR) $(sysconfdir)
Reid Spencera69b1ea2004-10-28 09:15:28 +0000380
Reid Spencercc2d1e22004-10-30 09:19:36 +0000381# To create other directories, as needed, and timestamp their creation
382%/.dir:
383 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfbbf3072004-11-29 05:00:33 +0000384 $(Verb) $(DATE) > $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000385
Reid Spencer815cbcf2004-11-18 10:03:46 +0000386.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
387.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000388
389#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000390# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000391#---------------------------------------------------------
392
Reid Spencercc2d1e22004-10-30 09:19:36 +0000393SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000394ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000395SubDirs += $(DIRS)
396$(RecursiveTargets)::
397 $(Verb) for dir in $(DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000398 if [ ! -f $$dir/Makefile ]; then \
399 $(MKDIR) $$dir; \
Reid Spencerc3719842004-12-16 18:26:53 +0000400 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000401 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000402 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
403 ($(MAKE) -C $$dir $@ ) || exit 1; \
404 fi ; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000405 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000406endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000407
Reid Spencer3a561f52004-10-23 20:04:14 +0000408#---------------------------------------------------------
409# Handle the EXPERIMENTAL_DIRS options ensuring success
410# after each directory is built.
411#---------------------------------------------------------
412ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000413$(RecursiveTargets)::
414 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer3a561f52004-10-23 20:04:14 +0000415 if [ ! -f $$dir/Makefile ]; then \
416 $(MKDIR) $$dir; \
Reid Spencerc3719842004-12-16 18:26:53 +0000417 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000418 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000419 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
420 ($(MAKE) -C $$dir $@ ) || exit 0; \
421 fi ; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000422 done
423endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000424
Reid Spencer3a561f52004-10-23 20:04:14 +0000425#---------------------------------------------------------
426# Handle the PARALLEL_DIRS options for parallel construction
427#---------------------------------------------------------
428ifdef PARALLEL_DIRS
429
Reid Spencercc2d1e22004-10-30 09:19:36 +0000430SubDirs += $(PARALLEL_DIRS)
431
Reid Spencer44cb1b32004-12-03 20:08:48 +0000432# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencercc2d1e22004-10-30 09:19:36 +0000433all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
434clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000435clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000436install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000437uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencer44cb1b32004-12-03 20:08:48 +0000438install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000439
Reid Spencer345235ca2004-12-04 22:34:09 +0000440ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000441
Reid Spencer345235ca2004-12-04 22:34:09 +0000442$(ParallelTargets) :
Reid Spencercc2d1e22004-10-30 09:19:36 +0000443 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000444 $(MKDIR) $(@D); \
Reid Spencerc3719842004-12-16 18:26:53 +0000445 $(CP) $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000446 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000447 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
448 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
449 fi
Chris Lattner00950542001-06-06 20:29:01 +0000450endif
451
Reid Spencer3a561f52004-10-23 20:04:14 +0000452#---------------------------------------------------------
453# Handle the OPTIONAL_DIRS options for directores that may
454# or may not exist.
455#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000456ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000457
Reid Spencercc2d1e22004-10-30 09:19:36 +0000458SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000459
Reid Spencercc2d1e22004-10-30 09:19:36 +0000460$(RecursiveTargets)::
461 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000462 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
463 if [ ! -f $$dir/Makefile ]; then \
464 $(MKDIR) $$dir; \
Reid Spencerc3719842004-12-16 18:26:53 +0000465 $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000466 fi; \
Reid Spencera23c0662004-12-08 22:58:34 +0000467 if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
468 ($(MAKE) -C$$dir $@ ) || exit 1; \
469 fi ; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000470 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000471 done
472endif
473
Reid Spencerfc945082004-08-20 09:20:05 +0000474#---------------------------------------------------------
475# Handle the CONFIG_FILES options
476#---------------------------------------------------------
477ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000478
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000479install-local:: $(sysconfdir) $(CONFIG_FILES)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000480 $(Echo) Installing Configuration Files To $(sysconfdir)
481 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer1b426ab2004-11-23 05:59:53 +0000482 if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
483 $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
484 elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
485 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
486 else \
487 $(ECHO) Error: cannot find config file $${file}. ; \
488 fi \
Reid Spencerfc945082004-08-20 09:20:05 +0000489 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000490
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000491uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000492 $(Echo) Uninstalling Configuration Files From $(sysconfdir)
493 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000494 $(RM) -f $(sysconfdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000495 done
496
Reid Spencerfc945082004-08-20 09:20:05 +0000497endif
498
Reid Spencer3a561f52004-10-23 20:04:14 +0000499###############################################################################
500# Library Build Rules: Four ways to build a library
501###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000502
Reid Spencer7980ea42004-12-05 05:17:22 +0000503#---------------------------------------------------------
504# Bytecode Module Targets:
505# If the user set MODULE_NAME then they want to build a
506# bytecode module from the sources. We compile all the
507# sources and link it together into a single bytecode
508# module.
509#---------------------------------------------------------
510
511ifdef MODULE_NAME
512
513Module := $(LibDir)/$(MODULE_NAME).bc
514LinkModule := $(LLVMGCC) -shared -nostdlib
515
516ifdef EXPORTED_SYMBOL_FILE
517LinkMOdule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
518endif
519
520$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
521 $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
522 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
523
524all-local:: $(Module)
525
526clean-local::
527ifneq ($(strip $(Module)),)
528 -$(Verb) $(RM) -f $(Module)
529endif
530
Reid Spencerab3690b2004-12-13 07:38:07 +0000531ifdef BYTECODE_DESTINATION
532ModuleDestDir := $(BYTECODE_DESTINATION)
533else
Reid Spencer18d3b982004-12-14 22:44:05 +0000534ModuleDestDir := $(libdir)
Reid Spencerab3690b2004-12-13 07:38:07 +0000535endif
Reid Spencer7980ea42004-12-05 05:17:22 +0000536
Reid Spencerab3690b2004-12-13 07:38:07 +0000537DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
538
539install-module:: $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +0000540install-local:: $(DestModule)
541
Reid Spencerab3690b2004-12-13 07:38:07 +0000542$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencer7980ea42004-12-05 05:17:22 +0000543 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
544 $(Verb) $(INSTALL) $(Module) $@
545
546uninstall-local::
547 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
548 -$(Verb) $(RM) -f $(DestModule)
549
550endif
Brian Gaeke8abff792004-01-22 22:53:48 +0000551
Reid Spencer3a561f52004-10-23 20:04:14 +0000552# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000553ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000554
Chris Lattner2a548c52002-09-16 22:36:42 +0000555# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000556LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000557LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
558LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
559LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer9a2f1372004-12-02 09:28:21 +0000560LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000561
Reid Spencer3a561f52004-10-23 20:04:14 +0000562#---------------------------------------------------------
563# Shared Library Targets:
564# If the user asked for a shared library to be built
565# with the SHARED_LIBRARY variable, then we provide
566# targets for building them.
567#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000568ifdef SHARED_LIBRARY
569
Reid Spencercc2d1e22004-10-30 09:19:36 +0000570all-local:: $(LibName.LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000571
Reid Spencerf2ac1892004-12-16 07:36:08 +0000572$(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000573 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000574 $(Verb) $(Link) -o $@ $(ObjectsLO)
575 $(Verb) $(LTInstall) $@ $(LibDir)
Reid Spencer3a561f52004-10-23 20:04:14 +0000576
577clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000578ifneq ($(strip $(LibName.LA)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000579 -$(Verb) $(RM) -f $(LibName.LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000580endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000581
Reid Spencere5487ba2004-10-24 07:53:21 +0000582DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000583
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000584install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000585
Reid Spencercc2d1e22004-10-30 09:19:36 +0000586$(DestSharedLib): $(libdir) $(LibName.LA)
Reid Spencer9af3b292004-11-01 07:50:27 +0000587 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000588 $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
589 $(Verb) $(LIBTOOL) --finish $(libdir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000590
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000591uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000592 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencer12d79512004-11-12 02:27:36 +0000593 -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
Reid Spencere5487ba2004-10-24 07:53:21 +0000594
Reid Spencer4d71b662004-10-22 21:01:56 +0000595endif
596
Reid Spencer3a561f52004-10-23 20:04:14 +0000597#---------------------------------------------------------
598# Bytecode Library Targets:
599# If the user asked for a bytecode library to be built
600# with the BYTECODE_LIBRARY variable, then we provide
601# targets for building them.
602#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000603ifdef BYTECODE_LIBRARY
604
Reid Spencer776b8052004-12-03 06:04:35 +0000605# make the C and C++ compilers strip debug info out of bytecode libraries.
606BCCompile.C += -Wa,-strip-debug
607BCCompile.CXX += -Wa,-strip-debug
608
Reid Spencer9a2f1372004-12-02 09:28:21 +0000609all-local:: $(LibName.BCA)
610
611ifdef EXPORTED_SYMBOL_FILE
612BCLinkLib = $(LLVMGCC) -shared -nostdlib -Xlinker \
613 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
614
Reid Spencerf2ac1892004-12-16 07:36:08 +0000615$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000616 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000617 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
618 "(internalize)"
Chris Lattnerb0ea8642004-12-02 21:23:43 +0000619 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000620 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000621 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
Reid Spencer4d71b662004-10-22 21:01:56 +0000622else
Reid Spencerf2ac1892004-12-16 07:36:08 +0000623$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattner264ccbe2004-12-15 17:14:06 +0000624 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +0000625 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencerefd6bb32004-12-13 03:59:35 +0000626 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +0000627 $(Verb) $(LArchive) $@ $(ObjectsBC)
628
Reid Spencer4d71b662004-10-22 21:01:56 +0000629endif
630
Reid Spencer3a561f52004-10-23 20:04:14 +0000631clean-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000632ifneq ($(strip $(LibName.BCA)),)
633 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000634endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000635
Reid Spencer8f094f32004-12-13 07:28:21 +0000636ifdef BYTECODE_DESTINATION
637BytecodeDestDir := $(BYTECODE_DESTINATION)
638else
639BytecodeDestDir := $(libdir)
640endif
641
642DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
Reid Spencer9a2f1372004-12-02 09:28:21 +0000643
Reid Spencer44cb1b32004-12-03 20:08:48 +0000644install-bytecode-local:: $(DestBytecodeLib)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000645
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000646install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000647
Reid Spencer8f094f32004-12-13 07:28:21 +0000648$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000649 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
650 $(Verb) $(INSTALL) $(LibName.BCA) $@
Reid Spencere5487ba2004-10-24 07:53:21 +0000651
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000652uninstall-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +0000653 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000654 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000655
656endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000657
Reid Spencercc2d1e22004-10-30 09:19:36 +0000658#---------------------------------------------------------
659# ReLinked Library Targets:
660# If the user didn't explicitly forbid building a
661# relinked then we provide targets for building them.
662#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000663ifndef DONT_BUILD_RELINKED
Reid Spencer4d71b662004-10-22 21:01:56 +0000664
Reid Spencercc2d1e22004-10-30 09:19:36 +0000665all-local:: $(LibName.O)
666
Reid Spencerf2ac1892004-12-16 07:36:08 +0000667$(LibName.O): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000668 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000669 $(Verb) $(Relink) -o $@ $(ObjectsO)
Reid Spencer4d71b662004-10-22 21:01:56 +0000670
Reid Spencer3a561f52004-10-23 20:04:14 +0000671clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000672ifneq ($(strip $(LibName.O)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000673 -$(Verb) $(RM) -f $(LibName.O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000674endif
675
676DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
677
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000678install-local:: $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000679
Reid Spencercc2d1e22004-10-30 09:19:36 +0000680$(DestRelinkedLib): $(libdir) $(LibName.O)
Reid Spencer9af3b292004-11-01 07:50:27 +0000681 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000682 $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000683
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000684uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000685 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000686 -$(Verb) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000687
Chris Lattnere62dbe92002-07-23 17:56:16 +0000688endif
Chris Lattner760da062003-03-14 20:25:22 +0000689
Reid Spencercc2d1e22004-10-30 09:19:36 +0000690#---------------------------------------------------------
691# Archive Library Targets:
692# If the user wanted a regular archive library built,
693# then we provide targets for building them.
694#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000695ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +0000696
Reid Spencercc2d1e22004-10-30 09:19:36 +0000697all-local:: $(LibName.A)
698
Reid Spencerf2ac1892004-12-16 07:36:08 +0000699$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +0000700 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000701 -$(Verb) $(RM) -f $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000702 $(Verb) $(Archive) $@ $(ObjectsO)
703 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000704
Reid Spencer3a561f52004-10-23 20:04:14 +0000705clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000706ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000707 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +0000708endif
709
Reid Spencere5487ba2004-10-24 07:53:21 +0000710DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
711
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000712install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000713
Reid Spencercc2d1e22004-10-30 09:19:36 +0000714$(DestArchiveLib): $(libdir) $(LibName.A)
Reid Spencer9af3b292004-11-01 07:50:27 +0000715 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000716 $(Verb) $(MKDIR) $(libdir)
717 $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000718
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000719uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000720 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000721 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000722
723endif
724
725# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000726endif
727
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000728###############################################################################
729# Tool Build Rules: Build executable tool based on TOOLNAME option
730###############################################################################
731
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000732ifdef TOOLNAME
733
Reid Spencercc2d1e22004-10-30 09:19:36 +0000734#---------------------------------------------------------
Reid Spencer7c787c92004-11-29 07:17:07 +0000735# Handle the special "JIT" value for LLVM_LIBS which is a
736# shorthand for a bunch of libraries that get the correct
737# JIT support for a tool that runs JIT.
738#---------------------------------------------------------
739ifeq ($(LLVMLIBS),JIT)
740
741# Make sure we can get our own symbols in the tool
742Link += -dlopen self
743
744# Generic JIT libraries
745JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
746
747# You can enable the X86 JIT on a non-X86 host by setting the flag
748# ENABLE_X86_JIT on the make command line. If not, it will still be
749# enabled automagically on an X86 host.
750ifeq ($(ARCH), x86)
751 ENABLE_X86_JIT = 1
752endif
753
754# What the X86 JIT requires
755ifdef ENABLE_X86_JIT
Chris Lattner10ce4962004-12-16 19:40:10 +0000756 JIT_LIBS += LLVMX86
Reid Spencer7c787c92004-11-29 07:17:07 +0000757endif
758
759# You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
760# ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
761# enabled automagically on an SparcV9 host.
762ifeq ($(ARCH), Sparc)
763 ENABLE_SPARCV9_JIT = 1
764endif
765
766# What the Sparc JIT requires
767ifdef ENABLE_SPARCV9_JIT
768 JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
769 LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
770 LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
771 LLVMDataStructure.a LLVMSparcV9RegAlloc
772endif
773
774# You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
775# ENABLE_PPC_JIT on the make command line. If not, it will still be
776# enabled automagically on an PowerPC host.
777ifeq ($(ARCH), PowerPC)
778 ENABLE_PPC_JIT = 1
779endif
780
781# What the PowerPC JIT requires
782ifdef ENABLE_PPC_JIT
783 JIT_LIBS += LLVMPowerPC
784endif
785
786LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
787 LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
788 LLVMSystem.a $(PLATFORMLIBDL)
789endif
790
791#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000792# Set up variables for building a tool.
793#---------------------------------------------------------
Reid Spencer815cbcf2004-11-18 10:03:46 +0000794ifdef EXAMPLE_TOOL
795ToolBuildPath := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
796else
Reid Spencercc2d1e22004-10-30 09:19:36 +0000797ToolBuildPath := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +0000798endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000799ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
800ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
801LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
802LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
803ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
804LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
805ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
806LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000807
Reid Spencercc2d1e22004-10-30 09:19:36 +0000808#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000809# Tell make that we need to rebuild subdirectories before
810# we can link the tool. This affects things like LLI which
811# has library subdirectories.
812#---------------------------------------------------------
813$(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000814
Reid Spencercc2d1e22004-10-30 09:19:36 +0000815#---------------------------------------------------------
816# Provide targets for building the tools
817#---------------------------------------------------------
818all-local:: $(ToolBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +0000819
Reid Spencer3a561f52004-10-23 20:04:14 +0000820clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +0000821ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000822 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +0000823endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000824
Reid Spencer815cbcf2004-11-18 10:03:46 +0000825ifdef EXAMPLE_TOOL
826$(ToolBuildPath): $(ExmplDir)/.dir
827else
828$(ToolBuildPath): $(ToolDir)/.dir
829endif
830
Reid Spencerf2ac1892004-12-16 07:36:08 +0000831$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +0000832 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000833 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
834 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
Reid Spencer9af3b292004-11-01 07:50:27 +0000835 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +0000836
837DestTool = $(bindir)/$(TOOLNAME)
838
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000839install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000840
Reid Spencercc2d1e22004-10-30 09:19:36 +0000841$(DestTool): $(bindir) $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +0000842 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000843 $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000844
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000845uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +0000846 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000847 -$(Verb) $(RM) -f $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000848
Reid Spencer4d71b662004-10-22 21:01:56 +0000849endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000850
Reid Spencercc2d1e22004-10-30 09:19:36 +0000851###############################################################################
852# Object Build Rules: Build object files based on sources
853###############################################################################
854
855# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000856ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000857
Reid Spencercc2d1e22004-10-30 09:19:36 +0000858#---------------------------------------------------------
859# Create .lo files in the ObjDir directory from the .cpp and .c files...
860#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000861ifdef SHARED_LIBRARY
862
Chris Lattner3c473472004-12-16 17:28:50 +0000863$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000864 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000865 $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
866 then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
867 else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000868
Chris Lattner3c473472004-12-16 17:28:50 +0000869$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000870 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000871 $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
872 then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
873 else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000874
Reid Spencercc2d1e22004-10-30 09:19:36 +0000875#---------------------------------------------------------
876# Create .o files in the ObjDir directory from the .cpp and .c files...
877#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000878else
Reid Spencer4d71b662004-10-22 21:01:56 +0000879
Chris Lattner3c473472004-12-16 17:28:50 +0000880$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000881 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000882 $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
883 then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
884 else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000885
Chris Lattner3c473472004-12-16 17:28:50 +0000886$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000887 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000888 $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
889 then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
890 else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000891
892endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000893
Reid Spencercc2d1e22004-10-30 09:19:36 +0000894#---------------------------------------------------------
895# Create .bc files in the ObjDir directory from .cpp and .c files...
896#---------------------------------------------------------
Chris Lattner3c473472004-12-16 17:28:50 +0000897$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000898 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000899 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
900 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
901 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000902
Chris Lattner3c473472004-12-16 17:28:50 +0000903$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000904 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000905 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
906 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
907 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000908
Reid Spencercc2d1e22004-10-30 09:19:36 +0000909# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +0000910else
911
Reid Spencer3a561f52004-10-23 20:04:14 +0000912ifdef SHARED_LIBRARY
913
Chris Lattner3c473472004-12-16 17:28:50 +0000914$(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000915 $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000916 $(LTCompile.CXX) $< -o $@
917
Chris Lattner3c473472004-12-16 17:28:50 +0000918$(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerc3719842004-12-16 18:26:53 +0000919 $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000920 $(LTCompile.C) $< -o $@
921
922else
Reid Spencer4d71b662004-10-22 21:01:56 +0000923
Chris Lattner3c473472004-12-16 17:28:50 +0000924$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000925 $(Echo) "Compiling $*.cpp for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000926 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000927
Chris Lattner3c473472004-12-16 17:28:50 +0000928$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Reid Spencerc3719842004-12-16 18:26:53 +0000929 $(Echo) "Compiling $*.c for $(BuildMode) build"
Reid Spencer3a561f52004-10-23 20:04:14 +0000930 $(Compile.C) $< -o $@
931endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000932
Chris Lattner3c473472004-12-16 17:28:50 +0000933$(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000934 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000935 $(BCCompile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000936
Chris Lattner3c473472004-12-16 17:28:50 +0000937$(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
Reid Spencer9af3b292004-11-01 07:50:27 +0000938 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Reid Spencer8676b7e2004-10-31 18:52:15 +0000939 $(BCCompile.C) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000940
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000941endif
942
Reid Spencercc2d1e22004-10-30 09:19:36 +0000943#---------------------------------------------------------
944# Provide rule to build .bc files from .ll sources,
945# regardless of dependencies
946#---------------------------------------------------------
947$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +0000948 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +0000949 $(Verb) $(LLVMAS) $< -f -o $@
950
951###############################################################################
952# TABLEGEN: Provide rules for running tblgen to produce *.inc files
953###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +0000954
Reid Spencer4d71b662004-10-22 21:01:56 +0000955ifdef TARGET
956
Reid Spencercc2d1e22004-10-30 09:19:36 +0000957TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
958INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner3c473472004-12-16 17:28:50 +0000959INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
960.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000961
Chris Lattner3c473472004-12-16 17:28:50 +0000962# All of these files depend on tblgen and the .td files.
963$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +0000964
Chris Lattner23ee7952004-12-16 17:38:56 +0000965# INCFiles rule: All of the tblgen generated files are emitted to
966# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
967# us to only "touch" the real file if the contents of it change. IOW, if
968# tblgen is modified, all of the .inc.tmp files are regereated, but no
969# dependencies of the .inc files are, unless the contents of the .inc file
970# changes.
971$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerc3719842004-12-16 18:26:53 +0000972 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner3c473472004-12-16 17:28:50 +0000973
974$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
975$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000976 $(Echo) "Building $(<F) register names with tblgen"
977 $(Verb) $(TableGen) -gen-register-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000978
Chris Lattner3c473472004-12-16 17:28:50 +0000979$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
980$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000981 $(Echo) "Building $(<F) register information header with tblgen"
982 $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000983
Chris Lattner3c473472004-12-16 17:28:50 +0000984$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
985$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000986 $(Echo) "Building $(<F) register info implementation with tblgen"
987 $(Verb) $(TableGen) -gen-register-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000988
Chris Lattner3c473472004-12-16 17:28:50 +0000989$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
990$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000991 $(Echo) "Building $(<F) instruction names with tblgen"
992 $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000993
Chris Lattner3c473472004-12-16 17:28:50 +0000994$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
995$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +0000996 $(Echo) "Building $(<F) instruction information with tblgen"
997 $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000998
Chris Lattner3c473472004-12-16 17:28:50 +0000999$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1000$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001001 $(Echo) "Building $(<F) assembly writer with tblgen"
1002 $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001003
Chris Lattner02a4f902004-12-16 17:34:04 +00001004$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1005$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1006 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Reid Spencercc2d1e22004-10-30 09:19:36 +00001007 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001008
Chris Lattner3c473472004-12-16 17:28:50 +00001009$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1010$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001011 $(Echo) "Building $(<F) code emitter with tblgen"
1012 $(Verb) $(TableGen) -gen-emitter -o $@ $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001013
Reid Spencer3a561f52004-10-23 20:04:14 +00001014clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001015 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001016
1017endif
Chris Lattner481cc7c2003-08-15 02:18:35 +00001018
Reid Spencercc2d1e22004-10-30 09:19:36 +00001019###############################################################################
1020# LEX AND YACC: Provide rules for generating sources with lex and yacc
1021###############################################################################
Chris Lattnere8996782003-01-16 22:44:19 +00001022
Reid Spencercc2d1e22004-10-30 09:19:36 +00001023#---------------------------------------------------------
1024# Provide rules for generating a .cpp source file from
1025# (f)lex input sources.
1026#---------------------------------------------------------
1027
Reid Spencer3d659492004-11-02 16:36:03 +00001028LexFiles := $(filter %.l,$(Sources))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001029
Reid Spencer3d659492004-11-02 16:36:03 +00001030ifneq ($(LexFiles),)
1031
1032LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001033
1034.PRECIOUS: $(LexOutput)
1035
1036# Note the extra sed filtering here, used to cut down on the warnings emited
1037# by GCC. The last line is a gross hack to work around flex aparently not
1038# being able to resize the buffer on a large token input. Currently, for
1039# uninitialized string buffers in LLVM we can generate very long tokens, so
1040# this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +00001041# FIXME. (f.e. char Buffer[10000] )
Chris Lattner00950542001-06-06 20:29:01 +00001042%.cpp: %.l
Reid Spencerc2ef8cd2004-12-10 19:44:16 +00001043 $(Echo) Flexing $*.l
Reid Spencercc2d1e22004-10-30 09:19:36 +00001044 $(Verb) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +00001045 $(SED) 's/void yyunput/inline void yyunput/' | \
1046 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1047 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer80f0ef72004-10-28 00:41:43 +00001048 > $@
Chris Lattner00950542001-06-06 20:29:01 +00001049
Reid Spencer9af3b292004-11-01 07:50:27 +00001050clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001051 -$(Verb) $(RM) -f $(LexOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001052 $(Verb) $(RM) -f $(LexOutput)
Reid Spencer9af3b292004-11-01 07:50:27 +00001053
Reid Spencercc2d1e22004-10-30 09:19:36 +00001054endif
1055
1056#---------------------------------------------------------
1057# Provide rules for generating a .cpp and .h source files
1058# from yacc (bison) input sources.
1059#---------------------------------------------------------
1060
Reid Spencer3d659492004-11-02 16:36:03 +00001061YaccFiles := $(filter %.y,$(Sources))
1062ifneq ($(YaccFiles),)
1063YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001064
1065.PRECIOUS: $(YaccOutput)
1066
1067# Cancel built-in rules for yacc
1068%.c: %.y
1069%.cpp: %.y
1070%.h: %.y
1071
Chris Lattner00950542001-06-06 20:29:01 +00001072# Rule for building the bison parsers...
Chris Lattner00950542001-06-06 20:29:01 +00001073%.cpp %.h : %.y
Reid Spencercc2d1e22004-10-30 09:19:36 +00001074 $(Echo) "Bisoning $*.y"
1075 $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1076 $(Verb) $(MV) -f $*.tab.c $*.cpp
1077 $(Verb) $(MV) -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +00001078
Reid Spencer9af3b292004-11-01 07:50:27 +00001079clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001080 -$(Verb) $(RM) -f $(YaccOutput)
Reid Spencer3d659492004-11-02 16:36:03 +00001081 $(Verb) $(RM) -f $(YaccOutput)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001082endif
Chris Lattner00950542001-06-06 20:29:01 +00001083
Reid Spencercc2d1e22004-10-30 09:19:36 +00001084###############################################################################
1085# OTHER RULES: Other rules needed
1086###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001087
Chris Lattner30440c62003-01-16 21:06:18 +00001088# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +00001089ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +00001090%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +00001091 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +00001092else
1093%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +00001094 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +00001095endif
Chris Lattner30440c62003-01-16 21:06:18 +00001096
John Criswell7f336952003-09-06 14:44:17 +00001097# This rules ensures that header files that are removed still have a rule for
1098# which they can be "generated." This allows make to ignore them and
1099# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +00001100%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +00001101
Reid Spencercc2d1e22004-10-30 09:19:36 +00001102# Define clean-local to clean the current directory. Note that this uses a
1103# very conservative approach ensuring that empty variables do not cause
1104# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +00001105clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001106ifneq ($(strip $(ObjDir)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001107 -$(Verb) $(RM) -rf $(ObjDir)
Reid Spencere5487ba2004-10-24 07:53:21 +00001108endif
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001109 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001110ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001111 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001112endif
John Criswell7a73b802003-06-30 21:59:07 +00001113
Reid Spencer3d659492004-11-02 16:36:03 +00001114clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001115 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +00001116
Reid Spencercc2d1e22004-10-30 09:19:36 +00001117# Build tags database for Emacs/Xemacs:
Reid Spencer12d79512004-11-12 02:27:36 +00001118tags:: TAGS CTAGS
1119
Reid Spencercc2d1e22004-10-30 09:19:36 +00001120TAGS:
Reid Spencer12d79512004-11-12 02:27:36 +00001121 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1122 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1123 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1124 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1125 -name '*.cpp' -o -name '*.h' | \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001126 $(ETAGS) $(ETAGSFLAGS) -
1127
Reid Spencer12d79512004-11-12 02:27:36 +00001128CTAGS:
1129 find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1130 $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1131 $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1132 $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1133 \( -name '*.cpp' -o -name '*.h' \) -print | \
1134 ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1135
1136
Reid Spencer3a561f52004-10-23 20:04:14 +00001137###############################################################################
1138# DEPENDENCIES: Include the dependency files if we should
1139###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +00001140ifndef DISABLE_AUTO_DEPENDENCIES
1141
Reid Spencer3a561f52004-10-23 20:04:14 +00001142# If its not one of the cleaning targets
Reid Spencercc2d1e22004-10-30 09:19:36 +00001143ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +00001144
Reid Spencer3a561f52004-10-23 20:04:14 +00001145# Get the list of dependency files
Reid Spencercc2d1e22004-10-30 09:19:36 +00001146DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
Reid Spencer9af3b292004-11-01 07:50:27 +00001147DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +00001148
Reid Spencer3a561f52004-10-23 20:04:14 +00001149-include /dev/null $(DependFiles)
1150
John Criswelld741bcf2003-08-12 18:51:51 +00001151endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +00001152
Reid Spencercc2d1e22004-10-30 09:19:36 +00001153endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001154
Reid Spencer151f8ba2004-10-25 08:27:37 +00001155###############################################################################
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001156# CHECK: Running the test suite
1157###############################################################################
1158
1159check::
1160 $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1161 if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1162 $(EchoCmd) Running test suite ; \
1163 $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1164 TESTSUITE=$(TESTSUITE) ; \
1165 else \
1166 $(EchoCmd) No Makefile in test directory ; \
1167 fi ; \
1168 else \
1169 $(EchoCmd) No test directory ; \
1170 fi
1171
1172###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001173# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +00001174###############################################################################
1175
Reid Spencere45ebfa2004-10-26 07:09:33 +00001176#------------------------------------------------------------------------
1177# Define distribution related variables
1178#------------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +00001179DistName := $(LLVM_TARBALL_NAME)
1180DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001181TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001182DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1183DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
1184DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1185DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1186 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001187 Makefile.config.in configure autoconf
1188DistOther := $(notdir $(wildcard \
1189 $(BUILD_SRC_DIR)/*.h \
1190 $(BUILD_SRC_DIR)/*.td \
1191 $(BUILD_SRC_DIR)/*.def \
1192 $(BUILD_SRC_DIR)/*.ll \
1193 $(BUILD_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00001194DistSubDirs := $(SubDirs)
Reid Spencerfbbf3072004-11-29 05:00:33 +00001195DistSources = $(Sources) $(EXTRA_DIST)
1196DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00001197
Reid Spencere45ebfa2004-10-26 07:09:33 +00001198#------------------------------------------------------------------------
1199# We MUST build distribution with OBJ_DIR != SRC_DIR
1200#------------------------------------------------------------------------
1201ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1202dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001203 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00001204
Reid Spencere45ebfa2004-10-26 07:09:33 +00001205else
1206
Reid Spencere45ebfa2004-10-26 07:09:33 +00001207#------------------------------------------------------------------------
1208# Prevent catastrophic remove
1209#------------------------------------------------------------------------
1210ifeq ($(LLVM_TARBALL_NAME),)
1211$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
1212endif
1213
1214#------------------------------------------------------------------------
1215# Prevent attempt to run dist targets from anywhere but the top level
1216#------------------------------------------------------------------------
1217ifneq ($(LEVEL),.)
1218
1219dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001220 $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001221
1222else
1223
1224#------------------------------------------------------------------------
1225# Provide the top level targets
1226#------------------------------------------------------------------------
1227
Reid Spencercc2d1e22004-10-30 09:19:36 +00001228dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001229
Reid Spencer345235ca2004-12-04 22:34:09 +00001230$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001231 $(Echo) Packing gzipped distribution tar file.
Reid Spencerfbbf3072004-11-29 05:00:33 +00001232 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1233 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00001234
Reid Spencercc2d1e22004-10-30 09:19:36 +00001235dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001236
Reid Spencer345235ca2004-12-04 22:34:09 +00001237$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001238 $(Echo) Packing bzipped distribution tar file.
Reid Spencerfbbf3072004-11-29 05:00:33 +00001239 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1240 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001241
Reid Spencercc2d1e22004-10-30 09:19:36 +00001242dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001243
Reid Spencer345235ca2004-12-04 22:34:09 +00001244$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00001245 $(Echo) Packing zipped distribution file.
1246 $(Verb) rm -f $(DistZip)
1247 $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001248
1249dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001250 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001251
1252DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1253
Reid Spencer345235ca2004-12-04 22:34:09 +00001254dist-check:: $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001255 $(Echo) Checking distribution tar file.
1256 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001257 $(RM) -rf $(DistCheckDir) ; \
1258 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00001259 $(Verb) $(MKDIR) $(DistCheckDir)
1260 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001261 $(MKDIR) $(DistCheckDir)/build && \
1262 $(MKDIR) $(DistCheckDir)/install && \
1263 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1264 cd build && \
1265 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1266 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
Reid Spencer345235ca2004-12-04 22:34:09 +00001267 $(MAKE) all && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001268 $(MAKE) check && \
1269 $(MAKE) install && \
1270 $(MAKE) uninstall && \
1271 $(MAKE) dist && \
1272 $(MAKE) clean && \
1273 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001274 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00001275
1276dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001277 $(Echo) Cleaning distribution files
Reid Spencer345235ca2004-12-04 22:34:09 +00001278 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1279 $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001280
1281endif
1282
1283#------------------------------------------------------------------------
1284# Provide the recursive distdir target for building the distribution directory
1285#------------------------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +00001286distdir: $(DistDir)/.makedistdir
1287$(DistDir)/.makedistdir: $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001288 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001289 if test -d "$(DistDir)" ; then \
1290 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1291 exit 1 ; \
1292 fi ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001293 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001294 $(RM) -rf $(DistDir); \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001295 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001296 $(MAKE) all ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001297 fi
Reid Spencerfbbf3072004-11-29 05:00:33 +00001298 $(Echo) Building Distribution Directory $(DistDir)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001299 $(Verb) $(MKDIR) $(DistDir)
1300 $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001301 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1302 for file in $(DistFiles) ; do \
1303 case "$$file" in \
Reid Spencer345235ca2004-12-04 22:34:09 +00001304 $(BUILD_SRC_DIR)/*) \
1305 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1306 ;; \
1307 $(BUILD_SRC_ROOT)/*) \
1308 file=`echo "$$file" | \
1309 sed "s#^$$srcrootstrip/##"` \
1310 ;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001311 esac; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001312 if test -f "$(BUILD_SRC_DIR)/$$file" || \
1313 test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1314 from_dir="$(BUILD_SRC_DIR)" ; \
1315 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001316 from_dir=. ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001317 fi ; \
1318 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001319 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1320 to_dir="$(DistDir)/$$dir"; \
1321 $(MKDIR) "$$to_dir" ; \
1322 else \
1323 to_dir="$(DistDir)"; \
1324 fi; \
1325 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1326 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001327 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001328 fi ; \
1329 if test -d "$$from_dir/$$file"; then \
1330 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1331 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00001332 $(CP) -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001333 fi; \
Reid Spencerc3719842004-12-16 18:26:53 +00001334 $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001335 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00001336 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001337 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00001338 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001339 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer345235ca2004-12-04 22:34:09 +00001340 $(EchoCmd) "===== WARNING: Distribution Source " \
1341 "$$from_dir/$$file Not Found!" ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00001342 elif test "$(Verb)" != '@' ; then \
1343 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001344 fi; \
1345 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00001346 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001347 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001348 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001349 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer345235ca2004-12-04 22:34:09 +00001350 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1351 exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001352 fi; \
1353 done
Reid Spencer345235ca2004-12-04 22:34:09 +00001354 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1355 $(EchoCmd) Eliminating CVS directories from distribution ; \
1356 $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1357 $(MAKE) dist-hook ; \
1358 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1359 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1360 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1361 -o ! -type d ! -perm -444 -exec \
1362 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1363 || chmod -R a+r $(DistDir) ; \
1364 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +00001365
Reid Spencercc2d1e22004-10-30 09:19:36 +00001366# This is invoked by distdir target, define it as a no-op to avoid errors if not
1367# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00001368dist-hook::
1369
Reid Spencere53e3972004-10-22 23:06:30 +00001370endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001371
1372###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00001373# TOP LEVEL - targets only to apply at the top level directory
1374###############################################################################
1375
1376ifeq ($(LEVEL),.)
1377
1378#------------------------------------------------------------------------
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001379# Install support for the project's include files:
Reid Spencere5487ba2004-10-24 07:53:21 +00001380#------------------------------------------------------------------------
1381install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001382 $(Echo) Installing include files
1383 $(Verb) $(MKDIR) $(includedir)
1384 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001385 cd $(BUILD_SRC_ROOT)/include && \
1386 find . -path '*/Internal' -prune -o '(' -type f \
1387 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1388 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1389 fi
1390
1391uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001392 $(Echo) Uninstalling include files
1393 $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
Reid Spencere5487ba2004-10-24 07:53:21 +00001394 cd $(BUILD_SRC_ROOT)/include && \
1395 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1396 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1397 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1398 fi
1399
Reid Spencere5487ba2004-10-24 07:53:21 +00001400endif
1401
Reid Spencer4d71b662004-10-22 21:01:56 +00001402#------------------------------------------------------------------------
1403# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00001404#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001405printvars::
Reid Spencer9af3b292004-11-01 07:50:27 +00001406 $(Echo) "BuildMode : " '$(BuildMode)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001407 $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1408 $(Echo) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1409 $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1410 $(Echo) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1411 $(Echo) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1412 $(Echo) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1413 $(Echo) "libdir : " '$(libdir)'
1414 $(Echo) "bindir : " '$(bindir)'
1415 $(Echo) "sysconfdir : " '$(sysconfdir)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001416 $(Echo) "UserTargets : " '$(UserTargets)'
1417 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1418 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1419 $(Echo) "ObjDir : " '$(ObjDir)'
1420 $(Echo) "LibDir : " '$(LibDir)'
1421 $(Echo) "ToolDir : " '$(ToolDir)'
Reid Spencer815cbcf2004-11-18 10:03:46 +00001422 $(Echo) "ExmplDir : " '$(ExmplDir)'
Reid Spencer7980ea42004-12-05 05:17:22 +00001423 $(Echo) "Sources : " '$(Sources)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001424 $(Echo) "TDFiles : " '$(TDFiles)'
1425 $(Echo) "INCFiles : " '$(INCFiles)'
Chris Lattner3c473472004-12-16 17:28:50 +00001426 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencercc2d1e22004-10-30 09:19:36 +00001427 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1428 $(Echo) "Compile.C : " '$(Compile.C)'
1429 $(Echo) "Archive : " '$(Archive)'
Reid Spencer3d659492004-11-02 16:36:03 +00001430 $(Echo) "YaccFiles : " '$(YaccFiles)'
1431 $(Echo) "LexFiles : " '$(LexFiles)'
Reid Spencer7980ea42004-12-05 05:17:22 +00001432 $(Echo) "Module : " '$(Module)'