blob: 4831d1d965e2436ed085dfc3ce4528adce7b0c2c [file] [log] [blame]
John Criswell7ec78aa2003-10-16 01:49:00 +00001#===-- Makefile.rules - Common make rules for LLVM -------*- makefile -*--====
John Criswelld8846c12003-10-21 14:33:46 +00002#
3# The LLVM Compiler Infrastructure
4#
5# This file was developed by the LLVM research group and is distributed under
6# the University of Illinois Open Source License. See LICENSE.TXT for details.
7#
8##===----------------------------------------------------------------------===##
Chris Lattner00950542001-06-06 20:29:01 +00009#
10# This file is included by all of the LLVM makefiles. This file defines common
Misha Brukman36bc6422003-08-21 22:02:18 +000011# rules to do things like compile a .cpp file or generate dependency info.
12# These are platform dependent, so this is the file used to specify these
13# system dependent operations.
Chris Lattner00950542001-06-06 20:29:01 +000014#
Vikram S. Advec214e712002-08-29 23:28:46 +000015# The following functionality can be set by setting incoming variables.
16# The variable $(LEVEL) *must* be set:
Chris Lattner00950542001-06-06 20:29:01 +000017#
18# 1. LEVEL - The level of the current subdirectory from the top of the
19# MagicStats view. This level should be expressed as a path, for
20# example, ../.. for two levels deep.
21#
22# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnera8abc222002-09-18 03:22:27 +000023# so that each of the targets "all", "install", and "clean" each build
24# the subdirectories before the local target. DIRS are guaranteed to be
25# built in order.
Chris Lattner00950542001-06-06 20:29:01 +000026#
Chris Lattnera8abc222002-09-18 03:22:27 +000027# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
28# built in any order. All DIRS are built in order before PARALLEL_DIRS are
29# built, which are then built in any order.
30#
31# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner00950542001-06-06 20:29:01 +000032# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000033# in the current directory. Also, if you want to build files in addition
34# to the local files, you can use the ExtraSource variable
Chris Lattner00950542001-06-06 20:29:01 +000035#
Chris Lattner694c5df2003-05-15 21:28:55 +000036# 5. SourceDir - If specified, this specifies a directory that the source files
37# are in, if they are not in the current directory. This should include a
38# trailing / character.
39#
John Criswell7a73b802003-06-30 21:59:07 +000040# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000041#
John Criswell7a73b802003-06-30 21:59:07 +000042# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
43# and usually the source code too (unless SourceDir is set).
44#
45# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
46#
47# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
48#
49# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
50# placed.
51#
52# For building,
Chris Lattnere430a1e2003-08-21 22:23:49 +000053# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
Chris Lattneraf06a082003-08-15 03:02:52 +000054#
Vikram S. Adved60aede2002-07-09 12:04:21 +000055#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000056
John Criswell2a6530f2003-06-27 16:58:44 +000057#
John Criswell7f336952003-09-06 14:44:17 +000058# Set the VPATH so that we can find source files.
John Criswell8bff5092003-06-11 13:55:44 +000059#
John Criswell613758d2003-09-11 18:03:50 +000060VPATH=$(SourceDir)
John Criswell8bff5092003-06-11 13:55:44 +000061
John Criswell7a73b802003-06-30 21:59:07 +000062###########################################################################
63# Default Targets:
64# The following targets are the standard top level targets for
65# building.
66###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +000067
John Criswellbd082802003-10-07 14:16:44 +000068# Ensure people re-run configure when it gets updated
Misha Brukman94fe1f92003-10-07 15:24:23 +000069all::$(LLVM_OBJ_ROOT)/config.status
John Criswellbd082802003-10-07 14:16:44 +000070
Chris Lattneredf1f232002-07-23 19:21:31 +000071ifdef SHARED_LIBRARY
72# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell7a73b802003-06-30 21:59:07 +000073all:: dynamic
Brian Gaeke7976e972004-01-16 21:12:34 +000074install:: install-dynamic-library
Chris Lattneredf1f232002-07-23 19:21:31 +000075endif
76
Chris Lattner95cc1b32003-08-14 21:10:25 +000077ifdef BYTECODE_LIBRARY
78# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
79all:: bytecodelib
Brian Gaeke78cb3f22003-12-18 20:57:48 +000080install:: install-bytecode-library
Chris Lattner95cc1b32003-08-14 21:10:25 +000081endif
82
Chris Lattnerb19e59c2001-06-29 05:20:16 +000083# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000084all ::
85
86# Default for install is to at least build everything...
87install ::
88
John Criswell8bff5092003-06-11 13:55:44 +000089# Default rule for test. It ensures everything has a test rule
90test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000091
Vikram S. Adve6edfe272003-07-10 19:25:29 +000092# Default rule for building only bytecode.
93bytecode::
94
John Criswell7a73b802003-06-30 21:59:07 +000095# Print out the directories used for building
96prdirs::
John Criswell7ec78aa2003-10-16 01:49:00 +000097 @${ECHO} "Build Source Root: " $(BUILD_SRC_ROOT)
98 @${ECHO} "Build Source Dir : " $(BUILD_SRC_DIR)
99 @${ECHO} "Build Object Root: " $(BUILD_OBJ_ROOT)
100 @${ECHO} "Build Object Dir : " $(BUILD_OBJ_DIR)
101 @${ECHO} "LLVM Source Root: " $(LLVM_SRC_ROOT)
102 @${ECHO} "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell7a73b802003-06-30 21:59:07 +0000103
John Criswell9621a2b2003-08-20 15:18:41 +0000104###########################################################################
105# Suffixes and implicit rules:
106# Empty out the list of suffixes, generate a list that is only
107# used by this Makefile, and cancel useless implicit rules. This
108# will hopefully speed up compilation a little bit.
109###########################################################################
110.SUFFIXES:
111.SUFFIXES: .c .cpp .h .hpp .y .l
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000112.SUFFIXES: .lo .o .a .$(SHLIBEXT) .bc .td
John Criswell9621a2b2003-08-20 15:18:41 +0000113.SUFFIXES: .ps .dot .d
114
John Criswell96914392003-07-16 20:26:06 +0000115#
116# Mark all of these targets as phony. This will hopefully speed up builds
117# slightly since GNU Make will not try to find implicit rules for targets
118# which are marked as Phony.
119#
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000120.PHONY: all dynamic bytecodelib install-bytecode-library
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000121.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000122
John Criswell7a73b802003-06-30 21:59:07 +0000123###########################################################################
124# Miscellaneous paths and commands:
125# This section defines various configuration macros, such as where
126# to find burg, tblgen, and libtool.
127###########################################################################
128
Chris Lattner00950542001-06-06 20:29:01 +0000129#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000130# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000131#--------------------------------------------------------------------
132
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000133BURG_OPTS = -I
134
Chris Lattner760da062003-03-14 20:25:22 +0000135ifdef ENABLE_PROFILING
136 ENABLE_OPTIMIZED = 1
137 CONFIGURATION := Profile
138else
139 ifdef ENABLE_OPTIMIZED
140 CONFIGURATION := Release
141 else
142 CONFIGURATION := Debug
143 endif
144endif
145
John Criswell7a73b802003-06-30 21:59:07 +0000146#
147# Enable this for profiling support with 'gprof'
148# This automatically enables optimized builds.
149#
150ifdef ENABLE_PROFILING
151 PROFILE = -pg
152endif
153
John Criswell8bff5092003-06-11 13:55:44 +0000154###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000155# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000156# These variables describe various library locations:
157#
158# DEST* = Location of where libraries that are built will be placed.
159# LLVM* = Location of LLVM libraries used for linking.
160# PROJ* = Location of previously built libraries used for linking.
161###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000162
John Criswell8bff5092003-06-11 13:55:44 +0000163# Libraries that are being built
164DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
165DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
166DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattnerad2be6c2003-09-10 19:37:51 +0000167DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
John Criswell8bff5092003-06-11 13:55:44 +0000168DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000169
John Criswell8bff5092003-06-11 13:55:44 +0000170# LLVM libraries used for linking
171LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
172LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
173LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
174LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000175
John Criswell8bff5092003-06-11 13:55:44 +0000176# Libraries that were built that will now be used for linking
177PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
178PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
179PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
180PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000181
John Criswell8bff5092003-06-11 13:55:44 +0000182###########################################################################
183# Tool Locations
184# These variables describe various tool locations:
185#
186# DEST* = Location of where tools that are built will be placed.
187# LLVM* = Location of LLVM tools used for building.
188# PROJ* = Location of previously built tools used for linking.
189###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000190
John Criswell8bff5092003-06-11 13:55:44 +0000191DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
192DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
193DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
194DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
195
196LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
197LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
198LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
199LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
200
201PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
202PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
203PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
204PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000205
John Criswell7a73b802003-06-30 21:59:07 +0000206#
207# Libtool is found in the current directory.
208#
John Criswell7f336952003-09-06 14:44:17 +0000209LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000210
211#
John Criswell82f4a5a2003-07-31 20:58:51 +0000212# If we're not building a shared library, use the disable-shared tag with
213# libtool. This will disable the building of objects for shared libraries and
214# only generate static library objects.
215#
216# For dynamic libraries, we'll take the performance hit for now, since we
217# almost never build them.
218#
219# This should speed up compilation and require no modifications to future
220# versions of libtool.
221#
222ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000223LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000224endif
225
226#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000227# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000228#
Chris Lattner760da062003-03-14 20:25:22 +0000229ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000230VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000231LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000232endif
233
John Criswell7a73b802003-06-30 21:59:07 +0000234###########################################################################
235# Miscellaneous paths and commands (part deux):
236# This section defines various configuration macros, such as where
237# to find burg, tblgen, and libtool.
238###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000239
John Criswell7a73b802003-06-30 21:59:07 +0000240#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000241# Utilities used while building the LLVM tree, which live in the utils dir
242#
Chris Lattnereefa3d32003-11-29 09:50:15 +0000243BURG := $(LLVMTOOLCURRENT)/burg
244RunBurg := $(BURG) $(BURG_OPTS)
245TBLGEN := $(LLVMTOOLCURRENT)/tblgen
246LGCCLDPROG := $(LLVMTOOLCURRENT)/gccld
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000247
Chris Lattner481cc7c2003-08-15 02:18:35 +0000248#--------------------------------------------------------------------------
249# The LLVM GCC front-end in C and C++ flavors
250#
Chris Lattner9a86a012003-08-15 15:20:52 +0000251LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattner9a86a012003-08-15 15:20:52 +0000252LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattner481cc7c2003-08-15 02:18:35 +0000253
254#--------------------------------------------------------------------------
255# Some of the compiled LLVM tools which are used for compilation of runtime
256# libraries.
257#
Misha Brukmana86b0422003-08-28 21:45:08 +0000258LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
Chris Lattner481cc7c2003-08-15 02:18:35 +0000259
Chris Lattner00950542001-06-06 20:29:01 +0000260
John Criswell8bff5092003-06-11 13:55:44 +0000261###########################################################################
262# Compile Time Flags
263###########################################################################
264
265#
John Criswell7a73b802003-06-30 21:59:07 +0000266# Include both the project headers and the LLVM headers for compilation and
267# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000268#
John Criswell7f336952003-09-06 14:44:17 +0000269# BUILD_OBJ_DIR : Files local to the particular object directory
270# (locallly generated header files).
271# BUILD_SRC_DIR : Files local to the particular source directory.
272# BUILD_SRC_ROOT/include : Files global to the project.
Chris Lattner00e730a2003-09-15 01:07:32 +0000273# LLVM_OBJ_ROOT/include : config.h files generated by autoconf
John Criswell7f336952003-09-06 14:44:17 +0000274# LEVEL/include : config.h files for the project
275# LLVM_SRC_ROOT/include : Files global to LLVM.
John Criswell7f336952003-09-06 14:44:17 +0000276#
Chris Lattner069f9302003-09-15 01:12:04 +0000277CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
278 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
279 -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000280
Vikram S. Advefeeae582002-09-18 11:55:13 +0000281# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000282ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000283STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000284STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000285endif
286
Brian Gaeke90eca552003-10-28 19:09:28 +0000287# Allow GNU extensions:
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000288CPPFLAGS += -D_GNU_SOURCE
Brian Gaeke90eca552003-10-28 19:09:28 +0000289# Pull in limit macros from stdint.h, even in C++:
290CPPFLAGS += -D__STDC_LIMIT_MACROS
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000291
Chris Lattnerd1803002003-12-06 20:59:45 +0000292CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000293CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
Chris Lattner00950542001-06-06 20:29:01 +0000294
John Criswell7a73b802003-06-30 21:59:07 +0000295#
296# Compile commands with libtool.
297#
298Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattner72987ee2003-08-23 15:56:38 +0000299CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000300
Chris Lattner172b6482002-09-22 02:47:15 +0000301# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000302CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000303CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
304CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000305
Chris Lattner172b6482002-09-22 02:47:15 +0000306# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000307CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000308CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
309CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000310
John Criswell7a73b802003-06-30 21:59:07 +0000311###########################################################################
312# Link Time Options
313###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000314
John Criswell7a73b802003-06-30 21:59:07 +0000315#
Chris Lattner00950542001-06-06 20:29:01 +0000316# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000317# (Note that we always link with the C++ compiler).
318#
John Criswell7a73b802003-06-30 21:59:07 +0000319Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000320
John Criswell7a73b802003-06-30 21:59:07 +0000321# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000322LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
323LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
324LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000325
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000326# TOOLLINKOPTSB to pass options to the linker like library search path etc
327# Note that this is different from TOOLLINKOPTS, these options
328# are passed to the linker *before* the USEDLIBS options are passed.
329# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
330ifdef TOOLLINKOPTSB
331LinkG := $(LinkG) $(TOOLLINKOPTSB)
Dinakar Dhurjati79903c82003-10-29 20:34:13 +0000332LinkO := $(LinkO) $(TOOLLINKOPTSB)
333LinkP := $(LinkP) $(TOOLLINKOPTSB)
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000334endif
335
Chris Lattnere62dbe92002-07-23 17:56:16 +0000336# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000337Relink := ${LIBTOOL} --mode=link $(CXX)
John Criswell7a73b802003-06-30 21:59:07 +0000338
339#
340# Configure where the item being compiled should go.
341#
342ifdef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000343Link += -rpath $(DESTLIBCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000344endif
345
346ifdef TOOLNAME
Chris Lattner95cc1b32003-08-14 21:10:25 +0000347Link += -rpath $(DESTTOOLCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000348endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000349
Misha Brukman36bc6422003-08-21 22:02:18 +0000350# Create dependency file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000351Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
352DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000353
354# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000355AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000356
357#----------------------------------------------------------
358
359# Source includes all of the cpp files, and objects are derived from the
360# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000361# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000362#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000363ifndef Source
Chris Lattner069f9302003-09-15 01:12:04 +0000364Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
John Criswellb1f5cfe2003-12-29 22:02:12 +0000365 $(SourceDir)/*.cc $(SourceDir)/*.c $(SourceDir)/*.y \
366 $(SourceDir)/*.l))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000367endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000368
John Criswell82f4a5a2003-07-31 20:58:51 +0000369#
370# Libtool Objects
371#
John Criswell410d1b52003-09-09 20:57:03 +0000372Srcs := $(sort $(basename $(Source)))
Chris Lattnereefa3d32003-11-29 09:50:15 +0000373ObjectsO := $(Srcs:%=$(BUILD_OBJ_DIR)/Release/%.lo)
374ObjectsP := $(Srcs:%=$(BUILD_OBJ_DIR)/Profile/%.lo)
375ObjectsG := $(Srcs:%=$(BUILD_OBJ_DIR)/Debug/%.lo)
376ObjectsBC := $(Srcs:%=$(BUILD_OBJ_DIR)/BytecodeObj/%.bc)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000377
John Criswell82f4a5a2003-07-31 20:58:51 +0000378#
379# The real objects underlying the libtool objects
380#
John Criswell410d1b52003-09-09 20:57:03 +0000381RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
John Criswell82f4a5a2003-07-31 20:58:51 +0000382RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
383RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
384RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
385
Chris Lattner00950542001-06-06 20:29:01 +0000386#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000387# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000388#---------------------------------------------------------
389
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000390ifdef DIRS
Chris Lattnera8df7bd2003-12-01 07:28:25 +0000391all install clean test bytecode stripped-bytecode::
Chris Lattner16d1f732002-09-17 23:45:34 +0000392 $(VERB) for dir in ${DIRS}; do \
John Criswell60577602003-11-25 17:49:22 +0000393 if [ ! -f $$dir/Makefile ]; \
394 then \
John Criswellb3866b62003-11-25 19:32:22 +0000395 $(MKDIR) $$dir; \
John Criswell60577602003-11-25 17:49:22 +0000396 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
397 fi; \
John Criswell5af06f62003-11-24 18:31:01 +0000398 ($(MAKE) -C $$dir $@) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000399 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000400endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000401
402# Handle PARALLEL_DIRS
403ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000404all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
405install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
406clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
407test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
408bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8df7bd2003-12-01 07:28:25 +0000409stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000410
Chris Lattnera8df7bd2003-12-01 07:28:25 +0000411%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode:
John Criswellb3866b62003-11-25 19:32:22 +0000412 $(VERB) if [ ! -f $(@D)/Makefile ]; \
413 then \
414 $(MKDIR) $(@D); \
415 cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \
416 fi; \
417 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000418endif
419
John Criswell7a73b802003-06-30 21:59:07 +0000420# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000421ifdef OPTIONAL_DIRS
Chris Lattnera8df7bd2003-12-01 07:28:25 +0000422all install clean test bytecode stripped-bytecode::
John Criswell2a6530f2003-06-27 16:58:44 +0000423 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
John Criswell60577602003-11-25 17:49:22 +0000424 if [ -d $(SourceDir)/$$dir ]; \
John Criswell2a6530f2003-06-27 16:58:44 +0000425 then\
John Criswell60577602003-11-25 17:49:22 +0000426 if [ ! -f $$dir/Makefile ]; \
427 then \
John Criswellb3866b62003-11-25 19:32:22 +0000428 $(MKDIR) $$dir; \
John Criswell60577602003-11-25 17:49:22 +0000429 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
430 fi; \
John Criswell5af06f62003-11-24 18:31:01 +0000431 ($(MAKE) -C$$dir $@) || exit 1; \
John Criswell2a6530f2003-06-27 16:58:44 +0000432 fi \
433 done
434endif
435
John Criswell7a73b802003-06-30 21:59:07 +0000436###########################################################################
437# Library Build Rules:
438#
Chris Lattner00950542001-06-06 20:29:01 +0000439#---------------------------------------------------------
440# Handle the LIBRARYNAME option - used when building libs...
441#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000442#
443# When libraries are built, they are allowed to optionally define the
444# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
445# from being built for the library. This .o files may then be linked to by a
446# tool if the tool does not need (or want) the semantics a .a file provides
447# (linking in only object files that are "needed"). If a library is never to
448# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
449# BUILD_ARCHIVE instead.
450#
451# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000452# 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 +0000453# linked into tools (for example gccas) even if they only use one of the parts
454# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000455###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000456
457ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000458
Chris Lattner2a548c52002-09-16 22:36:42 +0000459# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000460LIBRARYNAME := $(strip $(LIBRARYNAME))
461
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000462LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).$(SHLIBEXT)
463LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).$(SHLIBEXT)
464LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).$(SHLIBEXT)
465LIBNAME_CUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).$(SHLIBEXT)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000466LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
467LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
468LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000469LIBNAME_ACUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000470LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
471LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
472LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000473LIBNAME_OBJCUR := $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattner481cc7c2003-08-15 02:18:35 +0000474LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner00950542001-06-06 20:29:01 +0000475
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000476
John Criswell7a73b802003-06-30 21:59:07 +0000477#--------------------------------------------------------------------
478# Library Targets
479# Modify the top level targets to build the desired libraries.
480#--------------------------------------------------------------------
481
Chris Lattner760da062003-03-14 20:25:22 +0000482# dynamic target builds a shared object version of the library...
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000483dynamic:: $(LIBNAME_CUR)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000484bytecodelib:: $(LIBNAME_BC)
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000485install-bytecode-library:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
Chris Lattner481cc7c2003-08-15 02:18:35 +0000486
487$(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
John Criswell7ec78aa2003-10-16 01:49:00 +0000488 @${ECHO} ======= Installing $(LIBRARYNAME) bytecode library =======
Chris Lattner481cc7c2003-08-15 02:18:35 +0000489 cp $< $@
Vikram S. Adve60f56062002-08-02 18:34:12 +0000490
Chris Lattner760da062003-03-14 20:25:22 +0000491# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000492ifndef DONT_BUILD_RELINKED
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000493all:: $(LIBNAME_OBJCUR)
494install:: install-single-object-library
Chris Lattnere62dbe92002-07-23 17:56:16 +0000495endif
Chris Lattner760da062003-03-14 20:25:22 +0000496
497# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000498ifdef BUILD_ARCHIVE
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000499all:: $(LIBNAME_ACUR)
500install:: install-archive-library
Chris Lattnere62dbe92002-07-23 17:56:16 +0000501endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000502
John Criswell7a73b802003-06-30 21:59:07 +0000503#--------------------------------------------------------------------
504# Rules for building libraries
505#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000506
Chris Lattner771ed152003-10-21 18:00:37 +0000507LinkBCLib := $(LLVMGCC) -shared -nostdlib
Chris Lattner481cc7c2003-08-15 02:18:35 +0000508ifdef EXPORTED_SYMBOL_LIST
509LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
510else
Chris Lattner22c83282003-09-15 15:06:54 +0000511 ifdef EXPORTED_SYMBOL_FILE
512LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
513 else
Chris Lattner481cc7c2003-08-15 02:18:35 +0000514LinkBCLib += -Xlinker -disable-internalize
Chris Lattner22c83282003-09-15 15:06:54 +0000515 endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000516endif
517
518
519# Rule for building bytecode libraries.
Chris Lattneraf06a082003-08-15 03:02:52 +0000520$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000521 @${ECHO} Linking $(LIBRARYNAME) bytecode library
Chris Lattner481cc7c2003-08-15 02:18:35 +0000522 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswella4c53522003-11-03 21:12:49 +0000523 @${ECHO} ======= Finished building $(LIBRARYNAME) bytecode library =======
John Criswell7a73b802003-06-30 21:59:07 +0000524#
525# Rules for building dynamically linked libraries.
526#
John Criswellf4ccd992003-07-01 14:52:28 +0000527$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000528 @${ECHO} Linking $(LIBRARYNAME) dynamic release library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000529 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
530 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000531 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic release library =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000532
John Criswellf4ccd992003-07-01 14:52:28 +0000533$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000534 @${ECHO} Linking $(LIBRARYNAME) dynamic profile library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000535 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
536 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000537 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic profile library =======
Chris Lattner00950542001-06-06 20:29:01 +0000538
John Criswellf4ccd992003-07-01 14:52:28 +0000539$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000540 @${ECHO} Linking $(LIBRARYNAME) dynamic debug library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000541 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
542 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000543 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic debug library =======
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000544
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000545install-dynamic-library: $(LIBNAME_CUR)
546 $(MKDIR) $(libdir)
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000547 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_CUR) $(libdir)/lib$(LIBRARYNAME).$(SHLIBEXT)
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000548
John Criswell7a73b802003-06-30 21:59:07 +0000549#
550# Rules for building static archive libraries.
551#
John Criswellf4ccd992003-07-01 14:52:28 +0000552$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000553 @${ECHO} Linking $(LIBRARYNAME) archive release library
John Criswell7a73b802003-06-30 21:59:07 +0000554 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000555 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000556 @${ECHO} Finished building $(LIBRARYNAME) archive release library =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000557
John Criswellf4ccd992003-07-01 14:52:28 +0000558$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000559 @${ECHO} Linking $(LIBRARYNAME) archive profile library
John Criswell7a73b802003-06-30 21:59:07 +0000560 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000561 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000562 @${ECHO} ======= Finished building $(LIBRARYNAME) archive profile library =======
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000563
John Criswellf4ccd992003-07-01 14:52:28 +0000564$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000565 @${ECHO} Linking $(LIBRARYNAME) archive debug library
John Criswell7a73b802003-06-30 21:59:07 +0000566 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000567 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000568 @${ECHO} ======= Finished building $(LIBRARYNAME) archive debug library =======
John Criswell7a73b802003-06-30 21:59:07 +0000569
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000570install-archive-library: $(LIBNAME_ACUR)
571 $(MKDIR) $(libdir)
572 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_ACUR) $(libdir)/lib$(LIBRARYNAME).a
Chris Lattner481cc7c2003-08-15 02:18:35 +0000573
John Criswell7a73b802003-06-30 21:59:07 +0000574#
575# Rules for building .o libraries.
576#
John Criswell82f4a5a2003-07-31 20:58:51 +0000577# JTC:
578# Note that for this special case, we specify the actual object files
579# instead of their libtool counterparts. This is because libtool
580# doesn't want to generate a reloadable object file unless it is given
581# .o files explicitly.
582#
583# Note that we're making an assumption here: If we build a .lo file,
584# it's corresponding .o file will be placed in the same directory.
585#
586# I think that is safe.
587#
John Criswellf4ccd992003-07-01 14:52:28 +0000588$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000589 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000590 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000591
John Criswellf4ccd992003-07-01 14:52:28 +0000592$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000593 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000594 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000595
John Criswellf4ccd992003-07-01 14:52:28 +0000596$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000597 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000598 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000599
Brian Gaeke78cb3f22003-12-18 20:57:48 +0000600install-single-object-library: $(LIBNAME_OBJCUR)
601 $(MKDIR) $(libdir)
602 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_OBJCUR) $(libdir)/$(LIBRARYNAME).o
603
Chris Lattner00950542001-06-06 20:29:01 +0000604endif
605
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000606#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000607# Create a TAGS database for emacs
608#------------------------------------------------------------------------
609
John Criswelle0f9ac62003-10-02 19:02:02 +0000610ifneq ($(ETAGS),false)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000611ifeq ($(LEVEL), .)
John Criswell7f336952003-09-06 14:44:17 +0000612SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
Chris Lattner942f9042003-08-21 21:53:38 +0000613
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000614tags:
Chris Lattner942f9042003-08-21 21:53:38 +0000615 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000616all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000617endif
John Criswell7a73b802003-06-30 21:59:07 +0000618else
619tags:
620 ${ECHO} "Cannot build $@: The program etags is not installed"
621endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000622
623#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000624# Handle the TOOLNAME option - used when building tool executables...
625#------------------------------------------------------------------------
626#
627# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000628# libraries (and the order of the libs) that should be linked to the
629# tool. USEDLIBS should contain a list of library names (some with .a extension)
630# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000631#
632ifdef TOOLNAME
633
634# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000635TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
636TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
637TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
638TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000639
640# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000641PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
642PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
643PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
644PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
645
646LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
647LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
648LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
649LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
650
651LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000652LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000653LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
654
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000655# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000656# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000657# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000658#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000659STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000660USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
661USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
662USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000663
John Criswell7a73b802003-06-30 21:59:07 +0000664#
665# Libtool link options:
666# Ensure that all binaries have their symbols exported so that they can
667# by dlsym'ed.
668#
669LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000670
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000671
672
673
674
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000675# Tell make that we need to rebuild subdirectories before we can link the tool.
676# This affects things like LLI which has library subdirectories.
677$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
678 $(addsuffix /.makeall, $(PARALLEL_DIRS))
679
Chris Lattner669bd7c2001-10-13 05:10:29 +0000680all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000681
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000682clean::
John Criswell7a73b802003-06-30 21:59:07 +0000683 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000684
John Criswellf4ccd992003-07-01 14:52:28 +0000685$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000686 @${ECHO} Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)
John Criswellf4ccd992003-07-01 14:52:28 +0000687 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000688 @${ECHO} ======= Finished building $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000689
John Criswellf4ccd992003-07-01 14:52:28 +0000690$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000691 @${ECHO} Linking $(TOOLNAME) release executable
John Criswellf4ccd992003-07-01 14:52:28 +0000692 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000693 @${ECHO} ======= Finished building $(TOOLNAME) release executable =======
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
John Criswella4c53522003-11-03 21:12:49 +0000696 @${ECHO} Linking $(TOOLNAME) profile executable
John Criswellf4ccd992003-07-01 14:52:28 +0000697 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000698 @${ECHO} ======= Finished building $(TOOLNAME) profile executable =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000699
Brian Gaeke44909cf2003-12-10 00:26:28 +0000700install:: $(TOOLEXENAMES)
701 $(MKDIR) $(bindir)
702 $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -c -m 0755 $(TOOLEXENAMES) $(bindir)/$(TOOLNAME)
703
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000704endif
705
706
Chris Lattner00950542001-06-06 20:29:01 +0000707
708#---------------------------------------------------------
Chris Lattner0df847a2003-09-15 22:17:02 +0000709.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000710.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000711
John Criswell7a73b802003-06-30 21:59:07 +0000712# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
John Criswell410d1b52003-09-09 20:57:03 +0000713$(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000714 @${ECHO} "Compiling `basename $<`"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000715 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000716
John Criswell410d1b52003-09-09 20:57:03 +0000717$(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000718 @${ECHO} "Compiling `basename $<`"
Chris Lattner1eeac662002-10-22 23:28:23 +0000719 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000720
John Criswell410d1b52003-09-09 20:57:03 +0000721$(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000722 @${ECHO} "Compiling `basename $<`"
Vikram S. Adve41e78912002-09-20 14:03:13 +0000723 $(VERB) $(CompileP) $< -o $@
724
John Criswell410d1b52003-09-09 20:57:03 +0000725$(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000726 @${ECHO} "Compiling `basename $<`"
Chris Lattner172b6482002-09-22 02:47:15 +0000727 $(VERB) $(CompileCP) $< -o $@
728
John Criswell410d1b52003-09-09 20:57:03 +0000729$(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000730 @${ECHO} "Compiling `basename $<`"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000731 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000732
John Criswell410d1b52003-09-09 20:57:03 +0000733$(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000734 @${ECHO} "Compiling `basename $<`"
John Criswell7a73b802003-06-30 21:59:07 +0000735 $(VERB) $(CompileCG) $< -o $@
736
Chris Lattner0df847a2003-09-15 22:17:02 +0000737$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
John Criswell7ec78aa2003-10-16 01:49:00 +0000738 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattnerd1803002003-12-06 20:59:45 +0000739 $(VERB) $(LLVMGXX) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000740
Chris Lattner0df847a2003-09-15 22:17:02 +0000741$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
John Criswell7ec78aa2003-10-16 01:49:00 +0000742 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattnerd1803002003-12-06 20:59:45 +0000743 $(VERB) $(LLVMGCC) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000744
Chris Lattner0df847a2003-09-15 22:17:02 +0000745$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
John Criswell7ec78aa2003-10-16 01:49:00 +0000746 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000747 $(VERB) $(LLVMAS) $< -f -o $@
748
749
Chris Lattnere8996782003-01-16 22:44:19 +0000750#
751# Rules for building lex/yacc files
752#
753LEX_FILES = $(filter %.l, $(Source))
754LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
755YACC_FILES = $(filter %.y, $(Source))
756YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
757.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
758
Chris Lattner00950542001-06-06 20:29:01 +0000759# Create a .cpp source file from a flex input file... this uses sed to cut down
760# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000761#
762# The last line is a gross hack to work around flex aparently not being able to
763# resize the buffer on a large token input. Currently, for uninitialized string
764# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000765# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000766#
Chris Lattner00950542001-06-06 20:29:01 +0000767%.cpp: %.l
John Criswell7ec78aa2003-10-16 01:49:00 +0000768 @${ECHO} Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000769 $(VERB) $(FLEX) -t $< | \
770 $(SED) '/^find_rule/d' | \
771 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000772 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000773 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
774 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000775 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000776 @# remove the output of flex if it didn't get moved over...
777 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000778
779# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000780%.c: %.y # Cancel built-in rules for yacc
781%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000782%.cpp %.h : %.y
Misha Brukmanb6d59a22003-11-05 06:41:14 +0000783 @${ECHO} "Bisoning `basename $<`"
John Criswell410d1b52003-09-09 20:57:03 +0000784 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
John Criswelld741bcf2003-08-12 18:51:51 +0000785 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
786 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000787 @# If the files were not updated, don't leave them lying around...
788 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000789
790# To create the directories...
791%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000792 $(VERB) ${MKDIR} $* > /dev/null
793 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000794
Chris Lattner30440c62003-01-16 21:06:18 +0000795# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000796ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000797%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000798 ${DOT} -Tps < $< > $@
799else
800%.ps: %.dot
801 ${ECHO} "Cannot build $@: The program dot is not installed"
802endif
Chris Lattner30440c62003-01-16 21:06:18 +0000803
John Criswell7f336952003-09-06 14:44:17 +0000804#
805# This rules ensures that header files that are removed still have a rule for
806# which they can be "generated." This allows make to ignore them and
807# reproduce the dependency lists.
808#
John Criswell4b6e5d12003-09-18 18:37:08 +0000809%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000810
Chris Lattner172b6482002-09-22 02:47:15 +0000811# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000812clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000813 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
814 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
Chris Lattner0df847a2003-09-15 22:17:02 +0000815 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000816 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
817ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
818 $(VERB) $(RM) -f *$(SHLIBEXT)
819endif
John Criswell7a73b802003-06-30 21:59:07 +0000820 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
821
John Criswell7a73b802003-06-30 21:59:07 +0000822###########################################################################
823# C/C++ Dependencies
824# Define variables and rules that generate header file dependencies
825# from C/C++ source files.
826###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000827
Chris Lattner33ad24a2003-08-22 14:10:16 +0000828ifndef DISABLE_AUTO_DEPENDENCIES
829
Chris Lattner694c5df2003-05-15 21:28:55 +0000830# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000831# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000832#
John Criswell410d1b52003-09-09 20:57:03 +0000833SourceBaseNames := $(basename $(Source))
John Criswell8bff5092003-06-11 13:55:44 +0000834SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000835
836# Create dependencies for the *.cpp files...
John Criswell410d1b52003-09-09 20:57:03 +0000837$(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner52d792c2003-11-08 21:23:06 +0000838 $(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 +0000839
840# Create dependencies for the *.c files...
John Criswell410d1b52003-09-09 20:57:03 +0000841$(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner52d792c2003-11-08 21:23:06 +0000842 $(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 +0000843
John Criswell7a73b802003-06-30 21:59:07 +0000844#
John Criswellbd082802003-10-07 14:16:44 +0000845# Autoconf Dependencies.
846#
Misha Brukman94fe1f92003-10-07 15:24:23 +0000847$(LLVM_OBJ_ROOT)/config.status:: $(LLVM_SRC_ROOT)/configure
Chris Lattner4faf8602003-10-10 15:55:43 +0000848 @${ECHO} "****************************************************************"
849 @${ECHO} " You need to re-run $(LLVM_SRC_ROOT)/configure"
850 @${ECHO} " in directory $(LLVM_OBJ_ROOT)"
851 @${ECHO} "****************************************************************"
John Criswellbd082802003-10-07 14:16:44 +0000852 $(VERB) exit 1
853
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000854# If the Makefile in the source tree has been updated, copy it over into the
855# build tree.
856Makefile :: $(BUILD_SRC_DIR)/Makefile
Misha Brukman2fe69092003-11-11 00:05:29 +0000857 @${ECHO} "===== Updating Makefile from source dir: `dirname $<` ====="
John Criswellb3866b62003-11-25 19:32:22 +0000858 $(MKDIR) $(@D)
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000859 cp -f $< $@
860
John Criswellbd082802003-10-07 14:16:44 +0000861#
John Criswell7a73b802003-06-30 21:59:07 +0000862# Include dependencies generated from C/C++ source files, but not if we
863# are cleaning (this example taken from the GNU Make Manual).
864#
865ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000866ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner15444a92003-08-29 14:07:02 +0000867-include /dev/null $(SourceDepend)
John Criswell7a73b802003-06-30 21:59:07 +0000868endif
John Criswelld741bcf2003-08-12 18:51:51 +0000869endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000870
Chris Lattner33ad24a2003-08-22 14:10:16 +0000871endif # ifndef DISABLE_AUTO_DEPENDENCIES