blob: b13db1802d8b526bfe3fd2412cfb0c0981d5a7bb [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#
8# The following functionality may be set by setting incoming variables:
9#
10# 1. LEVEL - The level of the current subdirectory from the top of the
11# MagicStats view. This level should be expressed as a path, for
12# example, ../.. for two levels deep.
13#
14# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
15# so that each of the targets "all", "install", and "clean" each build.
16# the subdirectories before the local target.
17#
18# 3. Source - If specified, this sets the source code filenames. If this
19# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000020# in the current directory. Also, if you want to build files in addition
21# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000022#
Vikram S. Adved60aede2002-07-09 12:04:21 +000023#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000024
Chris Lattnere62dbe92002-07-23 17:56:16 +000025# These are options that can either be enabled here, or can be enabled on the
26# make command line (make ENABLE_PROFILING=1)
27#
28#ENABLE_PROFILING = 1
29#ENABLE_PURIFY = 1
30#ENABLE_OPTIMIZED = 1
31
Chris Lattneredf1f232002-07-23 19:21:31 +000032ifdef SHARED_LIBRARY
33# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
34dynamic ::
35endif
36
Chris Lattnerb19e59c2001-06-29 05:20:16 +000037# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000038all ::
39
40# Default for install is to at least build everything...
41install ::
42
43#--------------------------------------------------------------------
44# Installation configuration options...
45#--------------------------------------------------------------------
46
47#BinInstDir=/usr/local/bin
48#LibInstDir=/usrl/local/lib/xxx
49#DocInstDir=/usr/doc/xxx
50
Vikram S. Advedba59ef2001-08-06 19:01:20 +000051BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
52BURG_OPTS = -I
53
Chris Lattner6e390702001-10-30 20:24:08 +000054
Chris Lattnerec6bed22002-04-07 06:18:40 +000055PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +000056
Chris Lattnere62dbe92002-07-23 17:56:16 +000057# Shorthand for commonly accessed directories
58LIBDEBUG = $(LEVEL)/lib/Debug
59LIBRELEASE = $(LEVEL)/lib/Release
60TOOLDEBUG = $(LEVEL)/tools/Debug
61TOOLRELEASE = $(LEVEL)/tools/Release
62
Chris Lattner00950542001-06-06 20:29:01 +000063#---------------------------------------------------------
64# Compilation options...
65#---------------------------------------------------------
66
Vikram S. Advedba59ef2001-08-06 19:01:20 +000067# Special tools used while building
68RunBurg = $(BURG) $(BURG_OPTS)
69
Chris Lattner00950542001-06-06 20:29:01 +000070# Enable this for profiling support with 'gprof'
Chris Lattner18f47012002-05-10 18:51:54 +000071ifdef ENABLE_PROFILING
72PROFILE = -pg
73else
74PROFILE =
75endif
Chris Lattner00950542001-06-06 20:29:01 +000076
Chris Lattnerc7acf812002-01-23 05:46:01 +000077# -Wno-unused-parameter
Chris Lattner18f47012002-05-10 18:51:54 +000078CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner00950542001-06-06 20:29:01 +000079
80# Compile a file, don't link...
Vikram S. Adve60f56062002-08-02 18:34:12 +000081Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattner00950542001-06-06 20:29:01 +000082CompileG = $(Compile) -g -D_DEBUG
Chris Lattner00950542001-06-06 20:29:01 +000083CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
84
85# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +000086
Chris Lattner1917e952002-07-31 21:32:05 +000087ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
88Link = $(PURIFY) $(CXX) $(PROFILE) -static
Chris Lattner12604ed2002-04-05 18:56:58 +000089else
Chris Lattner1917e952002-07-31 21:32:05 +000090Link = $(CXX) $(PROFILE)
Chris Lattner12604ed2002-04-05 18:56:58 +000091endif
Chris Lattnere62dbe92002-07-23 17:56:16 +000092LinkG = $(Link) -g -L $(LIBDEBUG)
93LinkO = $(Link) -O3 -L $(LIBRELEASE)
Chris Lattner00950542001-06-06 20:29:01 +000094
Chris Lattnere62dbe92002-07-23 17:56:16 +000095# Create a .so file from a .o files...
Chris Lattner1917e952002-07-31 21:32:05 +000096#MakeSO = $(CXX) -shared $(PROFILE)
97MakeSO = $(CXX) -G $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +000098MakeSOO = $(MakeSO) -O3
99
Chris Lattnere62dbe92002-07-23 17:56:16 +0000100# Create one .o file from a bunch of .o files...
101Relink = ld -r
102
Chris Lattner00950542001-06-06 20:29:01 +0000103# Create dependancy file from CPP file, send to stdout.
104Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
105
106# Archive a bunch of .o files into a .a file...
107AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000108MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +0000109
110#----------------------------------------------------------
111
112# Source includes all of the cpp files, and objects are derived from the
113# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000114# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000115#
Chris Lattnere0010592001-10-18 01:48:09 +0000116Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000117
Chris Lattner4fa128c2002-07-25 15:01:19 +0000118Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
Chris Lattner00950542001-06-06 20:29:01 +0000119ObjectsO = $(addprefix Release/,$(Objs))
120ObjectsG = $(addprefix Debug/,$(Objs))
121
Chris Lattnere62dbe92002-07-23 17:56:16 +0000122
Chris Lattner00950542001-06-06 20:29:01 +0000123#---------------------------------------------------------
124# Handle the DIRS option
125#---------------------------------------------------------
126
127ifdef DIRS # Only do this if we're using DIRS!
128
129all :: $(addsuffix /.makeall , $(DIRS))
130install :: $(addsuffix /.makeinstall, $(DIRS))
131clean :: $(addsuffix /.makeclean , $(DIRS))
132
133%/.makeall %/.makeclean %/.makeinstall:
134 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
135endif
136
137#---------------------------------------------------------
138# Handle the LIBRARYNAME option - used when building libs...
139#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000140#
141# When libraries are built, they are allowed to optionally define the
142# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
143# from being built for the library. This .o files may then be linked to by a
144# tool if the tool does not need (or want) the semantics a .a file provides
145# (linking in only object files that are "needed"). If a library is never to
146# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
147# BUILD_ARCHIVE instead.
148#
149# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000150# 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 +0000151# linked into tools (for example gccas) even if they only use one of the parts
152# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000153
154ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000155
Chris Lattnere62dbe92002-07-23 17:56:16 +0000156LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
157LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
158LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
159LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
160LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
161LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000162
Vikram S. Adve60f56062002-08-02 18:34:12 +0000163
164ifndef ENABLE_OPTIMIZED
Chris Lattnere62dbe92002-07-23 17:56:16 +0000165BUILD_LIBNAME_G := $(LIBNAME_G)
166ifndef DONT_BUILD_RELINKED
167BUILD_LIBNAME_OBJG := $(LIBNAME_OBJG)
168endif
169ifdef BUILD_ARCHIVE
170BUILD_LIBNAME_AG := $(LIBNAME_AG)
171endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000172endif
Chris Lattner00950542001-06-06 20:29:01 +0000173
Chris Lattnere62dbe92002-07-23 17:56:16 +0000174# If optimized builds are enabled...
175ifdef ENABLE_OPTIMIZED
176BUILD_LIBNAME_O := $(LIBNAME_O)
177ifndef DONT_BUILD_RELINKED
178BUILD_LIBNAME_OBJO := $(LIBNAME_OBJO)
179endif
180ifdef BUILD_ARCHIVE
181BUILD_LIBNAME_AO := $(LIBNAME_AO)
182endif
183endif
184
185all:: $(BUILD_LIBNAME_AG) $(BUILD_LIBNAME_OBJG) # Debug
186all:: $(BUILD_LIBNAME_AO) $(BUILD_LIBNAME_OBJO) # Release
187dynamic:: $(BUILD_LIBNAME_G) $(BUILD_LIBNAME_O) # .so files
188
189$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000190 @echo ======= Linking $(LIBRARYNAME) release library =======
191 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
192
Chris Lattnere62dbe92002-07-23 17:56:16 +0000193$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000194 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattnere62dbe92002-07-23 17:56:16 +0000195 $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000196
Chris Lattnere62dbe92002-07-23 17:56:16 +0000197$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000198 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000199 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000200 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
201
Chris Lattnere62dbe92002-07-23 17:56:16 +0000202$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000203 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000204 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000205 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
206
Chris Lattnere62dbe92002-07-23 17:56:16 +0000207$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
208 $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
209
210$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
211 $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
212
Chris Lattner00950542001-06-06 20:29:01 +0000213endif
214
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000215#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000216# Create a TAGS database for emacs
217#------------------------------------------------------------------------
218
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000219ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000220tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000221 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000222all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000223endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000224
225#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000226# Handle the TOOLNAME option - used when building tool executables...
227#------------------------------------------------------------------------
228#
229# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000230# libraries (and the order of the libs) that should be linked to the
231# tool. USEDLIBS should contain a list of library names (some with .a extension)
232# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000233#
234ifdef TOOLNAME
235
236# TOOLEXENAME* - These compute the output filenames to generate...
237TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
238TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000239TOOLEXENAMES := $(TOOLEXENAME_G)
240ifdef ENABLE_OPTIMIZED
241TOOLEXENAMES += $(TOOLEXENAME_O)
242endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000243
244# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Chris Lattnere62dbe92002-07-23 17:56:16 +0000245USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
246USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
247USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
248
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000249
250# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000251# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
252# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000253#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000254STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
255USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
256USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000257
Chris Lattner669bd7c2001-10-13 05:10:29 +0000258all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000259clean::
260 rm -f $(TOOLEXENAMES)
261
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000262$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattnere62dbe92002-07-23 17:56:16 +0000263 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000264
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000265$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattnere62dbe92002-07-23 17:56:16 +0000266 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_O) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000267
268endif
269
270
Chris Lattner00950542001-06-06 20:29:01 +0000271
272#---------------------------------------------------------
Chris Lattneraa6ec732001-11-07 14:50:58 +0000273.PRECIOUS: Depend/.dir Debug/.dir Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000274
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000275# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000276Depend/%.d: %.cpp Depend/.dir
277 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
278
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000279# Create dependencies for the *.c files...
280Depend/%.d: %.c Depend/.dir
281 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
282
283# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner00950542001-06-06 20:29:01 +0000284Release/%.o: %.cpp Release/.dir Depend/.dir
285 $(CompileO) $< -o $@
286
Chris Lattnerc7acf812002-01-23 05:46:01 +0000287#Release/%.o: %.c Release/.dir Depend/.dir
288# $(CompileOC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000289
Chris Lattner00950542001-06-06 20:29:01 +0000290Debug/%.o: %.cpp Debug/.dir Depend/.dir
291 $(CompileG) $< -o $@
292
Chris Lattnerc7acf812002-01-23 05:46:01 +0000293#Debug/%.o: %.c Debug/.dir Depend/.dir
294# $(CompileGC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000295
Chris Lattner00950542001-06-06 20:29:01 +0000296# Create a .cpp source file from a flex input file... this uses sed to cut down
297# on the warnings emited by GCC...
298%.cpp: %.l
299 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
300
301# Rule for building the bison parsers...
302
303%.cpp %.h : %.y
Chris Lattner18f47012002-05-10 18:51:54 +0000304 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
Chris Lattner00950542001-06-06 20:29:01 +0000305 mv -f $(basename $@).tab.c $(basename $@).cpp
306 mv -f $(basename $@).tab.h $(basename $@).h
307
308# To create the directories...
309%/.dir:
310 mkdir -p $(@D)
311 @date > $@
312
Chris Lattner1917e952002-07-31 21:32:05 +0000313# Clean nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000314clean::
315 rm -rf Debug Release Depend
316 rm -f core *.o *.d *.so *~ *.flc
317
318# If dependancies were generated for the file that included this file,
319# include the dependancies now...
320#
Chris Lattner4fa128c2002-07-25 15:01:19 +0000321SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(filter-out Debug/%, $(Source)))))
Chris Lattner00950542001-06-06 20:29:01 +0000322ifneq ($(SourceDepend),)
323include $(SourceDepend)
324endif