blob: 46d18c61892a02562321d8e4d5d279965dc60c93 [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 Lattnerb19e59c2001-06-29 05:20:16 +000032# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000033all ::
34
35# Default for install is to at least build everything...
36install ::
37
38#--------------------------------------------------------------------
39# Installation configuration options...
40#--------------------------------------------------------------------
41
42#BinInstDir=/usr/local/bin
43#LibInstDir=/usrl/local/lib/xxx
44#DocInstDir=/usr/doc/xxx
45
Vikram S. Advedba59ef2001-08-06 19:01:20 +000046BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
47BURG_OPTS = -I
48
Chris Lattner6e390702001-10-30 20:24:08 +000049
Chris Lattnerec6bed22002-04-07 06:18:40 +000050PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +000051
Chris Lattnere62dbe92002-07-23 17:56:16 +000052# Shorthand for commonly accessed directories
53LIBDEBUG = $(LEVEL)/lib/Debug
54LIBRELEASE = $(LEVEL)/lib/Release
55TOOLDEBUG = $(LEVEL)/tools/Debug
56TOOLRELEASE = $(LEVEL)/tools/Release
57
Chris Lattner00950542001-06-06 20:29:01 +000058#---------------------------------------------------------
59# Compilation options...
60#---------------------------------------------------------
61
Vikram S. Advedba59ef2001-08-06 19:01:20 +000062# Special tools used while building
63RunBurg = $(BURG) $(BURG_OPTS)
64
Chris Lattner00950542001-06-06 20:29:01 +000065# Enable this for profiling support with 'gprof'
Chris Lattner18f47012002-05-10 18:51:54 +000066ifdef ENABLE_PROFILING
67PROFILE = -pg
68else
69PROFILE =
70endif
Chris Lattner00950542001-06-06 20:29:01 +000071
72# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
Chris Lattnerc7acf812002-01-23 05:46:01 +000073# -Wno-unused-parameter
Chris Lattner18f47012002-05-10 18:51:54 +000074CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner00950542001-06-06 20:29:01 +000075
76# Compile a file, don't link...
Chris Lattner18f47012002-05-10 18:51:54 +000077Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +000078CompileG = $(Compile) -g -D_DEBUG
Chris Lattner00950542001-06-06 20:29:01 +000079CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
80
81# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +000082
83# To enable purify, do it here:
Chris Lattner12604ed2002-04-05 18:56:58 +000084ifdef ENABLE_PURIFY
85Link = $(PURIFY) $(CXX) $(Prof) -static
86else
Chris Lattner18f47012002-05-10 18:51:54 +000087Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(PROFILE)
Chris Lattner12604ed2002-04-05 18:56:58 +000088endif
Chris Lattnere62dbe92002-07-23 17:56:16 +000089LinkG = $(Link) -g -L $(LIBDEBUG)
90LinkO = $(Link) -O3 -L $(LIBRELEASE)
Chris Lattner00950542001-06-06 20:29:01 +000091
Chris Lattnere62dbe92002-07-23 17:56:16 +000092# Create a .so file from a .o files...
Chris Lattner00950542001-06-06 20:29:01 +000093#MakeSO = $(CXX) -shared $(Prof)
94MakeSO = $(CXX) -G $(Prof)
Chris Lattner00950542001-06-06 20:29:01 +000095MakeSOO = $(MakeSO) -O3
96
Chris Lattnere62dbe92002-07-23 17:56:16 +000097# Create one .o file from a bunch of .o files...
98Relink = ld -r
99
Chris Lattner00950542001-06-06 20:29:01 +0000100# Create dependancy file from CPP file, send to stdout.
101Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
102
103# Archive a bunch of .o files into a .a file...
104AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000105MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +0000106
107#----------------------------------------------------------
108
109# Source includes all of the cpp files, and objects are derived from the
110# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000111# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000112#
Chris Lattnere0010592001-10-18 01:48:09 +0000113Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000114
Chris Lattnerc7acf812002-01-23 05:46:01 +0000115Objs := $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner00950542001-06-06 20:29:01 +0000116ObjectsO = $(addprefix Release/,$(Objs))
117ObjectsG = $(addprefix Debug/,$(Objs))
118
Chris Lattnere62dbe92002-07-23 17:56:16 +0000119
Chris Lattner00950542001-06-06 20:29:01 +0000120#---------------------------------------------------------
121# Handle the DIRS option
122#---------------------------------------------------------
123
124ifdef DIRS # Only do this if we're using DIRS!
125
126all :: $(addsuffix /.makeall , $(DIRS))
127install :: $(addsuffix /.makeinstall, $(DIRS))
128clean :: $(addsuffix /.makeclean , $(DIRS))
129
130%/.makeall %/.makeclean %/.makeinstall:
131 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
132endif
133
134#---------------------------------------------------------
135# Handle the LIBRARYNAME option - used when building libs...
136#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000137#
138# When libraries are built, they are allowed to optionally define the
139# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
140# from being built for the library. This .o files may then be linked to by a
141# tool if the tool does not need (or want) the semantics a .a file provides
142# (linking in only object files that are "needed"). If a library is never to
143# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
144# BUILD_ARCHIVE instead.
145#
146# Some libraries must be built as .a files (libscalar for example) because if
147# it's built as a .o file, then all of the constitent .o files in it will be
148# linked into tools (for example gccas) even if they only use one of the parts
149# of it. For this reason, sometimes it's useful to use libraries as .a files.
Chris Lattner00950542001-06-06 20:29:01 +0000150
151ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000152
Chris Lattnere62dbe92002-07-23 17:56:16 +0000153LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
154LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
155LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
156LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
157LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
158LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000159
Chris Lattnere62dbe92002-07-23 17:56:16 +0000160BUILD_LIBNAME_G := $(LIBNAME_G)
161ifndef DONT_BUILD_RELINKED
162BUILD_LIBNAME_OBJG := $(LIBNAME_OBJG)
163endif
164ifdef BUILD_ARCHIVE
165BUILD_LIBNAME_AG := $(LIBNAME_AG)
166endif
Chris Lattner00950542001-06-06 20:29:01 +0000167
Chris Lattnere62dbe92002-07-23 17:56:16 +0000168# If optimized builds are enabled...
169ifdef ENABLE_OPTIMIZED
170BUILD_LIBNAME_O := $(LIBNAME_O)
171ifndef DONT_BUILD_RELINKED
172BUILD_LIBNAME_OBJO := $(LIBNAME_OBJO)
173endif
174ifdef BUILD_ARCHIVE
175BUILD_LIBNAME_AO := $(LIBNAME_AO)
176endif
177endif
178
179all:: $(BUILD_LIBNAME_AG) $(BUILD_LIBNAME_OBJG) # Debug
180all:: $(BUILD_LIBNAME_AO) $(BUILD_LIBNAME_OBJO) # Release
181dynamic:: $(BUILD_LIBNAME_G) $(BUILD_LIBNAME_O) # .so files
182
183$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000184 @echo ======= Linking $(LIBRARYNAME) release library =======
185 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
186
Chris Lattnere62dbe92002-07-23 17:56:16 +0000187$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000188 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattnere62dbe92002-07-23 17:56:16 +0000189 $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
Chris Lattner00950542001-06-06 20:29:01 +0000190
Chris Lattnere62dbe92002-07-23 17:56:16 +0000191$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000192 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000193 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000194 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
195
Chris Lattnere62dbe92002-07-23 17:56:16 +0000196$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000197 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000198 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000199 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
200
Chris Lattnere62dbe92002-07-23 17:56:16 +0000201$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
202 $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
203
204$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
205 $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
206
Chris Lattner00950542001-06-06 20:29:01 +0000207endif
208
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000209#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000210# Create a TAGS database for emacs
211#------------------------------------------------------------------------
212
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000213ifeq ($(LEVEL), .)
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000214
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000215tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000216 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000217
218all:: tags
219
220endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000221
222#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000223# Handle the TOOLNAME option - used when building tool executables...
224#------------------------------------------------------------------------
225#
226# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000227# libraries (and the order of the libs) that should be linked to the
228# tool. USEDLIBS should contain a list of library names (some with .a extension)
229# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000230#
231ifdef TOOLNAME
232
233# TOOLEXENAME* - These compute the output filenames to generate...
234TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
235TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000236TOOLEXENAMES := $(TOOLEXENAME_G)
237ifdef ENABLE_OPTIMIZED
238TOOLEXENAMES += $(TOOLEXENAME_O)
239endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000240
241# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Chris Lattnere62dbe92002-07-23 17:56:16 +0000242USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
243USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
244USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
245
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000246
247# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000248# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
249# files seperately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000250#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000251STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
252USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
253USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000254
Chris Lattner669bd7c2001-10-13 05:10:29 +0000255all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000256clean::
257 rm -f $(TOOLEXENAMES)
258
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000259$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattnere62dbe92002-07-23 17:56:16 +0000260 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000261
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000262$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattnere62dbe92002-07-23 17:56:16 +0000263 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_O) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000264
265endif
266
267
Chris Lattner00950542001-06-06 20:29:01 +0000268
269#---------------------------------------------------------
Chris Lattneraa6ec732001-11-07 14:50:58 +0000270.PRECIOUS: Depend/.dir Debug/.dir Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000271
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000272# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000273Depend/%.d: %.cpp Depend/.dir
274 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
275
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000276# Create dependencies for the *.c files...
277Depend/%.d: %.c Depend/.dir
278 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
279
280# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner00950542001-06-06 20:29:01 +0000281Release/%.o: %.cpp Release/.dir Depend/.dir
282 $(CompileO) $< -o $@
283
Chris Lattnerc7acf812002-01-23 05:46:01 +0000284#Release/%.o: %.c Release/.dir Depend/.dir
285# $(CompileOC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000286
Chris Lattner00950542001-06-06 20:29:01 +0000287Debug/%.o: %.cpp Debug/.dir Depend/.dir
288 $(CompileG) $< -o $@
289
Chris Lattnerc7acf812002-01-23 05:46:01 +0000290#Debug/%.o: %.c Debug/.dir Depend/.dir
291# $(CompileGC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000292
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000293# Create a .cpp source file from a burg input file
Chris Lattner0cac4b82002-02-11 17:12:03 +0000294%.burm.cpp: Debug/%.burg Debug/.dir
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000295 $(RunBurg) $< -o $@
296
Chris Lattner00950542001-06-06 20:29:01 +0000297# Create a .cpp source file from a flex input file... this uses sed to cut down
298# on the warnings emited by GCC...
299%.cpp: %.l
300 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
301
302# Rule for building the bison parsers...
303
304%.cpp %.h : %.y
Chris Lattner18f47012002-05-10 18:51:54 +0000305 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
Chris Lattner00950542001-06-06 20:29:01 +0000306 mv -f $(basename $@).tab.c $(basename $@).cpp
307 mv -f $(basename $@).tab.h $(basename $@).h
308
309# To create the directories...
310%/.dir:
311 mkdir -p $(@D)
312 @date > $@
313
314# Clean does not remove the output files... just the temporaries
315clean::
316 rm -rf Debug Release Depend
317 rm -f core *.o *.d *.so *~ *.flc
318
319# If dependancies were generated for the file that included this file,
320# include the dependancies now...
321#
322SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
323ifneq ($(SourceDepend),)
324include $(SourceDepend)
325endif