blob: 0c735d24f648957998fbe27d0fb91512d44e6053 [file] [log] [blame]
Chris Lattner00950542001-06-06 20:29:01 +00001# 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
Chris Lattnerb19e59c2001-06-29 05:20:16 +000023# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000024all ::
25
26# Default for install is to at least build everything...
27install ::
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
Vikram S. Advedba59ef2001-08-06 19:01:20 +000037BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
38BURG_OPTS = -I
39
Chris Lattner00950542001-06-06 20:29:01 +000040#---------------------------------------------------------
41# Compilation options...
42#---------------------------------------------------------
43
44# Add -L options to the link command lines...
Vikram S. Advec4651a92001-07-21 12:38:14 +000045LibPathsO = -L $(LEVEL)/lib/Support/Release \
46 -L $(LEVEL)/lib/VMCore/Release \
Chris Lattner00950542001-06-06 20:29:01 +000047 -L $(LEVEL)/lib/Assembly/Parser/Release \
48 -L $(LEVEL)/lib/Assembly/Writer/Release \
49 -L $(LEVEL)/lib/Analysis/Release \
50 -L $(LEVEL)/lib/Bytecode/Writer/Release \
51 -L $(LEVEL)/lib/Bytecode/Reader/Release \
Vikram S. Advec4651a92001-07-21 12:38:14 +000052 -L $(LEVEL)/lib/Optimizations/Release \
53 -L $(LEVEL)/lib/CodeGen/InstrSelection/Release \
54 -L $(LEVEL)/lib/CodeGen/TargetMachine/Release \
Vikram S. Adve588f1482001-07-28 04:39:27 +000055 -L $(LEVEL)/lib/CodeGen/TargetMachine/Sparc/Release
Chris Lattner00950542001-06-06 20:29:01 +000056
Vikram S. Advedba59ef2001-08-06 19:01:20 +000057## -L $(LEVEL)/lib/CodeGen/InstrSched/Release \
58
59
Chris Lattner00950542001-06-06 20:29:01 +000060LibPathsG = $(LibPathsO:Release=Debug)
61
Vikram S. Advec4651a92001-07-21 12:38:14 +000062
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.
67LibsO = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsO)))
68LibsG = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsG)))
69
70
Vikram S. Advedba59ef2001-08-06 19:01:20 +000071# Special tools used while building
72RunBurg = $(BURG) $(BURG_OPTS)
73
Chris Lattner00950542001-06-06 20:29:01 +000074# Enable this for profiling support with 'gprof'
75#Prof = -pg
76
77# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
78CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
79
80# Compile a file, don't link...
81Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
82CompileG = $(Compile) -g -D_DEBUG
83# Add This for DebugMalloc: -fno-defer-pop
84CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
85
86# Link final executable
87Link = $(CXX) $(Prof)
88LinkG = $(Link) -g $(LibPathsG)
89LinkO = $(Link) -O3 $(LibPathsO)
90
91# Create a .so file from a .cpp file...
92#MakeSO = $(CXX) -shared $(Prof)
93MakeSO = $(CXX) -G $(Prof)
94MakeSOG = $(MakeSO) -g
95MakeSOO = $(MakeSO) -O3
96
97# Create dependancy file from CPP file, send to stdout.
98Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
99
100# Archive a bunch of .o files into a .a file...
101AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000102MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +0000103
104#----------------------------------------------------------
105
106# Source includes all of the cpp files, and objects are derived from the
107# source files...
108ifndef Source
109Source = $(wildcard *.cpp *.c *.y *.l)
110endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000111
Chris Lattnerfebb11f2001-07-18 23:43:37 +0000112Objs = $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner00950542001-06-06 20:29:01 +0000113ObjectsO = $(addprefix Release/,$(Objs))
114ObjectsG = $(addprefix Debug/,$(Objs))
115
116#---------------------------------------------------------
117# Handle the DIRS option
118#---------------------------------------------------------
119
120ifdef DIRS # Only do this if we're using DIRS!
121
122all :: $(addsuffix /.makeall , $(DIRS))
123install :: $(addsuffix /.makeinstall, $(DIRS))
124clean :: $(addsuffix /.makeclean , $(DIRS))
125
126%/.makeall %/.makeclean %/.makeinstall:
127 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
128endif
129
130#---------------------------------------------------------
131# Handle the LIBRARYNAME option - used when building libs...
132#---------------------------------------------------------
133
134ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000135
Chris Lattner00950542001-06-06 20:29:01 +0000136LIBNAME_O := Release/lib$(LIBRARYNAME).so
137LIBNAME_G := Debug/lib$(LIBRARYNAME).so
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000138LIBNAME_AO := Release/lib$(LIBRARYNAME).a
139LIBNAME_AG := Debug/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000140
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000141all:: $(LIBNAME_AG)
Chris Lattnerfebb11f2001-07-18 23:43:37 +0000142###all:: $(LIBNAME_G)
Chris Lattner00950542001-06-06 20:29:01 +0000143# TODO: Enable optimized builds
144
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000145$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000146 @echo ======= Linking $(LIBRARYNAME) release library =======
147 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
148
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000149$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000150 @echo ======= Linking $(LIBRARYNAME) debug library =======
151 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
152
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000153$(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
Chris Lattner00950542001-06-06 20:29:01 +0000163endif
164
165
166#---------------------------------------------------------
167
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000168# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000169Depend/%.d: %.cpp Depend/.dir
170 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
171
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000172# Create dependencies for the *.c files...
173Depend/%.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...
Chris Lattner00950542001-06-06 20:29:01 +0000177Release/%.o: %.cpp Release/.dir Depend/.dir
178 $(CompileO) $< -o $@
179
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000180Release/%.o: %.c Release/.dir Depend/.dir
181 $(CompileO) $< -o $@
182
Chris Lattner00950542001-06-06 20:29:01 +0000183Debug/%.o: %.cpp Debug/.dir Depend/.dir
184 $(CompileG) $< -o $@
185
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000186Debug/%.o: %.c Debug/.dir Depend/.dir
187 $(CompileG) $< -o $@
188
Chris Lattner00950542001-06-06 20:29:01 +0000189# Create a .cpp source file from a flex input file... this uses sed to cut down
190# on the warnings emited by GCC...
191%.cpp: %.l
192 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
193
194# Rule for building the bison parsers...
195
196%.cpp %.h : %.y
197 bison -d -p $(<:%Parser.y=%) $(basename $@).y
198 mv -f $(basename $@).tab.c $(basename $@).cpp
199 mv -f $(basename $@).tab.h $(basename $@).h
200
201# To create the directories...
202%/.dir:
203 mkdir -p $(@D)
204 @date > $@
205
206# Clean does not remove the output files... just the temporaries
207clean::
208 rm -rf Debug Release Depend
209 rm -f core *.o *.d *.so *~ *.flc
210
211# If dependancies were generated for the file that included this file,
212# include the dependancies now...
213#
214SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
215ifneq ($(SourceDepend),)
216include $(SourceDepend)
217endif