blob: c13ca250b0e6e896377c2f088aff075bbd1c2bf6 [file] [log] [blame]
Vikram S. Adved60aede2002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner00950542001-06-06 20:29:01 +00002#
3# This file is included by all of the LLVM makefiles. This file defines common
4# rules to do things like compile a .cpp file or generate dependancy info.
5# These are platform dependant, so this is the file used to specify these
6# system dependant operations.
7#
Vikram S. Advec214e712002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner00950542001-06-06 20:29:01 +000010#
11# 1. LEVEL - The level of the current subdirectory from the top of the
12# MagicStats view. This level should be expressed as a path, for
13# example, ../.. for two levels deep.
14#
15# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnera8abc222002-09-18 03:22:27 +000016# so that each of the targets "all", "install", and "clean" each build
17# the subdirectories before the local target. DIRS are guaranteed to be
18# built in order.
Chris Lattner00950542001-06-06 20:29:01 +000019#
Chris Lattnera8abc222002-09-18 03:22:27 +000020# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21# built in any order. All DIRS are built in order before PARALLEL_DIRS are
22# built, which are then built in any order.
23#
24# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner00950542001-06-06 20:29:01 +000025# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000026# in the current directory. Also, if you want to build files in addition
27# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000028#
Chris Lattner694c5df2003-05-15 21:28:55 +000029# 5. SourceDir - If specified, this specifies a directory that the source files
30# are in, if they are not in the current directory. This should include a
31# trailing / character.
32#
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000033# 6. PROJ_COMPILE - If set to 1, then this makefile can also be used to
34# compile other projects using llvm. Note if this option is set then the
35# following *must* hold
36# PROJLEVEL should be set to the top of the source directory for the
37# project files
38# LEVEL should be set to the top of LLVM source tree
39# LLVM_LIB_DIR should be set to the top of the LLVM build tree
40#
41#
Vikram S. Adved60aede2002-07-09 12:04:21 +000042#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000043
Vikram S. Advec214e712002-08-29 23:28:46 +000044# Configuration file to set paths specific to local installation of LLVM
45#
46include $(LEVEL)/Makefile.config
47
Chris Lattner4bb13b82002-09-13 22:14:47 +000048# Figure out how to do platform specific stuff on this platform. This is really
49# gross and should be autoconfiscated (automake actually), but should hopefully
50# work on Linux and solaris (SunOS).
51#
52UNAME := $(shell uname)
53include $(LEVEL)/Makefile.$(UNAME)
54
Chris Lattneredf1f232002-07-23 19:21:31 +000055ifdef SHARED_LIBRARY
56# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
57dynamic ::
58endif
59
Chris Lattnerb19e59c2001-06-29 05:20:16 +000060# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000061all ::
62
63# Default for install is to at least build everything...
64install ::
65
Chris Lattnere16b1b42002-08-09 15:41:55 +000066
67# Figure out which directory to build stuff into. We want to build into the
68# /shared directory by default because it is guaranteed to be local to the
69# current machine.
70#
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000071
Vikram S. Advec214e712002-08-29 23:28:46 +000072ifeq ($(LLVM_OBJ_DIR),.)
73BUILD_ROOT = $(LLVM_OBJ_DIR)
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000074
75ifdef PROJ_COMPILE
76BUILD_ROOT_TOP = $(PROJLEVEL)
77else
Vikram S. Advec214e712002-08-29 23:28:46 +000078BUILD_ROOT_TOP = $(LEVEL)
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000079endif
80
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#
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000091ifdef PROJ_COMPILE
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000092TOP_DIRECTORY := $(shell cd $(PROJLEVEL); pwd)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000093else
Chris Lattner285af382002-08-12 21:19:28 +000094TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000095endif
96
Vikram S. Advec214e712002-08-29 23:28:46 +000097BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
Chris Lattnere16b1b42002-08-09 15:41:55 +000098endif
99
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000100
101
102
Chris Lattner00950542001-06-06 20:29:01 +0000103#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000104# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000105#--------------------------------------------------------------------
106
107#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000108#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000109#DocInstDir=/usr/doc/xxx
110
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000111BURG_OPTS = -I
112
Vikram S. Advec214e712002-08-29 23:28:46 +0000113PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000114
Chris Lattner760da062003-03-14 20:25:22 +0000115ifdef ENABLE_PROFILING
116 ENABLE_OPTIMIZED = 1
117 CONFIGURATION := Profile
118else
119 ifdef ENABLE_OPTIMIZED
120 CONFIGURATION := Release
121 else
122 CONFIGURATION := Debug
123 endif
124endif
125
Chris Lattnere62dbe92002-07-23 17:56:16 +0000126# Shorthand for commonly accessed directories
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000127# DESTLIBXYZ indicates destination for the libraries built
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000128DESTLIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug
129DESTLIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release
130DESTLIBPROFILE := $(BUILD_ROOT_TOP)/lib/Profile
131DESTLIBCURRENT := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
132
133ifdef PROJ_COMPILE
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000134#get the llvm libraries from LLVM_LIB_DIR
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000135LLVMLIBDEBUGSOURCE := $(LLVM_LIB_DIR)/lib/Debug
136LLVMLIBRELEASESOURCE := $(LLVM_LIB_DIR)/lib/Release
137LLVMLIBPROFILESOURCE := $(LLVM_LIB_DIR)/lib/Profile
138LLVMLIBCURRENTSOURCE := $(LLVM_LIB_DIR)/lib/$(CONFIGURATION)
139
140PROJLIBDEBUGSOURCE := $(BUILD_ROOT_TOP)/lib/Debug
141PROJLIBRELEASESOURCE := $(BUILD_ROOT_TOP)/lib/Release
142PROJLIBPROFILESOURCE := $(BUILD_ROOT_TOP)/lib/Profile
143PROJLIBCURRENTSOURCE := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
144
145else
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000146#when we are building llvm, destination is same as source
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000147LLVMLIBDEBUGSOURCE := $(BUILD_ROOT_TOP)/lib/Debug
148LLVMLIBRELEASESOURCE := $(BUILD_ROOT_TOP)/lib/Release
149LLVMLIBPROFILESOURCE := $(BUILD_ROOT_TOP)/lib/Profile
150LLVMLIBCURRENTSOURCE := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
151endif
152
Chris Lattner760da062003-03-14 20:25:22 +0000153
Chris Lattner285af382002-08-12 21:19:28 +0000154TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug
155TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000156TOOLPROFILE := $(BUILD_ROOT_TOP)/tools/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000157TOOLCURRENT := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000158
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000159# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000160ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000161VERB := @
162endif
163
Chris Lattner00950542001-06-06 20:29:01 +0000164#---------------------------------------------------------
165# Compilation options...
166#---------------------------------------------------------
167
Chris Lattner9b947012002-09-19 19:42:24 +0000168# Special tools used while building the LLVM tree. Burg is built as part of the
169# utils directory.
170#
Chris Lattner760da062003-03-14 20:25:22 +0000171BURG := $(TOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000172RunBurg := $(BURG) $(BURG_OPTS)
173
Misha Brukmand58a6052003-05-29 20:09:23 +0000174TBLGEN := $(TOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000175
Chris Lattner00950542001-06-06 20:29:01 +0000176# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000177# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000178ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000179 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000180endif
Chris Lattner00950542001-06-06 20:29:01 +0000181
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000182#if PROJDIR is defined then we include project include directory
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000183ifndef PROJ_COMPILE
Chris Lattnerf9771432003-05-29 20:40:32 +0000184PROJ_INCLUDE = .
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000185else
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000186PROJ_INCLUDE = $(TOP_DIRECTORY)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000187endif
188
Vikram S. Advefeeae582002-09-18 11:55:13 +0000189# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000190ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000191STRIP = $(PLATFORMSTRIPOPTS)
192STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000193endif
194
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000195# Allow gnu extensions...
196CPPFLAGS += -D_GNU_SOURCE
197
Chris Lattnerc7acf812002-01-23 05:46:01 +0000198# -Wno-unused-parameter
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000199CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include -I$(PROJ_INCLUDE)
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000200CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000201
Chris Lattner172b6482002-09-22 02:47:15 +0000202# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000203Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
204CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000205CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
206CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000207
Chris Lattner172b6482002-09-22 02:47:15 +0000208# Compile a c file, don't link...
209CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
210CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000211CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
212CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000213
214
Chris Lattner00950542001-06-06 20:29:01 +0000215# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000216
Chris Lattner1917e952002-07-31 21:32:05 +0000217ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000218Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000219else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000220Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000221endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000222
223ifdef PROJ_COMPILE
Dinakar Dhurjati584dd182003-05-29 21:49:00 +0000224# include both projlib source and llvmlib source
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000225LinkG := $(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
250
251#----------------------------------------------------------
252
253# Source includes all of the cpp files, and objects are derived from the
254# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000255# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000256#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000257ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000258Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000259endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000260
Chris Lattner694c5df2003-05-15 21:28:55 +0000261Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000262ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
263ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
Chris Lattner9b947012002-09-19 19:42:24 +0000264ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000265
Chris Lattnere62dbe92002-07-23 17:56:16 +0000266
Chris Lattner00950542001-06-06 20:29:01 +0000267#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000268# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000269#---------------------------------------------------------
270
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000271ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000272all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000273 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000274 (cd $$dir; $(MAKE) $@) || exit 1; \
275 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000276endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000277
278# Handle PARALLEL_DIRS
279ifdef PARALLEL_DIRS
280all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
281install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
282clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000283test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000284
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000285%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000286 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000287endif
288
289#---------------------------------------------------------
290# Handle the LIBRARYNAME option - used when building libs...
291#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000292#
293# When libraries are built, they are allowed to optionally define the
294# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
295# from being built for the library. This .o files may then be linked to by a
296# tool if the tool does not need (or want) the semantics a .a file provides
297# (linking in only object files that are "needed"). If a library is never to
298# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
299# BUILD_ARCHIVE instead.
300#
301# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000302# 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 +0000303# linked into tools (for example gccas) even if they only use one of the parts
304# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000305
306ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000307
Chris Lattner2a548c52002-09-16 22:36:42 +0000308# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000309LIBRARYNAME := $(strip $(LIBRARYNAME))
310
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000311LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
312LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
313LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
314LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
315LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
316LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
317LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
318LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
319LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000320
Chris Lattner760da062003-03-14 20:25:22 +0000321# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000322dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000323
Chris Lattner760da062003-03-14 20:25:22 +0000324# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000325ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000326all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000327endif
Chris Lattner760da062003-03-14 20:25:22 +0000328
329# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000330ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000331all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000332endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000333
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000334$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000335 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000336 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000337
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000338$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000339 @echo ======= Linking $(LIBRARYNAME) profile library =======
340 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
341
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000342$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000343 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000344 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000345
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000346$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000347 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000348 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000349 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000350
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000351$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000352 @echo ======= Linking $(LIBRARYNAME) profile library =======
353 @rm -f $@
354 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
355
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000356$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000357 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000358 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000359 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000360
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000361$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000362 @echo "Linking $@"
363 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000364
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000365$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000366 @echo "Linking $@"
367 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
368
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000369$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000370 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000371 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000372
Chris Lattner00950542001-06-06 20:29:01 +0000373endif
374
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000375#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000376# Create a TAGS database for emacs
377#------------------------------------------------------------------------
378
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000379ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000380tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000381 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000382all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000383endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000384
385#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000386# Handle the TOOLNAME option - used when building tool executables...
387#------------------------------------------------------------------------
388#
389# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000390# libraries (and the order of the libs) that should be linked to the
391# tool. USEDLIBS should contain a list of library names (some with .a extension)
392# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000393#
394ifdef TOOLNAME
395
396# TOOLEXENAME* - These compute the output filenames to generate...
Chris Lattner285af382002-08-12 21:19:28 +0000397TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
398TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000399TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
Chris Lattner760da062003-03-14 20:25:22 +0000400TOOLEXENAMES := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000401
402# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000403ifdef PROJ_COMPILE
404
405PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
406PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
407PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
408PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
409
410LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
411LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
412LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
413LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
414
415LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
416LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P)
417LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
418
419else
420
421LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
422LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
423LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
424LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
425
426LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G)
427LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O)
428LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P)
429endif
430
431
432
433
Chris Lattnere62dbe92002-07-23 17:56:16 +0000434
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000435
436# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000437# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
438# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000439#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000440STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000441USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
442USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
443USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000444LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000445
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000446
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000447
448
449
450
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000451# Tell make that we need to rebuild subdirectories before we can link the tool.
452# This affects things like LLI which has library subdirectories.
453$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
454 $(addsuffix /.makeall, $(PARALLEL_DIRS))
455
Chris Lattner669bd7c2001-10-13 05:10:29 +0000456all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000457clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000458 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000459
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000460$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000461 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)=======
462 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000463
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000464$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000465 @echo ======= Linking $(TOOLNAME) release executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000466 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000467
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000468$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000469 @echo ======= Linking $(TOOLNAME) profile executable =======
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000470 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000471
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000472endif
473
474
Chris Lattner00950542001-06-06 20:29:01 +0000475
476#---------------------------------------------------------
Chris Lattnere16b1b42002-08-09 15:41:55 +0000477.PRECIOUS: $(BUILD_ROOT)/Depend/.dir
478.PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000479
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000480# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner694c5df2003-05-15 21:28:55 +0000481$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000482 @echo "Compiling $<"
483 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000484
Chris Lattner694c5df2003-05-15 21:28:55 +0000485$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000486 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000487
Chris Lattner694c5df2003-05-15 21:28:55 +0000488$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000489 @echo "Compiling $<"
490 $(VERB) $(CompileP) $< -o $@
491
Chris Lattner694c5df2003-05-15 21:28:55 +0000492$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000493 @echo "Compiling $<"
494 $(VERB) $(CompileCP) $< -o $@
495
Chris Lattner694c5df2003-05-15 21:28:55 +0000496$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000497 @echo "Compiling $<"
498 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000499
Chris Lattner694c5df2003-05-15 21:28:55 +0000500$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000501 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000502
Chris Lattnere8996782003-01-16 22:44:19 +0000503#
504# Rules for building lex/yacc files
505#
506LEX_FILES = $(filter %.l, $(Source))
507LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
508YACC_FILES = $(filter %.y, $(Source))
509YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
510.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
511
Chris Lattner00950542001-06-06 20:29:01 +0000512# Create a .cpp source file from a flex input file... this uses sed to cut down
513# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000514#
515# The last line is a gross hack to work around flex aparently not being able to
516# resize the buffer on a large token input. Currently, for uninitialized string
517# buffers in LLVM we can generate very long tokens, so this is a hack around it.
518# FIXME. (f.e. char Buffer[10000]; )
519#
Chris Lattner00950542001-06-06 20:29:01 +0000520%.cpp: %.l
John Criswell65aa59342003-05-29 18:52:10 +0000521 $(FLEX) -t $< | sed '/^find_rule/d' | \
Chris Lattner6d131b42003-01-23 16:33:10 +0000522 sed 's/void yyunput/inline void yyunput/' | \
523 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
524 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000525
526# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000527%.c: %.y # Cancel built-in rules for yacc
528%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000529%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000530 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000531 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
532 $(VERB) mv -f $*.tab.c $*.cpp
533 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000534
535# To create the directories...
536%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000537 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000538 @date > $@
539
Chris Lattner30440c62003-01-16 21:06:18 +0000540# To create postscript files from dot files...
541%.ps: %.dot
542 dot -Tps < $< > $@
543
Chris Lattner172b6482002-09-22 02:47:15 +0000544# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000545clean::
Vikram S. Adve41e78912002-09-20 14:03:13 +0000546 $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
Misha Brukmanab6d2932002-12-04 17:08:15 +0000547 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000548 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000549
Chris Lattner694c5df2003-05-15 21:28:55 +0000550# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000551# include the dependancies now...
552#
Chris Lattner694c5df2003-05-15 21:28:55 +0000553SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
554SourceDepend := $(SourceBaseNames:%=$(BUILD_ROOT)/Depend/%.d)
555
556# Create dependencies for the *.cpp files...
557#$(SourceDepend): \x
558$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_ROOT)/Depend/.dir
559 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
560
561# Create dependencies for the *.c files...
562#$(SourceDepend): \x
563$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.c $(BUILD_ROOT)/Depend/.dir
564 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
565
Chris Lattner00950542001-06-06 20:29:01 +0000566ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000567-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000568endif