blob: e8a0697e60ef66b90aa8d0bd5ffc175a45cae9af [file] [log] [blame]
Vikram S. Adved60aede2002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner00950542001-06-06 20:29:01 +00002#
3# This file is included by all of the LLVM makefiles. This file defines common
4# rules to do things like compile a .cpp file or generate dependancy info.
5# These are platform dependant, so this is the file used to specify these
6# system dependant operations.
7#
Vikram S. Advec214e712002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner00950542001-06-06 20:29:01 +000010#
11# 1. LEVEL - The level of the current subdirectory from the top of the
12# MagicStats view. This level should be expressed as a path, for
13# example, ../.. for two levels deep.
14#
15# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnera8abc222002-09-18 03:22:27 +000016# so that each of the targets "all", "install", and "clean" each build
17# the subdirectories before the local target. DIRS are guaranteed to be
18# built in order.
Chris Lattner00950542001-06-06 20:29:01 +000019#
Chris Lattnera8abc222002-09-18 03:22:27 +000020# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21# built in any order. All DIRS are built in order before PARALLEL_DIRS are
22# built, which are then built in any order.
23#
24# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner00950542001-06-06 20:29:01 +000025# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000026# in the current directory. Also, if you want to build files in addition
27# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000028#
Chris Lattner694c5df2003-05-15 21:28:55 +000029# 5. SourceDir - If specified, this specifies a directory that the source files
30# are in, if they are not in the current directory. This should include a
31# trailing / character.
32#
John Criswell7a73b802003-06-30 21:59:07 +000033# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000034#
John Criswell7a73b802003-06-30 21:59:07 +000035# 7. LLVM_OBJ_ROOT - If specified, points to the top directory where LLVM
36# object files are placed.
37#
38# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39# and usually the source code too (unless SourceDir is set).
40#
41# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
42#
43# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
44#
45# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
46# placed.
47#
48# For building,
49# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT, and
50# LLVM_OBJ_ROOT = BUILD_OBJ_ROOT.
Vikram S. Adved60aede2002-07-09 12:04:21 +000051#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000052
John Criswell2a6530f2003-06-27 16:58:44 +000053#
Vikram S. Advec214e712002-08-29 23:28:46 +000054# Configuration file to set paths specific to local installation of LLVM
55#
56include $(LEVEL)/Makefile.config
57
John Criswell8bff5092003-06-11 13:55:44 +000058###########################################################################
59# Directory Configuration
60# This section of the Makefile determines what is where. To be
61# specific, there are several locations that need to be defined:
62#
63# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
64# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
65#
66# o BUILD_SRC_DIR : The directory containing the code to build.
67# o BUILD_SRC_ROOT : The root directory of the code to build.
68#
69# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
70# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
71#
72###########################################################################
73
74#
75# Set the source build directory. That is almost always the current directory.
76#
77ifndef BUILD_SRC_DIR
78BUILD_SRC_DIR = $(shell pwd)
79endif
80
81#
82# Set the source root directory.
83#
84ifndef BUILD_SRC_ROOT
John Criswell890d5bd2003-06-16 19:14:31 +000085BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell8bff5092003-06-11 13:55:44 +000086endif
87
88#
John Criswell7a73b802003-06-30 21:59:07 +000089# Determine the path of the source tree relative from $HOME (the mythical
90# home directory).
91#
92HOME_OBJ_ROOT := $(OBJ_ROOT)/$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
93
94#
John Criswell8bff5092003-06-11 13:55:44 +000095# Set the object build directory. Its location depends upon the source path
96# and where object files should go.
97#
98ifndef BUILD_OBJ_DIR
99ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000100BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +0000101else
John Criswell7a73b802003-06-30 21:59:07 +0000102BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
John Criswell8bff5092003-06-11 13:55:44 +0000103endif
104endif
105
106#
107# Set the root of the object directory.
108#
109ifndef BUILD_OBJ_ROOT
110ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000111BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000112else
John Criswell7a73b802003-06-30 21:59:07 +0000113BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000114endif
115endif
116
117#
118# Set the LLVM source directory.
119# It is typically the root directory of what we're compiling now.
120#
121ifndef LLVM_SRC_ROOT
122LLVM_SRC_ROOT = $(BUILD_SRC_ROOT)
123endif
124
125#
126# Set the LLVM object directory.
127#
128ifndef LLVM_OBJ_ROOT
129LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT)
130endif
131
John Criswell7a73b802003-06-30 21:59:07 +0000132###########################################################################
133# Default Targets:
134# The following targets are the standard top level targets for
135# building.
136###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +0000137
Chris Lattneredf1f232002-07-23 19:21:31 +0000138ifdef SHARED_LIBRARY
139# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +0000140all:: dynamic
Chris Lattneredf1f232002-07-23 19:21:31 +0000141endif
142
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000143# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000144all ::
145
146# Default for install is to at least build everything...
147install ::
148
John Criswell8bff5092003-06-11 13:55:44 +0000149# Default rule for test. It ensures everything has a test rule
150test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000151
John Criswell7a73b802003-06-30 21:59:07 +0000152# Print out the directories used for building
153prdirs::
154 echo "Home Offset : " $(HOME_OBJ_ROOT);
155 echo "Build Source Root: " $(BUILD_SRC_ROOT);
156 echo "Build Source Dir : " $(BUILD_SRC_DIR);
157 echo "Build Object Root: " $(BUILD_OBJ_ROOT);
158 echo "Build Object Dir : " $(BUILD_OBJ_DIR);
159 echo "LLVM Source Root: " $(LLVM_SRC_ROOT);
160 echo "LLVM Object Root: " $(LLVM_OBJ_ROOT);
161
162###########################################################################
163# Miscellaneous paths and commands:
164# This section defines various configuration macros, such as where
165# to find burg, tblgen, and libtool.
166###########################################################################
167
Chris Lattner00950542001-06-06 20:29:01 +0000168#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000169# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000170#--------------------------------------------------------------------
171
172#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000173#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000174#DocInstDir=/usr/doc/xxx
175
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000176BURG_OPTS = -I
177
John Criswell8bff5092003-06-11 13:55:44 +0000178PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000179
Chris Lattner760da062003-03-14 20:25:22 +0000180ifdef ENABLE_PROFILING
181 ENABLE_OPTIMIZED = 1
182 CONFIGURATION := Profile
183else
184 ifdef ENABLE_OPTIMIZED
185 CONFIGURATION := Release
186 else
187 CONFIGURATION := Debug
188 endif
189endif
190
John Criswell7a73b802003-06-30 21:59:07 +0000191#
192# Enable this for profiling support with 'gprof'
193# This automatically enables optimized builds.
194#
195ifdef ENABLE_PROFILING
196 PROFILE = -pg
197endif
198
199#
200# Suffixes for library compilation rules
201#
202.SUFFIXES: .so
203
John Criswell8bff5092003-06-11 13:55:44 +0000204###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000205# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000206# These variables describe various library locations:
207#
208# DEST* = Location of where libraries that are built will be placed.
209# LLVM* = Location of LLVM libraries used for linking.
210# PROJ* = Location of previously built libraries used for linking.
211###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000212
John Criswell8bff5092003-06-11 13:55:44 +0000213# Libraries that are being built
214DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
215DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
216DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
217DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000218
John Criswell8bff5092003-06-11 13:55:44 +0000219# LLVM libraries used for linking
220LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
221LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
222LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
223LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000224
John Criswell8bff5092003-06-11 13:55:44 +0000225# Libraries that were built that will now be used for linking
226PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
227PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
228PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
229PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000230
John Criswell8bff5092003-06-11 13:55:44 +0000231###########################################################################
232# Tool Locations
233# These variables describe various tool locations:
234#
235# DEST* = Location of where tools that are built will be placed.
236# LLVM* = Location of LLVM tools used for building.
237# PROJ* = Location of previously built tools used for linking.
238###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000239
John Criswell8bff5092003-06-11 13:55:44 +0000240DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
241DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
242DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
243DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
244
245LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
246LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
247LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
248LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
249
250PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
251PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
252PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
253PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000254
John Criswell7a73b802003-06-30 21:59:07 +0000255#
256# Libtool is found in the current directory.
257#
258ifdef VERBOSE
259LIBTOOL=$(LLVM_SRC_ROOT)/libtool
260else
261LIBTOOL=$(LLVM_SRC_ROOT)/libtool --silent
262endif
263
264#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000265# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000266#
Chris Lattner760da062003-03-14 20:25:22 +0000267ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000268VERB := @
269endif
270
John Criswell7a73b802003-06-30 21:59:07 +0000271###########################################################################
272# Miscellaneous paths and commands (part deux):
273# This section defines various configuration macros, such as where
274# to find burg, tblgen, and libtool.
275###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000276
John Criswell7a73b802003-06-30 21:59:07 +0000277#--------------------------------------------------------------------------
278# Special tools used while building the LLVM tree. Burg is built as part
279# of the utils directory.
280#--------------------------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000281BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000282RunBurg := $(BURG) $(BURG_OPTS)
283
John Criswell8bff5092003-06-11 13:55:44 +0000284TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000285
Chris Lattner00950542001-06-06 20:29:01 +0000286
John Criswell8bff5092003-06-11 13:55:44 +0000287###########################################################################
288# Compile Time Flags
289###########################################################################
290
291#
John Criswell7a73b802003-06-30 21:59:07 +0000292# Include both the project headers and the LLVM headers for compilation and
293# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000294#
295CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000296
Vikram S. Advefeeae582002-09-18 11:55:13 +0000297# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000298ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000299STRIP = $(PLATFORMSTRIPOPTS)
300STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000301endif
302
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000303# Allow gnu extensions...
304CPPFLAGS += -D_GNU_SOURCE
305
Chris Lattnerc7acf812002-01-23 05:46:01 +0000306# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000307CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000308CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000309
John Criswell7a73b802003-06-30 21:59:07 +0000310#
311# Compile commands with libtool.
312#
313Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
314CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
315
316#
317# Add the LLVM specific "-only-static" option so that we only compile .o files
318# once when not building a shared library.
319#
320# For shared libraries, we will end up building twice, but that doesn't happen
321# very often, so we'll let it go.
322#
323ifndef SHARED_LIBRARY
324Compile := $(Compile) -only-static
325CompileC := $(CompileC) -only-static
326endif
327
Chris Lattner172b6482002-09-22 02:47:15 +0000328# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000329CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000330CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
331CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000332
Chris Lattner172b6482002-09-22 02:47:15 +0000333# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000334CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000335CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
336CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000337
John Criswell7a73b802003-06-30 21:59:07 +0000338###########################################################################
339# Link Time Options
340###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000341
John Criswell7a73b802003-06-30 21:59:07 +0000342#
Chris Lattner00950542001-06-06 20:29:01 +0000343# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000344# (Note that we always link with the C++ compiler).
345#
Chris Lattner1917e952002-07-31 21:32:05 +0000346ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
John Criswell7a73b802003-06-30 21:59:07 +0000347Link := $(PURIFY) $(LIBTOOL) --mode=link $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000348else
John Criswell7a73b802003-06-30 21:59:07 +0000349Link := $(LIBTOOL) --mode=link $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000350endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000351
John Criswell7a73b802003-06-30 21:59:07 +0000352# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000353LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
354LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
355LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000356
Chris Lattnere62dbe92002-07-23 17:56:16 +0000357# Create one .o file from a bunch of .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000358Relink = ${LIBTOOL} --mode=link $(CXX)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000359
Chris Lattner4bb13b82002-09-13 22:14:47 +0000360# MakeSO - Create a .so file from a .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000361#MakeSO := $(LIBTOOL) --mode=link $(CXX) $(MakeSharedObjectOption)
362#MakeSOO := $(MakeSO) -O3
363#MakeSOP := $(MakeSOO) $(PROFILE)
364
365#
366# Configure where the item being compiled should go.
367#
368ifdef SHARED_LIBRARY
369Link := $(Link) -rpath $(DESTLIBCURRENT)
370endif
371
372ifdef TOOLNAME
373Link := $(Link) -rpath $(DESTTOOLCURRENT)
374endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000375
Chris Lattner00950542001-06-06 20:29:01 +0000376# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000377Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
378DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000379
380# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000381AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000382
383#----------------------------------------------------------
384
385# Source includes all of the cpp files, and objects are derived from the
386# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000387# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000388#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000389ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000390Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000391endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000392
John Criswell7a73b802003-06-30 21:59:07 +0000393LObjs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
394LObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(LObjs))
395LObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(LObjs))
396LObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(LObjs))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000397
Chris Lattner00950542001-06-06 20:29:01 +0000398#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000399# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000400#---------------------------------------------------------
401
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000402ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000403all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000404 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000405 (cd $$dir; $(MAKE) $@) || exit 1; \
406 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000407endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000408
409# Handle PARALLEL_DIRS
410ifdef PARALLEL_DIRS
411all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
412install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
413clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000414test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000415
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000416%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000417 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000418endif
419
John Criswell7a73b802003-06-30 21:59:07 +0000420# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000421ifdef OPTIONAL_DIRS
422all install clean test ::
423 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
424 if [ -d $$dir ]; \
425 then\
426 (cd $$dir; $(MAKE) $@) || exit 1; \
427 fi \
428 done
429endif
430
John Criswell7a73b802003-06-30 21:59:07 +0000431###########################################################################
432# Library Build Rules:
433#
Chris Lattner00950542001-06-06 20:29:01 +0000434#---------------------------------------------------------
435# Handle the LIBRARYNAME option - used when building libs...
436#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000437#
438# When libraries are built, they are allowed to optionally define the
439# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
440# from being built for the library. This .o files may then be linked to by a
441# tool if the tool does not need (or want) the semantics a .a file provides
442# (linking in only object files that are "needed"). If a library is never to
443# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
444# BUILD_ARCHIVE instead.
445#
446# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000447# it's built as a .o file, then all of the constituent .o files in it will be
Chris Lattnere62dbe92002-07-23 17:56:16 +0000448# linked into tools (for example gccas) even if they only use one of the parts
449# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000450###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000451
452ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000453
Chris Lattner2a548c52002-09-16 22:36:42 +0000454# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000455LIBRARYNAME := $(strip $(LIBRARYNAME))
456
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000457LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
458LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
459LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
460LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
461LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
462LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
463LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
464LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
465LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000466
John Criswell7a73b802003-06-30 21:59:07 +0000467#--------------------------------------------------------------------
468# Library Targets
469# Modify the top level targets to build the desired libraries.
470#--------------------------------------------------------------------
471
Chris Lattner760da062003-03-14 20:25:22 +0000472# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000473dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000474
Chris Lattner760da062003-03-14 20:25:22 +0000475# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000476ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000477all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000478endif
Chris Lattner760da062003-03-14 20:25:22 +0000479
480# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000481ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000482all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000483endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000484
John Criswell7a73b802003-06-30 21:59:07 +0000485#--------------------------------------------------------------------
486# Rules for building libraries
487#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000488
John Criswell7a73b802003-06-30 21:59:07 +0000489#
490# Rules for building dynamically linked libraries.
491#
492$(LIBNAME_O): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
493 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
494 $(VERB) $(Link) -o $*.la $(LObjectsO) $(LibSubDirs) $(LibLinkOpts);
495 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve41e78912002-09-20 14:03:13 +0000496
John Criswell7a73b802003-06-30 21:59:07 +0000497$(LIBNAME_P): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
498 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
499 $(VERB) $(Link) -o $*.la $(LObjectsP) $(LibSubDirs) $(LibLinkOpts);
500 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner00950542001-06-06 20:29:01 +0000501
John Criswell7a73b802003-06-30 21:59:07 +0000502$(LIBNAME_G): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
503 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
504 $(VERB) $(Link) -o $*.la $(LObjectsG) $(LibSubDirs) $(LibLinkOpts);
505 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000506
John Criswell7a73b802003-06-30 21:59:07 +0000507#
508# Rules for building static archive libraries.
509#
510$(LIBNAME_AO): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
511 @echo ======= Linking $(LIBRARYNAME) archive release library =======
512 @$(RM) -f $@
513 $(VERB) $(Link) -03 -o $@ $(LObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000514
John Criswell7a73b802003-06-30 21:59:07 +0000515$(LIBNAME_AP): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
516 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
517 @$(RM) -f $@
518 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(LObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000519
John Criswell7a73b802003-06-30 21:59:07 +0000520$(LIBNAME_AG): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
521 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
522 @$(RM) -f $@
523 $(VERB) $(Link) -g $(STRIP) -o $@ $(LObjectsG) $(LibSubDirs) -static
524
525#
526# Rules for building .o libraries.
527#
528$(LIBNAME_OBJO): $(LObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000529 @echo "Linking $@"
John Criswell7a73b802003-06-30 21:59:07 +0000530 $(VERB) $(Relink) -o $@ $(LObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000531
John Criswell7a73b802003-06-30 21:59:07 +0000532$(LIBNAME_OBJP): $(LObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000533 @echo "Linking $@"
John Criswell7a73b802003-06-30 21:59:07 +0000534 $(VERB) $(Relink) -o $@ $(LObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000535
John Criswell7a73b802003-06-30 21:59:07 +0000536$(LIBNAME_OBJG): $(LObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000537 @echo "Linking $@"
John Criswell7a73b802003-06-30 21:59:07 +0000538 $(VERB) $(Relink) -o $@ $(LObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000539
Chris Lattner00950542001-06-06 20:29:01 +0000540endif
541
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000542#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000543# Create a TAGS database for emacs
544#------------------------------------------------------------------------
545
John Criswell7a73b802003-06-30 21:59:07 +0000546ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000547ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000548tags:
John Criswell7a73b802003-06-30 21:59:07 +0000549 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000550all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000551endif
John Criswell7a73b802003-06-30 21:59:07 +0000552else
553tags:
554 ${ECHO} "Cannot build $@: The program etags is not installed"
555endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000556
557#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000558# Handle the TOOLNAME option - used when building tool executables...
559#------------------------------------------------------------------------
560#
561# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000562# libraries (and the order of the libs) that should be linked to the
563# tool. USEDLIBS should contain a list of library names (some with .a extension)
564# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000565#
566ifdef TOOLNAME
567
568# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000569TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
570TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
571TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
572TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000573
574# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000575PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
576PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
577PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
578PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
579
580LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
581LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
582LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
583LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
584
585LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000586LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000587LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
588
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000589# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000590# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
591# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000592#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000593STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000594USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
595USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
596USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
John Criswell7a73b802003-06-30 21:59:07 +0000597#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000598
John Criswell7a73b802003-06-30 21:59:07 +0000599#
600# Libtool link options:
601# Ensure that all binaries have their symbols exported so that they can
602# by dlsym'ed.
603#
604LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000605
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000606
607
608
609
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000610# Tell make that we need to rebuild subdirectories before we can link the tool.
611# This affects things like LLI which has library subdirectories.
612$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
613 $(addsuffix /.makeall, $(PARALLEL_DIRS))
614
Chris Lattner669bd7c2001-10-13 05:10:29 +0000615all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000616
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000617clean::
John Criswell7a73b802003-06-30 21:59:07 +0000618 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000619
John Criswell7a73b802003-06-30 21:59:07 +0000620$(TOOLEXENAME_G): $(LObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000621 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
John Criswell7a73b802003-06-30 21:59:07 +0000622 $(VERB) $(LinkG) -o $@ $(LObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000623
John Criswell7a73b802003-06-30 21:59:07 +0000624$(TOOLEXENAME_O): $(LObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000625 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswell7a73b802003-06-30 21:59:07 +0000626 $(VERB) $(LinkO) -o $@ $(LObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000627
John Criswell7a73b802003-06-30 21:59:07 +0000628$(TOOLEXENAME_P): $(LObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000629 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswell7a73b802003-06-30 21:59:07 +0000630 $(VERB) $(LinkP) -o $@ $(LObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000631
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000632endif
633
634
Chris Lattner00950542001-06-06 20:29:01 +0000635
636#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000637.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
638.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000639
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000640# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell7a73b802003-06-30 21:59:07 +0000641#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
642 #@echo "Compiling $<"
643 #$(VERB) $(CompileO) $< -o $@
644
645#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
646 #$(VERB) $(CompileCO) $< -o $@
647
648#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
649 #@echo "Compiling $<"
650 #$(VERB) $(CompileP) $< -o $@
651
652#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
653 #@echo "Compiling $<"
654 #$(VERB) $(CompileCP) $< -o $@
655
656#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
657 #@echo "Compiling $<"
658 #$(VERB) $(CompileG) $< -o $@
659
660#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
661 #$(VERB) $(CompileCG) $< -o $@
662
663# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
664$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000665 @echo "Compiling $<"
666 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000667
John Criswell7a73b802003-06-30 21:59:07 +0000668$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
669 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000670 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000671
John Criswell7a73b802003-06-30 21:59:07 +0000672$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000673 @echo "Compiling $<"
674 $(VERB) $(CompileP) $< -o $@
675
John Criswell7a73b802003-06-30 21:59:07 +0000676$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000677 @echo "Compiling $<"
678 $(VERB) $(CompileCP) $< -o $@
679
John Criswell7a73b802003-06-30 21:59:07 +0000680$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000681 @echo "Compiling $<"
682 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000683
John Criswell7a73b802003-06-30 21:59:07 +0000684$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
685 @echo "Compiling $<"
686 $(VERB) $(CompileCG) $< -o $@
687
688# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
689$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
690 @echo "Compiling $<"
691 $(VERB) $(CompileO) $< -o $@
692
693$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
694 $(VERB) $(CompileCO) $< -o $@
695
696$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
697 @echo "Compiling $<"
698 $(VERB) $(CompileP) $< -o $@
699
700$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
701 @echo "Compiling $<"
702 $(VERB) $(CompileCP) $< -o $@
703
704$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
705 @echo "Compiling $<"
706 $(VERB) $(CompileG) $< -o $@
707
708$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000709 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000710
Chris Lattnere8996782003-01-16 22:44:19 +0000711#
712# Rules for building lex/yacc files
713#
714LEX_FILES = $(filter %.l, $(Source))
715LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
716YACC_FILES = $(filter %.y, $(Source))
717YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
718.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
719
Chris Lattner00950542001-06-06 20:29:01 +0000720# Create a .cpp source file from a flex input file... this uses sed to cut down
721# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000722#
723# The last line is a gross hack to work around flex aparently not being able to
724# resize the buffer on a large token input. Currently, for uninitialized string
725# buffers in LLVM we can generate very long tokens, so this is a hack around it.
726# FIXME. (f.e. char Buffer[10000]; )
727#
Chris Lattner00950542001-06-06 20:29:01 +0000728%.cpp: %.l
John Criswell7a73b802003-06-30 21:59:07 +0000729 $(FLEX) -t $< | $(SED) '/^find_rule/d' | \
730 $(SED) 's/void yyunput/inline void yyunput/' | \
731 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
732 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000733
734# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000735%.c: %.y # Cancel built-in rules for yacc
736%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000737%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000738 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000739 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswell7a73b802003-06-30 21:59:07 +0000740 $(VERB) ${MV} -f $*.tab.c $*.cpp
741 $(VERB) ${MV} -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000742
743# To create the directories...
744%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000745 $(VERB) ${MKDIR} $* > /dev/null
746 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000747
Chris Lattner30440c62003-01-16 21:06:18 +0000748# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000749ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000750%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000751 ${DOT} -Tps < $< > $@
752else
753%.ps: %.dot
754 ${ECHO} "Cannot build $@: The program dot is not installed"
755endif
Chris Lattner30440c62003-01-16 21:06:18 +0000756
Chris Lattner172b6482002-09-22 02:47:15 +0000757# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000758clean::
John Criswell7a73b802003-06-30 21:59:07 +0000759 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
760 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
761 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
762
763distclean:: clean
764 $(VERB) (cd $(LLVM_SRC_ROOT); $(RM) -rf $(LEVEL)/Makefile.config \
765 $(LEVEL)/include/Config/config.h \
766 $(LEVEL)/autom4te.cache \
767 $(LEVEL)/config.log)
768
769###########################################################################
770# C/C++ Dependencies
771# Define variables and rules that generate header file dependencies
772# from C/C++ source files.
773###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000774
Chris Lattner694c5df2003-05-15 21:28:55 +0000775# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000776# include the dependancies now...
777#
Chris Lattner694c5df2003-05-15 21:28:55 +0000778SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000779SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000780
John Criswell7a73b802003-06-30 21:59:07 +0000781#
782# Depend target:
783# This allows a user to manually ask for an update in the dependencies
784#
785depend: $(SourceDepend)
786
787
Chris Lattner694c5df2003-05-15 21:28:55 +0000788# Create dependencies for the *.cpp files...
789#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000790$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000791 $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000792
793# Create dependencies for the *.c files...
794#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000795$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000796 $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000797
John Criswell7a73b802003-06-30 21:59:07 +0000798#
799# Include dependencies generated from C/C++ source files, but not if we
800# are cleaning (this example taken from the GNU Make Manual).
801#
802ifneq ($(MAKECMDGOALS),clean)
Chris Lattner00950542001-06-06 20:29:01 +0000803ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000804-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000805endif
John Criswell7a73b802003-06-30 21:59:07 +0000806endif