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