blob: c3f5af220113ed0f94c024a2b6f12e4e190e44b7 [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#
Misha Brukmanf8873ed2003-07-07 22:27:05 +000092HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
John Criswell7a73b802003-06-30 21:59:07 +000093
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
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000152# Default rule for building only bytecode.
153bytecode::
154
John Criswell7a73b802003-06-30 21:59:07 +0000155# Print out the directories used for building
156prdirs::
157 echo "Home Offset : " $(HOME_OBJ_ROOT);
158 echo "Build Source Root: " $(BUILD_SRC_ROOT);
159 echo "Build Source Dir : " $(BUILD_SRC_DIR);
160 echo "Build Object Root: " $(BUILD_OBJ_ROOT);
161 echo "Build Object Dir : " $(BUILD_OBJ_DIR);
162 echo "LLVM Source Root: " $(LLVM_SRC_ROOT);
163 echo "LLVM Object Root: " $(LLVM_OBJ_ROOT);
164
John Criswell96914392003-07-16 20:26:06 +0000165#
166# Mark all of these targets as phony. This will hopefully speed up builds
167# slightly since GNU Make will not try to find implicit rules for targets
168# which are marked as Phony.
169#
170.PHONY: all dynamic clean distclean install test bytecode prdirs
171
John Criswell7a73b802003-06-30 21:59:07 +0000172###########################################################################
173# Miscellaneous paths and commands:
174# This section defines various configuration macros, such as where
175# to find burg, tblgen, and libtool.
176###########################################################################
177
Chris Lattner00950542001-06-06 20:29:01 +0000178#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000179# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000180#--------------------------------------------------------------------
181
182#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000183#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000184#DocInstDir=/usr/doc/xxx
185
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000186BURG_OPTS = -I
187
John Criswell8bff5092003-06-11 13:55:44 +0000188PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000189
Chris Lattner760da062003-03-14 20:25:22 +0000190ifdef ENABLE_PROFILING
191 ENABLE_OPTIMIZED = 1
192 CONFIGURATION := Profile
193else
194 ifdef ENABLE_OPTIMIZED
195 CONFIGURATION := Release
196 else
197 CONFIGURATION := Debug
198 endif
199endif
200
John Criswell7a73b802003-06-30 21:59:07 +0000201#
202# Enable this for profiling support with 'gprof'
203# This automatically enables optimized builds.
204#
205ifdef ENABLE_PROFILING
206 PROFILE = -pg
207endif
208
209#
210# Suffixes for library compilation rules
211#
212.SUFFIXES: .so
213
John Criswell8bff5092003-06-11 13:55:44 +0000214###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000215# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000216# These variables describe various library locations:
217#
218# DEST* = Location of where libraries that are built will be placed.
219# LLVM* = Location of LLVM libraries used for linking.
220# PROJ* = Location of previously built libraries used for linking.
221###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000222
John Criswell8bff5092003-06-11 13:55:44 +0000223# Libraries that are being built
224DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
225DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
226DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
227DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000228
John Criswell8bff5092003-06-11 13:55:44 +0000229# LLVM libraries used for linking
230LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
231LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
232LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
233LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000234
John Criswell8bff5092003-06-11 13:55:44 +0000235# Libraries that were built that will now be used for linking
236PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
237PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
238PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
239PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000240
John Criswell8bff5092003-06-11 13:55:44 +0000241###########################################################################
242# Tool Locations
243# These variables describe various tool locations:
244#
245# DEST* = Location of where tools that are built will be placed.
246# LLVM* = Location of LLVM tools used for building.
247# PROJ* = Location of previously built tools used for linking.
248###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000249
John Criswell8bff5092003-06-11 13:55:44 +0000250DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
251DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
252DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
253DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
254
255LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
256LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
257LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
258LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
259
260PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
261PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
262PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
263PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000264
John Criswell7a73b802003-06-30 21:59:07 +0000265#
266# Libtool is found in the current directory.
267#
268ifdef VERBOSE
John Criswell8d4221e2003-07-23 16:52:50 +0000269LIBTOOL=$(LLVM_SRC_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000270else
John Criswell8d4221e2003-07-23 16:52:50 +0000271LIBTOOL=$(LLVM_SRC_ROOT)/mklib --silent
John Criswell7a73b802003-06-30 21:59:07 +0000272endif
273
274#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000275# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000276#
Chris Lattner760da062003-03-14 20:25:22 +0000277ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000278VERB := @
279endif
280
John Criswell7a73b802003-06-30 21:59:07 +0000281###########################################################################
282# Miscellaneous paths and commands (part deux):
283# This section defines various configuration macros, such as where
284# to find burg, tblgen, and libtool.
285###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000286
John Criswell7a73b802003-06-30 21:59:07 +0000287#--------------------------------------------------------------------------
288# Special tools used while building the LLVM tree. Burg is built as part
289# of the utils directory.
290#--------------------------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000291BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000292RunBurg := $(BURG) $(BURG_OPTS)
293
John Criswell8bff5092003-06-11 13:55:44 +0000294TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000295
Chris Lattner00950542001-06-06 20:29:01 +0000296
John Criswell8bff5092003-06-11 13:55:44 +0000297###########################################################################
298# Compile Time Flags
299###########################################################################
300
301#
John Criswell7a73b802003-06-30 21:59:07 +0000302# Include both the project headers and the LLVM headers for compilation and
303# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000304#
305CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000306
Vikram S. Advefeeae582002-09-18 11:55:13 +0000307# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000308ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000309STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000310STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000311endif
312
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000313# Allow gnu extensions...
314CPPFLAGS += -D_GNU_SOURCE
315
Chris Lattnerc7acf812002-01-23 05:46:01 +0000316# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000317CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000318CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000319
John Criswell7a73b802003-06-30 21:59:07 +0000320#
321# Compile commands with libtool.
322#
323Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
324CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
325
326#
327# Add the LLVM specific "-only-static" option so that we only compile .o files
328# once when not building a shared library.
329#
330# For shared libraries, we will end up building twice, but that doesn't happen
331# very often, so we'll let it go.
332#
333ifndef SHARED_LIBRARY
334Compile := $(Compile) -only-static
335CompileC := $(CompileC) -only-static
336endif
337
Chris Lattner172b6482002-09-22 02:47:15 +0000338# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000339CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000340CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
341CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000342
Chris Lattner172b6482002-09-22 02:47:15 +0000343# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000344CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000345CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
346CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000347
John Criswell7a73b802003-06-30 21:59:07 +0000348###########################################################################
349# Link Time Options
350###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000351
John Criswell7a73b802003-06-30 21:59:07 +0000352#
Chris Lattner00950542001-06-06 20:29:01 +0000353# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000354# (Note that we always link with the C++ compiler).
355#
Chris Lattner1917e952002-07-31 21:32:05 +0000356ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
John Criswell7a73b802003-06-30 21:59:07 +0000357Link := $(PURIFY) $(LIBTOOL) --mode=link $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000358else
John Criswell7a73b802003-06-30 21:59:07 +0000359Link := $(LIBTOOL) --mode=link $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000360endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000361
John Criswell7a73b802003-06-30 21:59:07 +0000362# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000363LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
364LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
365LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000366
Chris Lattnere62dbe92002-07-23 17:56:16 +0000367# Create one .o file from a bunch of .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000368Relink = ${LIBTOOL} --mode=link $(CXX)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000369
Chris Lattner4bb13b82002-09-13 22:14:47 +0000370# MakeSO - Create a .so file from a .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000371#MakeSO := $(LIBTOOL) --mode=link $(CXX) $(MakeSharedObjectOption)
372#MakeSOO := $(MakeSO) -O3
373#MakeSOP := $(MakeSOO) $(PROFILE)
374
375#
376# Configure where the item being compiled should go.
377#
378ifdef SHARED_LIBRARY
379Link := $(Link) -rpath $(DESTLIBCURRENT)
380endif
381
382ifdef TOOLNAME
383Link := $(Link) -rpath $(DESTTOOLCURRENT)
384endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000385
Chris Lattner00950542001-06-06 20:29:01 +0000386# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000387Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
388DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000389
390# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000391AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000392
393#----------------------------------------------------------
394
395# Source includes all of the cpp files, and objects are derived from the
396# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000397# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000398#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000399ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000400Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000401endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000402
John Criswellf4ccd992003-07-01 14:52:28 +0000403Objs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
404ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
405ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
406ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000407
Chris Lattner00950542001-06-06 20:29:01 +0000408#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000409# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000410#---------------------------------------------------------
411
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000412ifdef DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000413all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000414 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000415 (cd $$dir; $(MAKE) $@) || exit 1; \
416 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000417endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000418
419# Handle PARALLEL_DIRS
420ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000421all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
422install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
423clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
424test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
425bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000426
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000427%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000428 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000429endif
430
John Criswell7a73b802003-06-30 21:59:07 +0000431# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000432ifdef OPTIONAL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000433all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000434 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
435 if [ -d $$dir ]; \
436 then\
437 (cd $$dir; $(MAKE) $@) || exit 1; \
438 fi \
439 done
440endif
441
John Criswell7a73b802003-06-30 21:59:07 +0000442###########################################################################
443# Library Build Rules:
444#
Chris Lattner00950542001-06-06 20:29:01 +0000445#---------------------------------------------------------
446# Handle the LIBRARYNAME option - used when building libs...
447#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000448#
449# When libraries are built, they are allowed to optionally define the
450# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
451# from being built for the library. This .o files may then be linked to by a
452# tool if the tool does not need (or want) the semantics a .a file provides
453# (linking in only object files that are "needed"). If a library is never to
454# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
455# BUILD_ARCHIVE instead.
456#
457# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000458# 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 +0000459# linked into tools (for example gccas) even if they only use one of the parts
460# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000461###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000462
463ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000464
Chris Lattner2a548c52002-09-16 22:36:42 +0000465# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000466LIBRARYNAME := $(strip $(LIBRARYNAME))
467
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000468LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
469LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
470LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
471LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
472LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
473LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
474LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
475LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
476LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000477
John Criswell7a73b802003-06-30 21:59:07 +0000478#--------------------------------------------------------------------
479# Library Targets
480# Modify the top level targets to build the desired libraries.
481#--------------------------------------------------------------------
482
Chris Lattner760da062003-03-14 20:25:22 +0000483# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000484dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000485
Chris Lattner760da062003-03-14 20:25:22 +0000486# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000487ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000488all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000489endif
Chris Lattner760da062003-03-14 20:25:22 +0000490
491# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000492ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000493all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000494endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000495
John Criswell7a73b802003-06-30 21:59:07 +0000496#--------------------------------------------------------------------
497# Rules for building libraries
498#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000499
John Criswell7a73b802003-06-30 21:59:07 +0000500#
501# Rules for building dynamically linked libraries.
502#
John Criswellf4ccd992003-07-01 14:52:28 +0000503$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000504 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000505 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000506 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve41e78912002-09-20 14:03:13 +0000507
John Criswellf4ccd992003-07-01 14:52:28 +0000508$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000509 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000510 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000511 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner00950542001-06-06 20:29:01 +0000512
John Criswellf4ccd992003-07-01 14:52:28 +0000513$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000514 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000515 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000516 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000517
John Criswell7a73b802003-06-30 21:59:07 +0000518#
519# Rules for building static archive libraries.
520#
John Criswellf4ccd992003-07-01 14:52:28 +0000521$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000522 @echo ======= Linking $(LIBRARYNAME) archive release library =======
523 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000524 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000525
John Criswellf4ccd992003-07-01 14:52:28 +0000526$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000527 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
528 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000529 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000530
John Criswellf4ccd992003-07-01 14:52:28 +0000531$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000532 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
533 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000534 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000535
536#
537# Rules for building .o libraries.
538#
John Criswellf4ccd992003-07-01 14:52:28 +0000539$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000540 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000541 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000542
John Criswellf4ccd992003-07-01 14:52:28 +0000543$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000544 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000545 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000546
John Criswellf4ccd992003-07-01 14:52:28 +0000547$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000548 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000549 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000550
Chris Lattner00950542001-06-06 20:29:01 +0000551endif
552
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000553#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000554# Create a TAGS database for emacs
555#------------------------------------------------------------------------
556
John Criswell7a73b802003-06-30 21:59:07 +0000557ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000558ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000559tags:
John Criswell7a73b802003-06-30 21:59:07 +0000560 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000561all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000562endif
John Criswell7a73b802003-06-30 21:59:07 +0000563else
564tags:
565 ${ECHO} "Cannot build $@: The program etags is not installed"
566endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000567
568#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000569# Handle the TOOLNAME option - used when building tool executables...
570#------------------------------------------------------------------------
571#
572# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000573# libraries (and the order of the libs) that should be linked to the
574# tool. USEDLIBS should contain a list of library names (some with .a extension)
575# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000576#
577ifdef TOOLNAME
578
579# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000580TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
581TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
582TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
583TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000584
585# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000586PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
587PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
588PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
589PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
590
591LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
592LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
593LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
594LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
595
596LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000597LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000598LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
599
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000600# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000601# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000602# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000603#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000604STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000605USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
606USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
607USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
John Criswell7a73b802003-06-30 21:59:07 +0000608#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000609
John Criswell7a73b802003-06-30 21:59:07 +0000610#
611# Libtool link options:
612# Ensure that all binaries have their symbols exported so that they can
613# by dlsym'ed.
614#
615LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000616
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000617
618
619
620
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000621# Tell make that we need to rebuild subdirectories before we can link the tool.
622# This affects things like LLI which has library subdirectories.
623$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
624 $(addsuffix /.makeall, $(PARALLEL_DIRS))
625
Chris Lattner669bd7c2001-10-13 05:10:29 +0000626all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000627
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000628clean::
John Criswell7a73b802003-06-30 21:59:07 +0000629 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000630
John Criswellf4ccd992003-07-01 14:52:28 +0000631$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000632 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000633 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000634
John Criswellf4ccd992003-07-01 14:52:28 +0000635$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000636 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000637 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000638
John Criswellf4ccd992003-07-01 14:52:28 +0000639$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000640 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000641 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000642
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000643endif
644
645
Chris Lattner00950542001-06-06 20:29:01 +0000646
647#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000648.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
649.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000650
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000651# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell7a73b802003-06-30 21:59:07 +0000652#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
653 #@echo "Compiling $<"
654 #$(VERB) $(CompileO) $< -o $@
655
656#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
657 #$(VERB) $(CompileCO) $< -o $@
658
659#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
660 #@echo "Compiling $<"
661 #$(VERB) $(CompileP) $< -o $@
662
663#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
664 #@echo "Compiling $<"
665 #$(VERB) $(CompileCP) $< -o $@
666
667#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
668 #@echo "Compiling $<"
669 #$(VERB) $(CompileG) $< -o $@
670
671#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
672 #$(VERB) $(CompileCG) $< -o $@
673
674# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
675$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000676 @echo "Compiling $<"
677 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000678
John Criswell7a73b802003-06-30 21:59:07 +0000679$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
680 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000681 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000682
John Criswell7a73b802003-06-30 21:59:07 +0000683$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000684 @echo "Compiling $<"
685 $(VERB) $(CompileP) $< -o $@
686
John Criswell7a73b802003-06-30 21:59:07 +0000687$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000688 @echo "Compiling $<"
689 $(VERB) $(CompileCP) $< -o $@
690
John Criswell7a73b802003-06-30 21:59:07 +0000691$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000692 @echo "Compiling $<"
693 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000694
John Criswell7a73b802003-06-30 21:59:07 +0000695$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
696 @echo "Compiling $<"
697 $(VERB) $(CompileCG) $< -o $@
698
699# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
700$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
701 @echo "Compiling $<"
702 $(VERB) $(CompileO) $< -o $@
703
704$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
705 $(VERB) $(CompileCO) $< -o $@
706
707$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
708 @echo "Compiling $<"
709 $(VERB) $(CompileP) $< -o $@
710
711$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
712 @echo "Compiling $<"
713 $(VERB) $(CompileCP) $< -o $@
714
715$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
716 @echo "Compiling $<"
717 $(VERB) $(CompileG) $< -o $@
718
719$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000720 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000721
Chris Lattnere8996782003-01-16 22:44:19 +0000722#
723# Rules for building lex/yacc files
724#
725LEX_FILES = $(filter %.l, $(Source))
726LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
727YACC_FILES = $(filter %.y, $(Source))
728YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
729.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
730
Chris Lattner00950542001-06-06 20:29:01 +0000731# Create a .cpp source file from a flex input file... this uses sed to cut down
732# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000733#
734# The last line is a gross hack to work around flex aparently not being able to
735# resize the buffer on a large token input. Currently, for uninitialized string
736# buffers in LLVM we can generate very long tokens, so this is a hack around it.
737# FIXME. (f.e. char Buffer[10000]; )
738#
Chris Lattner00950542001-06-06 20:29:01 +0000739%.cpp: %.l
John Criswell7a73b802003-06-30 21:59:07 +0000740 $(FLEX) -t $< | $(SED) '/^find_rule/d' | \
741 $(SED) 's/void yyunput/inline void yyunput/' | \
742 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
743 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000744
745# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000746%.c: %.y # Cancel built-in rules for yacc
747%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000748%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000749 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000750 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswell7a73b802003-06-30 21:59:07 +0000751 $(VERB) ${MV} -f $*.tab.c $*.cpp
752 $(VERB) ${MV} -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000753
754# To create the directories...
755%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000756 $(VERB) ${MKDIR} $* > /dev/null
757 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000758
Chris Lattner30440c62003-01-16 21:06:18 +0000759# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000760ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000761%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000762 ${DOT} -Tps < $< > $@
763else
764%.ps: %.dot
765 ${ECHO} "Cannot build $@: The program dot is not installed"
766endif
Chris Lattner30440c62003-01-16 21:06:18 +0000767
Chris Lattner172b6482002-09-22 02:47:15 +0000768# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000769clean::
John Criswell7a73b802003-06-30 21:59:07 +0000770 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
771 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
772 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
773
774distclean:: clean
775 $(VERB) (cd $(LLVM_SRC_ROOT); $(RM) -rf $(LEVEL)/Makefile.config \
776 $(LEVEL)/include/Config/config.h \
777 $(LEVEL)/autom4te.cache \
778 $(LEVEL)/config.log)
779
780###########################################################################
781# C/C++ Dependencies
782# Define variables and rules that generate header file dependencies
783# from C/C++ source files.
784###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000785
Chris Lattner694c5df2003-05-15 21:28:55 +0000786# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000787# include the dependancies now...
788#
Chris Lattner694c5df2003-05-15 21:28:55 +0000789SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000790SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000791
John Criswell7a73b802003-06-30 21:59:07 +0000792#
793# Depend target:
794# This allows a user to manually ask for an update in the dependencies
795#
796depend: $(SourceDepend)
797
798
Chris Lattner694c5df2003-05-15 21:28:55 +0000799# Create dependencies for the *.cpp files...
800#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000801$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000802 $(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 +0000803
804# Create dependencies for the *.c files...
805#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000806$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000807 $(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 +0000808
John Criswell7a73b802003-06-30 21:59:07 +0000809#
810# Include dependencies generated from C/C++ source files, but not if we
811# are cleaning (this example taken from the GNU Make Manual).
812#
813ifneq ($(MAKECMDGOALS),clean)
Chris Lattner00950542001-06-06 20:29:01 +0000814ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000815-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000816endif
John Criswell7a73b802003-06-30 21:59:07 +0000817endif