blob: 5ef5fd6a7a87f1fc0358aaff30e952260f95e3b4 [file] [log] [blame]
Vikram S. Adved60aede2002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner00950542001-06-06 20:29:01 +00002#
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
Chris Lattnere0010592001-10-18 01:48:09 +000020# in the current directory. Also, if you want to build files in addition
21# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000022#
Vikram S. Adved60aede2002-07-09 12:04:21 +000023#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000024
Chris Lattnerb19e59c2001-06-29 05:20:16 +000025# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000026all ::
27
28# Default for install is to at least build everything...
29install ::
30
31#--------------------------------------------------------------------
32# Installation configuration options...
33#--------------------------------------------------------------------
34
35#BinInstDir=/usr/local/bin
36#LibInstDir=/usrl/local/lib/xxx
37#DocInstDir=/usr/doc/xxx
38
Vikram S. Advedba59ef2001-08-06 19:01:20 +000039BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
40BURG_OPTS = -I
41
Chris Lattner6e390702001-10-30 20:24:08 +000042
Chris Lattnerec6bed22002-04-07 06:18:40 +000043PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +000044
Chris Lattner00950542001-06-06 20:29:01 +000045#---------------------------------------------------------
46# Compilation options...
47#---------------------------------------------------------
48
Vikram S. Advedba59ef2001-08-06 19:01:20 +000049# Special tools used while building
50RunBurg = $(BURG) $(BURG_OPTS)
51
Chris Lattner00950542001-06-06 20:29:01 +000052# Enable this for profiling support with 'gprof'
Chris Lattner18f47012002-05-10 18:51:54 +000053ifdef ENABLE_PROFILING
54PROFILE = -pg
55else
56PROFILE =
57endif
Chris Lattner00950542001-06-06 20:29:01 +000058
59# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
Chris Lattnerc7acf812002-01-23 05:46:01 +000060# -Wno-unused-parameter
Chris Lattner18f47012002-05-10 18:51:54 +000061CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner00950542001-06-06 20:29:01 +000062
63# Compile a file, don't link...
Chris Lattner18f47012002-05-10 18:51:54 +000064Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +000065CompileG = $(Compile) -g -D_DEBUG
Chris Lattner00950542001-06-06 20:29:01 +000066CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
67
68# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +000069
70# To enable purify, do it here:
Chris Lattner12604ed2002-04-05 18:56:58 +000071ifdef ENABLE_PURIFY
72Link = $(PURIFY) $(CXX) $(Prof) -static
73else
Chris Lattner18f47012002-05-10 18:51:54 +000074Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(PROFILE)
Chris Lattner12604ed2002-04-05 18:56:58 +000075endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +000076LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
77LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
Chris Lattner00950542001-06-06 20:29:01 +000078
79# Create a .so file from a .cpp file...
80#MakeSO = $(CXX) -shared $(Prof)
81MakeSO = $(CXX) -G $(Prof)
82MakeSOG = $(MakeSO) -g
83MakeSOO = $(MakeSO) -O3
84
85# Create dependancy file from CPP file, send to stdout.
86Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
87
88# Archive a bunch of .o files into a .a file...
89AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +000090MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +000091
92#----------------------------------------------------------
93
94# Source includes all of the cpp files, and objects are derived from the
95# source files...
Chris Lattnere0010592001-10-18 01:48:09 +000096# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +000097#
Chris Lattnere0010592001-10-18 01:48:09 +000098Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Adve112a72c2001-07-15 13:16:47 +000099
Chris Lattnerc7acf812002-01-23 05:46:01 +0000100Objs := $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner00950542001-06-06 20:29:01 +0000101ObjectsO = $(addprefix Release/,$(Objs))
102ObjectsG = $(addprefix Debug/,$(Objs))
103
104#---------------------------------------------------------
105# Handle the DIRS option
106#---------------------------------------------------------
107
108ifdef DIRS # Only do this if we're using DIRS!
109
110all :: $(addsuffix /.makeall , $(DIRS))
111install :: $(addsuffix /.makeinstall, $(DIRS))
112clean :: $(addsuffix /.makeclean , $(DIRS))
113
114%/.makeall %/.makeclean %/.makeinstall:
115 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
116endif
117
118#---------------------------------------------------------
119# Handle the LIBRARYNAME option - used when building libs...
120#---------------------------------------------------------
121
122ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000123
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000124LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
125LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
126LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
127LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000128
Chris Lattner18f47012002-05-10 18:51:54 +0000129all:: $(LIBNAME_AG) ###$(LIBNAME_AO)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000130dynamic:: $(LIBNAME_G)
Chris Lattner00950542001-06-06 20:29:01 +0000131# TODO: Enable optimized builds
132
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000133$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000134 @echo ======= Linking $(LIBRARYNAME) release library =======
135 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
136
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000137$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000138 @echo ======= Linking $(LIBRARYNAME) debug library =======
139 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
140
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000141$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000142 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000143 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000144 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
145
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000146$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000147 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000148 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000149 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
150
Chris Lattner00950542001-06-06 20:29:01 +0000151endif
152
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000153#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000154# Create a TAGS database for emacs
155#------------------------------------------------------------------------
156
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000157ifeq ($(LEVEL), .)
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000158
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000159tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000160 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000161
162all:: tags
163
164endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000165
166#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000167# Handle the TOOLNAME option - used when building tool executables...
168#------------------------------------------------------------------------
169#
170# The TOOLNAME option should be used with a USEDLIBS variable that tells the
171# libraries (and the order of the libs) that should be linked to the tool.
172#
173ifdef TOOLNAME
174
175# TOOLEXENAME* - These compute the output filenames to generate...
176TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
177TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
Chris Lattnerc7acf812002-01-23 05:46:01 +0000178TOOLEXENAMES := $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000179
180# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
181USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
182
183# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
184# rebuilt if libraries change
185#
Chris Lattnerc7acf812002-01-23 05:46:01 +0000186STATICUSEDLIBS := $(addsuffix .a, $(USEDLIBS))
187USED_LIB_PATHS_G := $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
188USED_LIB_PATHS_O := $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000189
Chris Lattner669bd7c2001-10-13 05:10:29 +0000190all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000191clean::
192 rm -f $(TOOLEXENAMES)
193
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000194$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattner49f2b942001-09-10 04:49:26 +0000195 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000196
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000197$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattner49f2b942001-09-10 04:49:26 +0000198 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000199
200endif
201
202
Chris Lattner00950542001-06-06 20:29:01 +0000203
204#---------------------------------------------------------
Chris Lattneraa6ec732001-11-07 14:50:58 +0000205.PRECIOUS: Depend/.dir Debug/.dir Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000206
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000207# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000208Depend/%.d: %.cpp Depend/.dir
209 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
210
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000211# Create dependencies for the *.c files...
212Depend/%.d: %.c Depend/.dir
213 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
214
215# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner00950542001-06-06 20:29:01 +0000216Release/%.o: %.cpp Release/.dir Depend/.dir
217 $(CompileO) $< -o $@
218
Chris Lattnerc7acf812002-01-23 05:46:01 +0000219#Release/%.o: %.c Release/.dir Depend/.dir
220# $(CompileOC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000221
Chris Lattner00950542001-06-06 20:29:01 +0000222Debug/%.o: %.cpp Debug/.dir Depend/.dir
223 $(CompileG) $< -o $@
224
Chris Lattnerc7acf812002-01-23 05:46:01 +0000225#Debug/%.o: %.c Debug/.dir Depend/.dir
226# $(CompileGC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000227
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000228# Create a .cpp source file from a burg input file
Chris Lattner0cac4b82002-02-11 17:12:03 +0000229%.burm.cpp: Debug/%.burg Debug/.dir
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000230 $(RunBurg) $< -o $@
231
Chris Lattner00950542001-06-06 20:29:01 +0000232# Create a .cpp source file from a flex input file... this uses sed to cut down
233# on the warnings emited by GCC...
234%.cpp: %.l
235 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
236
237# Rule for building the bison parsers...
238
239%.cpp %.h : %.y
Chris Lattner18f47012002-05-10 18:51:54 +0000240 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
Chris Lattner00950542001-06-06 20:29:01 +0000241 mv -f $(basename $@).tab.c $(basename $@).cpp
242 mv -f $(basename $@).tab.h $(basename $@).h
243
244# To create the directories...
245%/.dir:
246 mkdir -p $(@D)
247 @date > $@
248
249# Clean does not remove the output files... just the temporaries
250clean::
251 rm -rf Debug Release Depend
252 rm -f core *.o *.d *.so *~ *.flc
253
254# If dependancies were generated for the file that included this file,
255# include the dependancies now...
256#
257SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
258ifneq ($(SourceDepend),)
259include $(SourceDepend)
260endif