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.
23 # Default Rule: Make sure it's also a :: rule
26 # Default for install is to at least build everything...
29 #--------------------------------------------------------------------
30 # Installation configuration options...
31 #--------------------------------------------------------------------
33 #BinInstDir=/usr/local/bin
34 #LibInstDir=/usrl/local/lib/xxx
35 #DocInstDir=/usr/doc/xxx
37 BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
40 #---------------------------------------------------------
41 # Compilation options...
42 #---------------------------------------------------------
44 # Special tools used while building
45 RunBurg = $(BURG) $(BURG_OPTS)
47 # Enable this for profiling support with 'gprof'
50 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
51 CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
53 # Compile a file, don't link...
54 Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
55 CompileG = $(Compile) -g -D_DEBUG
56 # Add This for DebugMalloc: -fno-defer-pop
57 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
59 # Link final executable
61 LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
62 LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
64 # Create a .so file from a .cpp file...
65 #MakeSO = $(CXX) -shared $(Prof)
66 MakeSO = $(CXX) -G $(Prof)
67 MakeSOG = $(MakeSO) -g
68 MakeSOO = $(MakeSO) -O3
70 # Create dependancy file from CPP file, send to stdout.
71 Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
73 # Archive a bunch of .o files into a .a file...
77 #----------------------------------------------------------
79 # Source includes all of the cpp files, and objects are derived from the
82 Source = $(wildcard *.cpp *.c *.y *.l)
85 Objs = $(sort $(addsuffix .o,$(basename $(Source))))
86 ObjectsO = $(addprefix Release/,$(Objs))
87 ObjectsG = $(addprefix Debug/,$(Objs))
89 #---------------------------------------------------------
90 # Handle the DIRS option
91 #---------------------------------------------------------
93 ifdef DIRS # Only do this if we're using DIRS!
95 all :: $(addsuffix /.makeall , $(DIRS))
96 install :: $(addsuffix /.makeinstall, $(DIRS))
97 clean :: $(addsuffix /.makeclean , $(DIRS))
99 %/.makeall %/.makeclean %/.makeinstall:
100 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
103 #---------------------------------------------------------
104 # Handle the LIBRARYNAME option - used when building libs...
105 #---------------------------------------------------------
109 LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
110 LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
111 LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
112 LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
115 dynamic:: $(LIBNAME_G)
116 # TODO: Enable optimized builds
118 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
119 @echo ======= Linking $(LIBRARYNAME) release library =======
120 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
122 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
123 @echo ======= Linking $(LIBRARYNAME) debug library =======
124 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
126 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
127 @echo ======= Linking $(LIBRARYNAME) release library =======
129 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
131 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
132 @echo ======= Linking $(LIBRARYNAME) debug library =======
134 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
138 #------------------------------------------------------------------------
139 # Handle the TOOLNAME option - used when building tool executables...
140 #------------------------------------------------------------------------
142 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
143 # libraries (and the order of the libs) that should be linked to the tool.
147 # TOOLEXENAME* - These compute the output filenames to generate...
148 TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
149 TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
150 TOOLEXENAMES = $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
152 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
153 USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
155 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
156 # rebuilt if libraries change
158 STATICUSEDLIBS = $(addsuffix .a, $(USEDLIBS))
159 USED_LIB_PATHS_G = $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
160 USED_LIB_PATHS_O = $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
162 all:: $(TOOLEXENAMES)
164 rm -f $(TOOLEXENAMES)
166 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
167 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
169 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
170 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
176 #---------------------------------------------------------
178 # Create dependencies for the *.cpp files...
179 Depend/%.d: %.cpp Depend/.dir
180 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
182 # Create dependencies for the *.c files...
183 Depend/%.d: %.c Depend/.dir
184 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
186 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
187 Release/%.o: %.cpp Release/.dir Depend/.dir
190 Release/%.o: %.c Release/.dir Depend/.dir
193 Debug/%.o: %.cpp Debug/.dir Depend/.dir
196 Debug/%.o: %.c Debug/.dir Depend/.dir
199 # Create a .cpp source file from a burg input file
203 # Create a .cpp source file from a flex input file... this uses sed to cut down
204 # on the warnings emited by GCC...
206 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
208 # Rule for building the bison parsers...
211 bison -d -p $(<:%Parser.y=%) $(basename $@).y
212 mv -f $(basename $@).tab.c $(basename $@).cpp
213 mv -f $(basename $@).tab.h $(basename $@).h
215 # To create the directories...
220 # Clean does not remove the output files... just the temporaries
222 rm -rf Debug Release Depend
223 rm -f core *.o *.d *.so *~ *.flc
225 # If dependancies were generated for the file that included this file,
226 # include the dependancies now...
228 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
229 ifneq ($(SourceDepend),)
230 include $(SourceDepend)