blob: 9152f8edc60327c5c5bc8ff06740b9e2f8a50263 [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#
John Criswell7f336952003-09-06 14:44:17 +000051# Set the VPATH so that we can find source files.
John Criswell8bff5092003-06-11 13:55:44 +000052#
John Criswell613758d2003-09-11 18:03:50 +000053VPATH=$(SourceDir)
John Criswell8bff5092003-06-11 13:55:44 +000054
John Criswell7a73b802003-06-30 21:59:07 +000055###########################################################################
56# Default Targets:
57# The following targets are the standard top level targets for
58# building.
59###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +000060
Chris Lattneredf1f232002-07-23 19:21:31 +000061ifdef SHARED_LIBRARY
62# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +000063all:: dynamic
Chris Lattneredf1f232002-07-23 19:21:31 +000064endif
65
Chris Lattner95cc1b32003-08-14 21:10:25 +000066ifdef BYTECODE_LIBRARY
67# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
68all:: bytecodelib
Chris Lattner481cc7c2003-08-15 02:18:35 +000069install:: bytecodelib-install
Chris Lattner95cc1b32003-08-14 21:10:25 +000070endif
71
Chris Lattnerb19e59c2001-06-29 05:20:16 +000072# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000073all ::
74
75# Default for install is to at least build everything...
76install ::
77
John Criswell8bff5092003-06-11 13:55:44 +000078# Default rule for test. It ensures everything has a test rule
79test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000080
Vikram S. Adve6edfe272003-07-10 19:25:29 +000081# Default rule for building only bytecode.
82bytecode::
83
John Criswell7a73b802003-06-30 21:59:07 +000084# Print out the directories used for building
85prdirs::
Chris Lattnere430a1e2003-08-21 22:23:49 +000086 @echo "Build Source Root: " $(BUILD_SRC_ROOT)
87 @echo "Build Source Dir : " $(BUILD_SRC_DIR)
88 @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
89 @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
90 @echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
91 @echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell7a73b802003-06-30 21:59:07 +000092
John Criswell9621a2b2003-08-20 15:18:41 +000093###########################################################################
94# Suffixes and implicit rules:
95# Empty out the list of suffixes, generate a list that is only
96# used by this Makefile, and cancel useless implicit rules. This
97# will hopefully speed up compilation a little bit.
98###########################################################################
99.SUFFIXES:
100.SUFFIXES: .c .cpp .h .hpp .y .l
John Criswell410d1b52003-09-09 20:57:03 +0000101.SUFFIXES: .lo .o .a .so .bc .td
John Criswell9621a2b2003-08-20 15:18:41 +0000102.SUFFIXES: .ps .dot .d
103
John Criswell96914392003-07-16 20:26:06 +0000104#
105# Mark all of these targets as phony. This will hopefully speed up builds
106# slightly since GNU Make will not try to find implicit rules for targets
107# which are marked as Phony.
108#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000109.PHONY: all dynamic bytecodelib bytecodelib-install
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000110.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000111
John Criswell7a73b802003-06-30 21:59:07 +0000112###########################################################################
113# Miscellaneous paths and commands:
114# This section defines various configuration macros, such as where
115# to find burg, tblgen, and libtool.
116###########################################################################
117
Chris Lattner00950542001-06-06 20:29:01 +0000118#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000119# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000120#--------------------------------------------------------------------
121
122#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000123#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000124#DocInstDir=/usr/doc/xxx
125
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000126BURG_OPTS = -I
127
Chris Lattner760da062003-03-14 20:25:22 +0000128ifdef ENABLE_PROFILING
129 ENABLE_OPTIMIZED = 1
130 CONFIGURATION := Profile
131else
132 ifdef ENABLE_OPTIMIZED
133 CONFIGURATION := Release
134 else
135 CONFIGURATION := Debug
136 endif
137endif
138
John Criswell7a73b802003-06-30 21:59:07 +0000139#
140# Enable this for profiling support with 'gprof'
141# This automatically enables optimized builds.
142#
143ifdef ENABLE_PROFILING
144 PROFILE = -pg
145endif
146
John Criswell8bff5092003-06-11 13:55:44 +0000147###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000148# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000149# These variables describe various library locations:
150#
151# DEST* = Location of where libraries that are built will be placed.
152# LLVM* = Location of LLVM libraries used for linking.
153# PROJ* = Location of previously built libraries used for linking.
154###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000155
John Criswell8bff5092003-06-11 13:55:44 +0000156# Libraries that are being built
157DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
158DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
159DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattnerad2be6c2003-09-10 19:37:51 +0000160DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
John Criswell8bff5092003-06-11 13:55:44 +0000161DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000162
John Criswell8bff5092003-06-11 13:55:44 +0000163# LLVM libraries used for linking
164LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
165LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
166LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
167LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000168
John Criswell8bff5092003-06-11 13:55:44 +0000169# Libraries that were built that will now be used for linking
170PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
171PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
172PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
173PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000174
John Criswell8bff5092003-06-11 13:55:44 +0000175###########################################################################
176# Tool Locations
177# These variables describe various tool locations:
178#
179# DEST* = Location of where tools that are built will be placed.
180# LLVM* = Location of LLVM tools used for building.
181# PROJ* = Location of previously built tools used for linking.
182###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000183
John Criswell8bff5092003-06-11 13:55:44 +0000184DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
185DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
186DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
187DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
188
189LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
190LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
191LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
192LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
193
194PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
195PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
196PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
197PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000198
John Criswell7a73b802003-06-30 21:59:07 +0000199#
200# Libtool is found in the current directory.
201#
John Criswell7f336952003-09-06 14:44:17 +0000202LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000203
204#
John Criswell82f4a5a2003-07-31 20:58:51 +0000205# If we're not building a shared library, use the disable-shared tag with
206# libtool. This will disable the building of objects for shared libraries and
207# only generate static library objects.
208#
209# For dynamic libraries, we'll take the performance hit for now, since we
210# almost never build them.
211#
212# This should speed up compilation and require no modifications to future
213# versions of libtool.
214#
215ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000216LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000217endif
218
219#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000220# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000221#
Chris Lattner760da062003-03-14 20:25:22 +0000222ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000223VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000224LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000225endif
226
John Criswell7a73b802003-06-30 21:59:07 +0000227###########################################################################
228# Miscellaneous paths and commands (part deux):
229# This section defines various configuration macros, such as where
230# to find burg, tblgen, and libtool.
231###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000232
John Criswell7a73b802003-06-30 21:59:07 +0000233#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000234# Utilities used while building the LLVM tree, which live in the utils dir
235#
John Criswell8bff5092003-06-11 13:55:44 +0000236BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000237RunBurg := $(BURG) $(BURG_OPTS)
John Criswell8bff5092003-06-11 13:55:44 +0000238TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000239
Chris Lattner481cc7c2003-08-15 02:18:35 +0000240#--------------------------------------------------------------------------
241# The LLVM GCC front-end in C and C++ flavors
242#
Chris Lattner9a86a012003-08-15 15:20:52 +0000243LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattner98892652003-08-20 22:11:45 +0000244LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
Chris Lattner9a86a012003-08-15 15:20:52 +0000245LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattner98892652003-08-20 22:11:45 +0000246LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
Chris Lattner481cc7c2003-08-15 02:18:35 +0000247
248#--------------------------------------------------------------------------
249# Some of the compiled LLVM tools which are used for compilation of runtime
250# libraries.
251#
Misha Brukmana86b0422003-08-28 21:45:08 +0000252LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
Chris Lattner481cc7c2003-08-15 02:18:35 +0000253
Chris Lattner00950542001-06-06 20:29:01 +0000254
John Criswell8bff5092003-06-11 13:55:44 +0000255###########################################################################
256# Compile Time Flags
257###########################################################################
258
259#
John Criswell7a73b802003-06-30 21:59:07 +0000260# Include both the project headers and the LLVM headers for compilation and
261# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000262#
John Criswell7f336952003-09-06 14:44:17 +0000263# BUILD_OBJ_DIR : Files local to the particular object directory
264# (locallly generated header files).
265# BUILD_SRC_DIR : Files local to the particular source directory.
266# BUILD_SRC_ROOT/include : Files global to the project.
Chris Lattner00e730a2003-09-15 01:07:32 +0000267# LLVM_OBJ_ROOT/include : config.h files generated by autoconf
John Criswell7f336952003-09-06 14:44:17 +0000268# LEVEL/include : config.h files for the project
269# LLVM_SRC_ROOT/include : Files global to LLVM.
John Criswell7f336952003-09-06 14:44:17 +0000270#
Chris Lattner069f9302003-09-15 01:12:04 +0000271CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
272 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
273 -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000274
Vikram S. Advefeeae582002-09-18 11:55:13 +0000275# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000276ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000277STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000278STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000279endif
280
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000281# Allow gnu extensions...
282CPPFLAGS += -D_GNU_SOURCE
283
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000284CompileWarnings := -Wall -W -Wwrite-strings -Wno-unused
John Criswell7f336952003-09-06 14:44:17 +0000285CompileCommonOpts := $(CompileWarnings) -fshort-enums
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000286CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
Chris Lattner00950542001-06-06 20:29:01 +0000287
John Criswell7a73b802003-06-30 21:59:07 +0000288#
289# Compile commands with libtool.
290#
291Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattner72987ee2003-08-23 15:56:38 +0000292CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000293
Chris Lattner172b6482002-09-22 02:47:15 +0000294# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000295CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000296CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
297CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000298
Chris Lattner172b6482002-09-22 02:47:15 +0000299# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000300CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000301CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
302CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000303
John Criswell7a73b802003-06-30 21:59:07 +0000304###########################################################################
305# Link Time Options
306###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000307
John Criswell7a73b802003-06-30 21:59:07 +0000308#
Chris Lattner00950542001-06-06 20:29:01 +0000309# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000310# (Note that we always link with the C++ compiler).
311#
John Criswell7a73b802003-06-30 21:59:07 +0000312Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000313
John Criswell7a73b802003-06-30 21:59:07 +0000314# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000315LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
316LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
317LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000318
Chris Lattnere62dbe92002-07-23 17:56:16 +0000319# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000320Relink := ${LIBTOOL} --mode=link $(CXX)
John Criswell7a73b802003-06-30 21:59:07 +0000321
322#
323# Configure where the item being compiled should go.
324#
325ifdef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000326Link += -rpath $(DESTLIBCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000327endif
328
329ifdef TOOLNAME
Chris Lattner95cc1b32003-08-14 21:10:25 +0000330Link += -rpath $(DESTTOOLCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000331endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000332
Misha Brukman36bc6422003-08-21 22:02:18 +0000333# Create dependency file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000334Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
335DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000336
337# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000338AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000339
340#----------------------------------------------------------
341
342# Source includes all of the cpp files, and objects are derived from the
343# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000344# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000345#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000346ifndef Source
Chris Lattner069f9302003-09-15 01:12:04 +0000347Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
348 $(SourceDir)/*.c $(SourceDir)/*.y $(SourceDir)/*.l))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000349endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000350
John Criswell82f4a5a2003-07-31 20:58:51 +0000351#
352# Libtool Objects
353#
John Criswell410d1b52003-09-09 20:57:03 +0000354Srcs := $(sort $(basename $(Source)))
Chris Lattner481cc7c2003-08-15 02:18:35 +0000355Objs := $(addsuffix .lo, $(Srcs))
John Criswellf4ccd992003-07-01 14:52:28 +0000356ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
357ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
358ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner0df847a2003-09-15 22:17:02 +0000359ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/BytecodeObj/,$(addsuffix .bc, $(Srcs)))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000360
John Criswell82f4a5a2003-07-31 20:58:51 +0000361#
362# The real objects underlying the libtool objects
363#
John Criswell410d1b52003-09-09 20:57:03 +0000364RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
John Criswell82f4a5a2003-07-31 20:58:51 +0000365RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
366RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
367RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
368
Chris Lattner00950542001-06-06 20:29:01 +0000369#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000370# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000371#---------------------------------------------------------
372
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000373ifdef DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000374all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000375 $(VERB) for dir in ${DIRS}; do \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000376 (cd $$dir; $(MAKE) $@) || exit 1; \
377 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000378endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000379
380# Handle PARALLEL_DIRS
381ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000382all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
383install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
384clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
385test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
386bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000387
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000388%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnera8abc222002-09-18 03:22:27 +0000389 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000390endif
391
John Criswell7a73b802003-06-30 21:59:07 +0000392# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000393ifdef OPTIONAL_DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000394all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000395 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
396 if [ -d $$dir ]; \
397 then\
398 (cd $$dir; $(MAKE) $@) || exit 1; \
399 fi \
400 done
401endif
402
John Criswell7a73b802003-06-30 21:59:07 +0000403###########################################################################
404# Library Build Rules:
405#
Chris Lattner00950542001-06-06 20:29:01 +0000406#---------------------------------------------------------
407# Handle the LIBRARYNAME option - used when building libs...
408#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000409#
410# When libraries are built, they are allowed to optionally define the
411# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
412# from being built for the library. This .o files may then be linked to by a
413# tool if the tool does not need (or want) the semantics a .a file provides
414# (linking in only object files that are "needed"). If a library is never to
415# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
416# BUILD_ARCHIVE instead.
417#
418# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000419# 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 +0000420# linked into tools (for example gccas) even if they only use one of the parts
421# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000422###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000423
424ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000425
Chris Lattner2a548c52002-09-16 22:36:42 +0000426# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000427LIBRARYNAME := $(strip $(LIBRARYNAME))
428
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000429LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
430LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
431LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
432LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
433LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
434LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
435LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
436LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
437LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner481cc7c2003-08-15 02:18:35 +0000438LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner00950542001-06-06 20:29:01 +0000439
John Criswell7a73b802003-06-30 21:59:07 +0000440#--------------------------------------------------------------------
441# Library Targets
442# Modify the top level targets to build the desired libraries.
443#--------------------------------------------------------------------
444
Chris Lattner760da062003-03-14 20:25:22 +0000445# dynamic target builds a shared object version of the library...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000446dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Chris Lattner481cc7c2003-08-15 02:18:35 +0000447bytecodelib:: $(LIBNAME_BC)
448bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
449
450$(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
451 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
452 cp $< $@
Vikram S. Adve60f56062002-08-02 18:34:12 +0000453
Chris Lattner760da062003-03-14 20:25:22 +0000454# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000455ifndef DONT_BUILD_RELINKED
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000456all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000457endif
Chris Lattner760da062003-03-14 20:25:22 +0000458
459# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000460ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000461all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000462endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000463
John Criswell7a73b802003-06-30 21:59:07 +0000464#--------------------------------------------------------------------
465# Rules for building libraries
466#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000467
Chris Lattner481cc7c2003-08-15 02:18:35 +0000468LinkBCLib := $(LLVMGCC) -shared
469ifdef EXPORTED_SYMBOL_LIST
470LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
471else
Chris Lattner22c83282003-09-15 15:06:54 +0000472 ifdef EXPORTED_SYMBOL_FILE
473LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
474 else
Chris Lattner481cc7c2003-08-15 02:18:35 +0000475LinkBCLib += -Xlinker -disable-internalize
Chris Lattner22c83282003-09-15 15:06:54 +0000476 endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000477endif
478
479
480# Rule for building bytecode libraries.
Chris Lattneraf06a082003-08-15 03:02:52 +0000481$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
Chris Lattner481cc7c2003-08-15 02:18:35 +0000482 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
483 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000484#
485# Rules for building dynamically linked libraries.
486#
John Criswellf4ccd992003-07-01 14:52:28 +0000487$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000488 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000489 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
490 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000491
John Criswellf4ccd992003-07-01 14:52:28 +0000492$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000493 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000494 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
495 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Chris Lattner00950542001-06-06 20:29:01 +0000496
John Criswellf4ccd992003-07-01 14:52:28 +0000497$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000498 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000499 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
500 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000501
John Criswell7a73b802003-06-30 21:59:07 +0000502#
503# Rules for building static archive libraries.
504#
John Criswellf4ccd992003-07-01 14:52:28 +0000505$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000506 @echo ======= Linking $(LIBRARYNAME) archive release library =======
507 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000508 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve41e78912002-09-20 14:03:13 +0000509
John Criswellf4ccd992003-07-01 14:52:28 +0000510$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000511 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
512 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000513 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000514
John Criswellf4ccd992003-07-01 14:52:28 +0000515$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000516 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
517 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000518 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell7a73b802003-06-30 21:59:07 +0000519
Chris Lattner481cc7c2003-08-15 02:18:35 +0000520
John Criswell7a73b802003-06-30 21:59:07 +0000521#
522# Rules for building .o libraries.
523#
John Criswell82f4a5a2003-07-31 20:58:51 +0000524# JTC:
525# Note that for this special case, we specify the actual object files
526# instead of their libtool counterparts. This is because libtool
527# doesn't want to generate a reloadable object file unless it is given
528# .o files explicitly.
529#
530# Note that we're making an assumption here: If we build a .lo file,
531# it's corresponding .o file will be placed in the same directory.
532#
533# I think that is safe.
534#
John Criswellf4ccd992003-07-01 14:52:28 +0000535$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000536 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000537 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000538
John Criswellf4ccd992003-07-01 14:52:28 +0000539$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000540 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000541 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000542
John Criswellf4ccd992003-07-01 14:52:28 +0000543$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner9e398162002-09-25 17:15:22 +0000544 @echo "Linking $@"
John Criswell82f4a5a2003-07-31 20:58:51 +0000545 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000546
Chris Lattner00950542001-06-06 20:29:01 +0000547endif
548
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000549#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000550# Create a TAGS database for emacs
551#------------------------------------------------------------------------
552
John Criswelle0f9ac62003-10-02 19:02:02 +0000553ifneq ($(ETAGS),false)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000554ifeq ($(LEVEL), .)
John Criswell7f336952003-09-06 14:44:17 +0000555SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
Chris Lattner942f9042003-08-21 21:53:38 +0000556
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000557tags:
Chris Lattner942f9042003-08-21 21:53:38 +0000558 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000559all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000560endif
John Criswell7a73b802003-06-30 21:59:07 +0000561else
562tags:
563 ${ECHO} "Cannot build $@: The program etags is not installed"
564endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000565
566#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000567# Handle the TOOLNAME option - used when building tool executables...
568#------------------------------------------------------------------------
569#
570# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000571# libraries (and the order of the libs) that should be linked to the
572# tool. USEDLIBS should contain a list of library names (some with .a extension)
573# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000574#
575ifdef TOOLNAME
576
577# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000578TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
579TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
580TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
581TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000582
583# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000584PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
585PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
586PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
587PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
588
589LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
590LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
591LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
592LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
593
594LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000595LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000596LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
597
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000598# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000599# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000600# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000601#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000602STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000603USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
604USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
605USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000606
John Criswell7a73b802003-06-30 21:59:07 +0000607#
608# Libtool link options:
609# Ensure that all binaries have their symbols exported so that they can
610# by dlsym'ed.
611#
612LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000613
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000614
615
616
617
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000618# Tell make that we need to rebuild subdirectories before we can link the tool.
619# This affects things like LLI which has library subdirectories.
620$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
621 $(addsuffix /.makeall, $(PARALLEL_DIRS))
622
Chris Lattner669bd7c2001-10-13 05:10:29 +0000623all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000624
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000625clean::
John Criswell7a73b802003-06-30 21:59:07 +0000626 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000627
John Criswellf4ccd992003-07-01 14:52:28 +0000628$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000629 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswellf4ccd992003-07-01 14:52:28 +0000630 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000631
John Criswellf4ccd992003-07-01 14:52:28 +0000632$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner287d4432002-09-12 17:02:40 +0000633 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000634 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000635
John Criswellf4ccd992003-07-01 14:52:28 +0000636$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000637 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswellf4ccd992003-07-01 14:52:28 +0000638 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000639
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000640endif
641
642
Chris Lattner00950542001-06-06 20:29:01 +0000643
644#---------------------------------------------------------
Chris Lattner0df847a2003-09-15 22:17:02 +0000645.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000646.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000647
John Criswell7a73b802003-06-30 21:59:07 +0000648# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
John Criswell410d1b52003-09-09 20:57:03 +0000649$(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000650 @echo "Compiling $<"
651 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000652
John Criswell410d1b52003-09-09 20:57:03 +0000653$(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000654 @echo "Compiling $<"
Chris Lattner1eeac662002-10-22 23:28:23 +0000655 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000656
John Criswell410d1b52003-09-09 20:57:03 +0000657$(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve41e78912002-09-20 14:03:13 +0000658 @echo "Compiling $<"
659 $(VERB) $(CompileP) $< -o $@
660
John Criswell410d1b52003-09-09 20:57:03 +0000661$(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattner172b6482002-09-22 02:47:15 +0000662 @echo "Compiling $<"
663 $(VERB) $(CompileCP) $< -o $@
664
John Criswell410d1b52003-09-09 20:57:03 +0000665$(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000666 @echo "Compiling $<"
667 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000668
John Criswell410d1b52003-09-09 20:57:03 +0000669$(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000670 @echo "Compiling $<"
671 $(VERB) $(CompileCG) $< -o $@
672
Chris Lattner0df847a2003-09-15 22:17:02 +0000673$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000674 @echo "Compiling $< to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000675 $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000676
Chris Lattner0df847a2003-09-15 22:17:02 +0000677$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000678 @echo "Compiling $< to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000679 $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000680
Chris Lattner0df847a2003-09-15 22:17:02 +0000681$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000682 @echo "Compiling $< to bytecode"
683 $(VERB) $(LLVMAS) $< -f -o $@
684
685
Chris Lattnere8996782003-01-16 22:44:19 +0000686#
687# Rules for building lex/yacc files
688#
689LEX_FILES = $(filter %.l, $(Source))
690LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
691YACC_FILES = $(filter %.y, $(Source))
692YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
693.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
694
Chris Lattner00950542001-06-06 20:29:01 +0000695# Create a .cpp source file from a flex input file... this uses sed to cut down
696# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000697#
698# The last line is a gross hack to work around flex aparently not being able to
699# resize the buffer on a large token input. Currently, for uninitialized string
700# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000701# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000702#
Chris Lattner00950542001-06-06 20:29:01 +0000703%.cpp: %.l
John Criswellb2f76bf2003-09-11 15:15:53 +0000704 @echo Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000705 $(VERB) $(FLEX) -t $< | \
706 $(SED) '/^find_rule/d' | \
707 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000708 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000709 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
710 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000711 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000712 @# remove the output of flex if it didn't get moved over...
713 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000714
715# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000716%.c: %.y # Cancel built-in rules for yacc
717%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000718%.cpp %.h : %.y
John Criswellb2f76bf2003-09-11 15:15:53 +0000719 @echo Bisoning $<
John Criswell410d1b52003-09-09 20:57:03 +0000720 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
John Criswelld741bcf2003-08-12 18:51:51 +0000721 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
722 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000723 @# If the files were not updated, don't leave them lying around...
724 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000725
726# To create the directories...
727%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000728 $(VERB) ${MKDIR} $* > /dev/null
729 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000730
Chris Lattner30440c62003-01-16 21:06:18 +0000731# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000732ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000733%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000734 ${DOT} -Tps < $< > $@
735else
736%.ps: %.dot
737 ${ECHO} "Cannot build $@: The program dot is not installed"
738endif
Chris Lattner30440c62003-01-16 21:06:18 +0000739
John Criswell7f336952003-09-06 14:44:17 +0000740#
741# This rules ensures that header files that are removed still have a rule for
742# which they can be "generated." This allows make to ignore them and
743# reproduce the dependency lists.
744#
John Criswell4b6e5d12003-09-18 18:37:08 +0000745%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000746
Chris Lattner172b6482002-09-22 02:47:15 +0000747# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000748clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000749 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
750 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
Chris Lattner0df847a2003-09-15 22:17:02 +0000751 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
John Criswell7a73b802003-06-30 21:59:07 +0000752 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
753 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
754
John Criswell7a73b802003-06-30 21:59:07 +0000755###########################################################################
756# C/C++ Dependencies
757# Define variables and rules that generate header file dependencies
758# from C/C++ source files.
759###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000760
Chris Lattner33ad24a2003-08-22 14:10:16 +0000761ifndef DISABLE_AUTO_DEPENDENCIES
762
Chris Lattner694c5df2003-05-15 21:28:55 +0000763# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000764# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000765#
John Criswell410d1b52003-09-09 20:57:03 +0000766SourceBaseNames := $(basename $(Source))
John Criswell8bff5092003-06-11 13:55:44 +0000767SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000768
769# Create dependencies for the *.cpp files...
John Criswell410d1b52003-09-09 20:57:03 +0000770$(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000771 $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000772
773# Create dependencies for the *.c files...
John Criswell410d1b52003-09-09 20:57:03 +0000774$(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell7a73b802003-06-30 21:59:07 +0000775 $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
Chris Lattner694c5df2003-05-15 21:28:55 +0000776
John Criswell7a73b802003-06-30 21:59:07 +0000777#
778# Include dependencies generated from C/C++ source files, but not if we
779# are cleaning (this example taken from the GNU Make Manual).
780#
781ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000782ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner15444a92003-08-29 14:07:02 +0000783-include /dev/null $(SourceDepend)
John Criswell7a73b802003-06-30 21:59:07 +0000784endif
John Criswelld741bcf2003-08-12 18:51:51 +0000785endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000786
Chris Lattner33ad24a2003-08-22 14:10:16 +0000787endif # ifndef DISABLE_AUTO_DEPENDENCIES