blob: 029c2c987a5814e5254d30acbb71311f6b91a0f6 [file] [log] [blame]
Vikram S. Adve24132e82002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner2f7c9632001-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. Adve728de922002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner2f7c9632001-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
16# so that each of the targets "all", "install", and "clean" each build.
17# the subdirectories before the local target.
18#
19# 3. Source - If specified, this sets the source code filenames. If this
20# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattneree6e1992001-10-18 01:48:09 +000021# in the current directory. Also, if you want to build files in addition
22# to the local files, you can use the ExtraSource variable
Chris Lattner2f7c9632001-06-06 20:29:01 +000023#
Vikram S. Adve24132e82002-07-09 12:04:21 +000024#===-----------------------------------------------------------------------====
Chris Lattner2f7c9632001-06-06 20:29:01 +000025
Vikram S. Adve728de922002-08-29 23:28:46 +000026# Configuration file to set paths specific to local installation of LLVM
27#
28include $(LEVEL)/Makefile.config
29
Chris Lattner76d98ba2002-07-23 17:56:16 +000030# These are options that can either be enabled here, or can be enabled on the
Chris Lattneread864f2002-08-03 20:19:30 +000031# make command line (ie, make ENABLE_PROFILING=1)
32#
33
34# When ENABLE_PROFILING is enabled, the llvm source base is built with profile
35# information to allow gprof to be used to get execution frequencies.
Chris Lattner76d98ba2002-07-23 17:56:16 +000036#
37#ENABLE_PROFILING = 1
Chris Lattneread864f2002-08-03 20:19:30 +000038
39# When ENABLE_PURIFY is enabled, the LLVM tools are linked with purify (which
40# must be locally installed) to allow for some automated memory error debugging.
41#
Chris Lattner76d98ba2002-07-23 17:56:16 +000042#ENABLE_PURIFY = 1
Chris Lattneread864f2002-08-03 20:19:30 +000043
44# When ENABLE_OPTIMIZED is enabled, Release builds of all of the LLVM code are
45# turned on, and Debug builds are turned off.
46#
Chris Lattner76d98ba2002-07-23 17:56:16 +000047#ENABLE_OPTIMIZED = 1
48
Chris Lattner570c6a62002-07-23 19:21:31 +000049ifdef SHARED_LIBRARY
50# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
51dynamic ::
52endif
53
Chris Lattner44601ba2001-06-29 05:20:16 +000054# Default Rule: Make sure it's also a :: rule
Chris Lattner2f7c9632001-06-06 20:29:01 +000055all ::
56
57# Default for install is to at least build everything...
58install ::
59
Chris Lattner77330fa2002-08-09 15:41:55 +000060
61# Figure out which directory to build stuff into. We want to build into the
62# /shared directory by default because it is guaranteed to be local to the
63# current machine.
64#
Vikram S. Adve728de922002-08-29 23:28:46 +000065ifeq ($(LLVM_OBJ_DIR),.)
66BUILD_ROOT = $(LLVM_OBJ_DIR)
67BUILD_ROOT_TOP = $(LEVEL)
Chris Lattner01f68c62002-08-12 21:19:28 +000068else
69
Vikram S. Adve728de922002-08-29 23:28:46 +000070BUILD_ROOT := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(shell pwd))
Chris Lattner01f68c62002-08-12 21:19:28 +000071
72# Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree.
73# Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use
74# this expression because some of the directories on the source tree may not
75# exist in the build tree (for example the test/ heirarchy). Thus we evaluate
76# the directory to eliminate the ../'s
77#
78TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
Vikram S. Adve728de922002-08-29 23:28:46 +000079BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
Chris Lattner77330fa2002-08-09 15:41:55 +000080endif
81
Chris Lattner2f7c9632001-06-06 20:29:01 +000082#--------------------------------------------------------------------
Vikram S. Adve728de922002-08-29 23:28:46 +000083# Variables derived from configuration options...
Chris Lattner2f7c9632001-06-06 20:29:01 +000084#--------------------------------------------------------------------
85
86#BinInstDir=/usr/local/bin
87#LibInstDir=/usrl/local/lib/xxx
88#DocInstDir=/usr/doc/xxx
89
Vikram S. Adveca4a3822001-08-06 19:01:20 +000090BURG_OPTS = -I
91
Vikram S. Adve728de922002-08-29 23:28:46 +000092PURIFY := $(PURIFY) -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all
Chris Lattnerb20b290c2001-10-30 20:24:08 +000093
Chris Lattner76d98ba2002-07-23 17:56:16 +000094# Shorthand for commonly accessed directories
Chris Lattner01f68c62002-08-12 21:19:28 +000095LIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug
96LIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release
97TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug
98TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release
Chris Lattner76d98ba2002-07-23 17:56:16 +000099
Misha Brukman1326a7c2002-09-12 16:05:39 +0000100# Verbosity levels
101ifdef VERBOSE
102VERB :=
103else
104VERB := @
105endif
106
Chris Lattner2f7c9632001-06-06 20:29:01 +0000107#---------------------------------------------------------
108# Compilation options...
109#---------------------------------------------------------
110
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000111# Special tools used while building
Chris Lattner01f68c62002-08-12 21:19:28 +0000112RunBurg := $(BURG) $(BURG_OPTS)
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000113
Chris Lattner2f7c9632001-06-06 20:29:01 +0000114# Enable this for profiling support with 'gprof'
Chris Lattner198d5eb2002-05-10 18:51:54 +0000115ifdef ENABLE_PROFILING
116PROFILE = -pg
117else
118PROFILE =
119endif
Chris Lattner2f7c9632001-06-06 20:29:01 +0000120
Chris Lattner2efcf432002-09-13 16:02:26 +0000121# Allow gnu extensions...
122CPPFLAGS += -D_GNU_SOURCE
123
Chris Lattner068f8222002-01-23 05:46:01 +0000124# -Wno-unused-parameter
Chris Lattner01f68c62002-08-12 21:19:28 +0000125CompileCommonOpts := $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner2f7c9632001-06-06 20:29:01 +0000126
127# Compile a file, don't link...
Chris Lattner01f68c62002-08-12 21:19:28 +0000128Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
129CompileG := $(Compile) -g -D_DEBUG
130CompileO := $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
Chris Lattner2f7c9632001-06-06 20:29:01 +0000131
132# Link final executable
Chris Lattnerb20b290c2001-10-30 20:24:08 +0000133
Chris Lattnerd711a5e2002-07-31 21:32:05 +0000134ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
Chris Lattner01f68c62002-08-12 21:19:28 +0000135Link := $(PURIFY) $(CXX) $(PROFILE) -static
Chris Lattnerf0a88d12002-04-05 18:56:58 +0000136else
Chris Lattner01f68c62002-08-12 21:19:28 +0000137Link := $(CXX) $(PROFILE)
Chris Lattnerf0a88d12002-04-05 18:56:58 +0000138endif
Chris Lattner01f68c62002-08-12 21:19:28 +0000139LinkG := $(Link) -g -L $(LIBDEBUG)
140LinkO := $(Link) -O3 -L $(LIBRELEASE)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000141
Chris Lattner76d98ba2002-07-23 17:56:16 +0000142# Create a .so file from a .o files...
Chris Lattner01f68c62002-08-12 21:19:28 +0000143#MakeSO := $(CXX) -shared $(PROFILE)
144MakeSO := $(CXX) -G $(PROFILE)
145MakeSOO := $(MakeSO) -O3
Chris Lattner2f7c9632001-06-06 20:29:01 +0000146
Chris Lattner76d98ba2002-07-23 17:56:16 +0000147# Create one .o file from a bunch of .o files...
148Relink = ld -r
149
Chris Lattner2f7c9632001-06-06 20:29:01 +0000150# Create dependancy file from CPP file, send to stdout.
Chris Lattner01f68c62002-08-12 21:19:28 +0000151Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000152
153# Archive a bunch of .o files into a .a file...
154AR = ar cq
155
156#----------------------------------------------------------
157
158# Source includes all of the cpp files, and objects are derived from the
159# source files...
Chris Lattneree6e1992001-10-18 01:48:09 +0000160# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advebd9cae22001-10-17 12:33:55 +0000161#
Chris Lattneree6e1992001-10-18 01:48:09 +0000162Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advefe346892001-07-15 13:16:47 +0000163
Chris Lattnerd1a72292002-07-25 15:01:19 +0000164Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
Chris Lattner77330fa2002-08-09 15:41:55 +0000165ObjectsO = $(addprefix $(BUILD_ROOT)/Release/,$(Objs)))
166ObjectsG = $(addprefix $(BUILD_ROOT)/Debug/,$(Objs))
Chris Lattner2f7c9632001-06-06 20:29:01 +0000167
Chris Lattner76d98ba2002-07-23 17:56:16 +0000168
Chris Lattner2f7c9632001-06-06 20:29:01 +0000169#---------------------------------------------------------
170# Handle the DIRS option
171#---------------------------------------------------------
172
173ifdef DIRS # Only do this if we're using DIRS!
174
175all :: $(addsuffix /.makeall , $(DIRS))
176install :: $(addsuffix /.makeinstall, $(DIRS))
177clean :: $(addsuffix /.makeclean , $(DIRS))
178
179%/.makeall %/.makeclean %/.makeinstall:
Misha Brukman1326a7c2002-09-12 16:05:39 +0000180 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181endif
182
183#---------------------------------------------------------
184# Handle the LIBRARYNAME option - used when building libs...
185#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +0000186#
187# When libraries are built, they are allowed to optionally define the
188# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
189# from being built for the library. This .o files may then be linked to by a
190# tool if the tool does not need (or want) the semantics a .a file provides
191# (linking in only object files that are "needed"). If a library is never to
192# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
193# BUILD_ARCHIVE instead.
194#
195# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattnerd711a5e2002-07-31 21:32:05 +0000196# it's built as a .o file, then all of the constituent .o files in it will be
Chris Lattner76d98ba2002-07-23 17:56:16 +0000197# linked into tools (for example gccas) even if they only use one of the parts
198# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000199
200ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000201
Chris Lattner76d98ba2002-07-23 17:56:16 +0000202LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
203LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
204LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
205LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
206LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
207LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner2f7c9632001-06-06 20:29:01 +0000208
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000209
210ifndef ENABLE_OPTIMIZED
Chris Lattner76d98ba2002-07-23 17:56:16 +0000211BUILD_LIBNAME_G := $(LIBNAME_G)
212ifndef DONT_BUILD_RELINKED
213BUILD_LIBNAME_OBJG := $(LIBNAME_OBJG)
214endif
215ifdef BUILD_ARCHIVE
216BUILD_LIBNAME_AG := $(LIBNAME_AG)
217endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000218endif
Chris Lattner2f7c9632001-06-06 20:29:01 +0000219
Chris Lattner76d98ba2002-07-23 17:56:16 +0000220# If optimized builds are enabled...
221ifdef ENABLE_OPTIMIZED
222BUILD_LIBNAME_O := $(LIBNAME_O)
223ifndef DONT_BUILD_RELINKED
224BUILD_LIBNAME_OBJO := $(LIBNAME_OBJO)
225endif
226ifdef BUILD_ARCHIVE
227BUILD_LIBNAME_AO := $(LIBNAME_AO)
228endif
229endif
230
231all:: $(BUILD_LIBNAME_AG) $(BUILD_LIBNAME_OBJG) # Debug
232all:: $(BUILD_LIBNAME_AO) $(BUILD_LIBNAME_OBJO) # Release
233dynamic:: $(BUILD_LIBNAME_G) $(BUILD_LIBNAME_O) # .so files
234
Chris Lattner77330fa2002-08-09 15:41:55 +0000235$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000236 @echo ======= Linking $(LIBRARYNAME) release library =======
Misha Brukman1326a7c2002-09-12 16:05:39 +0000237 $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000238
Chris Lattner77330fa2002-08-09 15:41:55 +0000239$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000240 @echo ======= Linking $(LIBRARYNAME) debug library =======
Misha Brukman1326a7c2002-09-12 16:05:39 +0000241 $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000242
Chris Lattner77330fa2002-08-09 15:41:55 +0000243$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000244 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000245 @rm -f $@
Misha Brukman1326a7c2002-09-12 16:05:39 +0000246 $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs)
Vikram S. Advefe346892001-07-15 13:16:47 +0000247
Chris Lattner77330fa2002-08-09 15:41:55 +0000248$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000249 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000250 @rm -f $@
Misha Brukman1326a7c2002-09-12 16:05:39 +0000251 $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs)
Vikram S. Advefe346892001-07-15 13:16:47 +0000252
Chris Lattner77330fa2002-08-09 15:41:55 +0000253$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000254 @echo "Linking $@"
255 $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000256
Chris Lattner77330fa2002-08-09 15:41:55 +0000257$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000258 $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000259
Chris Lattner2f7c9632001-06-06 20:29:01 +0000260endif
261
Chris Lattner07c7c192001-09-07 22:57:58 +0000262#------------------------------------------------------------------------
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000263# Create a TAGS database for emacs
264#------------------------------------------------------------------------
265
Vikram S. Advea0e99082001-10-13 12:26:59 +0000266ifeq ($(LEVEL), .)
Vikram S. Advea0e99082001-10-13 12:26:59 +0000267tags:
Chris Lattner198d5eb2002-05-10 18:51:54 +0000268 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Advea0e99082001-10-13 12:26:59 +0000269all:: tags
Vikram S. Advea0e99082001-10-13 12:26:59 +0000270endif
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000271
272#------------------------------------------------------------------------
Chris Lattner07c7c192001-09-07 22:57:58 +0000273# Handle the TOOLNAME option - used when building tool executables...
274#------------------------------------------------------------------------
275#
276# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattner76d98ba2002-07-23 17:56:16 +0000277# libraries (and the order of the libs) that should be linked to the
278# tool. USEDLIBS should contain a list of library names (some with .a extension)
279# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner07c7c192001-09-07 22:57:58 +0000280#
281ifdef TOOLNAME
282
283# TOOLEXENAME* - These compute the output filenames to generate...
Chris Lattner01f68c62002-08-12 21:19:28 +0000284TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
285TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
286TOOLEXENAMES := $(TOOLEXENAME_G)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000287ifdef ENABLE_OPTIMIZED
288TOOLEXENAMES += $(TOOLEXENAME_O)
289endif
Chris Lattner07c7c192001-09-07 22:57:58 +0000290
291# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Chris Lattner76d98ba2002-07-23 17:56:16 +0000292USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
293USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
294USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
295
Chris Lattner07c7c192001-09-07 22:57:58 +0000296
297# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattner76d98ba2002-07-23 17:56:16 +0000298# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
299# files seperately.
Chris Lattner07c7c192001-09-07 22:57:58 +0000300#
Chris Lattner76d98ba2002-07-23 17:56:16 +0000301STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
302USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
303USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
Chris Lattner07c7c192001-09-07 22:57:58 +0000304
Chris Lattner1fd501f2001-10-13 05:10:29 +0000305all:: $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000306clean::
Misha Brukman1326a7c2002-09-12 16:05:39 +0000307 $(VERB) rm -f $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000308
Chris Lattner01f68c62002-08-12 21:19:28 +0000309$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(BUILD_ROOT_TOP)/tools/Debug/.dir
Chris Lattner500f0642002-09-12 17:02:40 +0000310 @echo ======= Linking $(TOOLNAME) debug executable =======
Misha Brukman1326a7c2002-09-12 16:05:39 +0000311 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000312
Chris Lattner01f68c62002-08-12 21:19:28 +0000313$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(BUILD_ROOT_TOP)/tools/Release/.dir
Chris Lattner500f0642002-09-12 17:02:40 +0000314 @echo ======= Linking $(TOOLNAME) release executable =======
Misha Brukman1326a7c2002-09-12 16:05:39 +0000315 $(VERB) $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_O) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000316
317endif
318
319
Chris Lattner2f7c9632001-06-06 20:29:01 +0000320
321#---------------------------------------------------------
Chris Lattner77330fa2002-08-09 15:41:55 +0000322.PRECIOUS: $(BUILD_ROOT)/Depend/.dir
323.PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000324
Vikram S. Advefe346892001-07-15 13:16:47 +0000325# Create dependencies for the *.cpp files...
Chris Lattner77330fa2002-08-09 15:41:55 +0000326$(BUILD_ROOT)/Depend/%.d: %.cpp $(BUILD_ROOT)/Depend/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000327 $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000328
Vikram S. Advefe346892001-07-15 13:16:47 +0000329# Create dependencies for the *.c files...
Chris Lattner77330fa2002-08-09 15:41:55 +0000330$(BUILD_ROOT)/Depend/%.d: %.c $(BUILD_ROOT)/Depend/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000331 $(VERB) $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000332
333# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner77330fa2002-08-09 15:41:55 +0000334$(BUILD_ROOT)/Release/%.o: %.cpp $(BUILD_ROOT)/Release/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000335 @echo "Compiling $<"
336 $(VERB) $(CompileO) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000337
Chris Lattner068f8222002-01-23 05:46:01 +0000338#Release/%.o: %.c Release/.dir Depend/.dir
339# $(CompileOC) $< -o $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000340
Chris Lattner77330fa2002-08-09 15:41:55 +0000341$(BUILD_ROOT)/Debug/%.o: %.cpp $(BUILD_ROOT)/Debug/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000342 @echo "Compiling $<"
343 $(VERB) $(CompileG) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000344
Chris Lattner77330fa2002-08-09 15:41:55 +0000345#Debug/%.o: %.c Debug/.dir
Chris Lattner068f8222002-01-23 05:46:01 +0000346# $(CompileGC) $< -o $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000347
Chris Lattner2f7c9632001-06-06 20:29:01 +0000348# Create a .cpp source file from a flex input file... this uses sed to cut down
349# on the warnings emited by GCC...
350%.cpp: %.l
351 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
352
353# Rule for building the bison parsers...
354
355%.cpp %.h : %.y
Misha Brukman1326a7c2002-09-12 16:05:39 +0000356 $(VERB) bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
357 $(VERB) mv -f $(basename $@).tab.c $(basename $@).cpp
358 $(VERB) mv -f $(basename $@).tab.h $(basename $@).h
Chris Lattner2f7c9632001-06-06 20:29:01 +0000359
360# To create the directories...
361%/.dir:
Misha Brukman1326a7c2002-09-12 16:05:39 +0000362 $(VERB) mkdir -p $(@D)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000363 @date > $@
364
Chris Lattnerd711a5e2002-07-31 21:32:05 +0000365# Clean nukes the tree
Chris Lattner2f7c9632001-06-06 20:29:01 +0000366clean::
Misha Brukman1326a7c2002-09-12 16:05:39 +0000367 $(VERB) rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Depend
368 $(VERB) rm -f core *.o *.d *.so *~ *.flc
Chris Lattner2f7c9632001-06-06 20:29:01 +0000369
370# If dependancies were generated for the file that included this file,
371# include the dependancies now...
372#
Chris Lattner01f68c62002-08-12 21:19:28 +0000373SourceDepend := $(addsuffix .d,$(addprefix $(BUILD_ROOT)/Depend/,$(basename $(filter-out Debug/%, $(Source)))))
Chris Lattner2f7c9632001-06-06 20:29:01 +0000374ifneq ($(SourceDepend),)
375include $(SourceDepend)
376endif