blob: a053bd0f23bf87e770dcfc59fc8bd218f6fe7022 [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#
95TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
Vikram S. Advec214e712002-08-29 23:28:46 +000096BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
Chris Lattnere16b1b42002-08-09 15:41:55 +000097endif
98
Chris Lattner00950542001-06-06 20:29:01 +000099#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000100# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000101#--------------------------------------------------------------------
102
103#BinInstDir=/usr/local/bin
104#LibInstDir=/usrl/local/lib/xxx
105#DocInstDir=/usr/doc/xxx
106
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000107BURG_OPTS = -I
108
Vikram S. Advec214e712002-08-29 23:28:46 +0000109PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000110
Chris Lattner760da062003-03-14 20:25:22 +0000111ifdef ENABLE_PROFILING
112 ENABLE_OPTIMIZED = 1
113 CONFIGURATION := Profile
114else
115 ifdef ENABLE_OPTIMIZED
116 CONFIGURATION := Release
117 else
118 CONFIGURATION := Debug
119 endif
120endif
121
Chris Lattnere62dbe92002-07-23 17:56:16 +0000122# Shorthand for commonly accessed directories
Chris Lattner285af382002-08-12 21:19:28 +0000123LIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug
124LIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000125LIBPROFILE := $(BUILD_ROOT_TOP)/lib/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000126LIBCURRENT := $(BUILD_ROOT_TOP)/lib/$(CONFIGURATION)
127
Chris Lattner285af382002-08-12 21:19:28 +0000128TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug
129TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
Vikram S. Adve41e78912002-09-20 14:03:13 +0000130TOOLPROFILE := $(BUILD_ROOT_TOP)/tools/Profile
Chris Lattner760da062003-03-14 20:25:22 +0000131TOOLCURRENT := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000132
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000133# Verbosity levels
Chris Lattner760da062003-03-14 20:25:22 +0000134ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000135VERB := @
136endif
137
Chris Lattner00950542001-06-06 20:29:01 +0000138#---------------------------------------------------------
139# Compilation options...
140#---------------------------------------------------------
141
Chris Lattner9b947012002-09-19 19:42:24 +0000142# Special tools used while building the LLVM tree. Burg is built as part of the
143# utils directory.
144#
Chris Lattner760da062003-03-14 20:25:22 +0000145BURG := $(TOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000146RunBurg := $(BURG) $(BURG_OPTS)
147
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000148
Chris Lattner00950542001-06-06 20:29:01 +0000149# Enable this for profiling support with 'gprof'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000150# This automatically enables optimized builds.
Chris Lattner18f47012002-05-10 18:51:54 +0000151ifdef ENABLE_PROFILING
Vikram S. Adve41e78912002-09-20 14:03:13 +0000152 PROFILE = -pg
Chris Lattner18f47012002-05-10 18:51:54 +0000153endif
Chris Lattner00950542001-06-06 20:29:01 +0000154
Vikram S. Advefeeae582002-09-18 11:55:13 +0000155# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000156ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000157STRIP = $(PLATFORMSTRIPOPTS)
158STRIP_WARN_MSG = "(without symbols) "
Vikram S. Advefeeae582002-09-18 11:55:13 +0000159endif
160
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000161# Allow gnu extensions...
162CPPFLAGS += -D_GNU_SOURCE
163
Chris Lattnerc7acf812002-01-23 05:46:01 +0000164# -Wno-unused-parameter
Vikram S. Adve41e78912002-09-20 14:03:13 +0000165CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000166CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000167
Chris Lattner172b6482002-09-22 02:47:15 +0000168# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000169Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
170CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000171CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
172CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000173
Chris Lattner172b6482002-09-22 02:47:15 +0000174# Compile a c file, don't link...
175CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
176CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000177CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
178CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000179
180
Chris Lattner00950542001-06-06 20:29:01 +0000181# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +0000182
Chris Lattner1917e952002-07-31 21:32:05 +0000183ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Vikram S. Adve41e78912002-09-20 14:03:13 +0000184Link := $(PURIFY) $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000185else
Vikram S. Adve41e78912002-09-20 14:03:13 +0000186Link := $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000187endif
Vikram S. Adveec4d3622002-12-16 01:31:18 +0000188LinkG := $(Link) -g -L$(LIBDEBUG) $(STRIP)
189LinkO := $(Link) -O3 -L$(LIBRELEASE)
190LinkP := $(Link) -O3 -L$(LIBPROFILE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000191
Chris Lattnere62dbe92002-07-23 17:56:16 +0000192# Create one .o file from a bunch of .o files...
193Relink = ld -r
194
Chris Lattner4bb13b82002-09-13 22:14:47 +0000195# MakeSO - Create a .so file from a .o files...
Vikram S. Adve41e78912002-09-20 14:03:13 +0000196MakeSO := $(CXX) $(MakeSharedObjectOption)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000197MakeSOO := $(MakeSO) -O3
Vikram S. Adve41e78912002-09-20 14:03:13 +0000198MakeSOP := $(MakeSOO) $(PROFILE)
Chris Lattner4bb13b82002-09-13 22:14:47 +0000199
Chris Lattner00950542001-06-06 20:29:01 +0000200# Create dependancy file from CPP file, send to stdout.
Chris Lattner285af382002-08-12 21:19:28 +0000201Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner172b6482002-09-22 02:47:15 +0000202DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000203
204# Archive a bunch of .o files into a .a file...
205AR = ar cq
Chris Lattner172b6482002-09-22 02:47:15 +0000206BISON = bison
Chris Lattner00950542001-06-06 20:29:01 +0000207
208#----------------------------------------------------------
209
210# Source includes all of the cpp files, and objects are derived from the
211# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000212# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000213#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000214ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000215Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000216endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000217
Chris Lattner694c5df2003-05-15 21:28:55 +0000218Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000219ObjectsO := $(addprefix $(BUILD_ROOT)/Release/,$(Objs))
220ObjectsP := $(addprefix $(BUILD_ROOT)/Profile/,$(Objs))
Chris Lattner9b947012002-09-19 19:42:24 +0000221ObjectsG := $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
Chris Lattner00950542001-06-06 20:29:01 +0000222
Chris Lattnere62dbe92002-07-23 17:56:16 +0000223
Chris Lattner00950542001-06-06 20:29:01 +0000224#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000225# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000226#---------------------------------------------------------
227
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000228ifdef DIRS
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000229all install clean test ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000230 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000231 (cd $$dir; $(MAKE) $@) || exit 1; \
232 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000233endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000234
235# Handle PARALLEL_DIRS
236ifdef PARALLEL_DIRS
237all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
238install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS))
239clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000240test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000241
Chris Lattnerdc95ade2003-01-16 20:02:30 +0000242%/.makeall %/.makeinstall %/.makeclean %/.maketest:
Chris Lattnera8abc222002-09-18 03:22:27 +0000243 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000244endif
245
246#---------------------------------------------------------
247# Handle the LIBRARYNAME option - used when building libs...
248#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000249#
250# When libraries are built, they are allowed to optionally define the
251# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
252# from being built for the library. This .o files may then be linked to by a
253# tool if the tool does not need (or want) the semantics a .a file provides
254# (linking in only object files that are "needed"). If a library is never to
255# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
256# BUILD_ARCHIVE instead.
257#
258# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000259# 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 +0000260# linked into tools (for example gccas) even if they only use one of the parts
261# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000262
263ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000264
Chris Lattner2a548c52002-09-16 22:36:42 +0000265# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000266LIBRARYNAME := $(strip $(LIBRARYNAME))
267
Chris Lattnere62dbe92002-07-23 17:56:16 +0000268LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
Vikram S. Adve41e78912002-09-20 14:03:13 +0000269LIBNAME_P := $(LIBPROFILE)/lib$(LIBRARYNAME).so
Chris Lattnere62dbe92002-07-23 17:56:16 +0000270LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
271LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
Vikram S. Adve41e78912002-09-20 14:03:13 +0000272LIBNAME_AP := $(LIBPROFILE)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000273LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
274LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
Vikram S. Adve41e78912002-09-20 14:03:13 +0000275LIBNAME_OBJP := $(LIBPROFILE)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000276LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000277
Chris Lattner760da062003-03-14 20:25:22 +0000278# dynamic target builds a shared object version of the library...
279dynamic:: $(LIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000280
Chris Lattner760da062003-03-14 20:25:22 +0000281# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000282ifndef DONT_BUILD_RELINKED
Chris Lattner760da062003-03-14 20:25:22 +0000283all:: $(LIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000284endif
Chris Lattner760da062003-03-14 20:25:22 +0000285
286# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000287ifdef BUILD_ARCHIVE
Chris Lattner760da062003-03-14 20:25:22 +0000288all:: $(LIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000289endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000290
Chris Lattnere16b1b42002-08-09 15:41:55 +0000291$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000292 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000293 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000294
Vikram S. Adve41e78912002-09-20 14:03:13 +0000295$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
296 @echo ======= Linking $(LIBRARYNAME) profile library =======
297 $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
298
Chris Lattnere16b1b42002-08-09 15:41:55 +0000299$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000300 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000301 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000302
Chris Lattnere16b1b42002-08-09 15:41:55 +0000303$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000304 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000305 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000306 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000307
Vikram S. Adve41e78912002-09-20 14:03:13 +0000308$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
309 @echo ======= Linking $(LIBRARYNAME) profile library =======
310 @rm -f $@
311 $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs)
312
Chris Lattnere16b1b42002-08-09 15:41:55 +0000313$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000314 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000315 @rm -f $@
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000316 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000317
Chris Lattnere16b1b42002-08-09 15:41:55 +0000318$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000319 @echo "Linking $@"
320 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000321
Vikram S. Adve41e78912002-09-20 14:03:13 +0000322$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(LIBPROFILE)/.dir
323 @echo "Linking $@"
324 $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs)
325
Chris Lattnere16b1b42002-08-09 15:41:55 +0000326$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000327 @echo "Linking $@"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000328 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000329
Chris Lattner00950542001-06-06 20:29:01 +0000330endif
331
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000332#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000333# Create a TAGS database for emacs
334#------------------------------------------------------------------------
335
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000336ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000337tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000338 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000339all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000340endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000341
342#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000343# Handle the TOOLNAME option - used when building tool executables...
344#------------------------------------------------------------------------
345#
346# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000347# libraries (and the order of the libs) that should be linked to the
348# tool. USEDLIBS should contain a list of library names (some with .a extension)
349# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000350#
351ifdef TOOLNAME
352
353# TOOLEXENAME* - These compute the output filenames to generate...
Chris Lattner285af382002-08-12 21:19:28 +0000354TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
355TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000356TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
Chris Lattner760da062003-03-14 20:25:22 +0000357TOOLEXENAMES := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000358
359# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Chris Lattnere62dbe92002-07-23 17:56:16 +0000360USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
361USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
362USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000363USED_LIBS_OPTIONS_P := $(patsubst %.o, $(LIBPROFILE)/%.o,$(USED_LIBS_OPTIONS))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000364
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000365
366# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000367# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
368# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000369#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000370STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
371USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
372USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
Vikram S. Adve41e78912002-09-20 14:03:13 +0000373USED_LIB_PATHS_P := $(addprefix $(LIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1c588502002-11-04 20:50:33 +0000374LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000375
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000376
377# Tell make that we need to rebuild subdirectories before we can link the tool.
378# This affects things like LLI which has library subdirectories.
379$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
380 $(addsuffix /.makeall, $(PARALLEL_DIRS))
381
Chris Lattner669bd7c2001-10-13 05:10:29 +0000382all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000383clean::
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000384 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000385
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000386$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
Chris Lattner527002c2003-01-31 19:00:26 +0000387 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
Chris Lattner1c588502002-11-04 20:50:33 +0000388 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000389
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000390$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000391 @echo ======= Linking $(TOOLNAME) release executable =======
Chris Lattner1c588502002-11-04 20:50:33 +0000392 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(USED_LIBS_OPTIONS_O) $(LINK_OPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000393
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000394$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000395 @echo ======= Linking $(TOOLNAME) profile executable =======
Chris Lattner1c588502002-11-04 20:50:33 +0000396 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(USED_LIBS_OPTIONS_P) $(LINK_OPTS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000397
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000398endif
399
400
Chris Lattner00950542001-06-06 20:29:01 +0000401
402#---------------------------------------------------------
Chris Lattnere16b1b42002-08-09 15:41:55 +0000403.PRECIOUS: $(BUILD_ROOT)/Depend/.dir
404.PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000405
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000406# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner694c5df2003-05-15 21:28:55 +0000407$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000408 @echo "Compiling $<"
409 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000410
Chris Lattner694c5df2003-05-15 21:28:55 +0000411$(BUILD_ROOT)/Release/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Release/.dir
Chris Lattner1eeac662002-10-22 23:28:23 +0000412 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000413
Chris Lattner694c5df2003-05-15 21:28:55 +0000414$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000415 @echo "Compiling $<"
416 $(VERB) $(CompileP) $< -o $@
417
Chris Lattner694c5df2003-05-15 21:28:55 +0000418$(BUILD_ROOT)/Profile/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000419 @echo "Compiling $<"
420 $(VERB) $(CompileCP) $< -o $@
421
Chris Lattner694c5df2003-05-15 21:28:55 +0000422$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_ROOT)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000423 @echo "Compiling $<"
424 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000425
Chris Lattner694c5df2003-05-15 21:28:55 +0000426$(BUILD_ROOT)/Debug/%.o: $(SourceDir)%.c $(BUILD_ROOT)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000427 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000428
Chris Lattnere8996782003-01-16 22:44:19 +0000429#
430# Rules for building lex/yacc files
431#
432LEX_FILES = $(filter %.l, $(Source))
433LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
434YACC_FILES = $(filter %.y, $(Source))
435YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
436.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
437
Chris Lattner00950542001-06-06 20:29:01 +0000438# Create a .cpp source file from a flex input file... this uses sed to cut down
439# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000440#
441# The last line is a gross hack to work around flex aparently not being able to
442# resize the buffer on a large token input. Currently, for uninitialized string
443# buffers in LLVM we can generate very long tokens, so this is a hack around it.
444# FIXME. (f.e. char Buffer[10000]; )
445#
Chris Lattner00950542001-06-06 20:29:01 +0000446%.cpp: %.l
Chris Lattner6d131b42003-01-23 16:33:10 +0000447 flex -t $< | sed '/^find_rule/d' | \
448 sed 's/void yyunput/inline void yyunput/' | \
449 sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
450 sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000451
452# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000453%.c: %.y # Cancel built-in rules for yacc
454%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000455%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000456 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000457 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
458 $(VERB) mv -f $*.tab.c $*.cpp
459 $(VERB) mv -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000460
461# To create the directories...
462%/.dir:
Chris Lattnere8996782003-01-16 22:44:19 +0000463 $(VERB) mkdir -p $*
Chris Lattner00950542001-06-06 20:29:01 +0000464 @date > $@
465
Chris Lattner30440c62003-01-16 21:06:18 +0000466# To create postscript files from dot files...
467%.ps: %.dot
468 dot -Tps < $< > $@
469
Chris Lattner172b6482002-09-22 02:47:15 +0000470# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000471clean::
Vikram S. Adve41e78912002-09-20 14:03:13 +0000472 $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Profile $(BUILD_ROOT)/Depend
Misha Brukmanab6d2932002-12-04 17:08:15 +0000473 $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
Chris Lattnere8996782003-01-16 22:44:19 +0000474 $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT)
Chris Lattner00950542001-06-06 20:29:01 +0000475
Chris Lattner694c5df2003-05-15 21:28:55 +0000476# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000477# include the dependancies now...
478#
Chris Lattner694c5df2003-05-15 21:28:55 +0000479SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
480SourceDepend := $(SourceBaseNames:%=$(BUILD_ROOT)/Depend/%.d)
481
482# Create dependencies for the *.cpp files...
483#$(SourceDepend): \x
484$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_ROOT)/Depend/.dir
485 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Profile/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
486
487# Create dependencies for the *.c files...
488#$(SourceDepend): \x
489$(BUILD_ROOT)/Depend/%.d: $(SourceDir)%.c $(BUILD_ROOT)/Depend/.dir
490 $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@
491
Chris Lattner00950542001-06-06 20:29:01 +0000492ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000493-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000494endif