blob: 7b6c9867d8f1aaf8b49dc14c185922394e0bda2e [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
Misha Brukman36bc6422003-08-21 22:02:18 +00004# rules to do things like compile a .cpp file or generate dependency info.
5# These are platform dependent, so this is the file used to specify these
6# system dependent operations.
Chris Lattner00950542001-06-06 20:29:01 +00007#
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# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
36# and usually the source code too (unless SourceDir is set).
37#
38# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
39#
40# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
41#
42# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
43# placed.
44#
45# For building,
Chris Lattnere430a1e2003-08-21 22:23:49 +000046# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
Chris Lattneraf06a082003-08-15 03:02:52 +000047#
Vikram S. Adved60aede2002-07-09 12:04:21 +000048#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000049
John Criswell2a6530f2003-06-27 16:58:44 +000050#
Vikram S. Advec214e712002-08-29 23:28:46 +000051# Configuration file to set paths specific to local installation of LLVM
52#
Chris Lattner56e4fa42003-08-21 22:28:46 +000053ifdef LLVM_SRC_ROOT
54include $(LLVM_SRC_ROOT)/Makefile.config
55else
Vikram S. Advec214e712002-08-29 23:28:46 +000056include $(LEVEL)/Makefile.config
Chris Lattner56e4fa42003-08-21 22:28:46 +000057endif
Vikram S. Advec214e712002-08-29 23:28:46 +000058
John Criswell8bff5092003-06-11 13:55:44 +000059###########################################################################
60# Directory Configuration
61# This section of the Makefile determines what is where. To be
62# specific, there are several locations that need to be defined:
63#
64# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
65# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
66#
67# o BUILD_SRC_DIR : The directory containing the code to build.
68# o BUILD_SRC_ROOT : The root directory of the code to build.
69#
70# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
71# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
72#
73###########################################################################
74
75#
76# Set the source build directory. That is almost always the current directory.
77#
78ifndef BUILD_SRC_DIR
79BUILD_SRC_DIR = $(shell pwd)
80endif
81
82#
83# Set the source root directory.
84#
85ifndef BUILD_SRC_ROOT
John Criswell890d5bd2003-06-16 19:14:31 +000086BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell8bff5092003-06-11 13:55:44 +000087endif
88
89#
John Criswell7a73b802003-06-30 21:59:07 +000090# Determine the path of the source tree relative from $HOME (the mythical
91# home directory).
92#
Misha Brukmanf8873ed2003-07-07 22:27:05 +000093HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
John Criswell7a73b802003-06-30 21:59:07 +000094
95#
John Criswell8bff5092003-06-11 13:55:44 +000096# Set the object build directory. Its location depends upon the source path
97# and where object files should go.
98#
99ifndef BUILD_OBJ_DIR
100ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000101BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +0000102else
John Criswell7a73b802003-06-30 21:59:07 +0000103BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
John Criswell8bff5092003-06-11 13:55:44 +0000104endif
105endif
106
107#
108# Set the root of the object directory.
109#
110ifndef BUILD_OBJ_ROOT
111ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000112BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000113else
John Criswell7a73b802003-06-30 21:59:07 +0000114BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000115endif
116endif
117
118#
Chris Lattnerf0f463e2003-08-22 05:18:49 +0000119# Set the LLVM object directory.
120#
121ifndef LLVM_OBJ_ROOT
122ifdef LLVM_SRC_ROOT
123LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_DIR); cd $(LLVM_SRC_ROOT); pwd)
124else
Chris Lattner7d4d8922003-08-22 05:22:13 +0000125LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_ROOT); pwd)
Chris Lattnerf0f463e2003-08-22 05:18:49 +0000126endif
127endif
128
129#
John Criswell8bff5092003-06-11 13:55:44 +0000130# Set the LLVM source directory.
131# It is typically the root directory of what we're compiling now.
132#
133ifndef LLVM_SRC_ROOT
Chris Lattner481cc7c2003-08-15 02:18:35 +0000134LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000135endif
136
John Criswell7a73b802003-06-30 21:59:07 +0000137###########################################################################
138# Default Targets:
139# The following targets are the standard top level targets for
140# building.
141###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +0000142
Chris Lattneredf1f232002-07-23 19:21:31 +0000143ifdef SHARED_LIBRARY
144# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +0000145all:: dynamic
Chris Lattneredf1f232002-07-23 19:21:31 +0000146endif
147
Chris Lattner95cc1b32003-08-14 21:10:25 +0000148ifdef BYTECODE_LIBRARY
149# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
150all:: bytecodelib
Chris Lattner481cc7c2003-08-15 02:18:35 +0000151install:: bytecodelib-install
Chris Lattner95cc1b32003-08-14 21:10:25 +0000152endif
153
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000154# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000155all ::
156
157# Default for install is to at least build everything...
158install ::
159
John Criswell8bff5092003-06-11 13:55:44 +0000160# Default rule for test. It ensures everything has a test rule
161test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000162
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000163# Default rule for building only bytecode.
164bytecode::
165
John Criswell7a73b802003-06-30 21:59:07 +0000166# Print out the directories used for building
167prdirs::
Chris Lattnere430a1e2003-08-21 22:23:49 +0000168 @echo "Home Offset : " $(HOME_OBJ_ROOT)
169 @echo "Build Source Root: " $(BUILD_SRC_ROOT)
170 @echo "Build Source Dir : " $(BUILD_SRC_DIR)
171 @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
172 @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
173 @echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
174 @echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell7a73b802003-06-30 21:59:07 +0000175
John Criswell9621a2b2003-08-20 15:18:41 +0000176###########################################################################
177# Suffixes and implicit rules:
178# Empty out the list of suffixes, generate a list that is only
179# used by this Makefile, and cancel useless implicit rules. This
180# will hopefully speed up compilation a little bit.
181###########################################################################
182.SUFFIXES:
183.SUFFIXES: .c .cpp .h .hpp .y .l
184.SUFFIXES: .lo .o .a .so .bc
185.SUFFIXES: .ps .dot .d
186
John Criswell96914392003-07-16 20:26:06 +0000187#
188# Mark all of these targets as phony. This will hopefully speed up builds
189# slightly since GNU Make will not try to find implicit rules for targets
190# which are marked as Phony.
191#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000192.PHONY: all dynamic bytecodelib bytecodelib-install
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000193.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000194
John Criswell7a73b802003-06-30 21:59:07 +0000195###########################################################################
196# Miscellaneous paths and commands:
197# This section defines various configuration macros, such as where
198# to find burg, tblgen, and libtool.
199###########################################################################
200
Chris Lattner00950542001-06-06 20:29:01 +0000201#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000202# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000203#--------------------------------------------------------------------
204
205#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000206#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000207#DocInstDir=/usr/doc/xxx
208
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000209BURG_OPTS = -I
210
Chris Lattner760da062003-03-14 20:25:22 +0000211ifdef ENABLE_PROFILING
212 ENABLE_OPTIMIZED = 1
213 CONFIGURATION := Profile
214else
215 ifdef ENABLE_OPTIMIZED
216 CONFIGURATION := Release
217 else
218 CONFIGURATION := Debug
219 endif
220endif
221
John Criswell7a73b802003-06-30 21:59:07 +0000222#
223# Enable this for profiling support with 'gprof'
224# This automatically enables optimized builds.
225#
226ifdef ENABLE_PROFILING
227 PROFILE = -pg
228endif
229
John Criswell8bff5092003-06-11 13:55:44 +0000230###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000231# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000232# These variables describe various library locations:
233#
234# DEST* = Location of where libraries that are built will be placed.
235# LLVM* = Location of LLVM libraries used for linking.
236# PROJ* = Location of previously built libraries used for linking.
237###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000238
John Criswell8bff5092003-06-11 13:55:44 +0000239# Libraries that are being built
240DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
241DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
242DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattner481cc7c2003-08-15 02:18:35 +0000243DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
John Criswell8bff5092003-06-11 13:55:44 +0000244DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000245
John Criswell8bff5092003-06-11 13:55:44 +0000246# LLVM libraries used for linking
247LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
248LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
249LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
250LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000251
John Criswell8bff5092003-06-11 13:55:44 +0000252# Libraries that were built that will now be used for linking
253PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
254PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
255PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
256PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000257
John Criswell8bff5092003-06-11 13:55:44 +0000258###########################################################################
259# Tool Locations
260# These variables describe various tool locations:
261#
262# DEST* = Location of where tools that are built will be placed.
263# LLVM* = Location of LLVM tools used for building.
264# PROJ* = Location of previously built tools used for linking.
265###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000266
John Criswell8bff5092003-06-11 13:55:44 +0000267DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
268DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
269DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
270DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
271
272LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
273LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
274LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
275LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
276
277PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
278PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
279PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
280PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000281
John Criswell7a73b802003-06-30 21:59:07 +0000282#
283# Libtool is found in the current directory.
284#
Chris Lattner95cc1b32003-08-14 21:10:25 +0000285LIBTOOL := $(LLVM_SRC_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000286
287#
John Criswell82f4a5a2003-07-31 20:58:51 +0000288# If we're not building a shared library, use the disable-shared tag with
289# libtool. This will disable the building of objects for shared libraries and
290# only generate static library objects.
291#
292# For dynamic libraries, we'll take the performance hit for now, since we
293# almost never build them.
294#
295# This should speed up compilation and require no modifications to future
296# versions of libtool.
297#
298ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000299LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000300endif
301
302#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000303# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000304#
Chris Lattner760da062003-03-14 20:25:22 +0000305ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000306VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000307LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000308endif
309
John Criswell7a73b802003-06-30 21:59:07 +0000310###########################################################################
311# Miscellaneous paths and commands (part deux):
312# This section defines various configuration macros, such as where
313# to find burg, tblgen, and libtool.
314###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000315
John Criswell7a73b802003-06-30 21:59:07 +0000316#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000317# Utilities used while building the LLVM tree, which live in the utils dir
318#
John Criswell8bff5092003-06-11 13:55:44 +0000319BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000320RunBurg := $(BURG) $(BURG_OPTS)
John Criswell8bff5092003-06-11 13:55:44 +0000321TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000322
Chris Lattner481cc7c2003-08-15 02:18:35 +0000323#--------------------------------------------------------------------------
324# The LLVM GCC front-end in C and C++ flavors
325#
Chris Lattner9a86a012003-08-15 15:20:52 +0000326LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattner98892652003-08-20 22:11:45 +0000327LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
Chris Lattner9a86a012003-08-15 15:20:52 +0000328LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattner98892652003-08-20 22:11:45 +0000329LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
Chris Lattner481cc7c2003-08-15 02:18:35 +0000330
331#--------------------------------------------------------------------------
332# Some of the compiled LLVM tools which are used for compilation of runtime
333# libraries.
334#
335LLVMAS := $(LLVMTOOLCURRENT)/as
336
Chris Lattner00950542001-06-06 20:29:01 +0000337
John Criswell8bff5092003-06-11 13:55:44 +0000338###########################################################################
339# Compile Time Flags
340###########################################################################
341
342#
John Criswell7a73b802003-06-30 21:59:07 +0000343# Include both the project headers and the LLVM headers for compilation and
344# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000345#
346CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000347
Vikram S. Advefeeae582002-09-18 11:55:13 +0000348# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000349ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000350STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000351STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000352endif
353
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000354# Allow gnu extensions...
355CPPFLAGS += -D_GNU_SOURCE
356
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000357CompileWarnings := -Wall -W -Wwrite-strings -Wno-unused
358CompileCommonOpts := $(CompileWarnings) -I$(LEVEL)/include -fshort-enums
359CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
Chris Lattner00950542001-06-06 20:29:01 +0000360
John Criswell7a73b802003-06-30 21:59:07 +0000361#
362# Compile commands with libtool.
363#
364Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattner72987ee2003-08-23 15:56:38 +0000365CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000366
Chris Lattner172b6482002-09-22 02:47:15 +0000367# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000368CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000369CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
370CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000371
Chris Lattner172b6482002-09-22 02:47:15 +0000372# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000373CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000374CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
375CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000376
John Criswell7a73b802003-06-30 21:59:07 +0000377###########################################################################
378# Link Time Options
379###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000380
John Criswell7a73b802003-06-30 21:59:07 +0000381#
Chris Lattner00950542001-06-06 20:29:01 +0000382# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000383# (Note that we always link with the C++ compiler).
384#
John Criswell7a73b802003-06-30 21:59:07 +0000385Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000386
John Criswell7a73b802003-06-30 21:59:07 +0000387# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000388LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
389LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
390LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000391
Chris Lattnere62dbe92002-07-23 17:56:16 +0000392# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000393Relink := ${LIBTOOL} --mode=link $(CXX)
John Criswell7a73b802003-06-30 21:59:07 +0000394
395#
396# Configure where the item being compiled should go.
397#
398ifdef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000399Link += -rpath $(DESTLIBCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000400endif
401
402ifdef TOOLNAME
Chris Lattner95cc1b32003-08-14 21:10:25 +0000403Link += -rpath $(DESTTOOLCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000404endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000405
Misha Brukman36bc6422003-08-21 22:02:18 +0000406# Create dependency file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000407Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
408DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000409
410# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000411AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000412
413#----------------------------------------------------------
414
415# Source includes all of the cpp files, and objects are derived from the
416# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000417# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000418#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000419ifndef Source
Chris Lattnere0010592001-10-18 01:48:09 +0000420Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l)
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000421endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000422
John Criswell82f4a5a2003-07-31 20:58:51 +0000423#
424# Libtool Objects
425#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000426Srcs := $(sort $(notdir $(basename $(Source))))
427Objs := $(addsuffix .lo, $(Srcs))
John Criswellf4ccd992003-07-01 14:52:28 +0000428ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
429ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
430ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner481cc7c2003-08-15 02:18:35 +0000431ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/Bytecode/,$(addsuffix .bc, $(Srcs)))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000432
John Criswell82f4a5a2003-07-31 20:58:51 +0000433#
434# The real objects underlying the libtool objects
435#
436RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source))))))
437RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
438RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
439RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
440
Chris Lattner00950542001-06-06 20:29:01 +0000441#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000442# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000443#---------------------------------------------------------
444
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000445ifdef DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000446all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000447 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000448 (cd $$dir; $(MAKE) $@) || exit 1; \
449 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000450endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000451
452# Handle PARALLEL_DIRS
453ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000454all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
455install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
456clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
457test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
458bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000459
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000460%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000461 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000462endif
463
John Criswell7a73b802003-06-30 21:59:07 +0000464# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000465ifdef OPTIONAL_DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000466all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000467 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
468 if [ -d $$dir ]; \
469 then\
470 (cd $$dir; $(MAKE) $@) || exit 1; \
471 fi \
472 done
473endif
474
John Criswell7a73b802003-06-30 21:59:07 +0000475###########################################################################
476# Library Build Rules:
477#
Chris Lattner00950542001-06-06 20:29:01 +0000478#---------------------------------------------------------
479# Handle the LIBRARYNAME option - used when building libs...
480#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000481#
482# When libraries are built, they are allowed to optionally define the
483# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
484# from being built for the library. This .o files may then be linked to by a
485# tool if the tool does not need (or want) the semantics a .a file provides
486# (linking in only object files that are "needed"). If a library is never to
487# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
488# BUILD_ARCHIVE instead.
489#
490# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000491# 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 +0000492# linked into tools (for example gccas) even if they only use one of the parts
493# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000494###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000495
496ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000497
Chris Lattner2a548c52002-09-16 22:36:42 +0000498# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000499LIBRARYNAME := $(strip $(LIBRARYNAME))
500
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000501LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
502LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
503LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
504LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
505LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
506LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
507LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
508LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
509LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner481cc7c2003-08-15 02:18:35 +0000510LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner00950542001-06-06 20:29:01 +0000511
John Criswell7a73b802003-06-30 21:59:07 +0000512#--------------------------------------------------------------------
513# Library Targets
514# Modify the top level targets to build the desired libraries.
515#--------------------------------------------------------------------
516
Chris Lattner760da062003-03-14 20:25:22 +0000517# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000518dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Chris Lattner481cc7c2003-08-15 02:18:35 +0000519bytecodelib:: $(LIBNAME_BC)
520bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
521
522$(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
523 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
524 cp $< $@
Vikram S. Adve60f56062002-08-02 18:34:12 +0000525
Chris Lattner760da062003-03-14 20:25:22 +0000526# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000527ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000528all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000529endif
Chris Lattner760da062003-03-14 20:25:22 +0000530
531# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000532ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000533all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000534endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000535
John Criswell7a73b802003-06-30 21:59:07 +0000536#--------------------------------------------------------------------
537# Rules for building libraries
538#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000539
Chris Lattner481cc7c2003-08-15 02:18:35 +0000540LinkBCLib := $(LLVMGCC) -shared
541ifdef EXPORTED_SYMBOL_LIST
542LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
543else
544LinkBCLib += -Xlinker -disable-internalize
545endif
546
547
548# Rule for building bytecode libraries.
Chris Lattneraf06a082003-08-15 03:02:52 +0000549$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
Chris Lattner481cc7c2003-08-15 02:18:35 +0000550 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
551 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000552#
553# Rules for building dynamically linked libraries.
554#
John Criswellf4ccd992003-07-01 14:52:28 +0000555$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000556 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000557 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
558 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000559
John Criswellf4ccd992003-07-01 14:52:28 +0000560$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000561 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000562 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
563 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Chris Lattner00950542001-06-06 20:29:01 +0000564
John Criswellf4ccd992003-07-01 14:52:28 +0000565$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000566 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000567 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
568 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000569
John Criswell7a73b802003-06-30 21:59:07 +0000570#
571# Rules for building static archive libraries.
572#
John Criswellf4ccd992003-07-01 14:52:28 +0000573$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000574 @echo ======= Linking $(LIBRARYNAME) archive release library =======
575 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000576 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000577
John Criswellf4ccd992003-07-01 14:52:28 +0000578$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000579 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
580 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000581 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000582
John Criswellf4ccd992003-07-01 14:52:28 +0000583$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000584 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
585 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000586 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000587
Chris Lattner481cc7c2003-08-15 02:18:35 +0000588
John Criswell7a73b802003-06-30 21:59:07 +0000589#
590# Rules for building .o libraries.
591#
John Criswell82f4a5a2003-07-31 20:58:51 +0000592# JTC:
593# Note that for this special case, we specify the actual object files
594# instead of their libtool counterparts. This is because libtool
595# doesn't want to generate a reloadable object file unless it is given
596# .o files explicitly.
597#
598# Note that we're making an assumption here: If we build a .lo file,
599# it's corresponding .o file will be placed in the same directory.
600#
601# I think that is safe.
602#
John Criswellf4ccd992003-07-01 14:52:28 +0000603$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000604 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000605 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000606
John Criswellf4ccd992003-07-01 14:52:28 +0000607$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000608 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000609 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000610
John Criswellf4ccd992003-07-01 14:52:28 +0000611$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000612 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000613 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000614
Chris Lattner00950542001-06-06 20:29:01 +0000615endif
616
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000617#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000618# Create a TAGS database for emacs
619#------------------------------------------------------------------------
620
John Criswell7a73b802003-06-30 21:59:07 +0000621ifdef ETAGS
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000622ifeq ($(LEVEL), .)
Chris Lattner942f9042003-08-21 21:53:38 +0000623SRCDIRS := $(wildcard include lib tools)
624
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000625tags:
Chris Lattner942f9042003-08-21 21:53:38 +0000626 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000627all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000628endif
John Criswell7a73b802003-06-30 21:59:07 +0000629else
630tags:
631 ${ECHO} "Cannot build $@: The program etags is not installed"
632endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000633
634#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000635# Handle the TOOLNAME option - used when building tool executables...
636#------------------------------------------------------------------------
637#
638# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000639# libraries (and the order of the libs) that should be linked to the
640# tool. USEDLIBS should contain a list of library names (some with .a extension)
641# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000642#
643ifdef TOOLNAME
644
645# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000646TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
647TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
648TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
649TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000650
651# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000652PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
653PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
654PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
655PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
656
657LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
658LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
659LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
660LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
661
662LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000663LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000664LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
665
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000666# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000667# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000668# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000669#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000670STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000671USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
672USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
673USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000674
John Criswell7a73b802003-06-30 21:59:07 +0000675#
676# Libtool link options:
677# Ensure that all binaries have their symbols exported so that they can
678# by dlsym'ed.
679#
680LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000681
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000682
683
684
685
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000686# Tell make that we need to rebuild subdirectories before we can link the tool.
687# This affects things like LLI which has library subdirectories.
688$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
689 $(addsuffix /.makeall, $(PARALLEL_DIRS))
690
Chris Lattner669bd7c2001-10-13 05:10:29 +0000691all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000692
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000693clean::
John Criswell7a73b802003-06-30 21:59:07 +0000694 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000695
John Criswellf4ccd992003-07-01 14:52:28 +0000696$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000697 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000698 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000699
John Criswellf4ccd992003-07-01 14:52:28 +0000700$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000701 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000702 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000703
John Criswellf4ccd992003-07-01 14:52:28 +0000704$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000705 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000706 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000707
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000708endif
709
710
Chris Lattner00950542001-06-06 20:29:01 +0000711
712#---------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000713.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000714.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000715
John Criswell7a73b802003-06-30 21:59:07 +0000716# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
717$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000718 @echo "Compiling $<"
719 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000720
John Criswell7a73b802003-06-30 21:59:07 +0000721$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
722 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000723 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000724
John Criswell7a73b802003-06-30 21:59:07 +0000725$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000726 @echo "Compiling $<"
727 $(VERB) $(CompileP) $< -o $@
728
John Criswell7a73b802003-06-30 21:59:07 +0000729$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000730 @echo "Compiling $<"
731 $(VERB) $(CompileCP) $< -o $@
732
John Criswell7a73b802003-06-30 21:59:07 +0000733$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000734 @echo "Compiling $<"
735 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000736
John Criswell7a73b802003-06-30 21:59:07 +0000737$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
738 @echo "Compiling $<"
739 $(VERB) $(CompileCG) $< -o $@
740
Chris Lattner481cc7c2003-08-15 02:18:35 +0000741$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
742 @echo "Compiling $< to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000743 $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000744
745$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
746 @echo "Compiling $< to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000747 $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000748
Chris Lattnereb6b47c2003-08-21 15:47:37 +0000749$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000750 @echo "Compiling $< to bytecode"
751 $(VERB) $(LLVMAS) $< -f -o $@
752
753
Chris Lattnere8996782003-01-16 22:44:19 +0000754#
755# Rules for building lex/yacc files
756#
757LEX_FILES = $(filter %.l, $(Source))
758LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
759YACC_FILES = $(filter %.y, $(Source))
760YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
761.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
762
Chris Lattner00950542001-06-06 20:29:01 +0000763# Create a .cpp source file from a flex input file... this uses sed to cut down
764# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000765#
766# The last line is a gross hack to work around flex aparently not being able to
767# resize the buffer on a large token input. Currently, for uninitialized string
768# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000769# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000770#
Chris Lattner00950542001-06-06 20:29:01 +0000771%.cpp: %.l
Chris Lattnera328f882003-08-04 19:47:06 +0000772 @echo Flex\'ing $<...
Chris Lattner7bb107d2003-08-04 19:48:10 +0000773 $(VERB) $(FLEX) -t $< | \
774 $(SED) '/^find_rule/d' | \
775 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000776 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000777 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
778 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000779 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000780 @# remove the output of flex if it didn't get moved over...
781 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000782
783# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000784%.c: %.y # Cancel built-in rules for yacc
785%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000786%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000787 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000788 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswelld741bcf2003-08-12 18:51:51 +0000789 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
790 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000791 @# If the files were not updated, don't leave them lying around...
792 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000793
794# To create the directories...
795%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000796 $(VERB) ${MKDIR} $* > /dev/null
797 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000798
Chris Lattner30440c62003-01-16 21:06:18 +0000799# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000800ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000801%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000802 ${DOT} -Tps < $< > $@
803else
804%.ps: %.dot
805 ${ECHO} "Cannot build $@: The program dot is not installed"
806endif
Chris Lattner30440c62003-01-16 21:06:18 +0000807
Chris Lattner172b6482002-09-22 02:47:15 +0000808# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000809clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000810 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
811 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
812 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
John Criswell7a73b802003-06-30 21:59:07 +0000813 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
814 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
815
John Criswell7a73b802003-06-30 21:59:07 +0000816###########################################################################
817# C/C++ Dependencies
818# Define variables and rules that generate header file dependencies
819# from C/C++ source files.
820###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000821
Chris Lattner33ad24a2003-08-22 14:10:16 +0000822ifndef DISABLE_AUTO_DEPENDENCIES
823
Chris Lattner694c5df2003-05-15 21:28:55 +0000824# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000825# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000826#
Chris Lattner694c5df2003-05-15 21:28:55 +0000827SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000828SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000829
830# Create dependencies for the *.cpp files...
John Criswell8bff5092003-06-11 13:55:44 +0000831$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000832 $(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 Lattnerfbb574d2003-08-21 20:39:08 +0000833 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.cpp||' | $(SED) 's|[^\]$$|&::|' >> $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000834
835# Create dependencies for the *.c files...
John Criswell8bff5092003-06-11 13:55:44 +0000836$(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000837 $(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 Lattnerfbb574d2003-08-21 20:39:08 +0000838 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.c||' | $(SED) 's|[^\]$$|&::|' >> $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000839
John Criswell7a73b802003-06-30 21:59:07 +0000840#
841# Include dependencies generated from C/C++ source files, but not if we
842# are cleaning (this example taken from the GNU Make Manual).
843#
844ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000845ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner00950542001-06-06 20:29:01 +0000846ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000847-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000848endif
John Criswell7a73b802003-06-30 21:59:07 +0000849endif
John Criswelld741bcf2003-08-12 18:51:51 +0000850endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000851
Chris Lattner33ad24a2003-08-22 14:10:16 +0000852endif # ifndef DISABLE_AUTO_DEPENDENCIES