blob: b2411900bf19ab1edbe75e5710307f2cba96bc10 [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#
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000033# 6. PROJ_COMPILE - If set to 1, then this makefile can also be used to
34# compile other projects using llvm. Note if this option is set then the
35# following *must* hold
36# PROJLEVEL should be set to the top of the source directory for the
37# project files
38# LEVEL should be set to the top of LLVM source tree
39# LLVM_LIB_DIR should be set to the top of the LLVM build tree
40#
41#
Vikram S. Adved60aede2002-07-09 12:04:21 +000042#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000043
Vikram S. Advec214e712002-08-29 23:28:46 +000044# Configuration file to set paths specific to local installation of LLVM
45#
46include $(LEVEL)/Makefile.config
47
John Criswell8bff5092003-06-11 13:55:44 +000048###########################################################################
49# Directory Configuration
50# This section of the Makefile determines what is where. To be
51# specific, there are several locations that need to be defined:
52#
53# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
54# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
55#
56# o BUILD_SRC_DIR : The directory containing the code to build.
57# o BUILD_SRC_ROOT : The root directory of the code to build.
58#
59# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
60# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
61#
62###########################################################################
63
64#
65# Set the source build directory. That is almost always the current directory.
66#
67ifndef BUILD_SRC_DIR
68BUILD_SRC_DIR = $(shell pwd)
69endif
70
71#
72# Set the source root directory.
73#
74ifndef BUILD_SRC_ROOT
75BUILD_SRC_ROOT = $(BUILD_SRC_DIR)/$(LEVEL)
76endif
77
78#
79# Set the object build directory. Its location depends upon the source path
80# and where object files should go.
81#
82ifndef BUILD_OBJ_DIR
83ifeq ($(OBJ_ROOT),.)
84BUILD_OBJ_DIR = $(shell pwd)
85else
86BUILD_OBJ_DIR := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(shell cd $(BUILD_SRC_DIR); pwd))
87endif
88endif
89
90#
91# Set the root of the object directory.
92#
93ifndef BUILD_OBJ_ROOT
94ifeq ($(OBJ_ROOT),.)
95BUILD_OBJ_ROOT = $(shell cd $(LEVEL); pwd)
96else
97BUILD_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(shell cd $(LEVEL); pwd))
98endif
99endif
100
101#
102# Set the LLVM source directory.
103# It is typically the root directory of what we're compiling now.
104#
105ifndef LLVM_SRC_ROOT
106LLVM_SRC_ROOT = $(BUILD_SRC_ROOT)
107endif
108
109#
110# Set the LLVM object directory.
111#
112ifndef LLVM_OBJ_ROOT
113LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT)
114endif
115
Chris Lattner4bb13b82002-09-13 22:14:47 +0000116# Figure out how to do platform specific stuff on this platform. This is really
117# gross and should be autoconfiscated (automake actually), but should hopefully
118# work on Linux and solaris (SunOS).
119#
120UNAME := $(shell uname)
John Criswell8bff5092003-06-11 13:55:44 +0000121include $(LLVM_SRC_ROOT)/Makefile.$(UNAME)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000122
Chris Lattneredf1f232002-07-23 19:21:31 +0000123ifdef SHARED_LIBRARY
124# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
125dynamic ::
126endif
127
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000128# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000129all ::
130
131# Default for install is to at least build everything...
132install ::
133
John Criswell8bff5092003-06-11 13:55:44 +0000134# Default rule for test. It ensures everything has a test rule
135test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000136
Chris Lattner00950542001-06-06 20:29:01 +0000137#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000138# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000139#--------------------------------------------------------------------
140
141#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000142#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000143#DocInstDir=/usr/doc/xxx
144
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000145BURG_OPTS = -I
146
John Criswell8bff5092003-06-11 13:55:44 +0000147PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000148
Chris Lattner760da062003-03-14 20:25:22 +0000149ifdef ENABLE_PROFILING
150 ENABLE_OPTIMIZED = 1
151 CONFIGURATION := Profile
152else
153 ifdef ENABLE_OPTIMIZED
154 CONFIGURATION := Release
155 else
156 CONFIGURATION := Debug
157 endif
158endif
159
John Criswell8bff5092003-06-11 13:55:44 +0000160###########################################################################
161# Library Locations
162# These variables describe various library locations:
163#
164# DEST* = Location of where libraries that are built will be placed.
165# LLVM* = Location of LLVM libraries used for linking.
166# PROJ* = Location of previously built libraries used for linking.
167###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000168
John Criswell8bff5092003-06-11 13:55:44 +0000169# Libraries that are being built
170DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
171DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
172DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
173DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000174
John Criswell8bff5092003-06-11 13:55:44 +0000175# LLVM libraries used for linking
176LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
177LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
178LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
179LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000180
John Criswell8bff5092003-06-11 13:55:44 +0000181# Libraries that were built that will now be used for linking
182PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
183PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
184PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
185PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000186
John Criswell8bff5092003-06-11 13:55:44 +0000187###########################################################################
188# Tool Locations
189# These variables describe various tool locations:
190#
191# DEST* = Location of where tools that are built will be placed.
192# LLVM* = Location of LLVM tools used for building.
193# PROJ* = Location of previously built tools used for linking.
194###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000195
John Criswell8bff5092003-06-11 13:55:44 +0000196DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
197DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
198DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
199DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
200
201LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
202LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
203LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
204LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
205
206PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
207PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
208PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
209PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000210
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000211# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000212ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000213VERB := @
214endif
215
Chris Lattner00950542001-06-06 20:29:01 +0000216#---------------------------------------------------------
217# Compilation options...
218#---------------------------------------------------------
219
John Criswell8bff5092003-06-11 13:55:44 +0000220###########################################################################
Chris Lattner9b947012002-09-19 19:42:24 +0000221# Special tools used while building the LLVM tree. Burg is built as part of the
222# utils directory.
John Criswell8bff5092003-06-11 13:55:44 +0000223###########################################################################
224BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000225RunBurg := $(BURG) $(BURG_OPTS)
226
John Criswell8bff5092003-06-11 13:55:44 +0000227TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000228
Chris Lattner00950542001-06-06 20:29:01 +0000229# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000230# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000231ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000232 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000233endif
Chris Lattner00950542001-06-06 20:29:01 +0000234
John Criswell8bff5092003-06-11 13:55:44 +0000235###########################################################################
236# Compile Time Flags
237###########################################################################
238
239#
240# Include both the project headers and the LLVM headers for compilation
241#
242CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000243
Vikram S. Advefeeae582002-09-18 11:55:13 +0000244# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000245ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000246STRIP = $(PLATFORMSTRIPOPTS)
247STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000248endif
249
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000250# Allow gnu extensions...
251CPPFLAGS += -D_GNU_SOURCE
252
Chris Lattnerc7acf812002-01-23 05:46:01 +0000253# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000254CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000255CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000256
Chris Lattner172b6482002-09-22 02:47:15 +0000257# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000258Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
259CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000260CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
261CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000262
Chris Lattner172b6482002-09-22 02:47:15 +0000263# Compile a c file, don't link...
264CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
265CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000266CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
267CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000268
269
Chris Lattner00950542001-06-06 20:29:01 +0000270# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000271
Chris Lattner1917e952002-07-31 21:32:05 +0000272ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000273Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000274else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000275Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000276endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000277
278ifdef PROJ_COMPILE
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000279# include both projlib source and llvmlib source
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000280LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
281LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
282LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
283else
284LinkG := $(Link) -g -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
285LinkO := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
286LinkP := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
287endif
288
289
Chris Lattner00950542001-06-06 20:29:01 +0000290
Chris Lattnere62dbe92002-07-23 17:56:16 +0000291# Create one .o file from a bunch of .o files...
John Criswell794fcd22003-05-30 15:50:31 +0000292Relink = ${LD} -r
Chris Lattnere62dbe92002-07-23 17:56:16 +0000293
Chris Lattner4bb13b82002-09-13 22:14:47 +0000294# MakeSO - Create a .so file from a .o files...
Vikram S. Adve41e78912002-09-20 14:03:13 +0000295MakeSO := $(CXX) $(MakeSharedObjectOption)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000296MakeSOO := $(MakeSO) -O3
Vikram S. Adve41e78912002-09-20 14:03:13 +0000297MakeSOP := $(MakeSOO) $(PROFILE)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000298
Chris Lattner00950542001-06-06 20:29:01 +0000299# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000300Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
301DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000302
303# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000304AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000305
306#----------------------------------------------------------
307
308# Source includes all of the cpp files, and objects are derived from the
309# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000310# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000311#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000312ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000313Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000314endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000315
Chris Lattner694c5df2003-05-15 21:28:55 +0000316Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
John Criswell8bff5092003-06-11 13:55:44 +0000317ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
318ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
319ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000320
Chris Lattnere62dbe92002-07-23 17:56:16 +0000321
Chris Lattner00950542001-06-06 20:29:01 +0000322#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000323# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000324#---------------------------------------------------------
325
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000326ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000327all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000328 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000329 (cd $$dir; $(MAKE) $@) || exit 1; \
330 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000331endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000332
333# Handle PARALLEL_DIRS
334ifdef PARALLEL_DIRS
335all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
336install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
337clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000338test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000339
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000340%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000341 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000342endif
343
344#---------------------------------------------------------
345# Handle the LIBRARYNAME option - used when building libs...
346#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000347#
348# When libraries are built, they are allowed to optionally define the
349# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
350# from being built for the library. This .o files may then be linked to by a
351# tool if the tool does not need (or want) the semantics a .a file provides
352# (linking in only object files that are "needed"). If a library is never to
353# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
354# BUILD_ARCHIVE instead.
355#
356# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000357# 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 +0000358# linked into tools (for example gccas) even if they only use one of the parts
359# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000360
361ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000362
Chris Lattner2a548c52002-09-16 22:36:42 +0000363# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000364LIBRARYNAME := $(strip $(LIBRARYNAME))
365
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000366LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
367LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
368LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
369LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
370LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
371LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
372LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
373LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
374LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000375
Chris Lattner760da062003-03-14 20:25:22 +0000376# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000377dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000378
Chris Lattner760da062003-03-14 20:25:22 +0000379# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000380ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000381all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000382endif
Chris Lattner760da062003-03-14 20:25:22 +0000383
384# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000385ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000386all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000387endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000388
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000389$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000390 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000391 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000392
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000393$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000394 @echo ======= Linking $(LIBRARYNAME) profile library =======
395 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
396
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000397$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000398 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000399 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000400
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000401$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000402 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000403 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000404 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000405
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000406$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000407 @echo ======= Linking $(LIBRARYNAME) profile library =======
408 @rm -f $@
409 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
410
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000411$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000412 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000413 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000414 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000415
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000416$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000417 @echo "Linking $@"
418 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000419
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000420$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000421 @echo "Linking $@"
422 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
423
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000424$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000425 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000426 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000427
Chris Lattner00950542001-06-06 20:29:01 +0000428endif
429
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000430#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000431# Create a TAGS database for emacs
432#------------------------------------------------------------------------
433
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000434ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000435tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000436 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000437all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000438endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000439
440#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000441# Handle the TOOLNAME option - used when building tool executables...
442#------------------------------------------------------------------------
443#
444# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000445# libraries (and the order of the libs) that should be linked to the
446# tool. USEDLIBS should contain a list of library names (some with .a extension)
447# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000448#
449ifdef TOOLNAME
450
451# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000452TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
453TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
454TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
455TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000456
457# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000458PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
459PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
460PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
461PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
462
463LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
464LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
465LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
466LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
467
468LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
469LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P)
470LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
471
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000472# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000473# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
474# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000475#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000476STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000477USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
478USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
479USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000480LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000481
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000482
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000483
484
485
486
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000487# Tell make that we need to rebuild subdirectories before we can link the tool.
488# This affects things like LLI which has library subdirectories.
489$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
490 $(addsuffix /.makeall, $(PARALLEL_DIRS))
491
Chris Lattner669bd7c2001-10-13 05:10:29 +0000492all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000493clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000494 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000495
John Criswell8bff5092003-06-11 13:55:44 +0000496$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000497 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
498 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000499
John Criswell8bff5092003-06-11 13:55:44 +0000500$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000501 @echo ======= Linking $(TOOLNAME) release executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000502 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000503
John Criswell8bff5092003-06-11 13:55:44 +0000504$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000505 @echo ======= Linking $(TOOLNAME) profile executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000506 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000507
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000508endif
509
510
Chris Lattner00950542001-06-06 20:29:01 +0000511
512#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000513.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
514.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000515
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000516# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell8bff5092003-06-11 13:55:44 +0000517$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000518 @echo "Compiling $<"
519 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000520
John Criswell8bff5092003-06-11 13:55:44 +0000521$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000522 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000523
John Criswell8bff5092003-06-11 13:55:44 +0000524$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000525 @echo "Compiling $<"
526 $(VERB) $(CompileP) $< -o $@
527
John Criswell8bff5092003-06-11 13:55:44 +0000528$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000529 @echo "Compiling $<"
530 $(VERB) $(CompileCP) $< -o $@
531
John Criswell8bff5092003-06-11 13:55:44 +0000532$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000533 @echo "Compiling $<"
534 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000535
John Criswell8bff5092003-06-11 13:55:44 +0000536$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000537 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000538
Chris Lattnere8996782003-01-16 22:44:19 +0000539#
540# Rules for building lex/yacc files
541#
542LEX_FILES = $(filter %.l, $(Source))
543LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
544YACC_FILES = $(filter %.y, $(Source))
545YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
546.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
547
Chris Lattner00950542001-06-06 20:29:01 +0000548# Create a .cpp source file from a flex input file... this uses sed to cut down
549# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000550#
551# The last line is a gross hack to work around flex aparently not being able to
552# resize the buffer on a large token input. Currently, for uninitialized string
553# buffers in LLVM we can generate very long tokens, so this is a hack around it.
554# FIXME. (f.e. char Buffer[10000]; )
555#
Chris Lattner00950542001-06-06 20:29:01 +0000556%.cpp: %.l
John Criswell65aa59342003-05-29 18:52:10 +0000557 $(FLEX) -t $< | sed '/^find_rule/d' | \
Chris Lattner6d131b42003-01-23 16:33:10 +0000558 sed 's/void yyunput/inline void yyunput/' | \
559 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
560 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000561
562# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000563%.c: %.y # Cancel built-in rules for yacc
564%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000565%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000566 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000567 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
568 $(VERB) mv -f $*.tab.c $*.cpp
569 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000570
571# To create the directories...
572%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000573 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000574 @date > $@
575
Chris Lattner30440c62003-01-16 21:06:18 +0000576# To create postscript files from dot files...
577%.ps: %.dot
578 dot -Tps < $< > $@
579
Chris Lattner172b6482002-09-22 02:47:15 +0000580# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000581clean::
John Criswell8bff5092003-06-11 13:55:44 +0000582 $(VERB) rm -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
Misha Brukmanab6d2932002-12-04 17:08:15 +0000583 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000584 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000585
Chris Lattner694c5df2003-05-15 21:28:55 +0000586# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000587# include the dependancies now...
588#
Chris Lattner694c5df2003-05-15 21:28:55 +0000589SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000590SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000591
592# Create dependencies for the *.cpp files...
593#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000594$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
595 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(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 +0000596
597# Create dependencies for the *.c files...
598#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000599$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner694c5df2003-05-15 21:28:55 +0000600 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
601
Chris Lattner00950542001-06-06 20:29:01 +0000602ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000603-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000604endif