blob: 9a69fc4c7aafd753263e4e4b3e8b357212aa518d [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#
Vikram S. Adved60aede2002-07-09 12:04:21 +000041#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000042
Vikram S. Advec214e712002-08-29 23:28:46 +000043# Configuration file to set paths specific to local installation of LLVM
44#
45include $(LEVEL)/Makefile.config
46
John Criswell8bff5092003-06-11 13:55:44 +000047###########################################################################
48# Directory Configuration
49# This section of the Makefile determines what is where. To be
50# specific, there are several locations that need to be defined:
51#
52# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
53# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
54#
55# o BUILD_SRC_DIR : The directory containing the code to build.
56# o BUILD_SRC_ROOT : The root directory of the code to build.
57#
58# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
59# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
60#
61###########################################################################
62
63#
64# Set the source build directory. That is almost always the current directory.
65#
66ifndef BUILD_SRC_DIR
67BUILD_SRC_DIR = $(shell pwd)
68endif
69
70#
71# Set the source root directory.
72#
73ifndef BUILD_SRC_ROOT
John Criswell890d5bd2003-06-16 19:14:31 +000074BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell8bff5092003-06-11 13:55:44 +000075endif
76
77#
78# Set the object build directory. Its location depends upon the source path
79# and where object files should go.
80#
81ifndef BUILD_OBJ_DIR
82ifeq ($(OBJ_ROOT),.)
83BUILD_OBJ_DIR = $(shell pwd)
84else
John Criswell6f4ad0b2003-06-20 21:24:54 +000085BUILD_OBJ_DIR := $(OBJ_ROOT)$(patsubst $(shell dirname $(BUILD_SRC_ROOT))%,%,$(shell cd $(BUILD_SRC_DIR); pwd))
John Criswell8bff5092003-06-11 13:55:44 +000086endif
87endif
88
89#
90# Set the root of the object directory.
91#
92ifndef BUILD_OBJ_ROOT
93ifeq ($(OBJ_ROOT),.)
94BUILD_OBJ_ROOT = $(shell cd $(LEVEL); pwd)
95else
John Criswell6f4ad0b2003-06-20 21:24:54 +000096BUILD_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(shell dirname $(BUILD_SRC_ROOT))%,%,$(shell cd $(BUILD_SRC_ROOT); pwd))
John Criswell8bff5092003-06-11 13:55:44 +000097endif
98endif
99
100#
101# Set the LLVM source directory.
102# It is typically the root directory of what we're compiling now.
103#
104ifndef LLVM_SRC_ROOT
105LLVM_SRC_ROOT = $(BUILD_SRC_ROOT)
106endif
107
108#
109# Set the LLVM object directory.
110#
111ifndef LLVM_OBJ_ROOT
112LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT)
113endif
114
Chris Lattner4bb13b82002-09-13 22:14:47 +0000115# Figure out how to do platform specific stuff on this platform. This is really
116# gross and should be autoconfiscated (automake actually), but should hopefully
117# work on Linux and solaris (SunOS).
118#
119UNAME := $(shell uname)
John Criswell8bff5092003-06-11 13:55:44 +0000120include $(LLVM_SRC_ROOT)/Makefile.$(UNAME)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000121
Chris Lattneredf1f232002-07-23 19:21:31 +0000122ifdef SHARED_LIBRARY
123# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
124dynamic ::
125endif
126
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000127# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000128all ::
129
130# Default for install is to at least build everything...
131install ::
132
John Criswell8bff5092003-06-11 13:55:44 +0000133# Default rule for test. It ensures everything has a test rule
134test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000135
Chris Lattner00950542001-06-06 20:29:01 +0000136#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000137# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000138#--------------------------------------------------------------------
139
140#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000141#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000142#DocInstDir=/usr/doc/xxx
143
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000144BURG_OPTS = -I
145
John Criswell8bff5092003-06-11 13:55:44 +0000146PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000147
Chris Lattner760da062003-03-14 20:25:22 +0000148ifdef ENABLE_PROFILING
149 ENABLE_OPTIMIZED = 1
150 CONFIGURATION := Profile
151else
152 ifdef ENABLE_OPTIMIZED
153 CONFIGURATION := Release
154 else
155 CONFIGURATION := Debug
156 endif
157endif
158
John Criswell8bff5092003-06-11 13:55:44 +0000159###########################################################################
160# Library Locations
161# These variables describe various library locations:
162#
163# DEST* = Location of where libraries that are built will be placed.
164# LLVM* = Location of LLVM libraries used for linking.
165# PROJ* = Location of previously built libraries used for linking.
166###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000167
John Criswell8bff5092003-06-11 13:55:44 +0000168# Libraries that are being built
169DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
170DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
171DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
172DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000173
John Criswell8bff5092003-06-11 13:55:44 +0000174# LLVM libraries used for linking
175LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
176LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
177LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
178LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000179
John Criswell8bff5092003-06-11 13:55:44 +0000180# Libraries that were built that will now be used for linking
181PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
182PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
183PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
184PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000185
John Criswell8bff5092003-06-11 13:55:44 +0000186###########################################################################
187# Tool Locations
188# These variables describe various tool locations:
189#
190# DEST* = Location of where tools that are built will be placed.
191# LLVM* = Location of LLVM tools used for building.
192# PROJ* = Location of previously built tools used for linking.
193###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000194
John Criswell8bff5092003-06-11 13:55:44 +0000195DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
196DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
197DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
198DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
199
200LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
201LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
202LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
203LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
204
205PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
206PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
207PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
208PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000209
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000210# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000211ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000212VERB := @
213endif
214
Chris Lattner00950542001-06-06 20:29:01 +0000215#---------------------------------------------------------
216# Compilation options...
217#---------------------------------------------------------
218
John Criswell8bff5092003-06-11 13:55:44 +0000219###########################################################################
Chris Lattner9b947012002-09-19 19:42:24 +0000220# Special tools used while building the LLVM tree. Burg is built as part of the
221# utils directory.
John Criswell8bff5092003-06-11 13:55:44 +0000222###########################################################################
223BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000224RunBurg := $(BURG) $(BURG_OPTS)
225
John Criswell8bff5092003-06-11 13:55:44 +0000226TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000227
Chris Lattner00950542001-06-06 20:29:01 +0000228# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000229# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000230ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000231 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000232endif
Chris Lattner00950542001-06-06 20:29:01 +0000233
John Criswell8bff5092003-06-11 13:55:44 +0000234###########################################################################
235# Compile Time Flags
236###########################################################################
237
238#
239# Include both the project headers and the LLVM headers for compilation
240#
241CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000242
Vikram S. Advefeeae582002-09-18 11:55:13 +0000243# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000244ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000245STRIP = $(PLATFORMSTRIPOPTS)
246STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000247endif
248
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000249# Allow gnu extensions...
250CPPFLAGS += -D_GNU_SOURCE
251
Chris Lattnerc7acf812002-01-23 05:46:01 +0000252# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000253CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000254CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000255
Chris Lattner172b6482002-09-22 02:47:15 +0000256# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000257Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
258CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000259CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
260CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000261
Chris Lattner172b6482002-09-22 02:47:15 +0000262# Compile a c file, don't link...
263CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
264CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000265CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
266CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000267
268
Chris Lattner00950542001-06-06 20:29:01 +0000269# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000270
Chris Lattner1917e952002-07-31 21:32:05 +0000271ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000272Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000273else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000274Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000275endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000276
277ifdef PROJ_COMPILE
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000278# include both projlib source and llvmlib source
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000279LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
280LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
281LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
282else
283LinkG := $(Link) -g -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
284LinkO := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
285LinkP := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
286endif
287
288
Chris Lattner00950542001-06-06 20:29:01 +0000289
Chris Lattnere62dbe92002-07-23 17:56:16 +0000290# Create one .o file from a bunch of .o files...
John Criswell794fcd22003-05-30 15:50:31 +0000291Relink = ${LD} -r
Chris Lattnere62dbe92002-07-23 17:56:16 +0000292
Chris Lattner4bb13b82002-09-13 22:14:47 +0000293# MakeSO - Create a .so file from a .o files...
Vikram S. Adve41e78912002-09-20 14:03:13 +0000294MakeSO := $(CXX) $(MakeSharedObjectOption)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000295MakeSOO := $(MakeSO) -O3
Vikram S. Adve41e78912002-09-20 14:03:13 +0000296MakeSOP := $(MakeSOO) $(PROFILE)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000297
Chris Lattner00950542001-06-06 20:29:01 +0000298# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000299Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
300DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000301
302# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000303AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000304
305#----------------------------------------------------------
306
307# Source includes all of the cpp files, and objects are derived from the
308# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000309# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000310#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000311ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000312Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000313endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000314
Chris Lattner694c5df2003-05-15 21:28:55 +0000315Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
John Criswell8bff5092003-06-11 13:55:44 +0000316ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
317ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
318ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000319
Chris Lattnere62dbe92002-07-23 17:56:16 +0000320
Chris Lattner00950542001-06-06 20:29:01 +0000321#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000322# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000323#---------------------------------------------------------
324
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000325ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000326all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000327 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000328 (cd $$dir; $(MAKE) $@) || exit 1; \
329 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000330endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000331
332# Handle PARALLEL_DIRS
333ifdef PARALLEL_DIRS
334all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
335install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
336clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000337test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000338
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000339%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000340 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000341endif
342
343#---------------------------------------------------------
344# Handle the LIBRARYNAME option - used when building libs...
345#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000346#
347# When libraries are built, they are allowed to optionally define the
348# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
349# from being built for the library. This .o files may then be linked to by a
350# tool if the tool does not need (or want) the semantics a .a file provides
351# (linking in only object files that are "needed"). If a library is never to
352# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
353# BUILD_ARCHIVE instead.
354#
355# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000356# 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 +0000357# linked into tools (for example gccas) even if they only use one of the parts
358# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000359
360ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000361
Chris Lattner2a548c52002-09-16 22:36:42 +0000362# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000363LIBRARYNAME := $(strip $(LIBRARYNAME))
364
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000365LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
366LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
367LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
368LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
369LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
370LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
371LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
372LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
373LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000374
Chris Lattner760da062003-03-14 20:25:22 +0000375# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000376dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000377
Chris Lattner760da062003-03-14 20:25:22 +0000378# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000379ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000380all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000381endif
Chris Lattner760da062003-03-14 20:25:22 +0000382
383# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000384ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000385all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000386endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000387
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000388$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000389 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000390 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000391
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000392$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000393 @echo ======= Linking $(LIBRARYNAME) profile library =======
394 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
395
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000396$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000397 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000398 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000399
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000400$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000401 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000402 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000403 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000404
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000405$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000406 @echo ======= Linking $(LIBRARYNAME) profile library =======
407 @rm -f $@
408 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
409
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000410$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000411 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000412 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000413 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000414
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000415$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000416 @echo "Linking $@"
417 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000418
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000419$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000420 @echo "Linking $@"
421 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
422
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000423$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000424 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000425 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000426
Chris Lattner00950542001-06-06 20:29:01 +0000427endif
428
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000429#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000430# Create a TAGS database for emacs
431#------------------------------------------------------------------------
432
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000433ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000434tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000435 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000436all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000437endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000438
439#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000440# Handle the TOOLNAME option - used when building tool executables...
441#------------------------------------------------------------------------
442#
443# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000444# libraries (and the order of the libs) that should be linked to the
445# tool. USEDLIBS should contain a list of library names (some with .a extension)
446# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000447#
448ifdef TOOLNAME
449
450# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000451TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
452TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
453TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
454TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000455
456# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000457PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
458PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
459PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
460PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
461
462LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
463LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
464LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
465LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
466
467LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000468LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000469LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
470
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000471# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000472# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
473# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000474#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000475STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000476USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
477USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
478USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000479LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000480
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000481
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000482
483
484
485
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000486# Tell make that we need to rebuild subdirectories before we can link the tool.
487# This affects things like LLI which has library subdirectories.
488$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
489 $(addsuffix /.makeall, $(PARALLEL_DIRS))
490
Chris Lattner669bd7c2001-10-13 05:10:29 +0000491all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000492clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000493 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000494
John Criswell8bff5092003-06-11 13:55:44 +0000495$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000496 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
497 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000498
John Criswell8bff5092003-06-11 13:55:44 +0000499$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000500 @echo ======= Linking $(TOOLNAME) release executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000501 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000502
John Criswell8bff5092003-06-11 13:55:44 +0000503$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000504 @echo ======= Linking $(TOOLNAME) profile executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000505 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000506
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000507endif
508
509
Chris Lattner00950542001-06-06 20:29:01 +0000510
511#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000512.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
513.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000514
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000515# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell8bff5092003-06-11 13:55:44 +0000516$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000517 @echo "Compiling $<"
518 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000519
John Criswell8bff5092003-06-11 13:55:44 +0000520$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000521 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000522
John Criswell8bff5092003-06-11 13:55:44 +0000523$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000524 @echo "Compiling $<"
525 $(VERB) $(CompileP) $< -o $@
526
John Criswell8bff5092003-06-11 13:55:44 +0000527$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000528 @echo "Compiling $<"
529 $(VERB) $(CompileCP) $< -o $@
530
John Criswell8bff5092003-06-11 13:55:44 +0000531$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000532 @echo "Compiling $<"
533 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000534
John Criswell8bff5092003-06-11 13:55:44 +0000535$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000536 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000537
Chris Lattnere8996782003-01-16 22:44:19 +0000538#
539# Rules for building lex/yacc files
540#
541LEX_FILES = $(filter %.l, $(Source))
542LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
543YACC_FILES = $(filter %.y, $(Source))
544YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
545.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
546
Chris Lattner00950542001-06-06 20:29:01 +0000547# Create a .cpp source file from a flex input file... this uses sed to cut down
548# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000549#
550# The last line is a gross hack to work around flex aparently not being able to
551# resize the buffer on a large token input. Currently, for uninitialized string
552# buffers in LLVM we can generate very long tokens, so this is a hack around it.
553# FIXME. (f.e. char Buffer[10000]; )
554#
Chris Lattner00950542001-06-06 20:29:01 +0000555%.cpp: %.l
John Criswell65aa59342003-05-29 18:52:10 +0000556 $(FLEX) -t $< | sed '/^find_rule/d' | \
Chris Lattner6d131b42003-01-23 16:33:10 +0000557 sed 's/void yyunput/inline void yyunput/' | \
558 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
559 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000560
561# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000562%.c: %.y # Cancel built-in rules for yacc
563%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000564%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000565 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000566 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
567 $(VERB) mv -f $*.tab.c $*.cpp
568 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000569
570# To create the directories...
571%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000572 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000573 @date > $@
574
Chris Lattner30440c62003-01-16 21:06:18 +0000575# To create postscript files from dot files...
576%.ps: %.dot
577 dot -Tps < $< > $@
578
Chris Lattner172b6482002-09-22 02:47:15 +0000579# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000580clean::
John Criswell8bff5092003-06-11 13:55:44 +0000581 $(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 +0000582 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000583 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000584
Chris Lattner694c5df2003-05-15 21:28:55 +0000585# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000586# include the dependancies now...
587#
Chris Lattner694c5df2003-05-15 21:28:55 +0000588SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000589SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000590
591# Create dependencies for the *.cpp files...
592#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000593$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
594 $(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 +0000595
596# Create dependencies for the *.c files...
597#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000598$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner694c5df2003-05-15 21:28:55 +0000599 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
600
Chris Lattner00950542001-06-06 20:29:01 +0000601ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000602-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000603endif