1. -Winline emits spurious warnings that aren't useful right now
[oota-llvm.git] / Makefile.common
1 #                                 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.  Also, if you want to build files in addition
21 #    to the local files, you can use the ExtraSource variable
22 #
23
24 # Default Rule:  Make sure it's also a :: rule
25 all ::
26
27 # Default for install is to at least build everything...
28 install ::
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
38 BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
39 BURG_OPTS = -I
40
41
42 PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="/home/vadve/lattner/purifycache" -chain-length="10" -messages=all
43
44 #---------------------------------------------------------
45 # Compilation options...
46 #---------------------------------------------------------
47
48 # Special tools used while building
49 RunBurg  = $(BURG) $(BURG_OPTS)
50
51 # Enable this for profiling support with 'gprof'
52 #Prof = -pg
53
54 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
55 CompileCommonOpts = $(Prof) -Wall -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include
56
57 # Compile a file, don't link...
58 Compile  = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
59 CompileG = $(Compile) -g  -D_DEBUG
60 # Add This for DebugMalloc: -fno-defer-pop
61 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
62
63 # Link final executable
64
65 # To enable purify, do it here:
66 ###Link     = $(PURIFY) $(CXX) $(Prof) -static
67 Link     = $(CXX) $(Prof) 
68 LinkG    = $(Link) -g  -L $(LEVEL)/lib/Debug
69 LinkO    = $(Link) -O3 -L $(LEVEL)/lib/Release
70
71 # Create a .so file from a .cpp file...
72 #MakeSO   = $(CXX) -shared $(Prof)
73 MakeSO   = $(CXX) -G $(Prof)
74 MakeSOG  = $(MakeSO) -g
75 MakeSOO  = $(MakeSO) -O3
76
77 # Create dependancy file from CPP file, send to stdout.
78 Depend   = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
79
80 # Archive a bunch of .o files into a .a file...
81 AR       = ar cq 
82 MakeLib   = $(AR)
83
84 #----------------------------------------------------------
85
86 # Source includes all of the cpp files, and objects are derived from the
87 # source files...
88 # The local Makefile can list other Source files via ExtraSource = ...
89
90 Source  := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
91
92 Objs = $(sort $(addsuffix .o,$(basename $(Source))))
93 ObjectsO = $(addprefix Release/,$(Objs))
94 ObjectsG = $(addprefix Debug/,$(Objs))
95
96 #---------------------------------------------------------
97 # Handle the DIRS option
98 #---------------------------------------------------------
99
100 ifdef DIRS  # Only do this if we're using DIRS!
101
102 all     :: $(addsuffix /.makeall    , $(DIRS))
103 install :: $(addsuffix /.makeinstall, $(DIRS))
104 clean   :: $(addsuffix /.makeclean  , $(DIRS))
105
106 %/.makeall %/.makeclean %/.makeinstall:
107         cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
108 endif
109
110 #---------------------------------------------------------
111 # Handle the LIBRARYNAME option - used when building libs...
112 #---------------------------------------------------------
113
114 ifdef LIBRARYNAME
115
116 LIBNAME_O  := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
117 LIBNAME_G  := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
118 LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
119 LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
120
121 all:: $(LIBNAME_AG)
122 dynamic:: $(LIBNAME_G)
123 # TODO: Enable optimized builds
124
125 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
126         @echo ======= Linking $(LIBRARYNAME) release library =======
127         $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
128
129 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
130         @echo ======= Linking $(LIBRARYNAME) debug library =======
131         $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
132
133 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
134         @echo ======= Linking $(LIBRARYNAME) release library =======
135         @rm -f $@
136         $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
137
138 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
139         @echo ======= Linking $(LIBRARYNAME) debug library =======
140         @rm -f $@
141         $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
142
143 endif
144
145 #------------------------------------------------------------------------
146 # Create a TAGS database for emacs
147 #------------------------------------------------------------------------
148
149 ifeq ($(LEVEL), .)
150
151 tags:
152         etags -l c++ `find . -name '*.cpp' -o -name '*.h'`
153
154 all:: tags
155
156 endif
157
158 #------------------------------------------------------------------------
159 # 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 #
165 ifdef TOOLNAME
166
167 # TOOLEXENAME* - These compute the output filenames to generate...
168 TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
169 TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
170 TOOLEXENAMES = $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
171
172 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
173 USED_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 #
178 STATICUSEDLIBS = $(addsuffix .a, $(USEDLIBS))
179 USED_LIB_PATHS_G = $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
180 USED_LIB_PATHS_O = $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
181
182 all::   $(TOOLEXENAMES)
183 clean::
184         rm -f $(TOOLEXENAMES)
185
186 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
187         $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
188
189 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
190         $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
191
192 endif
193
194
195
196 #---------------------------------------------------------
197 .PRECIOUS: Depend/.dir Debug/.dir Release/.dir
198
199 # Create dependencies for the *.cpp files...
200 Depend/%.d: %.cpp Depend/.dir
201         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
202
203 # Create dependencies for the *.c files...
204 Depend/%.d: %.c Depend/.dir
205         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
206
207 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
208 Release/%.o: %.cpp Release/.dir Depend/.dir
209         $(CompileO) $< -o $@
210
211 Release/%.o: %.c Release/.dir Depend/.dir
212         $(CompileO) $< -o $@
213
214 Debug/%.o: %.cpp Debug/.dir Depend/.dir
215         $(CompileG) $< -o $@
216
217 Debug/%.o: %.c Debug/.dir Depend/.dir
218         $(CompileG) $< -o $@
219
220 # Create a .cpp source file from a burg input file
221 %.burm.cpp: Debug/%.burg
222         $(RunBurg) $< -o $@
223
224 # Create a .cpp source file from a flex input file... this uses sed to cut down
225 # on the warnings emited by GCC...
226 %.cpp: %.l
227         flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
228
229 # Rule for building the bison parsers...
230
231 %.cpp %.h : %.y
232         bison -d -p $(<:%Parser.y=%) $(basename $@).y
233         mv -f $(basename $@).tab.c $(basename $@).cpp
234         mv -f $(basename $@).tab.h $(basename $@).h
235
236 # To create the directories...
237 %/.dir:
238         mkdir -p $(@D)
239         @date > $@
240
241 # Clean does not remove the output files... just the temporaries
242 clean::
243         rm -rf Debug Release Depend
244         rm -f core *.o *.d *.so *~ *.flc
245
246 # If dependancies were generated for the file that included this file,
247 # include the dependancies now...
248 #
249 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
250 ifneq ($(SourceDepend),)
251 include $(SourceDepend)
252 endif