blob: 48dfe35bf72eb04eb2419934bef688fed40b4b45 [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
Chris Lattneredf1f232002-07-23 19:21:31 +000074endif
75
Chris Lattner95cc1b32003-08-14 21:10:25 +000076ifdef BYTECODE_LIBRARY
77# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
78all:: bytecodelib
Chris Lattner481cc7c2003-08-15 02:18:35 +000079install:: bytecodelib-install
Chris Lattner95cc1b32003-08-14 21:10:25 +000080endif
81
Chris Lattnerb19e59c2001-06-29 05:20:16 +000082# Default Rule: Make sure it's also a :: rule
Chris Lattner00950542001-06-06 20:29:01 +000083all ::
84
85# Default for install is to at least build everything...
86install ::
87
John Criswell8bff5092003-06-11 13:55:44 +000088# Default rule for test. It ensures everything has a test rule
89test::
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +000090
Vikram S. Adve6edfe272003-07-10 19:25:29 +000091# Default rule for building only bytecode.
92bytecode::
93
John Criswell7a73b802003-06-30 21:59:07 +000094# Print out the directories used for building
95prdirs::
John Criswell7ec78aa2003-10-16 01:49:00 +000096 @${ECHO} "Build Source Root: " $(BUILD_SRC_ROOT)
97 @${ECHO} "Build Source Dir : " $(BUILD_SRC_DIR)
98 @${ECHO} "Build Object Root: " $(BUILD_OBJ_ROOT)
99 @${ECHO} "Build Object Dir : " $(BUILD_OBJ_DIR)
100 @${ECHO} "LLVM Source Root: " $(LLVM_SRC_ROOT)
101 @${ECHO} "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell7a73b802003-06-30 21:59:07 +0000102
John Criswell9621a2b2003-08-20 15:18:41 +0000103###########################################################################
104# Suffixes and implicit rules:
105# Empty out the list of suffixes, generate a list that is only
106# used by this Makefile, and cancel useless implicit rules. This
107# will hopefully speed up compilation a little bit.
108###########################################################################
109.SUFFIXES:
110.SUFFIXES: .c .cpp .h .hpp .y .l
John Criswell410d1b52003-09-09 20:57:03 +0000111.SUFFIXES: .lo .o .a .so .bc .td
John Criswell9621a2b2003-08-20 15:18:41 +0000112.SUFFIXES: .ps .dot .d
113
John Criswell96914392003-07-16 20:26:06 +0000114#
115# Mark all of these targets as phony. This will hopefully speed up builds
116# slightly since GNU Make will not try to find implicit rules for targets
117# which are marked as Phony.
118#
Chris Lattner481cc7c2003-08-15 02:18:35 +0000119.PHONY: all dynamic bytecodelib bytecodelib-install
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000120.PHONY: clean distclean install test bytecode prdirs
John Criswell96914392003-07-16 20:26:06 +0000121
John Criswell7a73b802003-06-30 21:59:07 +0000122###########################################################################
123# Miscellaneous paths and commands:
124# This section defines various configuration macros, such as where
125# to find burg, tblgen, and libtool.
126###########################################################################
127
Chris Lattner00950542001-06-06 20:29:01 +0000128#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000129# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000130#--------------------------------------------------------------------
131
132#BinInstDir=/usr/local/bin
John Criswell65aa59342003-05-29 18:52:10 +0000133#LibInstDir=/usr/local/lib/xxx
Chris Lattner00950542001-06-06 20:29:01 +0000134#DocInstDir=/usr/doc/xxx
135
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000136BURG_OPTS = -I
137
Chris Lattner760da062003-03-14 20:25:22 +0000138ifdef ENABLE_PROFILING
139 ENABLE_OPTIMIZED = 1
140 CONFIGURATION := Profile
141else
142 ifdef ENABLE_OPTIMIZED
143 CONFIGURATION := Release
144 else
145 CONFIGURATION := Debug
146 endif
147endif
148
John Criswell7a73b802003-06-30 21:59:07 +0000149#
150# Enable this for profiling support with 'gprof'
151# This automatically enables optimized builds.
152#
153ifdef ENABLE_PROFILING
154 PROFILE = -pg
155endif
156
John Criswell8bff5092003-06-11 13:55:44 +0000157###########################################################################
John Criswell7a73b802003-06-30 21:59:07 +0000158# Library Locations:
John Criswell8bff5092003-06-11 13:55:44 +0000159# These variables describe various library locations:
160#
161# DEST* = Location of where libraries that are built will be placed.
162# LLVM* = Location of LLVM libraries used for linking.
163# PROJ* = Location of previously built libraries used for linking.
164###########################################################################
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000165
John Criswell8bff5092003-06-11 13:55:44 +0000166# Libraries that are being built
167DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
168DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
169DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattnerad2be6c2003-09-10 19:37:51 +0000170DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
John Criswell8bff5092003-06-11 13:55:44 +0000171DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000172
John Criswell8bff5092003-06-11 13:55:44 +0000173# LLVM libraries used for linking
174LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
175LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
176LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
177LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000178
John Criswell8bff5092003-06-11 13:55:44 +0000179# Libraries that were built that will now be used for linking
180PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
181PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
182PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
183PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000184
John Criswell8bff5092003-06-11 13:55:44 +0000185###########################################################################
186# Tool Locations
187# These variables describe various tool locations:
188#
189# DEST* = Location of where tools that are built will be placed.
190# LLVM* = Location of LLVM tools used for building.
191# PROJ* = Location of previously built tools used for linking.
192###########################################################################
Chris Lattner760da062003-03-14 20:25:22 +0000193
John Criswell8bff5092003-06-11 13:55:44 +0000194DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
195DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
196DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
197DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
198
199LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
200LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
201LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
202LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
203
204PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
205PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
206PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
207PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000208
John Criswell7a73b802003-06-30 21:59:07 +0000209#
210# Libtool is found in the current directory.
211#
John Criswell7f336952003-09-06 14:44:17 +0000212LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
John Criswell7a73b802003-06-30 21:59:07 +0000213
214#
John Criswell82f4a5a2003-07-31 20:58:51 +0000215# If we're not building a shared library, use the disable-shared tag with
216# libtool. This will disable the building of objects for shared libraries and
217# only generate static library objects.
218#
219# For dynamic libraries, we'll take the performance hit for now, since we
220# almost never build them.
221#
222# This should speed up compilation and require no modifications to future
223# versions of libtool.
224#
225ifndef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000226LIBTOOL += --tag=disable-shared
John Criswell82f4a5a2003-07-31 20:58:51 +0000227endif
228
229#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000230# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000231#
Chris Lattner760da062003-03-14 20:25:22 +0000232ifndef VERBOSE
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000233VERB := @
Chris Lattner95cc1b32003-08-14 21:10:25 +0000234LIBTOOL += --silent
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000235endif
236
John Criswell7a73b802003-06-30 21:59:07 +0000237###########################################################################
238# Miscellaneous paths and commands (part deux):
239# This section defines various configuration macros, such as where
240# to find burg, tblgen, and libtool.
241###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000242
John Criswell7a73b802003-06-30 21:59:07 +0000243#--------------------------------------------------------------------------
Chris Lattner481cc7c2003-08-15 02:18:35 +0000244# Utilities used while building the LLVM tree, which live in the utils dir
245#
John Criswell8bff5092003-06-11 13:55:44 +0000246BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattner9b947012002-09-19 19:42:24 +0000247RunBurg := $(BURG) $(BURG_OPTS)
John Criswell8bff5092003-06-11 13:55:44 +0000248TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Advedba59ef2001-08-06 19:01:20 +0000249
Chris Lattner481cc7c2003-08-15 02:18:35 +0000250#--------------------------------------------------------------------------
251# The LLVM GCC front-end in C and C++ flavors
252#
Chris Lattner9a86a012003-08-15 15:20:52 +0000253LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattner98892652003-08-20 22:11:45 +0000254LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
Chris Lattner9a86a012003-08-15 15:20:52 +0000255LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattner98892652003-08-20 22:11:45 +0000256LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
Chris Lattner481cc7c2003-08-15 02:18:35 +0000257
258#--------------------------------------------------------------------------
259# Some of the compiled LLVM tools which are used for compilation of runtime
260# libraries.
261#
Misha Brukmana86b0422003-08-28 21:45:08 +0000262LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
Chris Lattner481cc7c2003-08-15 02:18:35 +0000263
Chris Lattner00950542001-06-06 20:29:01 +0000264
John Criswell8bff5092003-06-11 13:55:44 +0000265###########################################################################
266# Compile Time Flags
267###########################################################################
268
269#
John Criswell7a73b802003-06-30 21:59:07 +0000270# Include both the project headers and the LLVM headers for compilation and
271# dependency computation.
John Criswell8bff5092003-06-11 13:55:44 +0000272#
John Criswell7f336952003-09-06 14:44:17 +0000273# BUILD_OBJ_DIR : Files local to the particular object directory
274# (locallly generated header files).
275# BUILD_SRC_DIR : Files local to the particular source directory.
276# BUILD_SRC_ROOT/include : Files global to the project.
Chris Lattner00e730a2003-09-15 01:07:32 +0000277# LLVM_OBJ_ROOT/include : config.h files generated by autoconf
John Criswell7f336952003-09-06 14:44:17 +0000278# LEVEL/include : config.h files for the project
279# LLVM_SRC_ROOT/include : Files global to LLVM.
John Criswell7f336952003-09-06 14:44:17 +0000280#
Chris Lattner069f9302003-09-15 01:12:04 +0000281CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
282 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
283 -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000284
Vikram S. Advefeeae582002-09-18 11:55:13 +0000285# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000286ifndef KEEP_SYMBOLS
Chris Lattner527002c2003-01-31 19:00:26 +0000287STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukman9b51b6f2003-07-10 16:52:41 +0000288STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000289endif
290
Brian Gaeke90eca552003-10-28 19:09:28 +0000291# Allow GNU extensions:
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000292CPPFLAGS += -D_GNU_SOURCE
Brian Gaeke90eca552003-10-28 19:09:28 +0000293# Pull in limit macros from stdint.h, even in C++:
294CPPFLAGS += -D__STDC_LIMIT_MACROS
Chris Lattner73e1d0f2002-09-13 16:02:26 +0000295
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000296CompileWarnings := -Wall -W -Wwrite-strings -Wno-unused
John Criswell7f336952003-09-06 14:44:17 +0000297CompileCommonOpts := $(CompileWarnings) -fshort-enums
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000298CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
Chris Lattner00950542001-06-06 20:29:01 +0000299
John Criswell7a73b802003-06-30 21:59:07 +0000300#
301# Compile commands with libtool.
302#
303Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattner72987ee2003-08-23 15:56:38 +0000304CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
John Criswell7a73b802003-06-30 21:59:07 +0000305
Chris Lattner172b6482002-09-22 02:47:15 +0000306# Compile a cpp file, don't link...
Chris Lattner285af382002-08-12 21:19:28 +0000307CompileG := $(Compile) -g -D_DEBUG
Chris Lattner1d1e5b52003-02-13 16:56:30 +0000308CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
309CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000310
Chris Lattner172b6482002-09-22 02:47:15 +0000311# Compile a c file, don't link...
Chris Lattner172b6482002-09-22 02:47:15 +0000312CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattnerfe95dae2003-02-19 22:12:20 +0000313CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
314CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattner172b6482002-09-22 02:47:15 +0000315
John Criswell7a73b802003-06-30 21:59:07 +0000316###########################################################################
317# Link Time Options
318###########################################################################
Chris Lattner172b6482002-09-22 02:47:15 +0000319
John Criswell7a73b802003-06-30 21:59:07 +0000320#
Chris Lattner00950542001-06-06 20:29:01 +0000321# Link final executable
John Criswell7a73b802003-06-30 21:59:07 +0000322# (Note that we always link with the C++ compiler).
323#
John Criswell7a73b802003-06-30 21:59:07 +0000324Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000325
John Criswell7a73b802003-06-30 21:59:07 +0000326# link both projlib and llvmlib libraries
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000327LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
328LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
329LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner00950542001-06-06 20:29:01 +0000330
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000331# TOOLLINKOPTSB to pass options to the linker like library search path etc
332# Note that this is different from TOOLLINKOPTS, these options
333# are passed to the linker *before* the USEDLIBS options are passed.
334# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
335ifdef TOOLLINKOPTSB
336LinkG := $(LinkG) $(TOOLLINKOPTSB)
Dinakar Dhurjati79903c82003-10-29 20:34:13 +0000337LinkO := $(LinkO) $(TOOLLINKOPTSB)
338LinkP := $(LinkP) $(TOOLLINKOPTSB)
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000339endif
340
Chris Lattnere62dbe92002-07-23 17:56:16 +0000341# Create one .o file from a bunch of .o files...
Chris Lattner95cc1b32003-08-14 21:10:25 +0000342Relink := ${LIBTOOL} --mode=link $(CXX)
John Criswell7a73b802003-06-30 21:59:07 +0000343
344#
345# Configure where the item being compiled should go.
346#
347ifdef SHARED_LIBRARY
Chris Lattner95cc1b32003-08-14 21:10:25 +0000348Link += -rpath $(DESTLIBCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000349endif
350
351ifdef TOOLNAME
Chris Lattner95cc1b32003-08-14 21:10:25 +0000352Link += -rpath $(DESTTOOLCURRENT)
John Criswell7a73b802003-06-30 21:59:07 +0000353endif
Chris Lattner4bb13b82002-09-13 22:14:47 +0000354
Misha Brukman36bc6422003-08-21 22:02:18 +0000355# Create dependency file from CPP file, send to stdout.
John Criswell8bff5092003-06-11 13:55:44 +0000356Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
357DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000358
359# Archive a bunch of .o files into a .a file...
John Criswell794fcd22003-05-30 15:50:31 +0000360AR = ${AR_PATH} cq
Chris Lattner00950542001-06-06 20:29:01 +0000361
362#----------------------------------------------------------
363
364# Source includes all of the cpp files, and objects are derived from the
365# source files...
Chris Lattnere0010592001-10-18 01:48:09 +0000366# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000367#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000368ifndef Source
Chris Lattner069f9302003-09-15 01:12:04 +0000369Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
370 $(SourceDir)/*.c $(SourceDir)/*.y $(SourceDir)/*.l))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000371endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000372
John Criswell82f4a5a2003-07-31 20:58:51 +0000373#
374# Libtool Objects
375#
John Criswell410d1b52003-09-09 20:57:03 +0000376Srcs := $(sort $(basename $(Source)))
Chris Lattner481cc7c2003-08-15 02:18:35 +0000377Objs := $(addsuffix .lo, $(Srcs))
John Criswellf4ccd992003-07-01 14:52:28 +0000378ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
379ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
380ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner0df847a2003-09-15 22:17:02 +0000381ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/BytecodeObj/,$(addsuffix .bc, $(Srcs)))
Chris Lattnere62dbe92002-07-23 17:56:16 +0000382
John Criswell82f4a5a2003-07-31 20:58:51 +0000383#
384# The real objects underlying the libtool objects
385#
John Criswell410d1b52003-09-09 20:57:03 +0000386RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
John Criswell82f4a5a2003-07-31 20:58:51 +0000387RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
388RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
389RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
390
Chris Lattner00950542001-06-06 20:29:01 +0000391#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000392# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000393#---------------------------------------------------------
394
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000395ifdef DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000396all install clean test bytecode ::
Chris Lattner16d1f732002-09-17 23:45:34 +0000397 $(VERB) for dir in ${DIRS}; do \
John Criswell60577602003-11-25 17:49:22 +0000398 if [ ! -f $$dir/Makefile ]; \
399 then \
John Criswellb3866b62003-11-25 19:32:22 +0000400 $(MKDIR) $$dir; \
John Criswell60577602003-11-25 17:49:22 +0000401 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
402 fi; \
John Criswell5af06f62003-11-24 18:31:01 +0000403 ($(MAKE) -C $$dir $@) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000404 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000405endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000406
407# Handle PARALLEL_DIRS
408ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000409all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
410install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
411clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
412test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
413bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000414
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000415%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
John Criswellb3866b62003-11-25 19:32:22 +0000416 $(VERB) if [ ! -f $(@D)/Makefile ]; \
417 then \
418 $(MKDIR) $(@D); \
419 cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \
420 fi; \
421 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000422endif
423
John Criswell7a73b802003-06-30 21:59:07 +0000424# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000425ifdef OPTIONAL_DIRS
Chris Lattnerfbb574d2003-08-21 20:39:08 +0000426all install clean test bytecode ::
John Criswell2a6530f2003-06-27 16:58:44 +0000427 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
John Criswell60577602003-11-25 17:49:22 +0000428 if [ -d $(SourceDir)/$$dir ]; \
John Criswell2a6530f2003-06-27 16:58:44 +0000429 then\
John Criswell60577602003-11-25 17:49:22 +0000430 if [ ! -f $$dir/Makefile ]; \
431 then \
John Criswellb3866b62003-11-25 19:32:22 +0000432 $(MKDIR) $$dir; \
John Criswell60577602003-11-25 17:49:22 +0000433 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
434 fi; \
John Criswell5af06f62003-11-24 18:31:01 +0000435 ($(MAKE) -C$$dir $@) || exit 1; \
John Criswell2a6530f2003-06-27 16:58:44 +0000436 fi \
437 done
438endif
439
John Criswell7a73b802003-06-30 21:59:07 +0000440###########################################################################
441# Library Build Rules:
442#
Chris Lattner00950542001-06-06 20:29:01 +0000443#---------------------------------------------------------
444# Handle the LIBRARYNAME option - used when building libs...
445#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000446#
447# When libraries are built, they are allowed to optionally define the
448# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
449# from being built for the library. This .o files may then be linked to by a
450# tool if the tool does not need (or want) the semantics a .a file provides
451# (linking in only object files that are "needed"). If a library is never to
452# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
453# BUILD_ARCHIVE instead.
454#
455# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000456# 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 +0000457# linked into tools (for example gccas) even if they only use one of the parts
458# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000459###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000460
461ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000462
Chris Lattner2a548c52002-09-16 22:36:42 +0000463# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000464LIBRARYNAME := $(strip $(LIBRARYNAME))
465
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000466LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
467LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
468LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
469LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
470LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
471LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
472LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
473LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
474LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner481cc7c2003-08-15 02:18:35 +0000475LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner00950542001-06-06 20:29:01 +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...
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000483dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Chris Lattner481cc7c2003-08-15 02:18:35 +0000484bytecodelib:: $(LIBNAME_BC)
485bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
486
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
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000493all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattnere62dbe92002-07-23 17:56:16 +0000494endif
Chris Lattner760da062003-03-14 20:25:22 +0000495
496# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000497ifdef BUILD_ARCHIVE
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000498all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattnere62dbe92002-07-23 17:56:16 +0000499endif
Chris Lattnere62dbe92002-07-23 17:56:16 +0000500
John Criswell7a73b802003-06-30 21:59:07 +0000501#--------------------------------------------------------------------
502# Rules for building libraries
503#--------------------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000504
Chris Lattner771ed152003-10-21 18:00:37 +0000505LinkBCLib := $(LLVMGCC) -shared -nostdlib
Chris Lattner481cc7c2003-08-15 02:18:35 +0000506ifdef EXPORTED_SYMBOL_LIST
507LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
508else
Chris Lattner22c83282003-09-15 15:06:54 +0000509 ifdef EXPORTED_SYMBOL_FILE
510LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
511 else
Chris Lattner481cc7c2003-08-15 02:18:35 +0000512LinkBCLib += -Xlinker -disable-internalize
Chris Lattner22c83282003-09-15 15:06:54 +0000513 endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000514endif
515
516
517# Rule for building bytecode libraries.
Chris Lattneraf06a082003-08-15 03:02:52 +0000518$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000519 @${ECHO} Linking $(LIBRARYNAME) bytecode library
Chris Lattner481cc7c2003-08-15 02:18:35 +0000520 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswella4c53522003-11-03 21:12:49 +0000521 @${ECHO} ======= Finished building $(LIBRARYNAME) bytecode library =======
John Criswell7a73b802003-06-30 21:59:07 +0000522#
523# Rules for building dynamically linked libraries.
524#
John Criswellf4ccd992003-07-01 14:52:28 +0000525$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000526 @${ECHO} Linking $(LIBRARYNAME) dynamic release library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000527 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
528 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000529 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic release library =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000530
John Criswellf4ccd992003-07-01 14:52:28 +0000531$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000532 @${ECHO} Linking $(LIBRARYNAME) dynamic profile library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000533 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
534 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000535 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic profile library =======
Chris Lattner00950542001-06-06 20:29:01 +0000536
John Criswellf4ccd992003-07-01 14:52:28 +0000537$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000538 @${ECHO} Linking $(LIBRARYNAME) dynamic debug library
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000539 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
540 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
John Criswella4c53522003-11-03 21:12:49 +0000541 @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic debug library =======
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000542
John Criswell7a73b802003-06-30 21:59:07 +0000543#
544# Rules for building static archive libraries.
545#
John Criswellf4ccd992003-07-01 14:52:28 +0000546$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000547 @${ECHO} Linking $(LIBRARYNAME) archive release library
John Criswell7a73b802003-06-30 21:59:07 +0000548 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000549 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000550 @${ECHO} Finished building $(LIBRARYNAME) archive release library =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000551
John Criswellf4ccd992003-07-01 14:52:28 +0000552$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000553 @${ECHO} Linking $(LIBRARYNAME) archive profile library
John Criswell7a73b802003-06-30 21:59:07 +0000554 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000555 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000556 @${ECHO} ======= Finished building $(LIBRARYNAME) archive profile library =======
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000557
John Criswellf4ccd992003-07-01 14:52:28 +0000558$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000559 @${ECHO} Linking $(LIBRARYNAME) archive debug library
John Criswell7a73b802003-06-30 21:59:07 +0000560 @$(RM) -f $@
John Criswellf4ccd992003-07-01 14:52:28 +0000561 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswella4c53522003-11-03 21:12:49 +0000562 @${ECHO} ======= Finished building $(LIBRARYNAME) archive debug library =======
John Criswell7a73b802003-06-30 21:59:07 +0000563
Chris Lattner481cc7c2003-08-15 02:18:35 +0000564
John Criswell7a73b802003-06-30 21:59:07 +0000565#
566# Rules for building .o libraries.
567#
John Criswell82f4a5a2003-07-31 20:58:51 +0000568# JTC:
569# Note that for this special case, we specify the actual object files
570# instead of their libtool counterparts. This is because libtool
571# doesn't want to generate a reloadable object file unless it is given
572# .o files explicitly.
573#
574# Note that we're making an assumption here: If we build a .lo file,
575# it's corresponding .o file will be placed in the same directory.
576#
577# I think that is safe.
578#
John Criswellf4ccd992003-07-01 14:52:28 +0000579$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000580 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000581 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000582
John Criswellf4ccd992003-07-01 14:52:28 +0000583$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000584 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000585 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve41e78912002-09-20 14:03:13 +0000586
John Criswellf4ccd992003-07-01 14:52:28 +0000587$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000588 @${ECHO} "Linking `basename $@`"
John Criswell82f4a5a2003-07-31 20:58:51 +0000589 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000590
Chris Lattner00950542001-06-06 20:29:01 +0000591endif
592
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000593#------------------------------------------------------------------------
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000594# Create a TAGS database for emacs
595#------------------------------------------------------------------------
596
John Criswelle0f9ac62003-10-02 19:02:02 +0000597ifneq ($(ETAGS),false)
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000598ifeq ($(LEVEL), .)
John Criswell7f336952003-09-06 14:44:17 +0000599SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
Chris Lattner942f9042003-08-21 21:53:38 +0000600
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000601tags:
Chris Lattner942f9042003-08-21 21:53:38 +0000602 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000603all:: tags
Vikram S. Adve022d06c2001-10-13 12:26:59 +0000604endif
John Criswell7a73b802003-06-30 21:59:07 +0000605else
606tags:
607 ${ECHO} "Cannot build $@: The program etags is not installed"
608endif
Vikram S. Adve0193d5e2001-10-10 22:35:00 +0000609
610#------------------------------------------------------------------------
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000611# Handle the TOOLNAME option - used when building tool executables...
612#------------------------------------------------------------------------
613#
614# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000615# libraries (and the order of the libs) that should be linked to the
616# tool. USEDLIBS should contain a list of library names (some with .a extension)
617# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000618#
619ifdef TOOLNAME
620
621# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell8bff5092003-06-11 13:55:44 +0000622TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
623TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
624TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
625TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000626
627# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000628PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
629PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
630PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
631PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
632
633LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
634LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
635LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
636LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
637
638LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnere3ba95e2003-06-20 15:41:57 +0000639LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000640LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
641
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000642# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattnere62dbe92002-07-23 17:56:16 +0000643# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman1ba31382003-07-14 17:26:34 +0000644# files separately.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000645#
Chris Lattnere62dbe92002-07-23 17:56:16 +0000646STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000647USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
648USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
649USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000650
John Criswell7a73b802003-06-30 21:59:07 +0000651#
652# Libtool link options:
653# Ensure that all binaries have their symbols exported so that they can
654# by dlsym'ed.
655#
656LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000657
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000658
659
660
661
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000662# Tell make that we need to rebuild subdirectories before we can link the tool.
663# This affects things like LLI which has library subdirectories.
664$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
665 $(addsuffix /.makeall, $(PARALLEL_DIRS))
666
Chris Lattner669bd7c2001-10-13 05:10:29 +0000667all:: $(TOOLEXENAMES)
John Criswell2a6530f2003-06-27 16:58:44 +0000668
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000669clean::
John Criswell7a73b802003-06-30 21:59:07 +0000670 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000671
John Criswellf4ccd992003-07-01 14:52:28 +0000672$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000673 @${ECHO} Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)
John Criswellf4ccd992003-07-01 14:52:28 +0000674 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000675 @${ECHO} ======= Finished building $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000676
John Criswellf4ccd992003-07-01 14:52:28 +0000677$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000678 @${ECHO} Linking $(TOOLNAME) release executable
John Criswellf4ccd992003-07-01 14:52:28 +0000679 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000680 @${ECHO} ======= Finished building $(TOOLNAME) release executable =======
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000681
John Criswellf4ccd992003-07-01 14:52:28 +0000682$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
John Criswella4c53522003-11-03 21:12:49 +0000683 @${ECHO} Linking $(TOOLNAME) profile executable
John Criswellf4ccd992003-07-01 14:52:28 +0000684 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
John Criswella4c53522003-11-03 21:12:49 +0000685 @${ECHO} ======= Finished building $(TOOLNAME) profile executable =======
Vikram S. Adve41e78912002-09-20 14:03:13 +0000686
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000687endif
688
689
Chris Lattner00950542001-06-06 20:29:01 +0000690
691#---------------------------------------------------------
Chris Lattner0df847a2003-09-15 22:17:02 +0000692.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
John Criswell8bff5092003-06-11 13:55:44 +0000693.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner00950542001-06-06 20:29:01 +0000694
John Criswell7a73b802003-06-30 21:59:07 +0000695# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
John Criswell410d1b52003-09-09 20:57:03 +0000696$(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000697 @${ECHO} "Compiling `basename $<`"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000698 $(VERB) $(CompileO) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000699
John Criswell410d1b52003-09-09 20:57:03 +0000700$(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000701 @${ECHO} "Compiling `basename $<`"
Chris Lattner1eeac662002-10-22 23:28:23 +0000702 $(VERB) $(CompileCO) $< -o $@
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000703
John Criswell410d1b52003-09-09 20:57:03 +0000704$(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000705 @${ECHO} "Compiling `basename $<`"
Vikram S. Adve41e78912002-09-20 14:03:13 +0000706 $(VERB) $(CompileP) $< -o $@
707
John Criswell410d1b52003-09-09 20:57:03 +0000708$(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000709 @${ECHO} "Compiling `basename $<`"
Chris Lattner172b6482002-09-22 02:47:15 +0000710 $(VERB) $(CompileCP) $< -o $@
711
John Criswell410d1b52003-09-09 20:57:03 +0000712$(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000713 @${ECHO} "Compiling `basename $<`"
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000714 $(VERB) $(CompileG) $< -o $@
Chris Lattner00950542001-06-06 20:29:01 +0000715
John Criswell410d1b52003-09-09 20:57:03 +0000716$(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell7ec78aa2003-10-16 01:49:00 +0000717 @${ECHO} "Compiling `basename $<`"
John Criswell7a73b802003-06-30 21:59:07 +0000718 $(VERB) $(CompileCG) $< -o $@
719
Chris Lattner0df847a2003-09-15 22:17:02 +0000720$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
John Criswell7ec78aa2003-10-16 01:49:00 +0000721 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000722 $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000723
Chris Lattner0df847a2003-09-15 22:17:02 +0000724$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
John Criswell7ec78aa2003-10-16 01:49:00 +0000725 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattnerbb3dd472003-08-27 18:26:44 +0000726 $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner481cc7c2003-08-15 02:18:35 +0000727
Chris Lattner0df847a2003-09-15 22:17:02 +0000728$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
John Criswell7ec78aa2003-10-16 01:49:00 +0000729 @${ECHO} "Compiling `basename $<` to bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000730 $(VERB) $(LLVMAS) $< -f -o $@
731
732
Chris Lattnere8996782003-01-16 22:44:19 +0000733#
734# Rules for building lex/yacc files
735#
736LEX_FILES = $(filter %.l, $(Source))
737LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
738YACC_FILES = $(filter %.y, $(Source))
739YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
740.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
741
Chris Lattner00950542001-06-06 20:29:01 +0000742# Create a .cpp source file from a flex input file... this uses sed to cut down
743# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000744#
745# The last line is a gross hack to work around flex aparently not being able to
746# resize the buffer on a large token input. Currently, for uninitialized string
747# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000748# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000749#
Chris Lattner00950542001-06-06 20:29:01 +0000750%.cpp: %.l
John Criswell7ec78aa2003-10-16 01:49:00 +0000751 @${ECHO} Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000752 $(VERB) $(FLEX) -t $< | \
753 $(SED) '/^find_rule/d' | \
754 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell7a73b802003-06-30 21:59:07 +0000755 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattnera328f882003-08-04 19:47:06 +0000756 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
757 > $@.tmp
John Criswelld741bcf2003-08-12 18:51:51 +0000758 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000759 @# remove the output of flex if it didn't get moved over...
760 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000761
762# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000763%.c: %.y # Cancel built-in rules for yacc
764%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000765%.cpp %.h : %.y
Misha Brukmanb6d59a22003-11-05 06:41:14 +0000766 @${ECHO} "Bisoning `basename $<`"
John Criswell410d1b52003-09-09 20:57:03 +0000767 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
John Criswelld741bcf2003-08-12 18:51:51 +0000768 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
769 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000770 @# If the files were not updated, don't leave them lying around...
771 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000772
773# To create the directories...
774%/.dir:
John Criswell7a73b802003-06-30 21:59:07 +0000775 $(VERB) ${MKDIR} $* > /dev/null
776 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000777
Chris Lattner30440c62003-01-16 21:06:18 +0000778# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000779ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000780%.ps: %.dot
John Criswell7a73b802003-06-30 21:59:07 +0000781 ${DOT} -Tps < $< > $@
782else
783%.ps: %.dot
784 ${ECHO} "Cannot build $@: The program dot is not installed"
785endif
Chris Lattner30440c62003-01-16 21:06:18 +0000786
John Criswell7f336952003-09-06 14:44:17 +0000787#
788# This rules ensures that header files that are removed still have a rule for
789# which they can be "generated." This allows make to ignore them and
790# reproduce the dependency lists.
791#
John Criswell4b6e5d12003-09-18 18:37:08 +0000792%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000793
Chris Lattner172b6482002-09-22 02:47:15 +0000794# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000795clean::
Chris Lattner481cc7c2003-08-15 02:18:35 +0000796 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
797 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
Chris Lattner0df847a2003-09-15 22:17:02 +0000798 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
John Criswell7a73b802003-06-30 21:59:07 +0000799 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
800 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
801
John Criswell7a73b802003-06-30 21:59:07 +0000802###########################################################################
803# C/C++ Dependencies
804# Define variables and rules that generate header file dependencies
805# from C/C++ source files.
806###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000807
Chris Lattner33ad24a2003-08-22 14:10:16 +0000808ifndef DISABLE_AUTO_DEPENDENCIES
809
Chris Lattner694c5df2003-05-15 21:28:55 +0000810# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000811# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000812#
John Criswell410d1b52003-09-09 20:57:03 +0000813SourceBaseNames := $(basename $(Source))
John Criswell8bff5092003-06-11 13:55:44 +0000814SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner694c5df2003-05-15 21:28:55 +0000815
816# Create dependencies for the *.cpp files...
John Criswell410d1b52003-09-09 20:57:03 +0000817$(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner52d792c2003-11-08 21:23:06 +0000818 $(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 +0000819
820# Create dependencies for the *.c files...
John Criswell410d1b52003-09-09 20:57:03 +0000821$(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
Chris Lattner52d792c2003-11-08 21:23:06 +0000822 $(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 +0000823
John Criswell7a73b802003-06-30 21:59:07 +0000824#
John Criswellbd082802003-10-07 14:16:44 +0000825# Autoconf Dependencies.
826#
Misha Brukman94fe1f92003-10-07 15:24:23 +0000827$(LLVM_OBJ_ROOT)/config.status:: $(LLVM_SRC_ROOT)/configure
Chris Lattner4faf8602003-10-10 15:55:43 +0000828 @${ECHO} "****************************************************************"
829 @${ECHO} " You need to re-run $(LLVM_SRC_ROOT)/configure"
830 @${ECHO} " in directory $(LLVM_OBJ_ROOT)"
831 @${ECHO} "****************************************************************"
John Criswellbd082802003-10-07 14:16:44 +0000832 $(VERB) exit 1
833
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000834# If the Makefile in the source tree has been updated, copy it over into the
835# build tree.
836Makefile :: $(BUILD_SRC_DIR)/Makefile
Misha Brukman2fe69092003-11-11 00:05:29 +0000837 @${ECHO} "===== Updating Makefile from source dir: `dirname $<` ====="
John Criswellb3866b62003-11-25 19:32:22 +0000838 $(MKDIR) $(@D)
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000839 cp -f $< $@
840
John Criswellbd082802003-10-07 14:16:44 +0000841#
John Criswell7a73b802003-06-30 21:59:07 +0000842# Include dependencies generated from C/C++ source files, but not if we
843# are cleaning (this example taken from the GNU Make Manual).
844#
845ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000846ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner15444a92003-08-29 14:07:02 +0000847-include /dev/null $(SourceDepend)
John Criswell7a73b802003-06-30 21:59:07 +0000848endif
John Criswelld741bcf2003-08-12 18:51:51 +0000849endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000850
Chris Lattner33ad24a2003-08-22 14:10:16 +0000851endif # ifndef DISABLE_AUTO_DEPENDENCIES