blob: 921695c67d29add769fc8d966402b2eaa9256a94 [file] [log] [blame]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001# Makefile.common
2#
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 Lattneree6e1992001-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 Lattner2f7c9632001-06-06 20:29:01 +000022#
23
Chris Lattner44601ba2001-06-29 05:20:16 +000024# Default Rule: Make sure it's also a :: rule
Chris Lattner2f7c9632001-06-06 20:29:01 +000025all ::
26
27# Default for install is to at least build everything...
28install ::
29
30#--------------------------------------------------------------------
31# Installation configuration options...
32#--------------------------------------------------------------------
33
34#BinInstDir=/usr/local/bin
35#LibInstDir=/usrl/local/lib/xxx
36#DocInstDir=/usr/doc/xxx
37
Vikram S. Adveca4a3822001-08-06 19:01:20 +000038BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
39BURG_OPTS = -I
40
Chris Lattnerb20b290c2001-10-30 20:24:08 +000041
42PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="/home/vadve/lattner/purifycache" -chain-length="10" -messages=all
43
Chris Lattner2f7c9632001-06-06 20:29:01 +000044#---------------------------------------------------------
45# Compilation options...
46#---------------------------------------------------------
47
Vikram S. Adveca4a3822001-08-06 19:01:20 +000048# Special tools used while building
49RunBurg = $(BURG) $(BURG_OPTS)
50
Chris Lattner2f7c9632001-06-06 20:29:01 +000051# Enable this for profiling support with 'gprof'
52#Prof = -pg
53
54# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
55CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
56
57# Compile a file, don't link...
58Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
59CompileG = $(Compile) -g -D_DEBUG
60# Add This for DebugMalloc: -fno-defer-pop
61CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
62
63# Link final executable
Chris Lattnerb20b290c2001-10-30 20:24:08 +000064
65# To enable purify, do it here:
66###Link = $(PURIFY) $(CXX) $(Prof) -static
Chris Lattner2f7c9632001-06-06 20:29:01 +000067Link = $(CXX) $(Prof)
Chris Lattner07c7c192001-09-07 22:57:58 +000068LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
69LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
Chris Lattner2f7c9632001-06-06 20:29:01 +000070
71# Create a .so file from a .cpp file...
72#MakeSO = $(CXX) -shared $(Prof)
73MakeSO = $(CXX) -G $(Prof)
74MakeSOG = $(MakeSO) -g
75MakeSOO = $(MakeSO) -O3
76
77# Create dependancy file from CPP file, send to stdout.
78Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
79
80# Archive a bunch of .o files into a .a file...
81AR = ar cq
Vikram S. Advefe346892001-07-15 13:16:47 +000082MakeLib = $(AR)
Chris Lattner2f7c9632001-06-06 20:29:01 +000083
84#----------------------------------------------------------
85
86# Source includes all of the cpp files, and objects are derived from the
87# source files...
Chris Lattneree6e1992001-10-18 01:48:09 +000088# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advebd9cae22001-10-17 12:33:55 +000089#
Chris Lattneree6e1992001-10-18 01:48:09 +000090Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advefe346892001-07-15 13:16:47 +000091
Chris Lattner6244d182001-07-18 23:43:37 +000092Objs = $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner2f7c9632001-06-06 20:29:01 +000093ObjectsO = $(addprefix Release/,$(Objs))
94ObjectsG = $(addprefix Debug/,$(Objs))
95
96#---------------------------------------------------------
97# Handle the DIRS option
98#---------------------------------------------------------
99
100ifdef DIRS # Only do this if we're using DIRS!
101
102all :: $(addsuffix /.makeall , $(DIRS))
103install :: $(addsuffix /.makeinstall, $(DIRS))
104clean :: $(addsuffix /.makeclean , $(DIRS))
105
106%/.makeall %/.makeclean %/.makeinstall:
107 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
108endif
109
110#---------------------------------------------------------
111# Handle the LIBRARYNAME option - used when building libs...
112#---------------------------------------------------------
113
114ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000115
Chris Lattner07c7c192001-09-07 22:57:58 +0000116LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
117LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
118LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
119LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
Chris Lattner2f7c9632001-06-06 20:29:01 +0000120
Vikram S. Advefe346892001-07-15 13:16:47 +0000121all:: $(LIBNAME_AG)
Chris Lattner07c7c192001-09-07 22:57:58 +0000122dynamic:: $(LIBNAME_G)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000123# TODO: Enable optimized builds
124
Chris Lattner07c7c192001-09-07 22:57:58 +0000125$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000126 @echo ======= Linking $(LIBRARYNAME) release library =======
127 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
128
Chris Lattner07c7c192001-09-07 22:57:58 +0000129$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000130 @echo ======= Linking $(LIBRARYNAME) debug library =======
131 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
132
Chris Lattner07c7c192001-09-07 22:57:58 +0000133$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000134 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000135 @rm -f $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000136 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
137
Chris Lattner07c7c192001-09-07 22:57:58 +0000138$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000139 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000140 @rm -f $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000141 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
142
Chris Lattner2f7c9632001-06-06 20:29:01 +0000143endif
144
Chris Lattner07c7c192001-09-07 22:57:58 +0000145#------------------------------------------------------------------------
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000146# Create a TAGS database for emacs
147#------------------------------------------------------------------------
148
Vikram S. Advea0e99082001-10-13 12:26:59 +0000149ifeq ($(LEVEL), .)
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000150
Vikram S. Advea0e99082001-10-13 12:26:59 +0000151tags:
Vikram S. Adve4dedee52001-10-22 13:58:22 +0000152 etags -l c++ `find . -name '*.cpp' -o -name '*.h'`
Vikram S. Advea0e99082001-10-13 12:26:59 +0000153
154all:: tags
155
156endif
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000157
158#------------------------------------------------------------------------
Chris Lattner07c7c192001-09-07 22:57:58 +0000159# Handle the TOOLNAME option - used when building tool executables...
160#------------------------------------------------------------------------
161#
162# The TOOLNAME option should be used with a USEDLIBS variable that tells the
163# libraries (and the order of the libs) that should be linked to the tool.
164#
165ifdef TOOLNAME
166
167# TOOLEXENAME* - These compute the output filenames to generate...
168TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
169TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
170TOOLEXENAMES = $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
171
172# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
173USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
174
175# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
176# rebuilt if libraries change
177#
Chris Lattnerd196e042001-09-09 20:59:28 +0000178STATICUSEDLIBS = $(addsuffix .a, $(USEDLIBS))
Chris Lattner07c7c192001-09-07 22:57:58 +0000179USED_LIB_PATHS_G = $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
180USED_LIB_PATHS_O = $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
181
Chris Lattner1fd501f2001-10-13 05:10:29 +0000182all:: $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000183clean::
184 rm -f $(TOOLEXENAMES)
185
Chris Lattnerd196e042001-09-09 20:59:28 +0000186$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattnerf0afd8b2001-09-10 04:49:26 +0000187 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000188
Chris Lattnerd196e042001-09-09 20:59:28 +0000189$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattnerf0afd8b2001-09-10 04:49:26 +0000190 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000191
192endif
193
194
Chris Lattner2f7c9632001-06-06 20:29:01 +0000195
196#---------------------------------------------------------
197
Vikram S. Advefe346892001-07-15 13:16:47 +0000198# Create dependencies for the *.cpp files...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000199Depend/%.d: %.cpp Depend/.dir
200 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
201
Vikram S. Advefe346892001-07-15 13:16:47 +0000202# Create dependencies for the *.c files...
203Depend/%.d: %.c Depend/.dir
204 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
205
206# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000207Release/%.o: %.cpp Release/.dir Depend/.dir
208 $(CompileO) $< -o $@
209
Vikram S. Advefe346892001-07-15 13:16:47 +0000210Release/%.o: %.c Release/.dir Depend/.dir
211 $(CompileO) $< -o $@
212
Chris Lattner2f7c9632001-06-06 20:29:01 +0000213Debug/%.o: %.cpp Debug/.dir Depend/.dir
214 $(CompileG) $< -o $@
215
Vikram S. Advefe346892001-07-15 13:16:47 +0000216Debug/%.o: %.c Debug/.dir Depend/.dir
217 $(CompileG) $< -o $@
218
Vikram S. Adve75b9add2001-08-06 19:06:43 +0000219# Create a .cpp source file from a burg input file
Chris Lattner082479a2001-10-14 17:23:55 +0000220%.burm.cpp: Debug/%.burg
Vikram S. Adve75b9add2001-08-06 19:06:43 +0000221 $(RunBurg) $< -o $@
222
Chris Lattner2f7c9632001-06-06 20:29:01 +0000223# Create a .cpp source file from a flex input file... this uses sed to cut down
224# on the warnings emited by GCC...
225%.cpp: %.l
226 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
227
228# Rule for building the bison parsers...
229
230%.cpp %.h : %.y
231 bison -d -p $(<:%Parser.y=%) $(basename $@).y
232 mv -f $(basename $@).tab.c $(basename $@).cpp
233 mv -f $(basename $@).tab.h $(basename $@).h
234
235# To create the directories...
236%/.dir:
237 mkdir -p $(@D)
238 @date > $@
239
240# Clean does not remove the output files... just the temporaries
241clean::
242 rm -rf Debug Release Depend
243 rm -f core *.o *.d *.so *~ *.flc
244
245# If dependancies were generated for the file that included this file,
246# include the dependancies now...
247#
248SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
249ifneq ($(SourceDepend),)
250include $(SourceDepend)
251endif