blob: b803def09e2205ee88e273913e35f2cd463c9946 [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#
Vikram S. Adved60aede2002-07-09 12:04:21 +000029#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000030
Vikram S. Advec214e712002-08-29 23:28:46 +000031# Configuration file to set paths specific to local installation of LLVM
32#
33include $(LEVEL)/Makefile.config
34
Chris Lattnere62dbe92002-07-23 17:56:16 +000035# These are options that can either be enabled here, or can be enabled on the
Chris Lattner9dd794e2002-08-03 20:19:30 +000036# make command line (ie, make ENABLE_PROFILING=1)
37#
38
39# When ENABLE_PROFILING is enabled, the llvm source base is built with profile
40# information to allow gprof to be used to get execution frequencies.
Chris Lattnere62dbe92002-07-23 17:56:16 +000041#
42#ENABLE_PROFILING = 1
Chris Lattner9dd794e2002-08-03 20:19:30 +000043
44# When ENABLE_PURIFY is enabled, the LLVM tools are linked with purify (which
45# must be locally installed) to allow for some automated memory error debugging.
46#
Chris Lattnere62dbe92002-07-23 17:56:16 +000047#ENABLE_PURIFY = 1
Chris Lattner9dd794e2002-08-03 20:19:30 +000048
49# When ENABLE_OPTIMIZED is enabled, Release builds of all of the LLVM code are
50# turned on, and Debug builds are turned off.
51#
Chris Lattnere62dbe92002-07-23 17:56:16 +000052#ENABLE_OPTIMIZED = 1
53
Chris Lattner4bb13b82002-09-13 22:14:47 +000054
55# Figure out how to do platform specific stuff on this platform. This is really
56# gross and should be autoconfiscated (automake actually), but should hopefully
57# work on Linux and solaris (SunOS).
58#
59UNAME := $(shell uname)
60include $(LEVEL)/Makefile.$(UNAME)
61
Chris Lattneredf1f232002-07-23 19:21:31 +000062ifdef SHARED_LIBRARY
63# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
64dynamic ::
65endif
66
Chris Lattnerb19e59c2001-06-29 05:20:16 +000067# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000068all ::
69
70# Default for install is to at least build everything...
71install ::
72
Chris Lattnere16b1b42002-08-09 15:41:55 +000073
74# Figure out which directory to build stuff into. We want to build into the
75# /shared directory by default because it is guaranteed to be local to the
76# current machine.
77#
Vikram S. Advec214e712002-08-29 23:28:46 +000078ifeq ($(LLVM_OBJ_DIR),.)
79BUILD_ROOT = $(LLVM_OBJ_DIR)
80BUILD_ROOT_TOP = $(LEVEL)
Chris Lattner285af382002-08-12 21:19:28 +000081else
82
Vikram S. Advec214e712002-08-29 23:28:46 +000083BUILD_ROOT := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(shell pwd))
Chris Lattner285af382002-08-12 21:19:28 +000084
85# Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree.
86# Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use
87# this expression because some of the directories on the source tree may not
88# exist in the build tree (for example the test/ heirarchy). Thus we evaluate
89# the directory to eliminate the ../'s
90#
91TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
Vikram S. Advec214e712002-08-29 23:28:46 +000092BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
Chris Lattnere16b1b42002-08-09 15:41:55 +000093endif
94
Chris Lattner00950542001-06-06 20:29:01 +000095#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +000096# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +000097#--------------------------------------------------------------------
98
99#BinInstDir=/usr/local/bin
100#LibInstDir=/usrl/local/lib/xxx
101#DocInstDir=/usr/doc/xxx
102
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000103BURG_OPTS = -I
104
Vikram S. Advec214e712002-08-29 23:28:46 +0000105PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000106
Chris Lattner760da062003-03-14 20:25:22 +0000107ifdef ENABLE_PROFILING
108 ENABLE_OPTIMIZED = 1
109 CONFIGURATION := Profile
110else
111 ifdef ENABLE_OPTIMIZED
112 CONFIGURATION := Release
113 else
114 CONFIGURATION := Debug
115 endif
116endif
117
Chris Lattnere62dbe92002-07-23 17:56:16 +0000118# Shorthand for commonly accessed directories
Chris Lattner285af382002-08-12 21:19:28 +0000119LIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug
120LIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000121LIBPROFILE := $(BUILD_ROOT_TOP)/lib/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000122LIBCURRENT := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
123
Chris Lattner285af382002-08-12 21:19:28 +0000124TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug
125TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000126TOOLPROFILE := $(BUILD_ROOT_TOP)/tools/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000127TOOLCURRENT := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000128
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000129# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000130ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000131VERB := @
132endif
133
Chris Lattner00950542001-06-06 20:29:01 +0000134#---------------------------------------------------------
135# Compilation options...
136#---------------------------------------------------------
137
Chris Lattner9b947012002-09-19 19:42:24 +0000138# Special tools used while building the LLVM tree. Burg is built as part of the
139# utils directory.
140#
Chris Lattner760da062003-03-14 20:25:22 +0000141BURG := $(TOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000142RunBurg := $(BURG) $(BURG_OPTS)
143
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000144
Chris Lattner00950542001-06-06 20:29:01 +0000145# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000146# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000147ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000148 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000149endif
Chris Lattner00950542001-06-06 20:29:01 +0000150
Vikram S. Advefeeae582002-09-18 11:55:13 +0000151# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000152ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000153STRIP = $(PLATFORMSTRIPOPTS)
154STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000155endif
156
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000157# Allow gnu extensions...
158CPPFLAGS += -D_GNU_SOURCE
159
Chris Lattnerc7acf812002-01-23 05:46:01 +0000160# -Wno-unused-parameter
Vikram S. Adve41e78912002-09-20 14:03:13 +0000161CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000162CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000163
Chris Lattner172b6482002-09-22 02:47:15 +0000164# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000165Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
166CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000167CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
168CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000169
Chris Lattner172b6482002-09-22 02:47:15 +0000170# Compile a c file, don't link...
171CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
172CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000173CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
174CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000175
176
Chris Lattner00950542001-06-06 20:29:01 +0000177# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000178
Chris Lattner1917e952002-07-31 21:32:05 +0000179ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000180Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000181else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000182Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000183endif
Vikram S. Adveec4d3622002-12-16 01:31:18 +0000184LinkG := $(Link) -g -L$(LIBDEBUG) $(STRIP)
185LinkO := $(Link) -O3 -L$(LIBRELEASE)
186LinkP := $(Link) -O3 -L$(LIBPROFILE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000187
Chris Lattnere62dbe92002-07-23 17:56:16 +0000188# Create one .o file from a bunch of .o files...
189Relink = ld -r
190
Chris Lattner4bb13b82002-09-13 22:14:47 +0000191# MakeSO - Create a .so file from a .o files...
Vikram S. Adve41e78912002-09-20 14:03:13 +0000192MakeSO := $(CXX) $(MakeSharedObjectOption)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000193MakeSOO := $(MakeSO) -O3
Vikram S. Adve41e78912002-09-20 14:03:13 +0000194MakeSOP := $(MakeSOO) $(PROFILE)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000195
Chris Lattner00950542001-06-06 20:29:01 +0000196# Create dependancy file from CPP file, send to stdout.
Chris Lattner285af382002-08-12 21:19:28 +0000197Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner172b6482002-09-22 02:47:15 +0000198DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000199
200# Archive a bunch of .o files into a .a file...
201AR = ar cq
Chris Lattner172b6482002-09-22 02:47:15 +0000202BISON = bison
Chris Lattner00950542001-06-06 20:29:01 +0000203
204#----------------------------------------------------------
205
206# Source includes all of the cpp files, and objects are derived from the
207# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000208# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000209#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000210ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000211Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000212endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000213
Chris Lattner4fa128c2002-07-25 15:01:19 +0000214Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000215ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
216ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
Chris Lattner9b947012002-09-19 19:42:24 +0000217ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000218
Chris Lattnere62dbe92002-07-23 17:56:16 +0000219
Chris Lattner00950542001-06-06 20:29:01 +0000220#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000221# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000222#---------------------------------------------------------
223
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000224ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000225all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000226 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000227 (cd $$dir; $(MAKE) $@) || exit 1; \
228 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000229endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000230
231# Handle PARALLEL_DIRS
232ifdef PARALLEL_DIRS
233all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
234install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
235clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000236test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000237
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000238%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000239 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000240endif
241
242#---------------------------------------------------------
243# Handle the LIBRARYNAME option - used when building libs...
244#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000245#
246# When libraries are built, they are allowed to optionally define the
247# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
248# from being built for the library. This .o files may then be linked to by a
249# tool if the tool does not need (or want) the semantics a .a file provides
250# (linking in only object files that are "needed"). If a library is never to
251# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
252# BUILD_ARCHIVE instead.
253#
254# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000255# 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 +0000256# linked into tools (for example gccas) even if they only use one of the parts
257# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000258
259ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000260
Chris Lattner2a548c52002-09-16 22:36:42 +0000261# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000262LIBRARYNAME := $(strip $(LIBRARYNAME))
263
Chris Lattnere62dbe92002-07-23 17:56:16 +0000264LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
Vikram S. Adve41e78912002-09-20 14:03:13 +0000265LIBNAME_P := $(LIBPROFILE)/lib$(LIBRARYNAME).so
Chris Lattnere62dbe92002-07-23 17:56:16 +0000266LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
267LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
Vikram S. Adve41e78912002-09-20 14:03:13 +0000268LIBNAME_AP := $(LIBPROFILE)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000269LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
270LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
Vikram S. Adve41e78912002-09-20 14:03:13 +0000271LIBNAME_OBJP := $(LIBPROFILE)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000272LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000273
Chris Lattner760da062003-03-14 20:25:22 +0000274# dynamic target builds a shared object version of the library...
275dynamic:: $(LIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000276
Chris Lattner760da062003-03-14 20:25:22 +0000277# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000278ifndef DONT_BUILD_RELINKED
Chris Lattner760da062003-03-14 20:25:22 +0000279all:: $(LIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000280endif
Chris Lattner760da062003-03-14 20:25:22 +0000281
282# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000283ifdef BUILD_ARCHIVE
Chris Lattner760da062003-03-14 20:25:22 +0000284all:: $(LIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000285endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000286
Chris Lattnere16b1b42002-08-09 15:41:55 +0000287$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000288 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000289 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000290
Vikram S. Adve41e78912002-09-20 14:03:13 +0000291$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
292 @echo ======= Linking $(LIBRARYNAME) profile library =======
293 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
294
Chris Lattnere16b1b42002-08-09 15:41:55 +0000295$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000296 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000297 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000298
Chris Lattnere16b1b42002-08-09 15:41:55 +0000299$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000300 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000301 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000302 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000303
Vikram S. Adve41e78912002-09-20 14:03:13 +0000304$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
305 @echo ======= Linking $(LIBRARYNAME) profile library =======
306 @rm -f $@
307 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
308
Chris Lattnere16b1b42002-08-09 15:41:55 +0000309$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000310 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000311 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000312 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000313
Chris Lattnere16b1b42002-08-09 15:41:55 +0000314$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000315 @echo "Linking $@"
316 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000317
Vikram S. Adve41e78912002-09-20 14:03:13 +0000318$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
319 @echo "Linking $@"
320 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
321
Chris Lattnere16b1b42002-08-09 15:41:55 +0000322$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000323 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000324 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000325
Chris Lattner00950542001-06-06 20:29:01 +0000326endif
327
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000328#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000329# Create a TAGS database for emacs
330#------------------------------------------------------------------------
331
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000332ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000333tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000334 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000335all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000336endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000337
338#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000339# Handle the TOOLNAME option - used when building tool executables...
340#------------------------------------------------------------------------
341#
342# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000343# libraries (and the order of the libs) that should be linked to the
344# tool. USEDLIBS should contain a list of library names (some with .a extension)
345# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000346#
347ifdef TOOLNAME
348
349# TOOLEXENAME* - These compute the output filenames to generate...
Chris Lattner285af382002-08-12 21:19:28 +0000350TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
351TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000352TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
Chris Lattner760da062003-03-14 20:25:22 +0000353TOOLEXENAMES := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000354
355# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Chris Lattnere62dbe92002-07-23 17:56:16 +0000356USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
357USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
358USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000359USED_LIBS_OPTIONS_P := $(patsubst %.o, $(LIBPROFILE)/%.o,$(USED_LIBS_OPTIONS))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000360
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000361
362# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000363# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
364# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000365#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000366STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
367USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
368USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000369USED_LIB_PATHS_P := $(addprefix $(LIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000370LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000371
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000372
373# Tell make that we need to rebuild subdirectories before we can link the tool.
374# This affects things like LLI which has library subdirectories.
375$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
376 $(addsuffix /.makeall, $(PARALLEL_DIRS))
377
Chris Lattner669bd7c2001-10-13 05:10:29 +0000378all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000379clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000380 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000381
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000382$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
Chris Lattner527002c2003-01-31 19:00:26 +0000383 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
Chris Lattner1c588502002-11-04 20:50:33 +0000384 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000385
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000386$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000387 @echo ======= Linking $(TOOLNAME) release executable =======
Chris Lattner1c588502002-11-04 20:50:33 +0000388 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(USED_LIBS_OPTIONS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000389
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000390$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000391 @echo ======= Linking $(TOOLNAME) profile executable =======
Chris Lattner1c588502002-11-04 20:50:33 +0000392 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(USED_LIBS_OPTIONS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000393
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000394endif
395
396
Chris Lattner00950542001-06-06 20:29:01 +0000397
398#---------------------------------------------------------
Chris Lattnere16b1b42002-08-09 15:41:55 +0000399.PRECIOUS: $(BUILD_ROOT)/Depend/.dir
400.PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000401
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000402# Create dependencies for the *.cpp files...
Chris Lattnere16b1b42002-08-09 15:41:55 +0000403$(BUILD_ROOT)/Depend/%.d: %.cpp $(BUILD_ROOT)/Depend/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000404 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000405
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000406# Create dependencies for the *.c files...
Chris Lattnere16b1b42002-08-09 15:41:55 +0000407$(BUILD_ROOT)/Depend/%.d: %.c $(BUILD_ROOT)/Depend/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000408 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000409
410# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattnere16b1b42002-08-09 15:41:55 +0000411$(BUILD_ROOT)/Release/%.o: %.cpp $(BUILD_ROOT)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000412 @echo "Compiling $<"
413 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000414
Chris Lattner172b6482002-09-22 02:47:15 +0000415$(BUILD_ROOT)/Release/%.o: %.c $(BUILD_ROOT)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000416 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000417
Vikram S. Adve41e78912002-09-20 14:03:13 +0000418$(BUILD_ROOT)/Profile/%.o: %.cpp $(BUILD_ROOT)/Profile/.dir
419 @echo "Compiling $<"
420 $(VERB) $(CompileP) $< -o $@
421
Chris Lattner172b6482002-09-22 02:47:15 +0000422$(BUILD_ROOT)/Profile/%.o: %.c $(BUILD_ROOT)/Profile/.dir
423 @echo "Compiling $<"
424 $(VERB) $(CompileCP) $< -o $@
425
Chris Lattnere16b1b42002-08-09 15:41:55 +0000426$(BUILD_ROOT)/Debug/%.o: %.cpp $(BUILD_ROOT)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000427 @echo "Compiling $<"
428 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000429
Chris Lattner172b6482002-09-22 02:47:15 +0000430$(BUILD_ROOT)/Debug/%.o: %.c $(BUILD_ROOT)/Debug/.dir
431 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000432
Chris Lattnere8996782003-01-16 22:44:19 +0000433#
434# Rules for building lex/yacc files
435#
436LEX_FILES = $(filter %.l, $(Source))
437LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
438YACC_FILES = $(filter %.y, $(Source))
439YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
440.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
441
Chris Lattner00950542001-06-06 20:29:01 +0000442# Create a .cpp source file from a flex input file... this uses sed to cut down
443# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000444#
445# The last line is a gross hack to work around flex aparently not being able to
446# resize the buffer on a large token input. Currently, for uninitialized string
447# buffers in LLVM we can generate very long tokens, so this is a hack around it.
448# FIXME. (f.e. char Buffer[10000]; )
449#
Chris Lattner00950542001-06-06 20:29:01 +0000450%.cpp: %.l
Chris Lattner6d131b42003-01-23 16:33:10 +0000451 flex -t $< | sed '/^find_rule/d' | \
452 sed 's/void yyunput/inline void yyunput/' | \
453 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
454 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000455
456# Rule for building the bison parsers...
457
458%.cpp %.h : %.y
Chris Lattnere8996782003-01-16 22:44:19 +0000459 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
460 $(VERB) mv -f $*.tab.c $*.cpp
461 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000462
463# To create the directories...
464%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000465 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000466 @date > $@
467
Chris Lattner30440c62003-01-16 21:06:18 +0000468# To create postscript files from dot files...
469%.ps: %.dot
470 dot -Tps < $< > $@
471
Chris Lattner172b6482002-09-22 02:47:15 +0000472# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000473clean::
Vikram S. Adve41e78912002-09-20 14:03:13 +0000474 $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
Misha Brukmanab6d2932002-12-04 17:08:15 +0000475 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000476 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000477
478# If dependancies were generated for the file that included this file,
479# include the dependancies now...
480#
Chris Lattner285af382002-08-12 21:19:28 +0000481SourceDepend := $(addsuffix .d,$(addprefix $(BUILD_ROOT)/Depend/,$(basename $(filter-out Debug/%, $(Source)))))
Chris Lattner00950542001-06-06 20:29:01 +0000482ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000483-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000484endif