Remove lib/LLC library.
[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 #---------------------------------------------------------
38 # Compilation options...
39 #---------------------------------------------------------
40
41 # Add -L options to the link command lines...
42 LibPathsO = -L $(LEVEL)/lib/Support/Release \
43             -L $(LEVEL)/lib/VMCore/Release \
44             -L $(LEVEL)/lib/Assembly/Parser/Release \
45             -L $(LEVEL)/lib/Assembly/Writer/Release \
46             -L $(LEVEL)/lib/Analysis/Release \
47             -L $(LEVEL)/lib/Bytecode/Writer/Release \
48             -L $(LEVEL)/lib/Bytecode/Reader/Release \
49             -L $(LEVEL)/lib/Optimizations/Release \
50             -L $(LEVEL)/lib/CodeGen/InstrSelection/Release \
51             -L $(LEVEL)/lib/CodeGen/TargetMachine/Release \
52             -L $(LEVEL)/lib/CodeGen/TargetMachine/Sparc/Release
53
54 LibPathsG = $(LibPathsO:Release=Debug)
55
56
57 # List of libraries in all the directories on LibPathsG/O.
58 # Add one of these to the list of dependences for an executable
59 # to ensure it is relinked when any of the libs is updated.
60 # See llvm/lib/LLC/Makefile for an example.
61 LibsO = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsO)))
62 LibsG = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsG)))
63
64
65 # Enable this for profiling support with 'gprof'
66 #Prof = -pg
67
68 # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
69 CompileCommonOpts = $(Prof) -Wall -Winline -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include
70
71 # Compile a file, don't link...
72 Compile  = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
73 CompileG = $(Compile) -g  -D_DEBUG
74 # Add This for DebugMalloc: -fno-defer-pop
75 CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
76
77 # Link final executable
78 Link     = $(CXX) $(Prof) 
79 LinkG    = $(Link) -g $(LibPathsG)
80 LinkO    = $(Link) -O3 $(LibPathsO)
81
82 # Create a .so file from a .cpp file...
83 #MakeSO   = $(CXX) -shared $(Prof)
84 MakeSO   = $(CXX) -G $(Prof)
85 MakeSOG  = $(MakeSO) -g
86 MakeSOO  = $(MakeSO) -O3
87
88 # Create dependancy file from CPP file, send to stdout.
89 Depend   = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
90
91 # Archive a bunch of .o files into a .a file...
92 AR       = ar cq 
93 MakeLib   = $(AR)
94
95 #----------------------------------------------------------
96
97 # Source includes all of the cpp files, and objects are derived from the
98 # source files...
99 ifndef Source
100 Source   = $(wildcard *.cpp *.c *.y *.l)
101 endif
102
103 Objs = $(sort $(addsuffix .o,$(basename $(Source))))
104 ObjectsO = $(addprefix Release/,$(Objs))
105 ObjectsG = $(addprefix Debug/,$(Objs))
106
107 #---------------------------------------------------------
108 # Handle the DIRS option
109 #---------------------------------------------------------
110
111 ifdef DIRS  # Only do this if we're using DIRS!
112
113 all     :: $(addsuffix /.makeall    , $(DIRS))
114 install :: $(addsuffix /.makeinstall, $(DIRS))
115 clean   :: $(addsuffix /.makeclean  , $(DIRS))
116
117 %/.makeall %/.makeclean %/.makeinstall:
118         cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
119 endif
120
121 #---------------------------------------------------------
122 # Handle the LIBRARYNAME option - used when building libs...
123 #---------------------------------------------------------
124
125 ifdef LIBRARYNAME
126
127 LIBNAME_O := Release/lib$(LIBRARYNAME).so
128 LIBNAME_G := Debug/lib$(LIBRARYNAME).so
129 LIBNAME_AO := Release/lib$(LIBRARYNAME).a
130 LIBNAME_AG := Debug/lib$(LIBRARYNAME).a
131
132 all:: $(LIBNAME_AG)
133 ###all:: $(LIBNAME_G)
134 # TODO: Enable optimized builds
135
136 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
137         @echo ======= Linking $(LIBRARYNAME) release library =======
138         $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
139
140 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
141         @echo ======= Linking $(LIBRARYNAME) debug library =======
142         $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
143
144 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
145         @echo ======= Linking $(LIBRARYNAME) release library =======
146         rm -f $@
147         $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
148
149 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
150         @echo ======= Linking $(LIBRARYNAME) debug library =======
151         rm -f $@
152         $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
153
154 endif
155
156
157 #---------------------------------------------------------
158
159 # Create dependencies for the *.cpp files...
160 Depend/%.d: %.cpp Depend/.dir
161         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
162
163 # Create dependencies for the *.c files...
164 Depend/%.d: %.c Depend/.dir
165         $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
166
167 # Create .o files in the ObjectFiles directory from the .cpp and .c files...
168 Release/%.o: %.cpp Release/.dir Depend/.dir
169         $(CompileO) $< -o $@
170
171 Release/%.o: %.c Release/.dir Depend/.dir
172         $(CompileO) $< -o $@
173
174 Debug/%.o: %.cpp Debug/.dir Depend/.dir
175         $(CompileG) $< -o $@
176
177 Debug/%.o: %.c Debug/.dir Depend/.dir
178         $(CompileG) $< -o $@
179
180 # Create a .cpp source file from a flex input file... this uses sed to cut down
181 # on the warnings emited by GCC...
182 %.cpp: %.l
183         flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
184
185 # Rule for building the bison parsers...
186
187 %.cpp %.h : %.y
188         bison -d -p $(<:%Parser.y=%) $(basename $@).y
189         mv -f $(basename $@).tab.c $(basename $@).cpp
190         mv -f $(basename $@).tab.h $(basename $@).h
191
192 # To create the directories...
193 %/.dir:
194         mkdir -p $(@D)
195         @date > $@
196
197 # Clean does not remove the output files... just the temporaries
198 clean::
199         rm -rf Debug Release Depend
200         rm -f core *.o *.d *.so *~ *.flc
201
202 # If dependancies were generated for the file that included this file,
203 # include the dependancies now...
204 #
205 SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
206 ifneq ($(SourceDepend),)
207 include $(SourceDepend)
208 endif