blob: 81bfc6d2a223dddd8d0c3f450c52ff3ccad25d38 [file] [log] [blame]
Vikram S. Adve24132e82002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner2f7c9632001-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. Adve728de922002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner2f7c9632001-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 Lattnerf3dd5f52002-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 Lattner2f7c9632001-06-06 20:29:01 +000019#
Chris Lattnerf3dd5f52002-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 Lattner2f7c9632001-06-06 20:29:01 +000025# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattneree6e1992001-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 Lattner2f7c9632001-06-06 20:29:01 +000028#
Chris Lattner021249f2003-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 Criswell3ef61af2003-06-30 21:59:07 +000033# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati55512b12003-05-29 21:49:00 +000034#
John Criswell3ef61af2003-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. Adve24132e82002-07-09 12:04:21 +000051#===-----------------------------------------------------------------------====
Chris Lattner2f7c9632001-06-06 20:29:01 +000052
John Criswell8224df92003-06-27 16:58:44 +000053#
Vikram S. Adve728de922002-08-29 23:28:46 +000054# Configuration file to set paths specific to local installation of LLVM
55#
56include $(LEVEL)/Makefile.config
57
John Criswell0607d882003-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 Criswell668fbc22003-06-16 19:14:31 +000085BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell0607d882003-06-11 13:55:44 +000086endif
87
88#
John Criswell3ef61af2003-06-30 21:59:07 +000089# Determine the path of the source tree relative from $HOME (the mythical
90# home directory).
91#
Misha Brukman6d1871c2003-07-07 22:27:05 +000092HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
John Criswell3ef61af2003-06-30 21:59:07 +000093
94#
John Criswell0607d882003-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 Criswell3ef61af2003-06-30 21:59:07 +0000100BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
John Criswell0607d882003-06-11 13:55:44 +0000101else
John Criswell3ef61af2003-06-30 21:59:07 +0000102BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
John Criswell0607d882003-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 Criswell3ef61af2003-06-30 21:59:07 +0000111BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
John Criswell0607d882003-06-11 13:55:44 +0000112else
John Criswell3ef61af2003-06-30 21:59:07 +0000113BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
John Criswell0607d882003-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 Criswell3ef61af2003-06-30 21:59:07 +0000132###########################################################################
133# Default Targets:
134# The following targets are the standard top level targets for
135# building.
136###########################################################################
Chris Lattnere5ad7bd2002-09-13 22:14:47 +0000137
Chris Lattner570c6a62002-07-23 19:21:31 +0000138ifdef SHARED_LIBRARY
139# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell3ef61af2003-06-30 21:59:07 +0000140all:: dynamic
Chris Lattner570c6a62002-07-23 19:21:31 +0000141endif
142
Chris Lattner44601ba2001-06-29 05:20:16 +0000143# Default Rule: Make sure it's also a :: rule
Chris Lattner2f7c9632001-06-06 20:29:01 +0000144all ::
145
146# Default for install is to at least build everything...
147install ::
148
John Criswell0607d882003-06-11 13:55:44 +0000149# Default rule for test. It ensures everything has a test rule
150test::
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000151
John Criswell3ef61af2003-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 Lattner2f7c9632001-06-06 20:29:01 +0000168#--------------------------------------------------------------------
Vikram S. Adve728de922002-08-29 23:28:46 +0000169# Variables derived from configuration options...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000170#--------------------------------------------------------------------
171
172#BinInstDir=/usr/local/bin
John Criswell9cca31f2003-05-29 18:52:10 +0000173#LibInstDir=/usr/local/lib/xxx
Chris Lattner2f7c9632001-06-06 20:29:01 +0000174#DocInstDir=/usr/doc/xxx
175
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000176BURG_OPTS = -I
177
John Criswell0607d882003-06-11 13:55:44 +0000178PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattnerb20b290c2001-10-30 20:24:08 +0000179
Chris Lattnerc2bd7cf2003-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 Criswell3ef61af2003-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 Criswell0607d882003-06-11 13:55:44 +0000204###########################################################################
John Criswell3ef61af2003-06-30 21:59:07 +0000205# Library Locations:
John Criswell0607d882003-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 Dhurjati41f77482003-05-29 16:18:20 +0000212
John Criswell0607d882003-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 Dhurjati41f77482003-05-29 16:18:20 +0000218
John Criswell0607d882003-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 Dhurjati41f77482003-05-29 16:18:20 +0000224
John Criswell0607d882003-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 Dhurjati41f77482003-05-29 16:18:20 +0000230
John Criswell0607d882003-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 Lattnerc2bd7cf2003-03-14 20:25:22 +0000239
John Criswell0607d882003-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 Lattner76d98ba2002-07-23 17:56:16 +0000254
John Criswell3ef61af2003-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 Brukman1326a7c2002-09-12 16:05:39 +0000265# Verbosity levels
John Criswell3ef61af2003-06-30 21:59:07 +0000266#
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000267ifndef VERBOSE
Misha Brukman1326a7c2002-09-12 16:05:39 +0000268VERB := @
269endif
270
John Criswell3ef61af2003-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 Lattner2f7c9632001-06-06 20:29:01 +0000276
John Criswell3ef61af2003-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 Criswell0607d882003-06-11 13:55:44 +0000281BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattnerc58930c2002-09-19 19:42:24 +0000282RunBurg := $(BURG) $(BURG_OPTS)
283
John Criswell0607d882003-06-11 13:55:44 +0000284TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000285
Chris Lattner2f7c9632001-06-06 20:29:01 +0000286
John Criswell0607d882003-06-11 13:55:44 +0000287###########################################################################
288# Compile Time Flags
289###########################################################################
290
291#
John Criswell3ef61af2003-06-30 21:59:07 +0000292# Include both the project headers and the LLVM headers for compilation and
293# dependency computation.
John Criswell0607d882003-06-11 13:55:44 +0000294#
295CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000296
Vikram S. Adved141c282002-09-18 11:55:13 +0000297# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000298ifndef KEEP_SYMBOLS
Chris Lattnerd119b562003-01-31 19:00:26 +0000299STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukmanfd3e0af2003-07-10 16:52:41 +0000300STRIP_WARN_MSG = "(without symbols)"
Vikram S. Adved141c282002-09-18 11:55:13 +0000301endif
302
Chris Lattner2efcf432002-09-13 16:02:26 +0000303# Allow gnu extensions...
304CPPFLAGS += -D_GNU_SOURCE
305
Chris Lattner068f8222002-01-23 05:46:01 +0000306# -Wno-unused-parameter
John Criswell0607d882003-06-11 13:55:44 +0000307CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner4bb08062003-02-13 16:56:30 +0000308CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner2f7c9632001-06-06 20:29:01 +0000309
John Criswell3ef61af2003-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 Lattnera8ce09e2002-09-22 02:47:15 +0000328# Compile a cpp file, don't link...
Chris Lattner01f68c62002-08-12 21:19:28 +0000329CompileG := $(Compile) -g -D_DEBUG
Chris Lattner4bb08062003-02-13 16:56:30 +0000330CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
331CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000332
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000333# Compile a c file, don't link...
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000334CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattner61493ff2003-02-19 22:12:20 +0000335CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
336CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000337
John Criswell3ef61af2003-06-30 21:59:07 +0000338###########################################################################
339# Link Time Options
340###########################################################################
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000341
John Criswell3ef61af2003-06-30 21:59:07 +0000342#
Chris Lattner2f7c9632001-06-06 20:29:01 +0000343# Link final executable
John Criswell3ef61af2003-06-30 21:59:07 +0000344# (Note that we always link with the C++ compiler).
345#
Chris Lattnerd711a5e2002-07-31 21:32:05 +0000346ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
John Criswell3ef61af2003-06-30 21:59:07 +0000347Link := $(PURIFY) $(LIBTOOL) --mode=link $(CXX) -static
Chris Lattnerf0a88d12002-04-05 18:56:58 +0000348else
John Criswell3ef61af2003-06-30 21:59:07 +0000349Link := $(LIBTOOL) --mode=link $(CXX)
Chris Lattnerf0a88d12002-04-05 18:56:58 +0000350endif
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000351
John Criswell3ef61af2003-06-30 21:59:07 +0000352# link both projlib and llvmlib libraries
Dinakar Dhurjati41f77482003-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 Lattner2f7c9632001-06-06 20:29:01 +0000356
Chris Lattner76d98ba2002-07-23 17:56:16 +0000357# Create one .o file from a bunch of .o files...
John Criswell3ef61af2003-06-30 21:59:07 +0000358Relink = ${LIBTOOL} --mode=link $(CXX)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000359
Chris Lattnere5ad7bd2002-09-13 22:14:47 +0000360# MakeSO - Create a .so file from a .o files...
John Criswell3ef61af2003-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 Lattnere5ad7bd2002-09-13 22:14:47 +0000375
Chris Lattner2f7c9632001-06-06 20:29:01 +0000376# Create dependancy file from CPP file, send to stdout.
John Criswell0607d882003-06-11 13:55:44 +0000377Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
378DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000379
380# Archive a bunch of .o files into a .a file...
John Criswell857ec182003-05-30 15:50:31 +0000381AR = ${AR_PATH} cq
Chris Lattner2f7c9632001-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 Lattneree6e1992001-10-18 01:48:09 +0000387# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advebd9cae22001-10-17 12:33:55 +0000388#
Vikram S. Adve53738842002-10-14 16:40:04 +0000389ifndef Source
Chris Lattneree6e1992001-10-18 01:48:09 +0000390Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Adve53738842002-10-14 16:40:04 +0000391endif
Vikram S. Advefe346892001-07-15 13:16:47 +0000392
John Criswell7320d2f2003-07-01 14:52:28 +0000393Objs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
394ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
395ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
396ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner76d98ba2002-07-23 17:56:16 +0000397
Chris Lattner2f7c9632001-06-06 20:29:01 +0000398#---------------------------------------------------------
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000399# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner2f7c9632001-06-06 20:29:01 +0000400#---------------------------------------------------------
401
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000402ifdef DIRS
Chris Lattnere48c528442003-01-16 20:02:30 +0000403all install clean test ::
Chris Lattner59ded8e2002-09-17 23:45:34 +0000404 $(VERB) for dir in ${DIRS}; do \
Chris Lattner539a23c2002-09-17 23:35:02 +0000405 (cd $$dir; $(MAKE) $@) || exit 1; \
406 done
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000407endif
Chris Lattnerf3dd5f52002-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 Lattnere48c528442003-01-16 20:02:30 +0000414test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000415
Chris Lattnere48c528442003-01-16 20:02:30 +0000416%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000417 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000418endif
419
John Criswell3ef61af2003-06-30 21:59:07 +0000420# Handle directories that may or may not exist
John Criswell8224df92003-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 Criswell3ef61af2003-06-30 21:59:07 +0000431###########################################################################
432# Library Build Rules:
433#
Chris Lattner2f7c9632001-06-06 20:29:01 +0000434#---------------------------------------------------------
435# Handle the LIBRARYNAME option - used when building libs...
436#---------------------------------------------------------
Chris Lattner76d98ba2002-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 Lattnerd711a5e2002-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 Lattner76d98ba2002-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 Criswell3ef61af2003-06-30 21:59:07 +0000450###########################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000451
452ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000453
Chris Lattner0100eab2002-09-16 22:36:42 +0000454# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000455LIBRARYNAME := $(strip $(LIBRARYNAME))
456
Dinakar Dhurjati41f77482003-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 Lattner2f7c9632001-06-06 20:29:01 +0000466
John Criswell3ef61af2003-06-30 21:59:07 +0000467#--------------------------------------------------------------------
468# Library Targets
469# Modify the top level targets to build the desired libraries.
470#--------------------------------------------------------------------
471
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000472# dynamic target builds a shared object version of the library...
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000473dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000474
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000475# Does the library want a .o version built?
Chris Lattner76d98ba2002-07-23 17:56:16 +0000476ifndef DONT_BUILD_RELINKED
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000477all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattner76d98ba2002-07-23 17:56:16 +0000478endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000479
480# Does the library want an archive version built?
Chris Lattner76d98ba2002-07-23 17:56:16 +0000481ifdef BUILD_ARCHIVE
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000482all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattner76d98ba2002-07-23 17:56:16 +0000483endif
Chris Lattner76d98ba2002-07-23 17:56:16 +0000484
John Criswell3ef61af2003-06-30 21:59:07 +0000485#--------------------------------------------------------------------
486# Rules for building libraries
487#--------------------------------------------------------------------
Chris Lattner2f7c9632001-06-06 20:29:01 +0000488
John Criswell3ef61af2003-06-30 21:59:07 +0000489#
490# Rules for building dynamically linked libraries.
491#
John Criswell7320d2f2003-07-01 14:52:28 +0000492$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000493 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
John Criswell7320d2f2003-07-01 14:52:28 +0000494 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
John Criswell3ef61af2003-06-30 21:59:07 +0000495 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000496
John Criswell7320d2f2003-07-01 14:52:28 +0000497$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000498 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
John Criswell7320d2f2003-07-01 14:52:28 +0000499 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
John Criswell3ef61af2003-06-30 21:59:07 +0000500 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000501
John Criswell7320d2f2003-07-01 14:52:28 +0000502$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000503 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
John Criswell7320d2f2003-07-01 14:52:28 +0000504 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
John Criswell3ef61af2003-06-30 21:59:07 +0000505 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Advefe346892001-07-15 13:16:47 +0000506
John Criswell3ef61af2003-06-30 21:59:07 +0000507#
508# Rules for building static archive libraries.
509#
John Criswell7320d2f2003-07-01 14:52:28 +0000510$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000511 @echo ======= Linking $(LIBRARYNAME) archive release library =======
512 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000513 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000514
John Criswell7320d2f2003-07-01 14:52:28 +0000515$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000516 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
517 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000518 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Advefe346892001-07-15 13:16:47 +0000519
John Criswell7320d2f2003-07-01 14:52:28 +0000520$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000521 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
522 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000523 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell3ef61af2003-06-30 21:59:07 +0000524
525#
526# Rules for building .o libraries.
527#
John Criswell7320d2f2003-07-01 14:52:28 +0000528$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000529 @echo "Linking $@"
John Criswell7320d2f2003-07-01 14:52:28 +0000530 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000531
John Criswell7320d2f2003-07-01 14:52:28 +0000532$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000533 @echo "Linking $@"
John Criswell7320d2f2003-07-01 14:52:28 +0000534 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000535
John Criswell7320d2f2003-07-01 14:52:28 +0000536$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner8d081dd2002-09-25 17:15:22 +0000537 @echo "Linking $@"
John Criswell7320d2f2003-07-01 14:52:28 +0000538 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000539
Chris Lattner2f7c9632001-06-06 20:29:01 +0000540endif
541
Chris Lattner07c7c192001-09-07 22:57:58 +0000542#------------------------------------------------------------------------
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000543# Create a TAGS database for emacs
544#------------------------------------------------------------------------
545
John Criswell3ef61af2003-06-30 21:59:07 +0000546ifdef ETAGS
Vikram S. Advea0e99082001-10-13 12:26:59 +0000547ifeq ($(LEVEL), .)
Vikram S. Advea0e99082001-10-13 12:26:59 +0000548tags:
John Criswell3ef61af2003-06-30 21:59:07 +0000549 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Advea0e99082001-10-13 12:26:59 +0000550all:: tags
Vikram S. Advea0e99082001-10-13 12:26:59 +0000551endif
John Criswell3ef61af2003-06-30 21:59:07 +0000552else
553tags:
554 ${ECHO} "Cannot build $@: The program etags is not installed"
555endif
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000556
557#------------------------------------------------------------------------
Chris Lattner07c7c192001-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 Lattner76d98ba2002-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 Lattner07c7c192001-09-07 22:57:58 +0000565#
566ifdef TOOLNAME
567
568# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell0607d882003-06-11 13:55:44 +0000569TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
570TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
571TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
572TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner07c7c192001-09-07 22:57:58 +0000573
574# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjati41f77482003-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 Lattnerf6791e52003-06-20 15:41:57 +0000586LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000587LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
588
Chris Lattner07c7c192001-09-07 22:57:58 +0000589# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattner76d98ba2002-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 Lattner07c7c192001-09-07 22:57:58 +0000592#
Chris Lattner76d98ba2002-07-23 17:56:16 +0000593STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjati41f77482003-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 Criswell3ef61af2003-06-30 21:59:07 +0000597#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000598
John Criswell3ef61af2003-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 Lattner3ecb7762003-01-22 16:13:31 +0000605
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000606
607
608
609
Chris Lattner3ecb7762003-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 Lattner1fd501f2001-10-13 05:10:29 +0000615all:: $(TOOLEXENAMES)
John Criswell8224df92003-06-27 16:58:44 +0000616
Chris Lattner07c7c192001-09-07 22:57:58 +0000617clean::
John Criswell3ef61af2003-06-30 21:59:07 +0000618 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000619
John Criswell7320d2f2003-07-01 14:52:28 +0000620$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukmanfd3e0af2003-07-10 16:52:41 +0000621 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswell7320d2f2003-07-01 14:52:28 +0000622 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000623
John Criswell7320d2f2003-07-01 14:52:28 +0000624$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner500f0642002-09-12 17:02:40 +0000625 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswell7320d2f2003-07-01 14:52:28 +0000626 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000627
John Criswell7320d2f2003-07-01 14:52:28 +0000628$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000629 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswell7320d2f2003-07-01 14:52:28 +0000630 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000631
Chris Lattner07c7c192001-09-07 22:57:58 +0000632endif
633
634
Chris Lattner2f7c9632001-06-06 20:29:01 +0000635
636#---------------------------------------------------------
John Criswell0607d882003-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 Lattner2f7c9632001-06-06 20:29:01 +0000639
Vikram S. Advefe346892001-07-15 13:16:47 +0000640# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell3ef61af2003-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 Brukman1326a7c2002-09-12 16:05:39 +0000665 @echo "Compiling $<"
666 $(VERB) $(CompileO) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000667
John Criswell3ef61af2003-06-30 21:59:07 +0000668$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
669 @echo "Compiling $<"
Chris Lattnerd3fcf422002-10-22 23:28:23 +0000670 $(VERB) $(CompileCO) $< -o $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000671
John Criswell3ef61af2003-06-30 21:59:07 +0000672$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000673 @echo "Compiling $<"
674 $(VERB) $(CompileP) $< -o $@
675
John Criswell3ef61af2003-06-30 21:59:07 +0000676$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000677 @echo "Compiling $<"
678 $(VERB) $(CompileCP) $< -o $@
679
John Criswell3ef61af2003-06-30 21:59:07 +0000680$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000681 @echo "Compiling $<"
682 $(VERB) $(CompileG) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000683
John Criswell3ef61af2003-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 Lattnera8ce09e2002-09-22 02:47:15 +0000709 $(VERB) $(CompileCG) $< -o $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000710
Chris Lattnerdb644dd2003-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 Lattner2f7c9632001-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 Lattner9e461662003-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 Lattner2f7c9632001-06-06 20:29:01 +0000728%.cpp: %.l
John Criswell3ef61af2003-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 Lattner2f7c9632001-06-06 20:29:01 +0000733
734# Rule for building the bison parsers...
Chris Lattner021249f2003-05-15 21:28:55 +0000735%.c: %.y # Cancel built-in rules for yacc
736%.h: %.y # Cancel built-in rules for yacc
Chris Lattner2f7c9632001-06-06 20:29:01 +0000737%.cpp %.h : %.y
Chris Lattner021249f2003-05-15 21:28:55 +0000738 @echo Bison\'ing $<...
Chris Lattnerdb644dd2003-01-16 22:44:19 +0000739 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswell3ef61af2003-06-30 21:59:07 +0000740 $(VERB) ${MV} -f $*.tab.c $*.cpp
741 $(VERB) ${MV} -f $*.tab.h $*.h
Chris Lattner2f7c9632001-06-06 20:29:01 +0000742
743# To create the directories...
744%/.dir:
John Criswell3ef61af2003-06-30 21:59:07 +0000745 $(VERB) ${MKDIR} $* > /dev/null
746 @$(DATE) > $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000747
Chris Lattner23d47392003-01-16 21:06:18 +0000748# To create postscript files from dot files...
John Criswell3ef61af2003-06-30 21:59:07 +0000749ifdef DOT
Chris Lattner23d47392003-01-16 21:06:18 +0000750%.ps: %.dot
John Criswell3ef61af2003-06-30 21:59:07 +0000751 ${DOT} -Tps < $< > $@
752else
753%.ps: %.dot
754 ${ECHO} "Cannot build $@: The program dot is not installed"
755endif
Chris Lattner23d47392003-01-16 21:06:18 +0000756
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000757# 'make clean' nukes the tree
Chris Lattner2f7c9632001-06-06 20:29:01 +0000758clean::
John Criswell3ef61af2003-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 Lattner2f7c9632001-06-06 20:29:01 +0000774
Chris Lattner021249f2003-05-15 21:28:55 +0000775# If dependencies were generated for the file that included this file,
Chris Lattner2f7c9632001-06-06 20:29:01 +0000776# include the dependancies now...
777#
Chris Lattner021249f2003-05-15 21:28:55 +0000778SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell0607d882003-06-11 13:55:44 +0000779SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner021249f2003-05-15 21:28:55 +0000780
John Criswell3ef61af2003-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 Lattner021249f2003-05-15 21:28:55 +0000788# Create dependencies for the *.cpp files...
789#$(SourceDepend): \x
John Criswell0607d882003-06-11 13:55:44 +0000790$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell3ef61af2003-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 Lattner021249f2003-05-15 21:28:55 +0000792
793# Create dependencies for the *.c files...
794#$(SourceDepend): \x
John Criswell0607d882003-06-11 13:55:44 +0000795$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell3ef61af2003-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 Lattner021249f2003-05-15 21:28:55 +0000797
John Criswell3ef61af2003-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 Lattner2f7c9632001-06-06 20:29:01 +0000803ifneq ($(SourceDepend),)
Chris Lattner1ad7c122002-10-25 14:32:42 +0000804-include $(SourceDepend)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000805endif
John Criswell3ef61af2003-06-30 21:59:07 +0000806endif