blob: 915cd8a3f4a51ab5d4e31d3cfd4a3cd03e5d6b17 [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
Chris Lattner481cc7c2003-08-15 02:18:35 +0000122LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000123endif
124
125#
126# Set the LLVM object directory.
127#
128ifndef LLVM_OBJ_ROOT
Chris Lattner481cc7c2003-08-15 02:18:35 +0000129LLVM_OBJ_ROOT := $(BUILD_OBJ_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000130endif
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 Lattner95cc1b32003-08-14 21:10:25 +0000143ifdef BYTECODE_LIBRARY
144# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
145all:: bytecodelib
Chris Lattner481cc7c2003-08-15 02:18:35 +0000146install:: bytecodelib-install
Chris Lattner95cc1b32003-08-14 21:10:25 +0000147endif
148
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000149# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000150all ::
151
152# Default for install is to at least build everything...
153install ::
154
John Criswell8bff5092003-06-11 13:55:44 +0000155# Default rule for test. It ensures everything has a test rule
156test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000157
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000158# Default rule for building only bytecode.
159bytecode::
160
John Criswell7a73b802003-06-30 21:59:07 +0000161# Print out the directories used for building
162prdirs::
163 echo "Home Offset : " $(HOME_OBJ_ROOT);
164 echo "Build Source Root: " $(BUILD_SRC_ROOT);
165 echo "Build Source Dir : " $(BUILD_SRC_DIR);
166 echo "Build Object Root: " $(BUILD_OBJ_ROOT);
167 echo "Build Object Dir : " $(BUILD_OBJ_DIR);
168 echo "LLVM Source Root: " $(LLVM_SRC_ROOT);
169 echo "LLVM Object Root: " $(LLVM_OBJ_ROOT);
170
John Criswell96914392003-07-16 20:26:06 +0000171#
172# Mark all of these targets as phony. This will hopefully speed up builds
173# slightly since GNU Make will not try to find implicit rules for targets
174# which are marked as Phony.
175#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000176.PHONY: all dynamic bytecodelib bytecodelib-install
177.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000178
John Criswell7a73b802003-06-30 21:59:07 +0000179###########################################################################
180# Miscellaneous paths and commands:
181# This section defines various configuration macros, such as where
182# to find burg, tblgen, and libtool.
183###########################################################################
184
Chris Lattner00950542001-06-06 20:29:01 +0000185#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000186# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000187#--------------------------------------------------------------------
188
189#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000190#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000191#DocInstDir=/usr/doc/xxx
192
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000193BURG_OPTS = -I
194
Chris Lattner760da062003-03-14 20:25:22 +0000195ifdef ENABLE_PROFILING
196 ENABLE_OPTIMIZED = 1
197 CONFIGURATION := Profile
198else
199 ifdef ENABLE_OPTIMIZED
200 CONFIGURATION := Release
201 else
202 CONFIGURATION := Debug
203 endif
204endif
205
John Criswell7a73b802003-06-30 21:59:07 +0000206#
207# Enable this for profiling support with 'gprof'
208# This automatically enables optimized builds.
209#
210ifdef ENABLE_PROFILING
211 PROFILE = -pg
212endif
213
214#
215# Suffixes for library compilation rules
216#
217.SUFFIXES: .so
218
John Criswell8bff5092003-06-11 13:55:44 +0000219###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000220# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000221# These variables describe various library locations:
222#
223# DEST* = Location of where libraries that are built will be placed.
224# LLVM* = Location of LLVM libraries used for linking.
225# PROJ* = Location of previously built libraries used for linking.
226###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000227
John Criswell8bff5092003-06-11 13:55:44 +0000228# Libraries that are being built
229DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
230DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
231DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattner481cc7c2003-08-15 02:18:35 +0000232DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
John Criswell8bff5092003-06-11 13:55:44 +0000233DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000234
John Criswell8bff5092003-06-11 13:55:44 +0000235# LLVM libraries used for linking
236LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
237LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
238LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
239LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000240
John Criswell8bff5092003-06-11 13:55:44 +0000241# Libraries that were built that will now be used for linking
242PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
243PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
244PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
245PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000246
John Criswell8bff5092003-06-11 13:55:44 +0000247###########################################################################
248# Tool Locations
249# These variables describe various tool locations:
250#
251# DEST* = Location of where tools that are built will be placed.
252# LLVM* = Location of LLVM tools used for building.
253# PROJ* = Location of previously built tools used for linking.
254###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000255
John Criswell8bff5092003-06-11 13:55:44 +0000256DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
257DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
258DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
259DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
260
261LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
262LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
263LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
264LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
265
266PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
267PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
268PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
269PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000270
John Criswell7a73b802003-06-30 21:59:07 +0000271#
272# Libtool is found in the current directory.
273#
Chris Lattner95cc1b32003-08-14 21:10:25 +0000274LIBTOOL := $(LLVM_SRC_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000275
276#
John Criswell82f4a5a2003-07-31 20:58:51 +0000277# If we're not building a shared library, use the disable-shared tag with
278# libtool. This will disable the building of objects for shared libraries and
279# only generate static library objects.
280#
281# For dynamic libraries, we'll take the performance hit for now, since we
282# almost never build them.
283#
284# This should speed up compilation and require no modifications to future
285# versions of libtool.
286#
287ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000288LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000289endif
290
291#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000292# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000293#
Chris Lattner760da062003-03-14 20:25:22 +0000294ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000295VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000296LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000297endif
298
John Criswell7a73b802003-06-30 21:59:07 +0000299###########################################################################
300# Miscellaneous paths and commands (part deux):
301# This section defines various configuration macros, such as where
302# to find burg, tblgen, and libtool.
303###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000304
John Criswell7a73b802003-06-30 21:59:07 +0000305#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000306# Utilities used while building the LLVM tree, which live in the utils dir
307#
John Criswell8bff5092003-06-11 13:55:44 +0000308BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000309RunBurg := $(BURG) $(BURG_OPTS)
John Criswell8bff5092003-06-11 13:55:44 +0000310TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000311
Chris Lattner481cc7c2003-08-15 02:18:35 +0000312#--------------------------------------------------------------------------
313# The LLVM GCC front-end in C and C++ flavors
314#
315LLVMGCC := $(LLVMGCCDIR)/bin/gcc
316LCC1 := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1
317LLVMGXX := $(LLVMGCCDIR)/bin/g++
318LCC1XX := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1plus
319
320#--------------------------------------------------------------------------
321# Some of the compiled LLVM tools which are used for compilation of runtime
322# libraries.
323#
324LLVMAS := $(LLVMTOOLCURRENT)/as
325
Chris Lattner00950542001-06-06 20:29:01 +0000326
John Criswell8bff5092003-06-11 13:55:44 +0000327###########################################################################
328# Compile Time Flags
329###########################################################################
330
331#
John Criswell7a73b802003-06-30 21:59:07 +0000332# Include both the project headers and the LLVM headers for compilation and
333# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000334#
335CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000336
Vikram S. Advefeeae582002-09-18 11:55:13 +0000337# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000338ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000339STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000340STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000341endif
342
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000343# Allow gnu extensions...
344CPPFLAGS += -D_GNU_SOURCE
345
John Criswell8bff5092003-06-11 13:55:44 +0000346CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000347CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000348
John Criswell7a73b802003-06-30 21:59:07 +0000349#
350# Compile commands with libtool.
351#
352Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
353CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
354
Chris Lattner172b6482002-09-22 02:47:15 +0000355# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000356CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000357CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
358CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000359
Chris Lattner172b6482002-09-22 02:47:15 +0000360# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000361CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000362CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
363CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000364
John Criswell7a73b802003-06-30 21:59:07 +0000365###########################################################################
366# Link Time Options
367###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000368
John Criswell7a73b802003-06-30 21:59:07 +0000369#
Chris Lattner00950542001-06-06 20:29:01 +0000370# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000371# (Note that we always link with the C++ compiler).
372#
John Criswell7a73b802003-06-30 21:59:07 +0000373Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000374
John Criswell7a73b802003-06-30 21:59:07 +0000375# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000376LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
377LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
378LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000379
Chris Lattnere62dbe92002-07-23 17:56:16 +0000380# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000381Relink := ${LIBTOOL} --mode=link $(CXX)
382ifndef SHARED_LIBRARY
383Relink += -only-static
384endif
John Criswell7a73b802003-06-30 21:59:07 +0000385
386#
387# Configure where the item being compiled should go.
388#
389ifdef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000390Link += -rpath $(DESTLIBCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000391endif
392
393ifdef TOOLNAME
Chris Lattner95cc1b32003-08-14 21:10:25 +0000394Link += -rpath $(DESTTOOLCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000395endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000396
Chris Lattner00950542001-06-06 20:29:01 +0000397# Create dependancy file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000398Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
399DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000400
401# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000402AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000403
404#----------------------------------------------------------
405
406# Source includes all of the cpp files, and objects are derived from the
407# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000408# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000409#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000410ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000411Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000412endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000413
John Criswell82f4a5a2003-07-31 20:58:51 +0000414#
415# Libtool Objects
416#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000417Srcs := $(sort $(notdir $(basename $(Source))))
418Objs := $(addsuffix .lo, $(Srcs))
John Criswellf4ccd992003-07-01 14:52:28 +0000419ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
420ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
421ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner481cc7c2003-08-15 02:18:35 +0000422ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/Bytecode/,$(addsuffix .bc, $(Srcs)))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000423
John Criswell82f4a5a2003-07-31 20:58:51 +0000424#
425# The real objects underlying the libtool objects
426#
427RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
428RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
429RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
430RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
431
Chris Lattner00950542001-06-06 20:29:01 +0000432#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000433# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000434#---------------------------------------------------------
435
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000436ifdef DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000437all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000438 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000439 (cd $$dir; $(MAKE) $@) || exit 1; \
440 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000441endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000442
443# Handle PARALLEL_DIRS
444ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000445all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
446install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
447clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
448test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
449bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000450
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000451%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000452 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000453endif
454
John Criswell7a73b802003-06-30 21:59:07 +0000455# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000456ifdef OPTIONAL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000457all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000458 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
459 if [ -d $$dir ]; \
460 then\
461 (cd $$dir; $(MAKE) $@) || exit 1; \
462 fi \
463 done
464endif
465
John Criswell7a73b802003-06-30 21:59:07 +0000466###########################################################################
467# Library Build Rules:
468#
Chris Lattner00950542001-06-06 20:29:01 +0000469#---------------------------------------------------------
470# Handle the LIBRARYNAME option - used when building libs...
471#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000472#
473# When libraries are built, they are allowed to optionally define the
474# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
475# from being built for the library. This .o files may then be linked to by a
476# tool if the tool does not need (or want) the semantics a .a file provides
477# (linking in only object files that are "needed"). If a library is never to
478# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
479# BUILD_ARCHIVE instead.
480#
481# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000482# 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 +0000483# linked into tools (for example gccas) even if they only use one of the parts
484# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000485###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000486
487ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000488
Chris Lattner2a548c52002-09-16 22:36:42 +0000489# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000490LIBRARYNAME := $(strip $(LIBRARYNAME))
491
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000492LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
493LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
494LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
495LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
496LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
497LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
498LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
499LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
500LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner481cc7c2003-08-15 02:18:35 +0000501LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner00950542001-06-06 20:29:01 +0000502
John Criswell7a73b802003-06-30 21:59:07 +0000503#--------------------------------------------------------------------
504# Library Targets
505# Modify the top level targets to build the desired libraries.
506#--------------------------------------------------------------------
507
Chris Lattner760da062003-03-14 20:25:22 +0000508# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000509dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Chris Lattner481cc7c2003-08-15 02:18:35 +0000510bytecodelib:: $(LIBNAME_BC)
511bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
512
513$(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
514 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
515 cp $< $@
Vikram S. Adve60f56062002-08-02 18:34:12 +0000516
Chris Lattner760da062003-03-14 20:25:22 +0000517# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000518ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000519all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000520endif
Chris Lattner760da062003-03-14 20:25:22 +0000521
522# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000523ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000524all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000525endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000526
John Criswell7a73b802003-06-30 21:59:07 +0000527#--------------------------------------------------------------------
528# Rules for building libraries
529#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000530
Chris Lattner481cc7c2003-08-15 02:18:35 +0000531LinkBCLib := $(LLVMGCC) -shared
532ifdef EXPORTED_SYMBOL_LIST
533LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
534else
535LinkBCLib += -Xlinker -disable-internalize
536endif
537
538
539# Rule for building bytecode libraries.
540$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs)
541 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
542 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000543#
544# Rules for building dynamically linked libraries.
545#
John Criswellf4ccd992003-07-01 14:52:28 +0000546$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000547 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000548 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000549 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve41e78912002-09-20 14:03:13 +0000550
John Criswellf4ccd992003-07-01 14:52:28 +0000551$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000552 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000553 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000554 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Chris Lattner00950542001-06-06 20:29:01 +0000555
John Criswellf4ccd992003-07-01 14:52:28 +0000556$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000557 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
John Criswellf4ccd992003-07-01 14:52:28 +0000558 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts);
John Criswell7a73b802003-06-30 21:59:07 +0000559 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT);
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000560
John Criswell7a73b802003-06-30 21:59:07 +0000561#
562# Rules for building static archive libraries.
563#
John Criswellf4ccd992003-07-01 14:52:28 +0000564$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000565 @echo ======= Linking $(LIBRARYNAME) archive release library =======
566 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000567 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000568
John Criswellf4ccd992003-07-01 14:52:28 +0000569$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000570 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
571 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000572 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000573
John Criswellf4ccd992003-07-01 14:52:28 +0000574$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000575 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
576 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000577 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000578
Chris Lattner481cc7c2003-08-15 02:18:35 +0000579
John Criswell7a73b802003-06-30 21:59:07 +0000580#
581# Rules for building .o libraries.
582#
John Criswell82f4a5a2003-07-31 20:58:51 +0000583# JTC:
584# Note that for this special case, we specify the actual object files
585# instead of their libtool counterparts. This is because libtool
586# doesn't want to generate a reloadable object file unless it is given
587# .o files explicitly.
588#
589# Note that we're making an assumption here: If we build a .lo file,
590# it's corresponding .o file will be placed in the same directory.
591#
592# I think that is safe.
593#
John Criswellf4ccd992003-07-01 14:52:28 +0000594$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000595 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000596 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000597
John Criswellf4ccd992003-07-01 14:52:28 +0000598$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000599 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000600 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000601
John Criswellf4ccd992003-07-01 14:52:28 +0000602$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000603 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000604 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000605
Chris Lattner00950542001-06-06 20:29:01 +0000606endif
607
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000608#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000609# Create a TAGS database for emacs
610#------------------------------------------------------------------------
611
John Criswell7a73b802003-06-30 21:59:07 +0000612ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000613ifeq ($(LEVEL), .)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000614tags:
John Criswell7a73b802003-06-30 21:59:07 +0000615 $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000616all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000617endif
John Criswell7a73b802003-06-30 21:59:07 +0000618else
619tags:
620 ${ECHO} "Cannot build $@: The program etags is not installed"
621endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000622
623#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000624# Handle the TOOLNAME option - used when building tool executables...
625#------------------------------------------------------------------------
626#
627# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000628# libraries (and the order of the libs) that should be linked to the
629# tool. USEDLIBS should contain a list of library names (some with .a extension)
630# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000631#
632ifdef TOOLNAME
633
634# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000635TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
636TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
637TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
638TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000639
640# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000641PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
642PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
643PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
644PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
645
646LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
647LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
648LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
649LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
650
651LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000652LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000653LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
654
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000655# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000656# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000657# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000658#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000659STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000660USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
661USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
662USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
John Criswell7a73b802003-06-30 21:59:07 +0000663#LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000664
John Criswell7a73b802003-06-30 21:59:07 +0000665#
666# Libtool link options:
667# Ensure that all binaries have their symbols exported so that they can
668# by dlsym'ed.
669#
670LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000671
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000672
673
674
675
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000676# Tell make that we need to rebuild subdirectories before we can link the tool.
677# This affects things like LLI which has library subdirectories.
678$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
679 $(addsuffix /.makeall, $(PARALLEL_DIRS))
680
Chris Lattner669bd7c2001-10-13 05:10:29 +0000681all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000682
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000683clean::
John Criswell7a73b802003-06-30 21:59:07 +0000684 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000685
John Criswellf4ccd992003-07-01 14:52:28 +0000686$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000687 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000688 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000689
John Criswellf4ccd992003-07-01 14:52:28 +0000690$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000691 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000692 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000693
John Criswellf4ccd992003-07-01 14:52:28 +0000694$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000695 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000696 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000697
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000698endif
699
700
Chris Lattner00950542001-06-06 20:29:01 +0000701
702#---------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000703.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000704.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000705
John Criswell7a73b802003-06-30 21:59:07 +0000706# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
707$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000708 @echo "Compiling $<"
709 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000710
John Criswell7a73b802003-06-30 21:59:07 +0000711$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
712 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000713 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000714
John Criswell7a73b802003-06-30 21:59:07 +0000715$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000716 @echo "Compiling $<"
717 $(VERB) $(CompileP) $< -o $@
718
John Criswell7a73b802003-06-30 21:59:07 +0000719$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000720 @echo "Compiling $<"
721 $(VERB) $(CompileCP) $< -o $@
722
John Criswell7a73b802003-06-30 21:59:07 +0000723$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000724 @echo "Compiling $<"
725 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000726
John Criswell7a73b802003-06-30 21:59:07 +0000727$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
728 @echo "Compiling $<"
729 $(VERB) $(CompileCG) $< -o $@
730
Chris Lattner481cc7c2003-08-15 02:18:35 +0000731$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
732 @echo "Compiling $< to bytecode"
733 $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
734
735$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
736 @echo "Compiling $< to bytecode"
737 $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
738
739$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
740 @echo "Compiling $< to bytecode"
741 $(VERB) $(LLVMAS) $< -f -o $@
742
743
Chris Lattnere8996782003-01-16 22:44:19 +0000744#
745# Rules for building lex/yacc files
746#
747LEX_FILES = $(filter %.l, $(Source))
748LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
749YACC_FILES = $(filter %.y, $(Source))
750YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
751.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
752
Chris Lattner00950542001-06-06 20:29:01 +0000753# Create a .cpp source file from a flex input file... this uses sed to cut down
754# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000755#
756# The last line is a gross hack to work around flex aparently not being able to
757# resize the buffer on a large token input. Currently, for uninitialized string
758# buffers in LLVM we can generate very long tokens, so this is a hack around it.
759# FIXME. (f.e. char Buffer[10000]; )
760#
Chris Lattner00950542001-06-06 20:29:01 +0000761%.cpp: %.l
Chris Lattnera328f882003-08-04 19:47:06 +0000762 @echo Flex\'ing $<...
Chris Lattner7bb107d2003-08-04 19:48:10 +0000763 $(VERB) $(FLEX) -t $< | \
764 $(SED) '/^find_rule/d' | \
765 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000766 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000767 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
768 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000769 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000770 @# remove the output of flex if it didn't get moved over...
771 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000772
773# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000774%.c: %.y # Cancel built-in rules for yacc
775%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000776%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000777 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000778 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswelld741bcf2003-08-12 18:51:51 +0000779 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
780 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000781 @# If the files were not updated, don't leave them lying around...
782 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000783
784# To create the directories...
785%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000786 $(VERB) ${MKDIR} $* > /dev/null
787 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000788
Chris Lattner30440c62003-01-16 21:06:18 +0000789# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000790ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000791%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000792 ${DOT} -Tps < $< > $@
793else
794%.ps: %.dot
795 ${ECHO} "Cannot build $@: The program dot is not installed"
796endif
Chris Lattner30440c62003-01-16 21:06:18 +0000797
Chris Lattner172b6482002-09-22 02:47:15 +0000798# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000799clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000800 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
801 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
802 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
John Criswell7a73b802003-06-30 21:59:07 +0000803 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
804 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
805
John Criswell7a73b802003-06-30 21:59:07 +0000806###########################################################################
807# C/C++ Dependencies
808# Define variables and rules that generate header file dependencies
809# from C/C++ source files.
810###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000811
Chris Lattner694c5df2003-05-15 21:28:55 +0000812# If dependencies were generated for the file that included this file,
Chris Lattner00950542001-06-06 20:29:01 +0000813# include the dependancies now...
814#
Chris Lattner694c5df2003-05-15 21:28:55 +0000815SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000816SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000817
818# Create dependencies for the *.cpp files...
819#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000820$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000821 $(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 +0000822
823# Create dependencies for the *.c files...
824#$(SourceDepend): \x
John Criswell8bff5092003-06-11 13:55:44 +0000825$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000826 $(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 +0000827
John Criswell7a73b802003-06-30 21:59:07 +0000828#
829# Include dependencies generated from C/C++ source files, but not if we
830# are cleaning (this example taken from the GNU Make Manual).
831#
832ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000833ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner00950542001-06-06 20:29:01 +0000834ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000835-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000836endif
John Criswell7a73b802003-06-30 21:59:07 +0000837endif
John Criswelld741bcf2003-08-12 18:51:51 +0000838endif