blob: e60ed8a6e1df6607613fb3cdc06455024f44cd5c [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#
Vikram S. Adved60aede2002-07-09 12:04:21 +000033#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000034
Vikram S. Advec214e712002-08-29 23:28:46 +000035# Configuration file to set paths specific to local installation of LLVM
36#
37include $(LEVEL)/Makefile.config
38
Chris Lattnere62dbe92002-07-23 17:56:16 +000039# These are options that can either be enabled here, or can be enabled on the
Chris Lattner9dd794e2002-08-03 20:19:30 +000040# make command line (ie, make ENABLE_PROFILING=1)
41#
42
43# When ENABLE_PROFILING is enabled, the llvm source base is built with profile
44# information to allow gprof to be used to get execution frequencies.
Chris Lattnere62dbe92002-07-23 17:56:16 +000045#
46#ENABLE_PROFILING = 1
Chris Lattner9dd794e2002-08-03 20:19:30 +000047
48# When ENABLE_PURIFY is enabled, the LLVM tools are linked with purify (which
49# must be locally installed) to allow for some automated memory error debugging.
50#
Chris Lattnere62dbe92002-07-23 17:56:16 +000051#ENABLE_PURIFY = 1
Chris Lattner9dd794e2002-08-03 20:19:30 +000052
53# When ENABLE_OPTIMIZED is enabled, Release builds of all of the LLVM code are
54# turned on, and Debug builds are turned off.
55#
Chris Lattnere62dbe92002-07-23 17:56:16 +000056#ENABLE_OPTIMIZED = 1
57
Chris Lattner4bb13b82002-09-13 22:14:47 +000058
59# Figure out how to do platform specific stuff on this platform. This is really
60# gross and should be autoconfiscated (automake actually), but should hopefully
61# work on Linux and solaris (SunOS).
62#
63UNAME := $(shell uname)
64include $(LEVEL)/Makefile.$(UNAME)
65
Chris Lattneredf1f232002-07-23 19:21:31 +000066ifdef SHARED_LIBRARY
67# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
68dynamic ::
69endif
70
Chris Lattnerb19e59c2001-06-29 05:20:16 +000071# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000072all ::
73
74# Default for install is to at least build everything...
75install ::
76
Chris Lattnere16b1b42002-08-09 15:41:55 +000077
78# Figure out which directory to build stuff into. We want to build into the
79# /shared directory by default because it is guaranteed to be local to the
80# current machine.
81#
Vikram S. Advec214e712002-08-29 23:28:46 +000082ifeq ($(LLVM_OBJ_DIR),.)
83BUILD_ROOT = $(LLVM_OBJ_DIR)
84BUILD_ROOT_TOP = $(LEVEL)
Chris Lattner285af382002-08-12 21:19:28 +000085else
86
Vikram S. Advec214e712002-08-29 23:28:46 +000087BUILD_ROOT := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(shell pwd))
Chris Lattner285af382002-08-12 21:19:28 +000088
89# Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree.
90# Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use
91# this expression because some of the directories on the source tree may not
92# exist in the build tree (for example the test/ heirarchy). Thus we evaluate
93# the directory to eliminate the ../'s
94#
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000095ifdef PROJ_COMPILE
96TOP_DIRECTORY := $(shell cd $(TOPLEVEL); pwd)
97else
Chris Lattner285af382002-08-12 21:19:28 +000098TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000099endif
100
Vikram S. Advec214e712002-08-29 23:28:46 +0000101BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
Chris Lattnere16b1b42002-08-09 15:41:55 +0000102endif
103
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000104
105
106
Chris Lattner00950542001-06-06 20:29:01 +0000107#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000108# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000109#--------------------------------------------------------------------
110
111#BinInstDir=/usr/local/bin
112#LibInstDir=/usrl/local/lib/xxx
113#DocInstDir=/usr/doc/xxx
114
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000115BURG_OPTS = -I
116
Vikram S. Advec214e712002-08-29 23:28:46 +0000117PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000118
Chris Lattner760da062003-03-14 20:25:22 +0000119ifdef ENABLE_PROFILING
120 ENABLE_OPTIMIZED = 1
121 CONFIGURATION := Profile
122else
123 ifdef ENABLE_OPTIMIZED
124 CONFIGURATION := Release
125 else
126 CONFIGURATION := Debug
127 endif
128endif
129
Chris Lattnere62dbe92002-07-23 17:56:16 +0000130# Shorthand for commonly accessed directories
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000131DESTLIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug
132DESTLIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release
133DESTLIBPROFILE := $(BUILD_ROOT_TOP)/lib/Profile
134DESTLIBCURRENT := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
135
136ifdef PROJ_COMPILE
137LLVMLIBDEBUGSOURCE := $(LLVM_LIB_DIR)/lib/Debug
138LLVMLIBRELEASESOURCE := $(LLVM_LIB_DIR)/lib/Release
139LLVMLIBPROFILESOURCE := $(LLVM_LIB_DIR)/lib/Profile
140LLVMLIBCURRENTSOURCE := $(LLVM_LIB_DIR)/lib/$(CONFIGURATION)
141
142PROJLIBDEBUGSOURCE := $(BUILD_ROOT_TOP)/lib/Debug
143PROJLIBRELEASESOURCE := $(BUILD_ROOT_TOP)/lib/Release
144PROJLIBPROFILESOURCE := $(BUILD_ROOT_TOP)/lib/Profile
145PROJLIBCURRENTSOURCE := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
146
147else
148
149LLVMLIBDEBUGSOURCE := $(BUILD_ROOT_TOP)/lib/Debug
150LLVMLIBRELEASESOURCE := $(BUILD_ROOT_TOP)/lib/Release
151LLVMLIBPROFILESOURCE := $(BUILD_ROOT_TOP)/lib/Profile
152LLVMLIBCURRENTSOURCE := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
153endif
154
Chris Lattner760da062003-03-14 20:25:22 +0000155
Chris Lattner285af382002-08-12 21:19:28 +0000156TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug
157TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000158TOOLPROFILE := $(BUILD_ROOT_TOP)/tools/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000159TOOLCURRENT := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000160
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000161# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000162ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000163VERB := @
164endif
165
Chris Lattner00950542001-06-06 20:29:01 +0000166#---------------------------------------------------------
167# Compilation options...
168#---------------------------------------------------------
169
Chris Lattner9b947012002-09-19 19:42:24 +0000170# Special tools used while building the LLVM tree. Burg is built as part of the
171# utils directory.
172#
Chris Lattner760da062003-03-14 20:25:22 +0000173BURG := $(TOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000174RunBurg := $(BURG) $(BURG_OPTS)
175
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000176
Chris Lattner00950542001-06-06 20:29:01 +0000177# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000178# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000179ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000180 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000181endif
Chris Lattner00950542001-06-06 20:29:01 +0000182
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000183#if PROJDIR is defined then we include PROJ DIR includes and libraries
184ifndef PROJ_COMPILE
185PROJ_INCLUDE = "."
186else
187PROJ_INCLUDE = $(PROJ_DIR)/include
188endif
189
Vikram S. Advefeeae582002-09-18 11:55:13 +0000190# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000191ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000192STRIP = $(PLATFORMSTRIPOPTS)
193STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000194endif
195
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000196# Allow gnu extensions...
197CPPFLAGS += -D_GNU_SOURCE
198
Chris Lattnerc7acf812002-01-23 05:46:01 +0000199# -Wno-unused-parameter
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000200CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include -I$(PROJ_INCLUDE)
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000201CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000202
Chris Lattner172b6482002-09-22 02:47:15 +0000203# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000204Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
205CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000206CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
207CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000208
Chris Lattner172b6482002-09-22 02:47:15 +0000209# Compile a c file, don't link...
210CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
211CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000212CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
213CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000214
215
Chris Lattner00950542001-06-06 20:29:01 +0000216# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000217
Chris Lattner1917e952002-07-31 21:32:05 +0000218ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000219Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000220else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000221Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000222endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000223
224ifdef PROJ_COMPILE
225LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
226LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
227LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
228else
229LinkG := $(Link) -g -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
230LinkO := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE)
231LinkP := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
232endif
233
234
Chris Lattner00950542001-06-06 20:29:01 +0000235
Chris Lattnere62dbe92002-07-23 17:56:16 +0000236# Create one .o file from a bunch of .o files...
237Relink = ld -r
238
Chris Lattner4bb13b82002-09-13 22:14:47 +0000239# MakeSO - Create a .so file from a .o files...
Vikram S. Adve41e78912002-09-20 14:03:13 +0000240MakeSO := $(CXX) $(MakeSharedObjectOption)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000241MakeSOO := $(MakeSO) -O3
Vikram S. Adve41e78912002-09-20 14:03:13 +0000242MakeSOP := $(MakeSOO) $(PROFILE)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000243
Chris Lattner00950542001-06-06 20:29:01 +0000244# Create dependancy file from CPP file, send to stdout.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000245Depend := $(CXX) -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS)
246DependC := $(CC) -MM -I$(LEVEL)/include -I$(PROJ_INCLUDE) $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000247
248# Archive a bunch of .o files into a .a file...
249AR = ar cq
Chris Lattner172b6482002-09-22 02:47:15 +0000250BISON = bison
Chris Lattner00950542001-06-06 20:29:01 +0000251
252#----------------------------------------------------------
253
254# Source includes all of the cpp files, and objects are derived from the
255# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000256# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000257#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000258ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000259Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000260endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000261
Chris Lattner694c5df2003-05-15 21:28:55 +0000262Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000263ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
264ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
Chris Lattner9b947012002-09-19 19:42:24 +0000265ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000266
Chris Lattnere62dbe92002-07-23 17:56:16 +0000267
Chris Lattner00950542001-06-06 20:29:01 +0000268#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000269# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000270#---------------------------------------------------------
271
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000272ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000273all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000274 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000275 (cd $$dir; $(MAKE) $@) || exit 1; \
276 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000277endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000278
279# Handle PARALLEL_DIRS
280ifdef PARALLEL_DIRS
281all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
282install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
283clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000284test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000285
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000286%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000287 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000288endif
289
290#---------------------------------------------------------
291# Handle the LIBRARYNAME option - used when building libs...
292#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000293#
294# When libraries are built, they are allowed to optionally define the
295# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
296# from being built for the library. This .o files may then be linked to by a
297# tool if the tool does not need (or want) the semantics a .a file provides
298# (linking in only object files that are "needed"). If a library is never to
299# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
300# BUILD_ARCHIVE instead.
301#
302# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000303# 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 +0000304# linked into tools (for example gccas) even if they only use one of the parts
305# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000306
307ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000308
Chris Lattner2a548c52002-09-16 22:36:42 +0000309# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000310LIBRARYNAME := $(strip $(LIBRARYNAME))
311
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000312LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
313LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
314LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
315LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
316LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
317LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
318LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
319LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
320LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000321
Chris Lattner760da062003-03-14 20:25:22 +0000322# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000323dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000324
Chris Lattner760da062003-03-14 20:25:22 +0000325# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000326ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000327all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000328endif
Chris Lattner760da062003-03-14 20:25:22 +0000329
330# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000331ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000332all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000333endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000334
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000335$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000336 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000337 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000338
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000339$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000340 @echo ======= Linking $(LIBRARYNAME) profile library =======
341 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
342
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000343$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000344 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000345 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000346
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000347$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000348 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000349 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000350 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000351
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000352$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000353 @echo ======= Linking $(LIBRARYNAME) profile library =======
354 @rm -f $@
355 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
356
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000357$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000358 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000359 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000360 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000361
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000362$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000363 @echo "Linking $@"
364 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000365
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000366$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000367 @echo "Linking $@"
368 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
369
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000370$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000371 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000372 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000373
Chris Lattner00950542001-06-06 20:29:01 +0000374endif
375
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000376#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000377# Create a TAGS database for emacs
378#------------------------------------------------------------------------
379
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000380ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000381tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000382 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000383all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000384endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000385
386#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000387# Handle the TOOLNAME option - used when building tool executables...
388#------------------------------------------------------------------------
389#
390# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000391# libraries (and the order of the libs) that should be linked to the
392# tool. USEDLIBS should contain a list of library names (some with .a extension)
393# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000394#
395ifdef TOOLNAME
396
397# TOOLEXENAME* - These compute the output filenames to generate...
Chris Lattner285af382002-08-12 21:19:28 +0000398TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
399TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000400TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
Chris Lattner760da062003-03-14 20:25:22 +0000401TOOLEXENAMES := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000402
403# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000404ifdef PROJ_COMPILE
405
406PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
407PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
408PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
409PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
410
411LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
412LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
413LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
414LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
415
416LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
417LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P)
418LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
419
420else
421
422LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
423LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
424LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
425LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
426
427LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G)
428LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O)
429LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P)
430endif
431
432
433
434
Chris Lattnere62dbe92002-07-23 17:56:16 +0000435
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000436
437# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000438# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
439# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000440#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000441STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000442USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
443USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
444USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000445LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000446
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000447
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000448
449
450
451
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000452# Tell make that we need to rebuild subdirectories before we can link the tool.
453# This affects things like LLI which has library subdirectories.
454$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
455 $(addsuffix /.makeall, $(PARALLEL_DIRS))
456
Chris Lattner669bd7c2001-10-13 05:10:29 +0000457all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000458clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000459 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000460
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000461$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000462 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
463 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000464
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000465$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000466 @echo ======= Linking $(TOOLNAME) release executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000467 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000468
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000469$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000470 @echo ======= Linking $(TOOLNAME) profile executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000471 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000472
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000473endif
474
475
Chris Lattner00950542001-06-06 20:29:01 +0000476
477#---------------------------------------------------------
Chris Lattnere16b1b42002-08-09 15:41:55 +0000478.PRECIOUS: $(BUILD_ROOT)/Depend/.dir
479.PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000480
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000481# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner694c5df2003-05-15 21:28:55 +0000482$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000483 @echo "Compiling $<"
484 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000485
Chris Lattner694c5df2003-05-15 21:28:55 +0000486$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000487 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000488
Chris Lattner694c5df2003-05-15 21:28:55 +0000489$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000490 @echo "Compiling $<"
491 $(VERB) $(CompileP) $< -o $@
492
Chris Lattner694c5df2003-05-15 21:28:55 +0000493$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000494 @echo "Compiling $<"
495 $(VERB) $(CompileCP) $< -o $@
496
Chris Lattner694c5df2003-05-15 21:28:55 +0000497$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000498 @echo "Compiling $<"
499 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000500
Chris Lattner694c5df2003-05-15 21:28:55 +0000501$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000502 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000503
Chris Lattnere8996782003-01-16 22:44:19 +0000504#
505# Rules for building lex/yacc files
506#
507LEX_FILES = $(filter %.l, $(Source))
508LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
509YACC_FILES = $(filter %.y, $(Source))
510YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
511.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
512
Chris Lattner00950542001-06-06 20:29:01 +0000513# Create a .cpp source file from a flex input file... this uses sed to cut down
514# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000515#
516# The last line is a gross hack to work around flex aparently not being able to
517# resize the buffer on a large token input. Currently, for uninitialized string
518# buffers in LLVM we can generate very long tokens, so this is a hack around it.
519# FIXME. (f.e. char Buffer[10000]; )
520#
Chris Lattner00950542001-06-06 20:29:01 +0000521%.cpp: %.l
Chris Lattner6d131b42003-01-23 16:33:10 +0000522 flex -t $< | sed '/^find_rule/d' | \
523 sed 's/void yyunput/inline void yyunput/' | \
524 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
525 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000526
527# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000528%.c: %.y # Cancel built-in rules for yacc
529%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000530%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000531 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000532 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
533 $(VERB) mv -f $*.tab.c $*.cpp
534 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000535
536# To create the directories...
537%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000538 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000539 @date > $@
540
Chris Lattner30440c62003-01-16 21:06:18 +0000541# To create postscript files from dot files...
542%.ps: %.dot
543 dot -Tps < $< > $@
544
Chris Lattner172b6482002-09-22 02:47:15 +0000545# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000546clean::
Vikram S. Adve41e78912002-09-20 14:03:13 +0000547 $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
Misha Brukmanab6d2932002-12-04 17:08:15 +0000548 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000549 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000550
Chris Lattner694c5df2003-05-15 21:28:55 +0000551# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000552# include the dependancies now...
553#
Chris Lattner694c5df2003-05-15 21:28:55 +0000554SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
555SourceDepend := $(SourceBaseNames:%=$(BUILD_ROOT)/Depend/%.d)
556
557# Create dependencies for the *.cpp files...
558#$(SourceDepend): \x
559$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_ROOT)/Depend/.dir
560 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
561
562# Create dependencies for the *.c files...
563#$(SourceDepend): \x
564$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.c $(BUILD_ROOT)/Depend/.dir
565 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
566
Chris Lattner00950542001-06-06 20:29:01 +0000567ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000568-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000569endif