blob: 94195ebbd018edb5cb9794865b20a66dcaecd3da [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
37#---------------------------------------------------------
38# Compilation options...
39#---------------------------------------------------------
40
41# Add -L options to the link command lines...
Vikram S. Advec4651a92001-07-21 12:38:14 +000042LibPathsO = -L $(LEVEL)/lib/Support/Release \
43 -L $(LEVEL)/lib/VMCore/Release \
Chris Lattner00950542001-06-06 20:29:01 +000044 -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 \
Vikram S. Advec4651a92001-07-21 12:38:14 +000049 -L $(LEVEL)/lib/Optimizations/Release \
50 -L $(LEVEL)/lib/CodeGen/InstrSelection/Release \
51 -L $(LEVEL)/lib/CodeGen/TargetMachine/Release \
Vikram S. Adve588f1482001-07-28 04:39:27 +000052 -L $(LEVEL)/lib/CodeGen/TargetMachine/Sparc/Release
Chris Lattner00950542001-06-06 20:29:01 +000053
54LibPathsG = $(LibPathsO:Release=Debug)
55
Vikram S. Advec4651a92001-07-21 12:38:14 +000056
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.
61LibsO = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsO)))
62LibsG = $(addsuffix /lib*.a,$(subst -L,,$(LibPathsG)))
63
64
Chris Lattner00950542001-06-06 20:29:01 +000065# Enable this for profiling support with 'gprof'
66#Prof = -pg
67
68# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
69CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
70
71# Compile a file, don't link...
72Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
73CompileG = $(Compile) -g -D_DEBUG
74# Add This for DebugMalloc: -fno-defer-pop
75CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
76
77# Link final executable
78Link = $(CXX) $(Prof)
79LinkG = $(Link) -g $(LibPathsG)
80LinkO = $(Link) -O3 $(LibPathsO)
81
82# Create a .so file from a .cpp file...
83#MakeSO = $(CXX) -shared $(Prof)
84MakeSO = $(CXX) -G $(Prof)
85MakeSOG = $(MakeSO) -g
86MakeSOO = $(MakeSO) -O3
87
88# Create dependancy file from CPP file, send to stdout.
89Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
90
91# Archive a bunch of .o files into a .a file...
92AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +000093MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +000094
95#----------------------------------------------------------
96
97# Source includes all of the cpp files, and objects are derived from the
98# source files...
99ifndef Source
100Source = $(wildcard *.cpp *.c *.y *.l)
101endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000102
Chris Lattnerfebb11f2001-07-18 23:43:37 +0000103Objs = $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner00950542001-06-06 20:29:01 +0000104ObjectsO = $(addprefix Release/,$(Objs))
105ObjectsG = $(addprefix Debug/,$(Objs))
106
107#---------------------------------------------------------
108# Handle the DIRS option
109#---------------------------------------------------------
110
111ifdef DIRS # Only do this if we're using DIRS!
112
113all :: $(addsuffix /.makeall , $(DIRS))
114install :: $(addsuffix /.makeinstall, $(DIRS))
115clean :: $(addsuffix /.makeclean , $(DIRS))
116
117%/.makeall %/.makeclean %/.makeinstall:
118 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
119endif
120
121#---------------------------------------------------------
122# Handle the LIBRARYNAME option - used when building libs...
123#---------------------------------------------------------
124
125ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000126
Chris Lattner00950542001-06-06 20:29:01 +0000127LIBNAME_O := Release/lib$(LIBRARYNAME).so
128LIBNAME_G := Debug/lib$(LIBRARYNAME).so
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000129LIBNAME_AO := Release/lib$(LIBRARYNAME).a
130LIBNAME_AG := Debug/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000131
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000132all:: $(LIBNAME_AG)
Chris Lattnerfebb11f2001-07-18 23:43:37 +0000133###all:: $(LIBNAME_G)
Chris Lattner00950542001-06-06 20:29:01 +0000134# TODO: Enable optimized builds
135
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000136$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000137 @echo ======= Linking $(LIBRARYNAME) release library =======
138 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
139
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000140$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000141 @echo ======= Linking $(LIBRARYNAME) debug library =======
142 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
143
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000144$(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
Chris Lattner00950542001-06-06 20:29:01 +0000154endif
155
156
157#---------------------------------------------------------
158
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000159# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000160Depend/%.d: %.cpp Depend/.dir
161 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
162
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000163# Create dependencies for the *.c files...
164Depend/%.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...
Chris Lattner00950542001-06-06 20:29:01 +0000168Release/%.o: %.cpp Release/.dir Depend/.dir
169 $(CompileO) $< -o $@
170
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000171Release/%.o: %.c Release/.dir Depend/.dir
172 $(CompileO) $< -o $@
173
Chris Lattner00950542001-06-06 20:29:01 +0000174Debug/%.o: %.cpp Debug/.dir Depend/.dir
175 $(CompileG) $< -o $@
176
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000177Debug/%.o: %.c Debug/.dir Depend/.dir
178 $(CompileG) $< -o $@
179
Chris Lattner00950542001-06-06 20:29:01 +0000180# 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
198clean::
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#
205SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
206ifneq ($(SourceDepend),)
207include $(SourceDepend)
208endif