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 # These are options that can either be enabled here, or can be enabled on the
26 # make command line (make ENABLE_PROFILING=1)
33 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
37 # Default Rule: Make sure it's also a :: rule
40 # Default for install is to at least build everything...
43 #--------------------------------------------------------------------
44 # Installation configuration options...
45 #--------------------------------------------------------------------
47 #BinInstDir=/usr/local/bin
48 #LibInstDir=/usrl/local/lib/xxx
49 #DocInstDir=/usr/doc/xxx
51 BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
55 PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
57 # Shorthand for commonly accessed directories
58 LIBDEBUG = $(LEVEL)/lib/Debug
59 LIBRELEASE = $(LEVEL)/lib/Release
60 TOOLDEBUG = $(LEVEL)/tools/Debug
61 TOOLRELEASE = $(LEVEL)/tools/Release
63 #---------------------------------------------------------
64 # Compilation options...
65 #---------------------------------------------------------
67 # Special tools used while building
68 RunBurg = $(BURG) $(BURG_OPTS)
70 # Enable this for profiling support with 'gprof'
71 ifdef ENABLE_PROFILING
77 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
78 # -Wno-unused-parameter
79 CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
81 # Compile a file, don't link...
82 Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) $(PROFILE)
83 CompileG = $(Compile) -g -D_DEBUG
84 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
86 # Link final executable
88 # To enable purify, do it here:
90 Link = $(PURIFY) $(CXX) $(Prof) -static
92 Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(PROFILE)
94 LinkG = $(Link) -g -L $(LIBDEBUG)
95 LinkO = $(Link) -O3 -L $(LIBRELEASE)
97 # Create a .so file from a .o files...
98 #MakeSO = $(CXX) -shared $(Prof)
99 MakeSO = $(CXX) -G $(Prof)
100 MakeSOO = $(MakeSO) -O3
102 # Create one .o file from a bunch of .o files...
105 # Create dependancy file from CPP file, send to stdout.
106 Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
108 # Archive a bunch of .o files into a .a file...
112 #----------------------------------------------------------
114 # Source includes all of the cpp files, and objects are derived from the
116 # The local Makefile can list other Source files via ExtraSource = ...
118 Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
120 Objs := $(sort $(addsuffix .o,$(basename $(Source))))
121 ObjectsO = $(addprefix Release/,$(Objs))
122 ObjectsG = $(addprefix Debug/,$(Objs))
125 #---------------------------------------------------------
126 # Handle the DIRS option
127 #---------------------------------------------------------
129 ifdef DIRS # Only do this if we're using DIRS!
131 all :: $(addsuffix /.makeall , $(DIRS))
132 install :: $(addsuffix /.makeinstall, $(DIRS))
133 clean :: $(addsuffix /.makeclean , $(DIRS))
135 %/.makeall %/.makeclean %/.makeinstall:
136 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
139 #---------------------------------------------------------
140 # Handle the LIBRARYNAME option - used when building libs...
141 #---------------------------------------------------------
143 # When libraries are built, they are allowed to optionally define the
144 # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
145 # from being built for the library. This .o files may then be linked to by a
146 # tool if the tool does not need (or want) the semantics a .a file provides
147 # (linking in only object files that are "needed"). If a library is never to
148 # be used in this way, it is better to define DONT_BUILD_RELINKED, and define
149 # BUILD_ARCHIVE instead.
151 # Some libraries must be built as .a files (libscalar for example) because if
152 # it's built as a .o file, then all of the constitent .o files in it will be
153 # linked into tools (for example gccas) even if they only use one of the parts
154 # of it. For this reason, sometimes it's useful to use libraries as .a files.
158 LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so
159 LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so
160 LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a
161 LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a
162 LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o
163 LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o
165 BUILD_LIBNAME_G := $(LIBNAME_G)
166 ifndef DONT_BUILD_RELINKED
167 BUILD_LIBNAME_OBJG := $(LIBNAME_OBJG)
170 BUILD_LIBNAME_AG := $(LIBNAME_AG)
173 # If optimized builds are enabled...
174 ifdef ENABLE_OPTIMIZED
175 BUILD_LIBNAME_O := $(LIBNAME_O)
176 ifndef DONT_BUILD_RELINKED
177 BUILD_LIBNAME_OBJO := $(LIBNAME_OBJO)
180 BUILD_LIBNAME_AO := $(LIBNAME_AO)
184 all:: $(BUILD_LIBNAME_AG) $(BUILD_LIBNAME_OBJG) # Debug
185 all:: $(BUILD_LIBNAME_AO) $(BUILD_LIBNAME_OBJO) # Release
186 dynamic:: $(BUILD_LIBNAME_G) $(BUILD_LIBNAME_O) # .so files
188 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
189 @echo ======= Linking $(LIBRARYNAME) release library =======
190 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
192 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
193 @echo ======= Linking $(LIBRARYNAME) debug library =======
194 $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
196 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
197 @echo ======= Linking $(LIBRARYNAME) release library =======
199 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
201 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
202 @echo ======= Linking $(LIBRARYNAME) debug library =======
204 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
206 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir Depend/.dir
207 $(Relink) -o $@ $(ObjectsO) $(LibSubDirs)
209 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir Depend/.dir
210 $(Relink) -o $@ $(ObjectsG) $(LibSubDirs)
214 #------------------------------------------------------------------------
215 # Create a TAGS database for emacs
216 #------------------------------------------------------------------------
221 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
227 #------------------------------------------------------------------------
228 # Handle the TOOLNAME option - used when building tool executables...
229 #------------------------------------------------------------------------
231 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
232 # libraries (and the order of the libs) that should be linked to the
233 # tool. USEDLIBS should contain a list of library names (some with .a extension)
234 # that are automatically linked in as .o files unless the .a suffix is added.
238 # TOOLEXENAME* - These compute the output filenames to generate...
239 TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
240 TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
241 TOOLEXENAMES := $(TOOLEXENAME_G)
242 ifdef ENABLE_OPTIMIZED
243 TOOLEXENAMES += $(TOOLEXENAME_O)
246 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
247 USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
248 USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
249 USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
252 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
253 # rebuilt if libraries change. This has to make sure to handle .a/.so and .o
256 STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
257 USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
258 USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
260 all:: $(TOOLEXENAMES)
262 rm -f $(TOOLEXENAMES)
264 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
265 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(TOOLLINKOPTS)
267 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
268 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_O) $(TOOLLINKOPTS)
274 #---------------------------------------------------------
275 .PRECIOUS: Depend/.dir Debug/.dir Release/.dir
277 # Create dependencies for the *.cpp files...
278 Depend/%.d: %.cpp Depend/.dir
279 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
281 # Create dependencies for the *.c files...
282 Depend/%.d: %.c Depend/.dir
283 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
285 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
286 Release/%.o: %.cpp Release/.dir Depend/.dir
289 #Release/%.o: %.c Release/.dir Depend/.dir
290 # $(CompileOC) $< -o $@
292 Debug/%.o: %.cpp Debug/.dir Depend/.dir
295 #Debug/%.o: %.c Debug/.dir Depend/.dir
296 # $(CompileGC) $< -o $@
298 # Create a .cpp source file from a burg input file
299 %.burm.cpp: Debug/%.burg Debug/.dir
302 # Create a .cpp source file from a flex input file... this uses sed to cut down
303 # on the warnings emited by GCC...
305 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
307 # Rule for building the bison parsers...
310 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
311 mv -f $(basename $@).tab.c $(basename $@).cpp
312 mv -f $(basename $@).tab.h $(basename $@).h
314 # To create the directories...
319 # Clean does not remove the output files... just the temporaries
321 rm -rf Debug Release Depend
322 rm -f core *.o *.d *.so *~ *.flc
324 # If dependancies were generated for the file that included this file,
325 # include the dependancies now...
327 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
328 ifneq ($(SourceDepend),)
329 include $(SourceDepend)