1 #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
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.
8 # The following functionality may be set by setting incoming variables:
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.
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.
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
23 #===-----------------------------------------------------------------------====
25 # Default Rule: Make sure it's also a :: rule
28 # Default for install is to at least build everything...
31 #--------------------------------------------------------------------
32 # Installation configuration options...
33 #--------------------------------------------------------------------
35 #BinInstDir=/usr/local/bin
36 #LibInstDir=/usrl/local/lib/xxx
37 #DocInstDir=/usr/doc/xxx
39 BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
43 PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
45 #---------------------------------------------------------
46 # Compilation options...
47 #---------------------------------------------------------
49 # Special tools used while building
50 RunBurg = $(BURG) $(BURG_OPTS)
52 # Enable this for profiling support with 'gprof'
53 ifdef ENABLE_PROFILING
59 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
60 # -Wno-unused-parameter
61 CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
63 # Compile a file, don't link...
64 Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) $(PROFILE)
65 CompileG = $(Compile) -g -D_DEBUG
66 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
68 # Link final executable
70 # To enable purify, do it here:
72 Link = $(PURIFY) $(CXX) $(Prof) -static
74 Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(PROFILE)
76 LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
77 LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
79 # Create a .so file from a .cpp file...
80 #MakeSO = $(CXX) -shared $(Prof)
81 MakeSO = $(CXX) -G $(Prof)
82 MakeSOG = $(MakeSO) -g
83 MakeSOO = $(MakeSO) -O3
85 # Create dependancy file from CPP file, send to stdout.
86 Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
88 # Archive a bunch of .o files into a .a file...
92 #----------------------------------------------------------
94 # Source includes all of the cpp files, and objects are derived from the
96 # The local Makefile can list other Source files via ExtraSource = ...
98 Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
100 Objs := $(sort $(addsuffix .o,$(basename $(Source))))
101 ObjectsO = $(addprefix Release/,$(Objs))
102 ObjectsG = $(addprefix Debug/,$(Objs))
104 #---------------------------------------------------------
105 # Handle the DIRS option
106 #---------------------------------------------------------
108 ifdef DIRS # Only do this if we're using DIRS!
110 all :: $(addsuffix /.makeall , $(DIRS))
111 install :: $(addsuffix /.makeinstall, $(DIRS))
112 clean :: $(addsuffix /.makeclean , $(DIRS))
114 %/.makeall %/.makeclean %/.makeinstall:
115 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
118 #---------------------------------------------------------
119 # Handle the LIBRARYNAME option - used when building libs...
120 #---------------------------------------------------------
124 LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
125 LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
126 LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
127 LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
129 all:: $(LIBNAME_AG) ###$(LIBNAME_AO)
130 dynamic:: $(LIBNAME_G)
131 # TODO: Enable optimized builds
133 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
134 @echo ======= Linking $(LIBRARYNAME) release library =======
135 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
137 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
138 @echo ======= Linking $(LIBRARYNAME) debug library =======
139 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
141 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
142 @echo ======= Linking $(LIBRARYNAME) release library =======
144 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
146 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
147 @echo ======= Linking $(LIBRARYNAME) debug library =======
149 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
153 #------------------------------------------------------------------------
154 # Create a TAGS database for emacs
155 #------------------------------------------------------------------------
160 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
166 #------------------------------------------------------------------------
167 # Handle the TOOLNAME option - used when building tool executables...
168 #------------------------------------------------------------------------
170 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
171 # libraries (and the order of the libs) that should be linked to the tool.
175 # TOOLEXENAME* - These compute the output filenames to generate...
176 TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
177 TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
178 TOOLEXENAMES := $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
180 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
181 USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
183 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
184 # rebuilt if libraries change
186 STATICUSEDLIBS := $(addsuffix .a, $(USEDLIBS))
187 USED_LIB_PATHS_G := $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
188 USED_LIB_PATHS_O := $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
190 all:: $(TOOLEXENAMES)
192 rm -f $(TOOLEXENAMES)
194 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
195 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
197 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
198 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
204 #---------------------------------------------------------
205 .PRECIOUS: Depend/.dir Debug/.dir Release/.dir
207 # Create dependencies for the *.cpp files...
208 Depend/%.d: %.cpp Depend/.dir
209 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
211 # Create dependencies for the *.c files...
212 Depend/%.d: %.c Depend/.dir
213 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
215 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
216 Release/%.o: %.cpp Release/.dir Depend/.dir
219 #Release/%.o: %.c Release/.dir Depend/.dir
220 # $(CompileOC) $< -o $@
222 Debug/%.o: %.cpp Debug/.dir Depend/.dir
225 #Debug/%.o: %.c Debug/.dir Depend/.dir
226 # $(CompileGC) $< -o $@
228 # Create a .cpp source file from a burg input file
229 %.burm.cpp: Debug/%.burg Debug/.dir
232 # Create a .cpp source file from a flex input file... this uses sed to cut down
233 # on the warnings emited by GCC...
235 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
237 # Rule for building the bison parsers...
240 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
241 mv -f $(basename $@).tab.c $(basename $@).cpp
242 mv -f $(basename $@).tab.h $(basename $@).h
244 # To create the directories...
249 # Clean does not remove the output files... just the temporaries
251 rm -rf Debug Release Depend
252 rm -f core *.o *.d *.so *~ *.flc
254 # If dependancies were generated for the file that included this file,
255 # include the dependancies now...
257 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
258 ifneq ($(SourceDepend),)
259 include $(SourceDepend)