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 # Add -L options to the link command lines...
45 LibPathsO = -L $(LEVEL)/lib/Support/Release \
46 -L $(LEVEL)/lib/VMCore/Release \
47 -L $(LEVEL)/lib/Assembly/Parser/Release \
48 -L $(LEVEL)/lib/Assembly/Writer/Release \
49 -L $(LEVEL)/lib/Analysis/Release \
50 -L $(LEVEL)/lib/Analysis/LiveVar/Release \
51 -L $(LEVEL)/lib/Bytecode/Writer/Release \
52 -L $(LEVEL)/lib/Bytecode/Reader/Release \
53 -L $(LEVEL)/lib/Optimizations/Release \
54 -L $(LEVEL)/lib/CodeGen/InstrSched/Release \
55 -L $(LEVEL)/lib/CodeGen/InstrSelection/Release \
56 -L $(LEVEL)/lib/CodeGen/TargetMachine/Release \
57 -L $(LEVEL)/lib/CodeGen/TargetMachine/Sparc/Release \
60 LibPathsG = $(LibPathsO:Release=Debug)
63 # List of libraries in all the directories on LibPathsG/O.
64 # Add one of these to the list of dependences for an executable
65 # to ensure it is relinked when any of the libs is updated.
66 # See llvm/lib/LLC/Makefile for an example.
67 LibsO = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsO)))
68 LibsG = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsG)))
71 # Special tools used while building
72 RunBurg = $(BURG) $(BURG_OPTS)
74 # Enable this for profiling support with 'gprof'
77 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
78 CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
80 # Compile a file, don't link...
81 Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
82 CompileG = $(Compile) -g -D_DEBUG
83 # Add This for DebugMalloc: -fno-defer-pop
84 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
86 # Link final executable
88 LinkG = $(Link) -g $(LibPathsG)
89 LinkO = $(Link) -O3 $(LibPathsO)
91 # Create a .so file from a .cpp file...
92 #MakeSO = $(CXX) -shared $(Prof)
93 MakeSO = $(CXX) -G $(Prof)
94 MakeSOG = $(MakeSO) -g
95 MakeSOO = $(MakeSO) -O3
97 # Create dependancy file from CPP file, send to stdout.
98 Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
100 # Archive a bunch of .o files into a .a file...
104 #----------------------------------------------------------
106 # Source includes all of the cpp files, and objects are derived from the
109 Source = $(wildcard *.cpp *.c *.y *.l)
112 Objs = $(sort $(addsuffix .o,$(basename $(Source))))
113 ObjectsO = $(addprefix Release/,$(Objs))
114 ObjectsG = $(addprefix Debug/,$(Objs))
116 #---------------------------------------------------------
117 # Handle the DIRS option
118 #---------------------------------------------------------
120 ifdef DIRS # Only do this if we're using DIRS!
122 all :: $(addsuffix /.makeall , $(DIRS))
123 install :: $(addsuffix /.makeinstall, $(DIRS))
124 clean :: $(addsuffix /.makeclean , $(DIRS))
126 %/.makeall %/.makeclean %/.makeinstall:
127 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
130 #---------------------------------------------------------
131 # Handle the LIBRARYNAME option - used when building libs...
132 #---------------------------------------------------------
136 LIBNAME_O := Release/lib$(LIBRARYNAME).so
137 LIBNAME_G := Debug/lib$(LIBRARYNAME).so
138 LIBNAME_AO := Release/lib$(LIBRARYNAME).a
139 LIBNAME_AG := Debug/lib$(LIBRARYNAME).a
142 ###all:: $(LIBNAME_G)
143 # TODO: Enable optimized builds
145 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
146 @echo ======= Linking $(LIBRARYNAME) release library =======
147 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
149 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
150 @echo ======= Linking $(LIBRARYNAME) debug library =======
151 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
153 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
154 @echo ======= Linking $(LIBRARYNAME) release library =======
156 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
158 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
159 @echo ======= Linking $(LIBRARYNAME) debug library =======
161 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
166 #---------------------------------------------------------
168 # Create dependencies for the *.cpp files...
169 Depend/%.d: %.cpp Depend/.dir
170 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
172 # Create dependencies for the *.c files...
173 Depend/%.d: %.c Depend/.dir
174 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
176 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
177 Release/%.o: %.cpp Release/.dir Depend/.dir
180 Release/%.o: %.c Release/.dir Depend/.dir
183 Debug/%.o: %.cpp Debug/.dir Depend/.dir
186 Debug/%.o: %.c Debug/.dir Depend/.dir
189 # Create a .cpp source file from a burg input file
193 # Create a .cpp source file from a flex input file... this uses sed to cut down
194 # on the warnings emited by GCC...
196 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
198 # Rule for building the bison parsers...
201 bison -d -p $(<:%Parser.y=%) $(basename $@).y
202 mv -f $(basename $@).tab.c $(basename $@).cpp
203 mv -f $(basename $@).tab.h $(basename $@).h
205 # To create the directories...
210 # Clean does not remove the output files... just the temporaries
212 rm -rf Debug Release Depend
213 rm -f core *.o *.d *.so *~ *.flc
215 # If dependancies were generated for the file that included this file,
216 # include the dependancies now...
218 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
219 ifneq ($(SourceDepend),)
220 include $(SourceDepend)