blob: 2612e6fc656b3cbe090ff6e3efae8fceef716a4c [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#
Vikram S. Advec214e712002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner00950542001-06-06 20:29:01 +000010#
11# 1. LEVEL - The level of the current subdirectory from the top of the
12# MagicStats view. This level should be expressed as a path, for
13# example, ../.. for two levels deep.
14#
15# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnera8abc222002-09-18 03:22:27 +000016# so that each of the targets "all", "install", and "clean" each build
17# the subdirectories before the local target. DIRS are guaranteed to be
18# built in order.
Chris Lattner00950542001-06-06 20:29:01 +000019#
Chris Lattnera8abc222002-09-18 03:22:27 +000020# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21# built in any order. All DIRS are built in order before PARALLEL_DIRS are
22# built, which are then built in any order.
23#
24# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner00950542001-06-06 20:29:01 +000025# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000026# in the current directory. Also, if you want to build files in addition
27# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000028#
Chris Lattner694c5df2003-05-15 21:28:55 +000029# 5. SourceDir - If specified, this specifies a directory that the source files
30# are in, if they are not in the current directory. This should include a
31# trailing / character.
32#
John Criswell7a73b802003-06-30 21:59:07 +000033# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000034#
John Criswell7a73b802003-06-30 21:59:07 +000035# 7. LLVM_OBJ_ROOT - If specified, points to the top directory where LLVM
36# object files are placed.
37#
38# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39# and usually the source code too (unless SourceDir is set).
40#
41# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
42#
43# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
44#
45# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
46# placed.
47#
48# For building,
49# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT, and
50# LLVM_OBJ_ROOT = BUILD_OBJ_ROOT.
Vikram S. Adved60aede2002-07-09 12:04:21 +000051#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000052
John Criswell2a6530f2003-06-27 16:58:44 +000053#
Vikram S. Advec214e712002-08-29 23:28:46 +000054# Configuration file to set paths specific to local installation of LLVM
55#
56include $(LEVEL)/Makefile.config
57
John Criswell8bff5092003-06-11 13:55:44 +000058###########################################################################
59# Directory Configuration
60# This section of the Makefile determines what is where. To be
61# specific, there are several locations that need to be defined:
62#
63# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
64# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
65#
66# o BUILD_SRC_DIR : The directory containing the code to build.
67# o BUILD_SRC_ROOT : The root directory of the code to build.
68#
69# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
70# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
71#
72###########################################################################
73
74#
75# Set the source build directory. That is almost always the current directory.
76#
77ifndef BUILD_SRC_DIR
78BUILD_SRC_DIR = $(shell pwd)
79endif
80
81#
82# Set the source root directory.
83#
84ifndef BUILD_SRC_ROOT
John Criswell890d5bd2003-06-16 19:14:31 +000085BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell8bff5092003-06-11 13:55:44 +000086endif
87
88#
John Criswell7a73b802003-06-30 21:59:07 +000089# Determine the path of the source tree relative from $HOME (the mythical
90# home directory).
91#
Misha Brukmanf8873ed2003-07-07 22:27:05 +000092HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
John Criswell7a73b802003-06-30 21:59:07 +000093
94#
John Criswell8bff5092003-06-11 13:55:44 +000095# Set the object build directory. Its location depends upon the source path
96# and where object files should go.
97#
98ifndef BUILD_OBJ_DIR
99ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000100BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +0000101else
John Criswell7a73b802003-06-30 21:59:07 +0000102BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
John Criswell8bff5092003-06-11 13:55:44 +0000103endif
104endif
105
106#
107# Set the root of the object directory.
108#
109ifndef BUILD_OBJ_ROOT
110ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000111BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000112else
John Criswell7a73b802003-06-30 21:59:07 +0000113BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000114endif
115endif
116
117#
118# Set the LLVM source directory.
119# It is typically the root directory of what we're compiling now.
120#
121ifndef LLVM_SRC_ROOT
122LLVM_SRC_ROOT = $(BUILD_SRC_ROOT)
123endif
124
125#
126# Set the LLVM object directory.
127#
128ifndef LLVM_OBJ_ROOT
129LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT)
130endif
131
John Criswell7a73b802003-06-30 21:59:07 +0000132###########################################################################
133# Default Targets:
134# The following targets are the standard top level targets for
135# building.
136###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +0000137
Chris Lattneredf1f232002-07-23 19:21:31 +0000138ifdef SHARED_LIBRARY
139# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +0000140all:: dynamic
Chris Lattneredf1f232002-07-23 19:21:31 +0000141endif
142
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000143# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000144all ::
145
146# Default for install is to at least build everything...
147install ::
148
John Criswell8bff5092003-06-11 13:55:44 +0000149# Default rule for test. It ensures everything has a test rule
150test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000151
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000152# Default rule for building only bytecode.
153bytecode::
154
John Criswell7a73b802003-06-30 21:59:07 +0000155# Print out the directories used for building
156prdirs::
157 echo "Home Offset : " $(HOME_OBJ_ROOT);
158 echo "Build Source Root: " $(BUILD_SRC_ROOT);
159 echo "Build Source Dir : " $(BUILD_SRC_DIR);
160 echo "Build Object Root: " $(BUILD_OBJ_ROOT);
161 echo "Build Object Dir : " $(BUILD_OBJ_DIR);
162 echo "LLVM Source Root: " $(LLVM_SRC_ROOT);
163 echo "LLVM Object Root: " $(LLVM_OBJ_ROOT);
164
John Criswell96914392003-07-16 20:26:06 +0000165#
166# Mark all of these targets as phony. This will hopefully speed up builds
167# slightly since GNU Make will not try to find implicit rules for targets
168# which are marked as Phony.
169#
170.PHONY: all dynamic clean distclean install test bytecode prdirs
171
John Criswell7a73b802003-06-30 21:59:07 +0000172###########################################################################
173# Miscellaneous paths and commands:
174# This section defines various configuration macros, such as where
175# to find burg, tblgen, and libtool.
176###########################################################################
177
Chris Lattner00950542001-06-06 20:29:01 +0000178#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000179# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000180#--------------------------------------------------------------------
181
182#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000183#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000184#DocInstDir=/usr/doc/xxx
185
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000186BURG_OPTS = -I
187
John Criswell8bff5092003-06-11 13:55:44 +0000188PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all
Chris Lattner6e390702001-10-30 20:24:08 +0000189
Chris Lattner760da062003-03-14 20:25:22 +0000190ifdef ENABLE_PROFILING
191 ENABLE_OPTIMIZED = 1
192 CONFIGURATION := Profile
193else
194 ifdef ENABLE_OPTIMIZED
195 CONFIGURATION := Release
196 else
197 CONFIGURATION := Debug
198 endif
199endif
200
John Criswell7a73b802003-06-30 21:59:07 +0000201#
202# Enable this for profiling support with 'gprof'
203# This automatically enables optimized builds.
204#
205ifdef ENABLE_PROFILING
206 PROFILE = -pg
207endif
208
209#
210# Suffixes for library compilation rules
211#
212.SUFFIXES: .so
213
John Criswell8bff5092003-06-11 13:55:44 +0000214###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000215# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000216# These variables describe various library locations:
217#
218# DEST* = Location of where libraries that are built will be placed.
219# LLVM* = Location of LLVM libraries used for linking.
220# PROJ* = Location of previously built libraries used for linking.
221###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000222
John Criswell8bff5092003-06-11 13:55:44 +0000223# Libraries that are being built
224DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
225DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
226DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
227DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000228
John Criswell8bff5092003-06-11 13:55:44 +0000229# LLVM libraries used for linking
230LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
231LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
232LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
233LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000234
John Criswell8bff5092003-06-11 13:55:44 +0000235# Libraries that were built that will now be used for linking
236PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
237PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
238PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
239PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000240
John Criswell8bff5092003-06-11 13:55:44 +0000241###########################################################################
242# Tool Locations
243# These variables describe various tool locations:
244#
245# DEST* = Location of where tools that are built will be placed.
246# LLVM* = Location of LLVM tools used for building.
247# PROJ* = Location of previously built tools used for linking.
248###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000249
John Criswell8bff5092003-06-11 13:55:44 +0000250DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
251DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
252DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
253DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
254
255LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
256LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
257LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
258LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
259
260PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
261PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
262PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
263PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000264
John Criswell7a73b802003-06-30 21:59:07 +0000265#
266# Libtool is found in the current directory.
267#
268ifdef VERBOSE
John Criswell8d4221e2003-07-23 16:52:50 +0000269LIBTOOL=$(LLVM_SRC_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000270else
John Criswell8d4221e2003-07-23 16:52:50 +0000271LIBTOOL=$(LLVM_SRC_ROOT)/mklib --silent
John Criswell7a73b802003-06-30 21:59:07 +0000272endif
273
274#
John Criswell82f4a5a2003-07-31 20:58:51 +0000275# If we're not building a shared library, use the disable-shared tag with
276# libtool. This will disable the building of objects for shared libraries and
277# only generate static library objects.
278#
279# For dynamic libraries, we'll take the performance hit for now, since we
280# almost never build them.
281#
282# This should speed up compilation and require no modifications to future
283# versions of libtool.
284#
285ifndef SHARED_LIBRARY
286LIBTOOL := $(LIBTOOL) --tag=disable-shared
287endif
288
289#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000290# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000291#
Chris Lattner760da062003-03-14 20:25:22 +0000292ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000293VERB := @
294endif
295
John Criswell7a73b802003-06-30 21:59:07 +0000296###########################################################################
297# Miscellaneous paths and commands (part deux):
298# This section defines various configuration macros, such as where
299# to find burg, tblgen, and libtool.
300###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000301
John Criswell7a73b802003-06-30 21:59:07 +0000302#--------------------------------------------------------------------------
303# Special tools used while building the LLVM tree. Burg is built as part
304# of the utils directory.
305#--------------------------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000306BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000307RunBurg := $(BURG) $(BURG_OPTS)
308
John Criswell8bff5092003-06-11 13:55:44 +0000309TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000310
Chris Lattner00950542001-06-06 20:29:01 +0000311
John Criswell8bff5092003-06-11 13:55:44 +0000312###########################################################################
313# Compile Time Flags
314###########################################################################
315
316#
John Criswell7a73b802003-06-30 21:59:07 +0000317# Include both the project headers and the LLVM headers for compilation and
318# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000319#
320CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000321
Vikram S. Advefeeae582002-09-18 11:55:13 +0000322# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000323ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000324STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000325STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000326endif
327
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000328# Allow gnu extensions...
329CPPFLAGS += -D_GNU_SOURCE
330
Chris Lattnerc7acf812002-01-23 05:46:01 +0000331# -Wno-unused-parameter
John Criswell8bff5092003-06-11 13:55:44 +0000332CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000333CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000334
John Criswell7a73b802003-06-30 21:59:07 +0000335#
336# Compile commands with libtool.
337#
338Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
339CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
340
Chris Lattner172b6482002-09-22 02:47:15 +0000341# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000342CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000343CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
344CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000345
Chris Lattner172b6482002-09-22 02:47:15 +0000346# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000347CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000348CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
349CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000350
John Criswell7a73b802003-06-30 21:59:07 +0000351###########################################################################
352# Link Time Options
353###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000354
John Criswell7a73b802003-06-30 21:59:07 +0000355#
Chris Lattner00950542001-06-06 20:29:01 +0000356# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000357# (Note that we always link with the C++ compiler).
358#
Chris Lattner1917e952002-07-31 21:32:05 +0000359ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1'
John Criswell7a73b802003-06-30 21:59:07 +0000360Link := $(PURIFY) $(LIBTOOL) --mode=link $(CXX) -static
Chris Lattner12604ed2002-04-05 18:56:58 +0000361else
John Criswell7a73b802003-06-30 21:59:07 +0000362Link := $(LIBTOOL) --mode=link $(CXX)
Chris Lattner12604ed2002-04-05 18:56:58 +0000363endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000364
John Criswell7a73b802003-06-30 21:59:07 +0000365# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000366LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
367LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
368LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000369
Chris Lattnere62dbe92002-07-23 17:56:16 +0000370# Create one .o file from a bunch of .o files...
John Criswell82f4a5a2003-07-31 20:58:51 +0000371#ifdef SHARED_LIBRARY
John Criswell7a73b802003-06-30 21:59:07 +0000372Relink = ${LIBTOOL} --mode=link $(CXX)
John Criswell82f4a5a2003-07-31 20:58:51 +0000373#else
374Relink = ${LIBTOOL} --mode=link $(CXX) -only-static
375#endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000376
Chris Lattner4bb13b82002-09-13 22:14:47 +0000377# MakeSO - Create a .so file from a .o files...
John Criswell7a73b802003-06-30 21:59:07 +0000378#MakeSO := $(LIBTOOL) --mode=link $(CXX) $(MakeSharedObjectOption)
379#MakeSOO := $(MakeSO) -O3
380#MakeSOP := $(MakeSOO) $(PROFILE)
381
382#
383# Configure where the item being compiled should go.
384#
385ifdef SHARED_LIBRARY
386Link := $(Link) -rpath $(DESTLIBCURRENT)
387endif
388
389ifdef TOOLNAME
390Link := $(Link) -rpath $(DESTTOOLCURRENT)
391endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000392
Chris Lattner00950542001-06-06 20:29:01 +0000393# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000394Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
395DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000396
397# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000398AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000399
400#----------------------------------------------------------
401
402# Source includes all of the cpp files, and objects are derived from the
403# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000404# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000405#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000406ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000407Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000408endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000409
John Criswell82f4a5a2003-07-31 20:58:51 +0000410#
411# Libtool Objects
412#
John Criswellf4ccd992003-07-01 14:52:28 +0000413Objs := $(sort $(patsubst Debug/%.lo, %.lo, $(addsuffix .lo,$(notdir $(basename $(Source))))))
414ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
415ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
416ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000417
John Criswell82f4a5a2003-07-31 20:58:51 +0000418#
419# The real objects underlying the libtool objects
420#
421RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
422RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
423RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
424RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
425
Chris Lattner00950542001-06-06 20:29:01 +0000426#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000427# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000428#---------------------------------------------------------
429
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000430ifdef DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000431all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000432 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000433 (cd $$dir; $(MAKE) $@) || exit 1; \
434 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000435endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000436
437# Handle PARALLEL_DIRS
438ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000439all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
440install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
441clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
442test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
443bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000444
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000445%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000446 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000447endif
448
John Criswell7a73b802003-06-30 21:59:07 +0000449# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000450ifdef OPTIONAL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000451all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000452 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
453 if [ -d $$dir ]; \
454 then\
455 (cd $$dir; $(MAKE) $@) || exit 1; \
456 fi \
457 done
458endif
459
John Criswell7a73b802003-06-30 21:59:07 +0000460###########################################################################
461# Library Build Rules:
462#
Chris Lattner00950542001-06-06 20:29:01 +0000463#---------------------------------------------------------
464# Handle the LIBRARYNAME option - used when building libs...
465#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000466#
467# When libraries are built, they are allowed to optionally define the
468# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
469# from being built for the library. This .o files may then be linked to by a
470# tool if the tool does not need (or want) the semantics a .a file provides
471# (linking in only object files that are "needed"). If a library is never to
472# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
473# BUILD_ARCHIVE instead.
474#
475# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000476# it's built as a .o file, then all of the constituent .o files in it will be
Chris Lattnere62dbe92002-07-23 17:56:16 +0000477# linked into tools (for example gccas) even if they only use one of the parts
478# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000479###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000480
481ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000482
Chris Lattner2a548c52002-09-16 22:36:42 +0000483# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000484LIBRARYNAME := $(strip $(LIBRARYNAME))
485
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000486LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
487LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
488LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
489LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
490LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
491LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
492LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
493LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
494LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner00950542001-06-06 20:29:01 +0000495
John Criswell7a73b802003-06-30 21:59:07 +0000496#--------------------------------------------------------------------
497# Library Targets
498# Modify the top level targets to build the desired libraries.
499#--------------------------------------------------------------------
500
Chris Lattner760da062003-03-14 20:25:22 +0000501# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000502dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Vikram S. Adve60f56062002-08-02 18:34:12 +0000503
Chris Lattner760da062003-03-14 20:25:22 +0000504# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000505ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000506all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000507endif
Chris Lattner760da062003-03-14 20:25:22 +0000508
509# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000510ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000511all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000512endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000513
John Criswell7a73b802003-06-30 21:59:07 +0000514#--------------------------------------------------------------------
515# Rules for building libraries
516#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000517
John Criswell7a73b802003-06-30 21:59:07 +0000518#
519# Rules for building dynamically linked libraries.
520#
John Criswellf4ccd992003-07-01 14:52:28 +0000521$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000522 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000523 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000524 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve41e78912002-09-20 14:03:13 +0000525
John Criswellf4ccd992003-07-01 14:52:28 +0000526$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000527 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000528 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000529 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner00950542001-06-06 20:29:01 +0000530
John Criswellf4ccd992003-07-01 14:52:28 +0000531$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000532 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000533 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000534 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000535
John Criswell7a73b802003-06-30 21:59:07 +0000536#
537# Rules for building static archive libraries.
538#
John Criswellf4ccd992003-07-01 14:52:28 +0000539$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000540 @echo ======= Linking $(LIBRARYNAME) archive release library =======
541 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000542 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000543
John Criswellf4ccd992003-07-01 14:52:28 +0000544$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000545 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
546 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000547 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000548
John Criswellf4ccd992003-07-01 14:52:28 +0000549$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000550 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
551 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000552 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000553
554#
555# Rules for building .o libraries.
556#
John Criswell82f4a5a2003-07-31 20:58:51 +0000557# JTC:
558# Note that for this special case, we specify the actual object files
559# instead of their libtool counterparts. This is because libtool
560# doesn't want to generate a reloadable object file unless it is given
561# .o files explicitly.
562#
563# Note that we're making an assumption here: If we build a .lo file,
564# it's corresponding .o file will be placed in the same directory.
565#
566# I think that is safe.
567#
John Criswellf4ccd992003-07-01 14:52:28 +0000568$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000569 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000570 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000571
John Criswellf4ccd992003-07-01 14:52:28 +0000572$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000573 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000574 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000575
John Criswellf4ccd992003-07-01 14:52:28 +0000576$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000577 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000578 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000579
Chris Lattner00950542001-06-06 20:29:01 +0000580endif
581
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000582#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000583# Create a TAGS database for emacs
584#------------------------------------------------------------------------
585
John Criswell7a73b802003-06-30 21:59:07 +0000586ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000587ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000588tags:
John Criswell7a73b802003-06-30 21:59:07 +0000589 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000590all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000591endif
John Criswell7a73b802003-06-30 21:59:07 +0000592else
593tags:
594 ${ECHO} "Cannot build $@: The program etags is not installed"
595endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000596
597#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000598# Handle the TOOLNAME option - used when building tool executables...
599#------------------------------------------------------------------------
600#
601# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000602# libraries (and the order of the libs) that should be linked to the
603# tool. USEDLIBS should contain a list of library names (some with .a extension)
604# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000605#
606ifdef TOOLNAME
607
608# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000609TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
610TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
611TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
612TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000613
614# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000615PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
616PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
617PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
618PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
619
620LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
621LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
622LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
623LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
624
625LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000626LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000627LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
628
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000629# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000630# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000631# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000632#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000633STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000634USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
635USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
636USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
John Criswell7a73b802003-06-30 21:59:07 +0000637#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000638
John Criswell7a73b802003-06-30 21:59:07 +0000639#
640# Libtool link options:
641# Ensure that all binaries have their symbols exported so that they can
642# by dlsym'ed.
643#
644LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000645
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000646
647
648
649
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000650# Tell make that we need to rebuild subdirectories before we can link the tool.
651# This affects things like LLI which has library subdirectories.
652$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
653 $(addsuffix /.makeall, $(PARALLEL_DIRS))
654
Chris Lattner669bd7c2001-10-13 05:10:29 +0000655all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000656
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000657clean::
John Criswell7a73b802003-06-30 21:59:07 +0000658 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000659
John Criswellf4ccd992003-07-01 14:52:28 +0000660$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000661 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000662 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000663
John Criswellf4ccd992003-07-01 14:52:28 +0000664$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000665 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000666 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000667
John Criswellf4ccd992003-07-01 14:52:28 +0000668$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000669 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000670 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000671
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000672endif
673
674
Chris Lattner00950542001-06-06 20:29:01 +0000675
676#---------------------------------------------------------
John Criswell8bff5092003-06-11 13:55:44 +0000677.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir
678.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000679
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000680# Create .o files in the ObjectFiles directory from the .cpp and .c files...
John Criswell7a73b802003-06-30 21:59:07 +0000681#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
682 #@echo "Compiling $<"
683 #$(VERB) $(CompileO) $< -o $@
684
685#$(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
686 #$(VERB) $(CompileCO) $< -o $@
687
688#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
689 #@echo "Compiling $<"
690 #$(VERB) $(CompileP) $< -o $@
691
692#$(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
693 #@echo "Compiling $<"
694 #$(VERB) $(CompileCP) $< -o $@
695
696#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
697 #@echo "Compiling $<"
698 #$(VERB) $(CompileG) $< -o $@
699
700#$(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
701 #$(VERB) $(CompileCG) $< -o $@
702
703# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
704$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000705 @echo "Compiling $<"
706 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000707
John Criswell7a73b802003-06-30 21:59:07 +0000708$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
709 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000710 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000711
John Criswell7a73b802003-06-30 21:59:07 +0000712$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000713 @echo "Compiling $<"
714 $(VERB) $(CompileP) $< -o $@
715
John Criswell7a73b802003-06-30 21:59:07 +0000716$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000717 @echo "Compiling $<"
718 $(VERB) $(CompileCP) $< -o $@
719
John Criswell7a73b802003-06-30 21:59:07 +0000720$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000721 @echo "Compiling $<"
722 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000723
John Criswell7a73b802003-06-30 21:59:07 +0000724$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
725 @echo "Compiling $<"
726 $(VERB) $(CompileCG) $< -o $@
727
728# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
729$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
730 @echo "Compiling $<"
731 $(VERB) $(CompileO) $< -o $@
732
733$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
734 $(VERB) $(CompileCO) $< -o $@
735
736$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
737 @echo "Compiling $<"
738 $(VERB) $(CompileP) $< -o $@
739
740$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
741 @echo "Compiling $<"
742 $(VERB) $(CompileCP) $< -o $@
743
744$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
745 @echo "Compiling $<"
746 $(VERB) $(CompileG) $< -o $@
747
748$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000749 $(VERB) $(CompileCG) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000750
Chris Lattnere8996782003-01-16 22:44:19 +0000751#
752# Rules for building lex/yacc files
753#
754LEX_FILES = $(filter %.l, $(Source))
755LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
756YACC_FILES = $(filter %.y, $(Source))
757YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
758.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
759
Chris Lattner00950542001-06-06 20:29:01 +0000760# Create a .cpp source file from a flex input file... this uses sed to cut down
761# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000762#
763# The last line is a gross hack to work around flex aparently not being able to
764# resize the buffer on a large token input. Currently, for uninitialized string
765# buffers in LLVM we can generate very long tokens, so this is a hack around it.
766# FIXME. (f.e. char Buffer[10000]; )
767#
Chris Lattner00950542001-06-06 20:29:01 +0000768%.cpp: %.l
John Criswell7a73b802003-06-30 21:59:07 +0000769 $(FLEX) -t $< | $(SED) '/^find_rule/d' | \
770 $(SED) 's/void yyunput/inline void yyunput/' | \
771 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
772 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@
Chris Lattner00950542001-06-06 20:29:01 +0000773
774# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000775%.c: %.y # Cancel built-in rules for yacc
776%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000777%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000778 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000779 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswell7a73b802003-06-30 21:59:07 +0000780 $(VERB) ${MV} -f $*.tab.c $*.cpp
781 $(VERB) ${MV} -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000782
783# To create the directories...
784%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000785 $(VERB) ${MKDIR} $* > /dev/null
786 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000787
Chris Lattner30440c62003-01-16 21:06:18 +0000788# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000789ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000790%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000791 ${DOT} -Tps < $< > $@
792else
793%.ps: %.dot
794 ${ECHO} "Cannot build $@: The program dot is not installed"
795endif
Chris Lattner30440c62003-01-16 21:06:18 +0000796
Chris Lattner172b6482002-09-22 02:47:15 +0000797# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000798clean::
John Criswell7a73b802003-06-30 21:59:07 +0000799 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
800 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
801 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
802
803distclean:: clean
804 $(VERB) (cd $(LLVM_SRC_ROOT); $(RM) -rf $(LEVEL)/Makefile.config \
805 $(LEVEL)/include/Config/config.h \
806 $(LEVEL)/autom4te.cache \
807 $(LEVEL)/config.log)
808
809###########################################################################
810# C/C++ Dependencies
811# Define variables and rules that generate header file dependencies
812# from C/C++ source files.
813###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000814
Chris Lattner694c5df2003-05-15 21:28:55 +0000815# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000816# include the dependancies now...
817#
Chris Lattner694c5df2003-05-15 21:28:55 +0000818SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000819SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000820
821# Create dependencies for the *.cpp files...
822#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000823$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000824 $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000825
826# Create dependencies for the *.c files...
827#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000828$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000829 $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000830
John Criswell7a73b802003-06-30 21:59:07 +0000831#
832# Include dependencies generated from C/C++ source files, but not if we
833# are cleaning (this example taken from the GNU Make Manual).
834#
835ifneq ($(MAKECMDGOALS),clean)
Chris Lattner00950542001-06-06 20:29:01 +0000836ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000837-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000838endif
John Criswell7a73b802003-06-30 21:59:07 +0000839endif