blob: 7effb4cd204810fac74503f5cdff11a319e5b218 [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#
53include $(LEVEL)/Makefile.config
54
John Criswell8bff5092003-06-11 13:55:44 +000055###########################################################################
56# Directory Configuration
57# This section of the Makefile determines what is where. To be
58# specific, there are several locations that need to be defined:
59#
60# o LLVM_SRC_ROOT : The root directory of the LLVM source code.
61# o LLVM_OBJ_ROOT : The root directory containing the built LLVM code.
62#
63# o BUILD_SRC_DIR : The directory containing the code to build.
64# o BUILD_SRC_ROOT : The root directory of the code to build.
65#
66# o BUILD_OBJ_DIR : The directory in which compiled code will be placed.
67# o BUILD_OBJ_ROOT : The root directory in which compiled code is placed.
68#
69###########################################################################
70
71#
72# Set the source build directory. That is almost always the current directory.
73#
74ifndef BUILD_SRC_DIR
75BUILD_SRC_DIR = $(shell pwd)
76endif
77
78#
79# Set the source root directory.
80#
81ifndef BUILD_SRC_ROOT
John Criswell890d5bd2003-06-16 19:14:31 +000082BUILD_SRC_ROOT = $(shell cd $(BUILD_SRC_DIR)/$(LEVEL); pwd)
John Criswell8bff5092003-06-11 13:55:44 +000083endif
84
85#
John Criswell7a73b802003-06-30 21:59:07 +000086# Determine the path of the source tree relative from $HOME (the mythical
87# home directory).
88#
Misha Brukmanf8873ed2003-07-07 22:27:05 +000089HOME_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(BUILD_SRC_ROOT))
John Criswell7a73b802003-06-30 21:59:07 +000090
91#
John Criswell8bff5092003-06-11 13:55:44 +000092# Set the object build directory. Its location depends upon the source path
93# and where object files should go.
94#
95ifndef BUILD_OBJ_DIR
96ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +000097BUILD_OBJ_DIR = $(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +000098else
John Criswell7a73b802003-06-30 21:59:07 +000099BUILD_OBJ_DIR := $(HOME_OBJ_ROOT)$(patsubst $(BUILD_SRC_ROOT)%,%,$(BUILD_SRC_DIR))
John Criswell8bff5092003-06-11 13:55:44 +0000100endif
101endif
102
103#
104# Set the root of the object directory.
105#
106ifndef BUILD_OBJ_ROOT
107ifeq ($(OBJ_ROOT),.)
John Criswell7a73b802003-06-30 21:59:07 +0000108BUILD_OBJ_ROOT = $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000109else
John Criswell7a73b802003-06-30 21:59:07 +0000110BUILD_OBJ_ROOT := $(HOME_OBJ_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000111endif
112endif
113
114#
115# Set the LLVM source directory.
116# It is typically the root directory of what we're compiling now.
117#
118ifndef LLVM_SRC_ROOT
Chris Lattner481cc7c2003-08-15 02:18:35 +0000119LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
John Criswell8bff5092003-06-11 13:55:44 +0000120endif
121
122#
123# Set the LLVM object directory.
124#
125ifndef LLVM_OBJ_ROOT
Chris Lattnere430a1e2003-08-21 22:23:49 +0000126LLVM_OBJ_ROOT := $(shell cd $(BUILD_OBJ_DIR); cd $(LLVM_SRC_ROOT); pwd)
John Criswell8bff5092003-06-11 13:55:44 +0000127endif
128
John Criswell7a73b802003-06-30 21:59:07 +0000129###########################################################################
130# Default Targets:
131# The following targets are the standard top level targets for
132# building.
133###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +0000134
Chris Lattneredf1f232002-07-23 19:21:31 +0000135ifdef SHARED_LIBRARY
136# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +0000137all:: dynamic
Chris Lattneredf1f232002-07-23 19:21:31 +0000138endif
139
Chris Lattner95cc1b32003-08-14 21:10:25 +0000140ifdef BYTECODE_LIBRARY
141# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
142all:: bytecodelib
Chris Lattner481cc7c2003-08-15 02:18:35 +0000143install:: bytecodelib-install
Chris Lattner95cc1b32003-08-14 21:10:25 +0000144endif
145
Chris Lattnerb19e59c2001-06-29 05:20:16 +0000146# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +0000147all ::
148
149# Default for install is to at least build everything...
150install ::
151
John Criswell8bff5092003-06-11 13:55:44 +0000152# Default rule for test. It ensures everything has a test rule
153test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000154
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000155# Default rule for building only bytecode.
156bytecode::
157
John Criswell7a73b802003-06-30 21:59:07 +0000158# Print out the directories used for building
159prdirs::
Chris Lattnere430a1e2003-08-21 22:23:49 +0000160 @echo "Home Offset : " $(HOME_OBJ_ROOT)
161 @echo "Build Source Root: " $(BUILD_SRC_ROOT)
162 @echo "Build Source Dir : " $(BUILD_SRC_DIR)
163 @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
164 @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
165 @echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
166 @echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell7a73b802003-06-30 21:59:07 +0000167
John Criswell9621a2b2003-08-20 15:18:41 +0000168###########################################################################
169# Suffixes and implicit rules:
170# Empty out the list of suffixes, generate a list that is only
171# used by this Makefile, and cancel useless implicit rules. This
172# will hopefully speed up compilation a little bit.
173###########################################################################
174.SUFFIXES:
175.SUFFIXES: .c .cpp .h .hpp .y .l
176.SUFFIXES: .lo .o .a .so .bc
177.SUFFIXES: .ps .dot .d
178
John Criswell96914392003-07-16 20:26:06 +0000179#
180# Mark all of these targets as phony. This will hopefully speed up builds
181# slightly since GNU Make will not try to find implicit rules for targets
182# which are marked as Phony.
183#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000184.PHONY: all dynamic bytecodelib bytecodelib-install
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000185.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000186
John Criswell7a73b802003-06-30 21:59:07 +0000187###########################################################################
188# Miscellaneous paths and commands:
189# This section defines various configuration macros, such as where
190# to find burg, tblgen, and libtool.
191###########################################################################
192
Chris Lattner00950542001-06-06 20:29:01 +0000193#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000194# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000195#--------------------------------------------------------------------
196
197#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000198#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000199#DocInstDir=/usr/doc/xxx
200
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000201BURG_OPTS = -I
202
Chris Lattner760da062003-03-14 20:25:22 +0000203ifdef ENABLE_PROFILING
204 ENABLE_OPTIMIZED = 1
205 CONFIGURATION := Profile
206else
207 ifdef ENABLE_OPTIMIZED
208 CONFIGURATION := Release
209 else
210 CONFIGURATION := Debug
211 endif
212endif
213
John Criswell7a73b802003-06-30 21:59:07 +0000214#
215# Enable this for profiling support with 'gprof'
216# This automatically enables optimized builds.
217#
218ifdef ENABLE_PROFILING
219 PROFILE = -pg
220endif
221
John Criswell8bff5092003-06-11 13:55:44 +0000222###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000223# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000224# These variables describe various library locations:
225#
226# DEST* = Location of where libraries that are built will be placed.
227# LLVM* = Location of LLVM libraries used for linking.
228# PROJ* = Location of previously built libraries used for linking.
229###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000230
John Criswell8bff5092003-06-11 13:55:44 +0000231# Libraries that are being built
232DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
233DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
234DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattner481cc7c2003-08-15 02:18:35 +0000235DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
John Criswell8bff5092003-06-11 13:55:44 +0000236DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000237
John Criswell8bff5092003-06-11 13:55:44 +0000238# LLVM libraries used for linking
239LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
240LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
241LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
242LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000243
John Criswell8bff5092003-06-11 13:55:44 +0000244# Libraries that were built that will now be used for linking
245PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
246PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
247PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
248PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000249
John Criswell8bff5092003-06-11 13:55:44 +0000250###########################################################################
251# Tool Locations
252# These variables describe various tool locations:
253#
254# DEST* = Location of where tools that are built will be placed.
255# LLVM* = Location of LLVM tools used for building.
256# PROJ* = Location of previously built tools used for linking.
257###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000258
John Criswell8bff5092003-06-11 13:55:44 +0000259DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
260DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
261DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
262DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
263
264LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
265LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
266LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
267LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
268
269PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
270PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
271PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
272PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000273
John Criswell7a73b802003-06-30 21:59:07 +0000274#
275# Libtool is found in the current directory.
276#
Chris Lattner95cc1b32003-08-14 21:10:25 +0000277LIBTOOL := $(LLVM_SRC_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000278
279#
John Criswell82f4a5a2003-07-31 20:58:51 +0000280# If we're not building a shared library, use the disable-shared tag with
281# libtool. This will disable the building of objects for shared libraries and
282# only generate static library objects.
283#
284# For dynamic libraries, we'll take the performance hit for now, since we
285# almost never build them.
286#
287# This should speed up compilation and require no modifications to future
288# versions of libtool.
289#
290ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000291LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000292endif
293
294#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000295# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000296#
Chris Lattner760da062003-03-14 20:25:22 +0000297ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000298VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000299LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000300endif
301
John Criswell7a73b802003-06-30 21:59:07 +0000302###########################################################################
303# Miscellaneous paths and commands (part deux):
304# This section defines various configuration macros, such as where
305# to find burg, tblgen, and libtool.
306###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000307
John Criswell7a73b802003-06-30 21:59:07 +0000308#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000309# Utilities used while building the LLVM tree, which live in the utils dir
310#
John Criswell8bff5092003-06-11 13:55:44 +0000311BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000312RunBurg := $(BURG) $(BURG_OPTS)
John Criswell8bff5092003-06-11 13:55:44 +0000313TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000314
Chris Lattner481cc7c2003-08-15 02:18:35 +0000315#--------------------------------------------------------------------------
316# The LLVM GCC front-end in C and C++ flavors
317#
Chris Lattner9a86a012003-08-15 15:20:52 +0000318LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattner98892652003-08-20 22:11:45 +0000319LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
Chris Lattner9a86a012003-08-15 15:20:52 +0000320LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattner98892652003-08-20 22:11:45 +0000321LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
Chris Lattner481cc7c2003-08-15 02:18:35 +0000322
323#--------------------------------------------------------------------------
324# Some of the compiled LLVM tools which are used for compilation of runtime
325# libraries.
326#
327LLVMAS := $(LLVMTOOLCURRENT)/as
328
Chris Lattner00950542001-06-06 20:29:01 +0000329
John Criswell8bff5092003-06-11 13:55:44 +0000330###########################################################################
331# Compile Time Flags
332###########################################################################
333
334#
John Criswell7a73b802003-06-30 21:59:07 +0000335# Include both the project headers and the LLVM headers for compilation and
336# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000337#
338CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000339
Vikram S. Advefeeae582002-09-18 11:55:13 +0000340# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000341ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000342STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000343STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000344endif
345
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000346# Allow gnu extensions...
347CPPFLAGS += -D_GNU_SOURCE
348
John Criswell8bff5092003-06-11 13:55:44 +0000349CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000350CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
Chris Lattner00950542001-06-06 20:29:01 +0000351
John Criswell7a73b802003-06-30 21:59:07 +0000352#
353# Compile commands with libtool.
354#
355Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
356CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
357
Chris Lattner172b6482002-09-22 02:47:15 +0000358# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000359CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000360CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
361CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000362
Chris Lattner172b6482002-09-22 02:47:15 +0000363# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000364CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000365CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
366CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000367
John Criswell7a73b802003-06-30 21:59:07 +0000368###########################################################################
369# Link Time Options
370###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000371
John Criswell7a73b802003-06-30 21:59:07 +0000372#
Chris Lattner00950542001-06-06 20:29:01 +0000373# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000374# (Note that we always link with the C++ compiler).
375#
John Criswell7a73b802003-06-30 21:59:07 +0000376Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000377
John Criswell7a73b802003-06-30 21:59:07 +0000378# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000379LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
380LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
381LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000382
Chris Lattnere62dbe92002-07-23 17:56:16 +0000383# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000384Relink := ${LIBTOOL} --mode=link $(CXX)
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
Misha Brukman36bc6422003-08-21 22:02:18 +0000397# Create dependency 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
Chris Lattnerfbb574d2003-08-21 20:39:08 +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
Chris Lattnerfbb574d2003-08-21 20:39:08 +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
Chris Lattnerfbb574d2003-08-21 20:39:08 +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.
Chris Lattneraf06a082003-08-15 03:02:52 +0000540$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
Chris Lattner481cc7c2003-08-15 02:18:35 +0000541 @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 =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000548 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
549 $(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 =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000553 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
554 $(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 =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000558 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
559 $(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), .)
Chris Lattner942f9042003-08-21 21:53:38 +0000614SRCDIRS := $(wildcard include lib tools)
615
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000616tags:
Chris Lattner942f9042003-08-21 21:53:38 +0000617 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000618all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000619endif
John Criswell7a73b802003-06-30 21:59:07 +0000620else
621tags:
622 ${ECHO} "Cannot build $@: The program etags is not installed"
623endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000624
625#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000626# Handle the TOOLNAME option - used when building tool executables...
627#------------------------------------------------------------------------
628#
629# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000630# libraries (and the order of the libs) that should be linked to the
631# tool. USEDLIBS should contain a list of library names (some with .a extension)
632# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000633#
634ifdef TOOLNAME
635
636# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000637TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
638TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
639TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
640TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000641
642# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000643PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
644PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
645PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
646PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
647
648LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
649LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
650LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
651LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
652
653LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000654LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000655LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
656
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000657# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000658# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000659# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000660#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000661STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000662USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
663USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
664USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000665
John Criswell7a73b802003-06-30 21:59:07 +0000666#
667# Libtool link options:
668# Ensure that all binaries have their symbols exported so that they can
669# by dlsym'ed.
670#
671LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000672
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000673
674
675
676
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000677# Tell make that we need to rebuild subdirectories before we can link the tool.
678# This affects things like LLI which has library subdirectories.
679$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
680 $(addsuffix /.makeall, $(PARALLEL_DIRS))
681
Chris Lattner669bd7c2001-10-13 05:10:29 +0000682all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000683
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000684clean::
John Criswell7a73b802003-06-30 21:59:07 +0000685 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000686
John Criswellf4ccd992003-07-01 14:52:28 +0000687$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000688 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000689 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000690
John Criswellf4ccd992003-07-01 14:52:28 +0000691$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000692 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000693 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000694
John Criswellf4ccd992003-07-01 14:52:28 +0000695$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000696 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000697 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000698
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000699endif
700
701
Chris Lattner00950542001-06-06 20:29:01 +0000702
703#---------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000704.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000705.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000706
John Criswell7a73b802003-06-30 21:59:07 +0000707# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
708$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000709 @echo "Compiling $<"
710 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000711
John Criswell7a73b802003-06-30 21:59:07 +0000712$(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
713 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000714 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000715
John Criswell7a73b802003-06-30 21:59:07 +0000716$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000717 @echo "Compiling $<"
718 $(VERB) $(CompileP) $< -o $@
719
John Criswell7a73b802003-06-30 21:59:07 +0000720$(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000721 @echo "Compiling $<"
722 $(VERB) $(CompileCP) $< -o $@
723
John Criswell7a73b802003-06-30 21:59:07 +0000724$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000725 @echo "Compiling $<"
726 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000727
John Criswell7a73b802003-06-30 21:59:07 +0000728$(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir
729 @echo "Compiling $<"
730 $(VERB) $(CompileCG) $< -o $@
731
Chris Lattner481cc7c2003-08-15 02:18:35 +0000732$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
733 @echo "Compiling $< to bytecode"
734 $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
735
736$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
737 @echo "Compiling $< to bytecode"
738 $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
739
Chris Lattnereb6b47c2003-08-21 15:47:37 +0000740$(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LLVMAS)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000741 @echo "Compiling $< to bytecode"
742 $(VERB) $(LLVMAS) $< -f -o $@
743
744
Chris Lattnere8996782003-01-16 22:44:19 +0000745#
746# Rules for building lex/yacc files
747#
748LEX_FILES = $(filter %.l, $(Source))
749LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
750YACC_FILES = $(filter %.y, $(Source))
751YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
752.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
753
Chris Lattner00950542001-06-06 20:29:01 +0000754# Create a .cpp source file from a flex input file... this uses sed to cut down
755# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000756#
757# The last line is a gross hack to work around flex aparently not being able to
758# resize the buffer on a large token input. Currently, for uninitialized string
759# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000760# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000761#
Chris Lattner00950542001-06-06 20:29:01 +0000762%.cpp: %.l
Chris Lattnera328f882003-08-04 19:47:06 +0000763 @echo Flex\'ing $<...
Chris Lattner7bb107d2003-08-04 19:48:10 +0000764 $(VERB) $(FLEX) -t $< | \
765 $(SED) '/^find_rule/d' | \
766 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000767 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000768 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
769 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000770 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000771 @# remove the output of flex if it didn't get moved over...
772 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000773
774# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000775%.c: %.y # Cancel built-in rules for yacc
776%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000777%.cpp %.h : %.y
Chris Lattner694c5df2003-05-15 21:28:55 +0000778 @echo Bison\'ing $<...
Chris Lattnere8996782003-01-16 22:44:19 +0000779 $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
John Criswelld741bcf2003-08-12 18:51:51 +0000780 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
781 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000782 @# If the files were not updated, don't leave them lying around...
783 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000784
785# To create the directories...
786%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000787 $(VERB) ${MKDIR} $* > /dev/null
788 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000789
Chris Lattner30440c62003-01-16 21:06:18 +0000790# To create postscript files from dot files...
John Criswell7a73b802003-06-30 21:59:07 +0000791ifdef DOT
Chris Lattner30440c62003-01-16 21:06:18 +0000792%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000793 ${DOT} -Tps < $< > $@
794else
795%.ps: %.dot
796 ${ECHO} "Cannot build $@: The program dot is not installed"
797endif
Chris Lattner30440c62003-01-16 21:06:18 +0000798
Chris Lattner172b6482002-09-22 02:47:15 +0000799# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000800clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000801 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
802 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
803 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
John Criswell7a73b802003-06-30 21:59:07 +0000804 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
805 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
806
John Criswell7a73b802003-06-30 21:59:07 +0000807###########################################################################
808# C/C++ Dependencies
809# Define variables and rules that generate header file dependencies
810# from C/C++ source files.
811###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000812
Chris Lattner694c5df2003-05-15 21:28:55 +0000813# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000814# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000815#
Chris Lattner694c5df2003-05-15 21:28:55 +0000816SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
John Criswell8bff5092003-06-11 13:55:44 +0000817SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000818
819# Create dependencies for the *.cpp files...
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 Lattnerfbb574d2003-08-21 20:39:08 +0000822 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.cpp||' | $(SED) 's|[^\]$$|&::|' >> $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000823
824# Create dependencies for the *.c files...
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 Lattnerfbb574d2003-08-21 20:39:08 +0000827 $(VERB) $(Depend) $< | $(SED) 's|$*.o: $*.c||' | $(SED) 's|[^\]$$|&::|' >> $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000828
John Criswell7a73b802003-06-30 21:59:07 +0000829#
830# Include dependencies generated from C/C++ source files, but not if we
831# are cleaning (this example taken from the GNU Make Manual).
832#
833ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000834ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner00950542001-06-06 20:29:01 +0000835ifneq ($(SourceDepend),)
Chris Lattnered03bc92002-10-25 14:32:42 +0000836-include $(SourceDepend)
Chris Lattner00950542001-06-06 20:29:01 +0000837endif
John Criswell7a73b802003-06-30 21:59:07 +0000838endif
John Criswelld741bcf2003-08-12 18:51:51 +0000839endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000840
841cleandeps::
842 $(VERB) rm -f $(SourceDepend)
843