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