blob: d48647db9c5cdc86b9236f3719c0ddf71c78eb4d [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
165###########################################################################
166# Miscellaneous paths and commands:
167# This section defines various configuration macros, such as where
168# to find burg, tblgen, and libtool.
169###########################################################################
170
Chris Lattner00950542001-06-06 20:29:01 +0000171#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000172# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000173#--------------------------------------------------------------------
174
175#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000176#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000177#DocInstDir=/usr/doc/xxx
178
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000179BURG_OPTS = -I
180
John Criswell8bff5092003-06-11 13:55:44 +0000181PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000182
Chris Lattner760da062003-03-14 20:25:22 +0000183ifdef ENABLE_PROFILING
184 ENABLE_OPTIMIZED = 1
185 CONFIGURATION := Profile
186else
187 ifdef ENABLE_OPTIMIZED
188 CONFIGURATION := Release
189 else
190 CONFIGURATION := Debug
191 endif
192endif
193
John Criswell7a73b802003-06-30 21:59:07 +0000194#
195# Enable this for profiling support with 'gprof'
196# This automatically enables optimized builds.
197#
198ifdef ENABLE_PROFILING
199 PROFILE = -pg
200endif
201
202#
203# Suffixes for library compilation rules
204#
205.SUFFIXES: .so
206
John Criswell8bff5092003-06-11 13:55:44 +0000207###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000208# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000209# These variables describe various library locations:
210#
211# DEST* = Location of where libraries that are built will be placed.
212# LLVM* = Location of LLVM libraries used for linking.
213# PROJ* = Location of previously built libraries used for linking.
214###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000215
John Criswell8bff5092003-06-11 13:55:44 +0000216# Libraries that are being built
217DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
218DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
219DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
220DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000221
John Criswell8bff5092003-06-11 13:55:44 +0000222# LLVM libraries used for linking
223LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
224LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
225LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
226LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000227
John Criswell8bff5092003-06-11 13:55:44 +0000228# Libraries that were built that will now be used for linking
229PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
230PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
231PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
232PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000233
John Criswell8bff5092003-06-11 13:55:44 +0000234###########################################################################
235# Tool Locations
236# These variables describe various tool locations:
237#
238# DEST* = Location of where tools that are built will be placed.
239# LLVM* = Location of LLVM tools used for building.
240# PROJ* = Location of previously built tools used for linking.
241###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000242
John Criswell8bff5092003-06-11 13:55:44 +0000243DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
244DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
245DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
246DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
247
248LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
249LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
250LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
251LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
252
253PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
254PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
255PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
256PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000257
John Criswell7a73b802003-06-30 21:59:07 +0000258#
259# Libtool is found in the current directory.
260#
261ifdef VERBOSE
262LIBTOOL=$(LLVM_SRC_ROOT)/libtool
263else
264LIBTOOL=$(LLVM_SRC_ROOT)/libtool --silent
265endif
266
267#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000268# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000269#
Chris Lattner760da062003-03-14 20:25:22 +0000270ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000271VERB := @
272endif
273
John Criswell7a73b802003-06-30 21:59:07 +0000274###########################################################################
275# Miscellaneous paths and commands (part deux):
276# This section defines various configuration macros, such as where
277# to find burg, tblgen, and libtool.
278###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000279
John Criswell7a73b802003-06-30 21:59:07 +0000280#--------------------------------------------------------------------------
281# Special tools used while building the LLVM tree. Burg is built as part
282# of the utils directory.
283#--------------------------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000284BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000285RunBurg := $(BURG) $(BURG_OPTS)
286
John Criswell8bff5092003-06-11 13:55:44 +0000287TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000288
Chris Lattner00950542001-06-06 20:29:01 +0000289
John Criswell8bff5092003-06-11 13:55:44 +0000290###########################################################################
291# Compile Time Flags
292###########################################################################
293
294#
John Criswell7a73b802003-06-30 21:59:07 +0000295# Include both the project headers and the LLVM headers for compilation and
296# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000297#
298CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000299
Vikram S. Advefeeae582002-09-18 11:55:13 +0000300# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000301ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000302STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000303STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000304endif
305
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000306# Allow gnu extensions...
307CPPFLAGS += -D_GNU_SOURCE
308
Chris Lattnerc7acf812002-01-23 05:46:01 +0000309# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000310CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000311CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000312
John Criswell7a73b802003-06-30 21:59:07 +0000313#
314# Compile commands with libtool.
315#
316Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
317CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
318
319#
320# Add the LLVM specific "-only-static" option so that we only compile .o files
321# once when not building a shared library.
322#
323# For shared libraries, we will end up building twice, but that doesn't happen
324# very often, so we'll let it go.
325#
326ifndef SHARED_LIBRARY
327Compile := $(Compile) -only-static
328CompileC := $(CompileC) -only-static
329endif
330
Chris Lattner172b6482002-09-22 02:47:15 +0000331# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000332CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000333CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
334CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000335
Chris Lattner172b6482002-09-22 02:47:15 +0000336# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000337CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000338CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
339CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000340
John Criswell7a73b802003-06-30 21:59:07 +0000341###########################################################################
342# Link Time Options
343###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000344
John Criswell7a73b802003-06-30 21:59:07 +0000345#
Chris Lattner00950542001-06-06 20:29:01 +0000346# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000347# (Note that we always link with the C++ compiler).
348#
Chris Lattner1917e952002-07-31 21:32:05 +0000349ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
John Criswell7a73b802003-06-30 21:59:07 +0000350Link := $(PURIFY) $(LIBTOOL) --mode=link $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000351else
John Criswell7a73b802003-06-30 21:59:07 +0000352Link := $(LIBTOOL) --mode=link $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000353endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000354
John Criswell7a73b802003-06-30 21:59:07 +0000355# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000356LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
357LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
358LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000359
Chris Lattnere62dbe92002-07-23 17:56:16 +0000360# Create one .o file from a bunch of .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000361Relink = ${LIBTOOL} --mode=link $(CXX)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000362
Chris Lattner4bb13b82002-09-13 22:14:47 +0000363# MakeSO - Create a .so file from a .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000364#MakeSO := $(LIBTOOL) --mode=link $(CXX) $(MakeSharedObjectOption)
365#MakeSOO := $(MakeSO) -O3
366#MakeSOP := $(MakeSOO) $(PROFILE)
367
368#
369# Configure where the item being compiled should go.
370#
371ifdef SHARED_LIBRARY
372Link := $(Link) -rpath $(DESTLIBCURRENT)
373endif
374
375ifdef TOOLNAME
376Link := $(Link) -rpath $(DESTTOOLCURRENT)
377endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000378
Chris Lattner00950542001-06-06 20:29:01 +0000379# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000380Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
381DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000382
383# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000384AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000385
386#----------------------------------------------------------
387
388# Source includes all of the cpp files, and objects are derived from the
389# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000390# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000391#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000392ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000393Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000394endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000395
John Criswellf4ccd992003-07-01 14:52:28 +0000396Objs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
397ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
398ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
399ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000400
Chris Lattner00950542001-06-06 20:29:01 +0000401#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000402# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000403#---------------------------------------------------------
404
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000405ifdef DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000406all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000407 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000408 (cd $$dir; $(MAKE) $@) || exit 1; \
409 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000410endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000411
412# Handle PARALLEL_DIRS
413ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000414all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
415install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
416clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
417test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
418bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000419
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000420%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000421 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000422endif
423
John Criswell7a73b802003-06-30 21:59:07 +0000424# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000425ifdef OPTIONAL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000426all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000427 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
428 if [ -d $$dir ]; \
429 then\
430 (cd $$dir; $(MAKE) $@) || exit 1; \
431 fi \
432 done
433endif
434
John Criswell7a73b802003-06-30 21:59:07 +0000435###########################################################################
436# Library Build Rules:
437#
Chris Lattner00950542001-06-06 20:29:01 +0000438#---------------------------------------------------------
439# Handle the LIBRARYNAME option - used when building libs...
440#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000441#
442# When libraries are built, they are allowed to optionally define the
443# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
444# from being built for the library. This .o files may then be linked to by a
445# tool if the tool does not need (or want) the semantics a .a file provides
446# (linking in only object files that are "needed"). If a library is never to
447# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
448# BUILD_ARCHIVE instead.
449#
450# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000451# 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 +0000452# linked into tools (for example gccas) even if they only use one of the parts
453# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000454###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000455
456ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000457
Chris Lattner2a548c52002-09-16 22:36:42 +0000458# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000459LIBRARYNAME := $(strip $(LIBRARYNAME))
460
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000461LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
462LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
463LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
464LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
465LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
466LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
467LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
468LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
469LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000470
John Criswell7a73b802003-06-30 21:59:07 +0000471#--------------------------------------------------------------------
472# Library Targets
473# Modify the top level targets to build the desired libraries.
474#--------------------------------------------------------------------
475
Chris Lattner760da062003-03-14 20:25:22 +0000476# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000477dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000478
Chris Lattner760da062003-03-14 20:25:22 +0000479# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000480ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000481all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000482endif
Chris Lattner760da062003-03-14 20:25:22 +0000483
484# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000485ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000486all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000487endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000488
John Criswell7a73b802003-06-30 21:59:07 +0000489#--------------------------------------------------------------------
490# Rules for building libraries
491#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000492
John Criswell7a73b802003-06-30 21:59:07 +0000493#
494# Rules for building dynamically linked libraries.
495#
John Criswellf4ccd992003-07-01 14:52:28 +0000496$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000497 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000498 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000499 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve41e78912002-09-20 14:03:13 +0000500
John Criswellf4ccd992003-07-01 14:52:28 +0000501$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000502 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000503 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000504 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner00950542001-06-06 20:29:01 +0000505
John Criswellf4ccd992003-07-01 14:52:28 +0000506$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000507 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000508 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000509 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000510
John Criswell7a73b802003-06-30 21:59:07 +0000511#
512# Rules for building static archive libraries.
513#
John Criswellf4ccd992003-07-01 14:52:28 +0000514$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000515 @echo ======= Linking $(LIBRARYNAME) archive release library =======
516 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000517 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000518
John Criswellf4ccd992003-07-01 14:52:28 +0000519$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000520 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
521 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000522 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000523
John Criswellf4ccd992003-07-01 14:52:28 +0000524$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000525 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
526 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000527 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000528
529#
530# Rules for building .o libraries.
531#
John Criswellf4ccd992003-07-01 14:52:28 +0000532$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000533 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000534 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000535
John Criswellf4ccd992003-07-01 14:52:28 +0000536$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000537 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000538 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000539
John Criswellf4ccd992003-07-01 14:52:28 +0000540$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000541 @echo "Linking $@"
John Criswellf4ccd992003-07-01 14:52:28 +0000542 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000543
Chris Lattner00950542001-06-06 20:29:01 +0000544endif
545
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000546#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000547# Create a TAGS database for emacs
548#------------------------------------------------------------------------
549
John Criswell7a73b802003-06-30 21:59:07 +0000550ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000551ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000552tags:
John Criswell7a73b802003-06-30 21:59:07 +0000553 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000554all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000555endif
John Criswell7a73b802003-06-30 21:59:07 +0000556else
557tags:
558 ${ECHO} "Cannot build $@: The program etags is not installed"
559endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000560
561#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000562# Handle the TOOLNAME option - used when building tool executables...
563#------------------------------------------------------------------------
564#
565# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000566# libraries (and the order of the libs) that should be linked to the
567# tool. USEDLIBS should contain a list of library names (some with .a extension)
568# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000569#
570ifdef TOOLNAME
571
572# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000573TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
574TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
575TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
576TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000577
578# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000579PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
580PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
581PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
582PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
583
584LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
585LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
586LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
587LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
588
589LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000590LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000591LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
592
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000593# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000594# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
595# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000596#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000597STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000598USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
599USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
600USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
John Criswell7a73b802003-06-30 21:59:07 +0000601#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000602
John Criswell7a73b802003-06-30 21:59:07 +0000603#
604# Libtool link options:
605# Ensure that all binaries have their symbols exported so that they can
606# by dlsym'ed.
607#
608LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000609
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000610
611
612
613
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000614# Tell make that we need to rebuild subdirectories before we can link the tool.
615# This affects things like LLI which has library subdirectories.
616$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
617 $(addsuffix /.makeall, $(PARALLEL_DIRS))
618
Chris Lattner669bd7c2001-10-13 05:10:29 +0000619all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000620
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000621clean::
John Criswell7a73b802003-06-30 21:59:07 +0000622 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000623
John Criswellf4ccd992003-07-01 14:52:28 +0000624$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000625 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000626 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000627
John Criswellf4ccd992003-07-01 14:52:28 +0000628$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000629 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000630 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000631
John Criswellf4ccd992003-07-01 14:52:28 +0000632$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000633 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000634 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000635
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000636endif
637
638
Chris Lattner00950542001-06-06 20:29:01 +0000639
640#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000641.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
642.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000643
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000644# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell7a73b802003-06-30 21:59:07 +0000645#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
646 #@echo "Compiling $<"
647 #$(VERB) $(CompileO) $< -o $@
648
649#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
650 #$(VERB) $(CompileCO) $< -o $@
651
652#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
653 #@echo "Compiling $<"
654 #$(VERB) $(CompileP) $< -o $@
655
656#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
657 #@echo "Compiling $<"
658 #$(VERB) $(CompileCP) $< -o $@
659
660#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
661 #@echo "Compiling $<"
662 #$(VERB) $(CompileG) $< -o $@
663
664#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
665 #$(VERB) $(CompileCG) $< -o $@
666
667# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
668$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000669 @echo "Compiling $<"
670 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000671
John Criswell7a73b802003-06-30 21:59:07 +0000672$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
673 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000674 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000675
John Criswell7a73b802003-06-30 21:59:07 +0000676$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000677 @echo "Compiling $<"
678 $(VERB) $(CompileP) $< -o $@
679
John Criswell7a73b802003-06-30 21:59:07 +0000680$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000681 @echo "Compiling $<"
682 $(VERB) $(CompileCP) $< -o $@
683
John Criswell7a73b802003-06-30 21:59:07 +0000684$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000685 @echo "Compiling $<"
686 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000687
John Criswell7a73b802003-06-30 21:59:07 +0000688$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
689 @echo "Compiling $<"
690 $(VERB) $(CompileCG) $< -o $@
691
692# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
693$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
694 @echo "Compiling $<"
695 $(VERB) $(CompileO) $< -o $@
696
697$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
698 $(VERB) $(CompileCO) $< -o $@
699
700$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
701 @echo "Compiling $<"
702 $(VERB) $(CompileP) $< -o $@
703
704$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
705 @echo "Compiling $<"
706 $(VERB) $(CompileCP) $< -o $@
707
708$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
709 @echo "Compiling $<"
710 $(VERB) $(CompileG) $< -o $@
711
712$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000713 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000714
Chris Lattnere8996782003-01-16 22:44:19 +0000715#
716# Rules for building lex/yacc files
717#
718LEX_FILES = $(filter %.l, $(Source))
719LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
720YACC_FILES = $(filter %.y, $(Source))
721YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
722.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
723
Chris Lattner00950542001-06-06 20:29:01 +0000724# Create a .cpp source file from a flex input file... this uses sed to cut down
725# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000726#
727# The last line is a gross hack to work around flex aparently not being able to
728# resize the buffer on a large token input. Currently, for uninitialized string
729# buffers in LLVM we can generate very long tokens, so this is a hack around it.
730# FIXME. (f.e. char Buffer[10000]; )
731#
Chris Lattner00950542001-06-06 20:29:01 +0000732%.cpp: %.l
John Criswell7a73b802003-06-30 21:59:07 +0000733 $(FLEX) -t $< | $(SED) '/^find_rule/d' | \
734 $(SED) 's/void yyunput/inline void yyunput/' | \
735 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
736 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000737
738# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000739%.c: %.y # Cancel built-in rules for yacc
740%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000741%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000742 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000743 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswell7a73b802003-06-30 21:59:07 +0000744 $(VERB) ${MV} -f $*.tab.c $*.cpp
745 $(VERB) ${MV} -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000746
747# To create the directories...
748%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000749 $(VERB) ${MKDIR} $* > /dev/null
750 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000751
Chris Lattner30440c62003-01-16 21:06:18 +0000752# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000753ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000754%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000755 ${DOT} -Tps < $< > $@
756else
757%.ps: %.dot
758 ${ECHO} "Cannot build $@: The program dot is not installed"
759endif
Chris Lattner30440c62003-01-16 21:06:18 +0000760
Chris Lattner172b6482002-09-22 02:47:15 +0000761# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000762clean::
John Criswell7a73b802003-06-30 21:59:07 +0000763 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
764 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
765 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
766
767distclean:: clean
768 $(VERB) (cd $(LLVM_SRC_ROOT); $(RM) -rf $(LEVEL)/Makefile.config \
769 $(LEVEL)/include/Config/config.h \
770 $(LEVEL)/autom4te.cache \
771 $(LEVEL)/config.log)
772
773###########################################################################
774# C/C++ Dependencies
775# Define variables and rules that generate header file dependencies
776# from C/C++ source files.
777###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000778
Chris Lattner694c5df2003-05-15 21:28:55 +0000779# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000780# include the dependancies now...
781#
Chris Lattner694c5df2003-05-15 21:28:55 +0000782SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000783SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000784
John Criswell7a73b802003-06-30 21:59:07 +0000785#
786# Depend target:
787# This allows a user to manually ask for an update in the dependencies
788#
789depend: $(SourceDepend)
790
791
Chris Lattner694c5df2003-05-15 21:28:55 +0000792# Create dependencies for the *.cpp files...
793#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000794$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000795 $(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 +0000796
797# Create dependencies for the *.c files...
798#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000799$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000800 $(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 +0000801
John Criswell7a73b802003-06-30 21:59:07 +0000802#
803# Include dependencies generated from C/C++ source files, but not if we
804# are cleaning (this example taken from the GNU Make Manual).
805#
806ifneq ($(MAKECMDGOALS),clean)
Chris Lattner00950542001-06-06 20:29:01 +0000807ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000808-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000809endif
John Criswell7a73b802003-06-30 21:59:07 +0000810endif