blob: c64b26f3430b0d09e4719dc1f3342d10d1367916 [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
20# in the current directory.
21#
22
Chris Lattner44601ba2001-06-29 05:20:16 +000023# Default Rule: Make sure it's also a :: rule
Chris Lattner2f7c9632001-06-06 20:29:01 +000024all ::
25
26# Default for install is to at least build everything...
27install ::
28
29#--------------------------------------------------------------------
30# Installation configuration options...
31#--------------------------------------------------------------------
32
33#BinInstDir=/usr/local/bin
34#LibInstDir=/usrl/local/lib/xxx
35#DocInstDir=/usr/doc/xxx
36
Vikram S. Adveca4a3822001-08-06 19:01:20 +000037BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
38BURG_OPTS = -I
39
Chris Lattner2f7c9632001-06-06 20:29:01 +000040#---------------------------------------------------------
41# Compilation options...
42#---------------------------------------------------------
43
Vikram S. Adveca4a3822001-08-06 19:01:20 +000044# Special tools used while building
45RunBurg = $(BURG) $(BURG_OPTS)
46
Chris Lattner2f7c9632001-06-06 20:29:01 +000047# Enable this for profiling support with 'gprof'
48#Prof = -pg
49
50# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
51CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
52
53# Compile a file, don't link...
54Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
55CompileG = $(Compile) -g -D_DEBUG
56# Add This for DebugMalloc: -fno-defer-pop
57CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
58
59# Link final executable
60Link = $(CXX) $(Prof)
Chris Lattner07c7c192001-09-07 22:57:58 +000061LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
62LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
Chris Lattner2f7c9632001-06-06 20:29:01 +000063
64# Create a .so file from a .cpp file...
65#MakeSO = $(CXX) -shared $(Prof)
66MakeSO = $(CXX) -G $(Prof)
67MakeSOG = $(MakeSO) -g
68MakeSOO = $(MakeSO) -O3
69
70# Create dependancy file from CPP file, send to stdout.
71Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
72
73# Archive a bunch of .o files into a .a file...
74AR = ar cq
Vikram S. Advefe346892001-07-15 13:16:47 +000075MakeLib = $(AR)
Chris Lattner2f7c9632001-06-06 20:29:01 +000076
77#----------------------------------------------------------
78
79# Source includes all of the cpp files, and objects are derived from the
80# source files...
81ifndef Source
82Source = $(wildcard *.cpp *.c *.y *.l)
83endif
Vikram S. Advefe346892001-07-15 13:16:47 +000084
Chris Lattner6244d182001-07-18 23:43:37 +000085Objs = $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner2f7c9632001-06-06 20:29:01 +000086ObjectsO = $(addprefix Release/,$(Objs))
87ObjectsG = $(addprefix Debug/,$(Objs))
88
89#---------------------------------------------------------
90# Handle the DIRS option
91#---------------------------------------------------------
92
93ifdef DIRS # Only do this if we're using DIRS!
94
95all :: $(addsuffix /.makeall , $(DIRS))
96install :: $(addsuffix /.makeinstall, $(DIRS))
97clean :: $(addsuffix /.makeclean , $(DIRS))
98
99%/.makeall %/.makeclean %/.makeinstall:
100 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
101endif
102
103#---------------------------------------------------------
104# Handle the LIBRARYNAME option - used when building libs...
105#---------------------------------------------------------
106
107ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000108
Chris Lattner07c7c192001-09-07 22:57:58 +0000109LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
110LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
111LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
112LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
Chris Lattner2f7c9632001-06-06 20:29:01 +0000113
Vikram S. Advefe346892001-07-15 13:16:47 +0000114all:: $(LIBNAME_AG)
Chris Lattner07c7c192001-09-07 22:57:58 +0000115dynamic:: $(LIBNAME_G)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000116# TODO: Enable optimized builds
117
Chris Lattner07c7c192001-09-07 22:57:58 +0000118$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000119 @echo ======= Linking $(LIBRARYNAME) release library =======
120 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
121
Chris Lattner07c7c192001-09-07 22:57:58 +0000122$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000123 @echo ======= Linking $(LIBRARYNAME) debug library =======
124 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
125
Chris Lattner07c7c192001-09-07 22:57:58 +0000126$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000127 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000128 @rm -f $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000129 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
130
Chris Lattner07c7c192001-09-07 22:57:58 +0000131$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Vikram S. Advefe346892001-07-15 13:16:47 +0000132 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner07c7c192001-09-07 22:57:58 +0000133 @rm -f $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000134 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
135
Chris Lattner2f7c9632001-06-06 20:29:01 +0000136endif
137
Chris Lattner07c7c192001-09-07 22:57:58 +0000138#------------------------------------------------------------------------
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000139# Create a TAGS database for emacs
140#------------------------------------------------------------------------
141
142tags:
143 cd $(LEVEL); etags -l c++ `find . -name '*.cpp'` `find . -name '*.h'`
144
145
146#------------------------------------------------------------------------
Chris Lattner07c7c192001-09-07 22:57:58 +0000147# Handle the TOOLNAME option - used when building tool executables...
148#------------------------------------------------------------------------
149#
150# The TOOLNAME option should be used with a USEDLIBS variable that tells the
151# libraries (and the order of the libs) that should be linked to the tool.
152#
153ifdef TOOLNAME
154
155# TOOLEXENAME* - These compute the output filenames to generate...
156TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
157TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
158TOOLEXENAMES = $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
159
160# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
161USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
162
163# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
164# rebuilt if libraries change
165#
Chris Lattnerd196e042001-09-09 20:59:28 +0000166STATICUSEDLIBS = $(addsuffix .a, $(USEDLIBS))
Chris Lattner07c7c192001-09-07 22:57:58 +0000167USED_LIB_PATHS_G = $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
168USED_LIB_PATHS_O = $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
169
Chris Lattner1fd501f2001-10-13 05:10:29 +0000170all:: $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000171clean::
172 rm -f $(TOOLEXENAMES)
173
Chris Lattnerd196e042001-09-09 20:59:28 +0000174$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattnerf0afd8b2001-09-10 04:49:26 +0000175 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000176
Chris Lattnerd196e042001-09-09 20:59:28 +0000177$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattnerf0afd8b2001-09-10 04:49:26 +0000178 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000179
180endif
181
182
Chris Lattner2f7c9632001-06-06 20:29:01 +0000183
184#---------------------------------------------------------
185
Vikram S. Advefe346892001-07-15 13:16:47 +0000186# Create dependencies for the *.cpp files...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000187Depend/%.d: %.cpp Depend/.dir
188 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
189
Vikram S. Advefe346892001-07-15 13:16:47 +0000190# Create dependencies for the *.c files...
191Depend/%.d: %.c Depend/.dir
192 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
193
194# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000195Release/%.o: %.cpp Release/.dir Depend/.dir
196 $(CompileO) $< -o $@
197
Vikram S. Advefe346892001-07-15 13:16:47 +0000198Release/%.o: %.c Release/.dir Depend/.dir
199 $(CompileO) $< -o $@
200
Chris Lattner2f7c9632001-06-06 20:29:01 +0000201Debug/%.o: %.cpp Debug/.dir Depend/.dir
202 $(CompileG) $< -o $@
203
Vikram S. Advefe346892001-07-15 13:16:47 +0000204Debug/%.o: %.c Debug/.dir Depend/.dir
205 $(CompileG) $< -o $@
206
Vikram S. Adve75b9add2001-08-06 19:06:43 +0000207# Create a .cpp source file from a burg input file
208%.burm.cpp: %.burg
209 $(RunBurg) $< -o $@
210
Chris Lattner2f7c9632001-06-06 20:29:01 +0000211# Create a .cpp source file from a flex input file... this uses sed to cut down
212# on the warnings emited by GCC...
213%.cpp: %.l
214 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
215
216# Rule for building the bison parsers...
217
218%.cpp %.h : %.y
219 bison -d -p $(<:%Parser.y=%) $(basename $@).y
220 mv -f $(basename $@).tab.c $(basename $@).cpp
221 mv -f $(basename $@).tab.h $(basename $@).h
222
223# To create the directories...
224%/.dir:
225 mkdir -p $(@D)
226 @date > $@
227
228# Clean does not remove the output files... just the temporaries
229clean::
230 rm -rf Debug Release Depend
231 rm -f core *.o *.d *.so *~ *.flc
232
233# If dependancies were generated for the file that included this file,
234# include the dependancies now...
235#
236SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
237ifneq ($(SourceDepend),)
238include $(SourceDepend)
239endif