Added InstrSched library to link line.
[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.
21 #
22
23 # Default Rule:  Make sure it's also a :: rule
24 all ::
25
26 # Default for install is to at least build everything...
27 install ::
28
29 #--------------------------------------------------------------------
30 # Installation configuration options... 
31 #--------------------------------------------------------------------
32
33 #BinInstDir=/usr/local/bin
34 #LibInstDir=/usrl/local/lib/xxx
35 #DocInstDir=/usr/doc/xxx
36
37 BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
38 BURG_OPTS = -I
39
40 #---------------------------------------------------------
41 # Compilation options...
42 #---------------------------------------------------------
43
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 \
58
59
60 LibPathsG = $(LibPathsO:Release=Debug)
61
62
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)))
69
70
71 # Special tools used while building
72 RunBurg  = $(BURG) $(BURG_OPTS)
73
74 # Enable this for profiling support with 'gprof'
75 #Prof = -pg
76
77 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
78 CompileCommonOpts = $(Prof) -Wall -Winline -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include
79
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
85
86 # Link final executable
87 Link     = $(CXX) $(Prof) 
88 LinkG    = $(Link) -g $(LibPathsG)
89 LinkO    = $(Link) -O3 $(LibPathsO)
90
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
96
97 # Create dependancy file from CPP file, send to stdout.
98 Depend   = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
99
100 # Archive a bunch of .o files into a .a file...
101 AR       = ar cq 
102 MakeLib   = $(AR)
103
104 #----------------------------------------------------------
105
106 # Source includes all of the cpp files, and objects are derived from the
107 # source files...
108 ifndef Source
109 Source   = $(wildcard *.cpp *.c *.y *.l)
110 endif
111
112 Objs = $(sort $(addsuffix .o,$(basename $(Source))))
113 ObjectsO = $(addprefix Release/,$(Objs))
114 ObjectsG = $(addprefix Debug/,$(Objs))
115
116 #---------------------------------------------------------
117 # Handle the DIRS option
118 #---------------------------------------------------------
119
120 ifdef DIRS  # Only do this if we're using DIRS!
121
122 all     :: $(addsuffix /.makeall    , $(DIRS))
123 install :: $(addsuffix /.makeinstall, $(DIRS))
124 clean   :: $(addsuffix /.makeclean  , $(DIRS))
125
126 %/.makeall %/.makeclean %/.makeinstall:
127         cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
128 endif
129
130 #---------------------------------------------------------
131 # Handle the LIBRARYNAME option - used when building libs...
132 #---------------------------------------------------------
133
134 ifdef LIBRARYNAME
135
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
140
141 all:: $(LIBNAME_AG)
142 ###all:: $(LIBNAME_G)
143 # TODO: Enable optimized builds
144
145 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
146         @echo ======= Linking $(LIBRARYNAME) release library =======
147         $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
148
149 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
150         @echo ======= Linking $(LIBRARYNAME) debug library =======
151         $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
152
153 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
154         @echo ======= Linking $(LIBRARYNAME) release library =======
155         rm -f $@
156         $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
157
158 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
159         @echo ======= Linking $(LIBRARYNAME) debug library =======
160         rm -f $@
161         $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
162
163 endif
164
165
166 #---------------------------------------------------------
167
168 # Create dependencies for the *.cpp files...
169 Depend/%.d: %.cpp Depend/.dir
170         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
171
172 # Create dependencies for the *.c files...
173 Depend/%.d: %.c Depend/.dir
174         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
175
176 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
177 Release/%.o: %.cpp Release/.dir Depend/.dir
178         $(CompileO) $< -o $@
179
180 Release/%.o: %.c Release/.dir Depend/.dir
181         $(CompileO) $< -o $@
182
183 Debug/%.o: %.cpp Debug/.dir Depend/.dir
184         $(CompileG) $< -o $@
185
186 Debug/%.o: %.c Debug/.dir Depend/.dir
187         $(CompileG) $< -o $@
188
189 # Create a .cpp source file from a burg input file
190 %.burm.cpp: %.burg
191         $(RunBurg) $< -o $@
192
193 # Create a .cpp source file from a flex input file... this uses sed to cut down
194 # on the warnings emited by GCC...
195 %.cpp: %.l
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/' > $@
197
198 # Rule for building the bison parsers...
199
200 %.cpp %.h : %.y
201         bison -d -p $(<:%Parser.y=%) $(basename $@).y
202         mv -f $(basename $@).tab.c $(basename $@).cpp
203         mv -f $(basename $@).tab.h $(basename $@).h
204
205 # To create the directories...
206 %/.dir:
207         mkdir -p $(@D)
208         @date > $@
209
210 # Clean does not remove the output files... just the temporaries
211 clean::
212         rm -rf Debug Release Depend
213         rm -f core *.o *.d *.so *~ *.flc
214
215 # If dependancies were generated for the file that included this file,
216 # include the dependancies now...
217 #
218 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
219 ifneq ($(SourceDepend),)
220 include $(SourceDepend)
221 endif