blob: 03bca7e7df7d4c2f064a52be7e43a50a75b6636d [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
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#
23
Chris Lattnerb19e59c2001-06-29 05:20:16 +000024# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000025all ::
26
27# Default for install is to at least build everything...
28install ::
29
30#--------------------------------------------------------------------
31# Installation configuration options...
32#--------------------------------------------------------------------
33
34#BinInstDir=/usr/local/bin
35#LibInstDir=/usrl/local/lib/xxx
36#DocInstDir=/usr/doc/xxx
37
Vikram S. Advedba59ef2001-08-06 19:01:20 +000038BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg
39BURG_OPTS = -I
40
Chris Lattner6e390702001-10-30 20:24:08 +000041
Chris Lattnerec6bed22002-04-07 06:18:40 +000042PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +000043
Chris Lattner00950542001-06-06 20:29:01 +000044#---------------------------------------------------------
45# Compilation options...
46#---------------------------------------------------------
47
Vikram S. Advedba59ef2001-08-06 19:01:20 +000048# Special tools used while building
49RunBurg = $(BURG) $(BURG_OPTS)
50
Chris Lattner00950542001-06-06 20:29:01 +000051# Enable this for profiling support with 'gprof'
Chris Lattner18f47012002-05-10 18:51:54 +000052ifdef ENABLE_PROFILING
53PROFILE = -pg
54else
55PROFILE =
56endif
Chris Lattner00950542001-06-06 20:29:01 +000057
58# TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti
Chris Lattnerc7acf812002-01-23 05:46:01 +000059# -Wno-unused-parameter
Chris Lattner18f47012002-05-10 18:51:54 +000060CompileCommonOpts = $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner00950542001-06-06 20:29:01 +000061
62# Compile a file, don't link...
Chris Lattner18f47012002-05-10 18:51:54 +000063Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +000064CompileG = $(Compile) -g -D_DEBUG
Chris Lattner00950542001-06-06 20:29:01 +000065CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums
66
67# Link final executable
Chris Lattner6e390702001-10-30 20:24:08 +000068
69# To enable purify, do it here:
Chris Lattner12604ed2002-04-05 18:56:58 +000070ifdef ENABLE_PURIFY
71Link = $(PURIFY) $(CXX) $(Prof) -static
72else
Chris Lattner18f47012002-05-10 18:51:54 +000073Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(PROFILE)
Chris Lattner12604ed2002-04-05 18:56:58 +000074endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +000075LinkG = $(Link) -g -L $(LEVEL)/lib/Debug
76LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release
Chris Lattner00950542001-06-06 20:29:01 +000077
78# Create a .so file from a .cpp file...
79#MakeSO = $(CXX) -shared $(Prof)
80MakeSO = $(CXX) -G $(Prof)
81MakeSOG = $(MakeSO) -g
82MakeSOO = $(MakeSO) -O3
83
84# Create dependancy file from CPP file, send to stdout.
85Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
86
87# Archive a bunch of .o files into a .a file...
88AR = ar cq
Vikram S. Adve112a72c2001-07-15 13:16:47 +000089MakeLib = $(AR)
Chris Lattner00950542001-06-06 20:29:01 +000090
91#----------------------------------------------------------
92
93# Source includes all of the cpp files, and objects are derived from the
94# source files...
Chris Lattnere0010592001-10-18 01:48:09 +000095# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +000096#
Chris Lattnere0010592001-10-18 01:48:09 +000097Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Adve112a72c2001-07-15 13:16:47 +000098
Chris Lattnerc7acf812002-01-23 05:46:01 +000099Objs := $(sort $(addsuffix .o,$(basename $(Source))))
Chris Lattner00950542001-06-06 20:29:01 +0000100ObjectsO = $(addprefix Release/,$(Objs))
101ObjectsG = $(addprefix Debug/,$(Objs))
102
103#---------------------------------------------------------
104# Handle the DIRS option
105#---------------------------------------------------------
106
107ifdef DIRS # Only do this if we're using DIRS!
108
109all :: $(addsuffix /.makeall , $(DIRS))
110install :: $(addsuffix /.makeinstall, $(DIRS))
111clean :: $(addsuffix /.makeclean , $(DIRS))
112
113%/.makeall %/.makeclean %/.makeinstall:
114 cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
115endif
116
117#---------------------------------------------------------
118# Handle the LIBRARYNAME option - used when building libs...
119#---------------------------------------------------------
120
121ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000122
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000123LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so
124LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so
125LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a
126LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000127
Chris Lattner18f47012002-05-10 18:51:54 +0000128all:: $(LIBNAME_AG) ###$(LIBNAME_AO)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000129dynamic:: $(LIBNAME_G)
Chris Lattner00950542001-06-06 20:29:01 +0000130# TODO: Enable optimized builds
131
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000132$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000133 @echo ======= Linking $(LIBRARYNAME) release library =======
134 $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
135
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000136$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000137 @echo ======= Linking $(LIBRARYNAME) debug library =======
138 $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
139
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000140$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000141 @echo ======= Linking $(LIBRARYNAME) release library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000142 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000143 $(MakeLib) $@ $(ObjectsO) $(LibSubDirs)
144
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000145$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000146 @echo ======= Linking $(LIBRARYNAME) debug library =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000147 @rm -f $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000148 $(MakeLib) $@ $(ObjectsG) $(LibSubDirs)
149
Chris Lattner00950542001-06-06 20:29:01 +0000150endif
151
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000152#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000153# Create a TAGS database for emacs
154#------------------------------------------------------------------------
155
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000156ifeq ($(LEVEL), .)
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000157
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000158tags:
Chris Lattner18f47012002-05-10 18:51:54 +0000159 etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000160
161all:: tags
162
163endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000164
165#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000166# Handle the TOOLNAME option - used when building tool executables...
167#------------------------------------------------------------------------
168#
169# The TOOLNAME option should be used with a USEDLIBS variable that tells the
170# libraries (and the order of the libs) that should be linked to the tool.
171#
172ifdef TOOLNAME
173
174# TOOLEXENAME* - These compute the output filenames to generate...
175TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME)
176TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME)
Chris Lattnerc7acf812002-01-23 05:46:01 +0000177TOOLEXENAMES := $(TOOLEXENAME_G) ###$(TOOLEXENAME_O)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000178
179# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
180USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS))
181
182# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
183# rebuilt if libraries change
184#
Chris Lattnerc7acf812002-01-23 05:46:01 +0000185STATICUSEDLIBS := $(addsuffix .a, $(USEDLIBS))
186USED_LIB_PATHS_G := $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS))
187USED_LIB_PATHS_O := $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000188
Chris Lattner669bd7c2001-10-13 05:10:29 +0000189all:: $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000190clean::
191 rm -f $(TOOLEXENAMES)
192
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000193$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir
Chris Lattner49f2b942001-09-10 04:49:26 +0000194 $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000195
Chris Lattnerbf2f0432001-09-09 20:59:28 +0000196$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir
Chris Lattner49f2b942001-09-10 04:49:26 +0000197 $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000198
199endif
200
201
Chris Lattner00950542001-06-06 20:29:01 +0000202
203#---------------------------------------------------------
Chris Lattneraa6ec732001-11-07 14:50:58 +0000204.PRECIOUS: Depend/.dir Debug/.dir Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000205
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000206# Create dependencies for the *.cpp files...
Chris Lattner00950542001-06-06 20:29:01 +0000207Depend/%.d: %.cpp Depend/.dir
208 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
209
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000210# Create dependencies for the *.c files...
211Depend/%.d: %.c Depend/.dir
212 $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@
213
214# Create .o files in the ObjectFiles directory from the .cpp and .c files...
Chris Lattner00950542001-06-06 20:29:01 +0000215Release/%.o: %.cpp Release/.dir Depend/.dir
216 $(CompileO) $< -o $@
217
Chris Lattnerc7acf812002-01-23 05:46:01 +0000218#Release/%.o: %.c Release/.dir Depend/.dir
219# $(CompileOC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000220
Chris Lattner00950542001-06-06 20:29:01 +0000221Debug/%.o: %.cpp Debug/.dir Depend/.dir
222 $(CompileG) $< -o $@
223
Chris Lattnerc7acf812002-01-23 05:46:01 +0000224#Debug/%.o: %.c Debug/.dir Depend/.dir
225# $(CompileGC) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000226
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000227# Create a .cpp source file from a burg input file
Chris Lattner0cac4b82002-02-11 17:12:03 +0000228%.burm.cpp: Debug/%.burg Debug/.dir
Vikram S. Advebedbcf62001-08-06 19:06:43 +0000229 $(RunBurg) $< -o $@
230
Chris Lattner00950542001-06-06 20:29:01 +0000231# Create a .cpp source file from a flex input file... this uses sed to cut down
232# on the warnings emited by GCC...
233%.cpp: %.l
234 flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@
235
236# Rule for building the bison parsers...
237
238%.cpp %.h : %.y
Chris Lattner18f47012002-05-10 18:51:54 +0000239 bison -v -d -p $(<:%Parser.y=%) $(basename $@).y
Chris Lattner00950542001-06-06 20:29:01 +0000240 mv -f $(basename $@).tab.c $(basename $@).cpp
241 mv -f $(basename $@).tab.h $(basename $@).h
242
243# To create the directories...
244%/.dir:
245 mkdir -p $(@D)
246 @date > $@
247
248# Clean does not remove the output files... just the temporaries
249clean::
250 rm -rf Debug Release Depend
251 rm -f core *.o *.d *.so *~ *.flc
252
253# If dependancies were generated for the file that included this file,
254# include the dependancies now...
255#
256SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source))))
257ifneq ($(SourceDepend),)
258include $(SourceDepend)
259endif