blob: 33205b2e0af10e2a7bcefb10fc6b82fe6f7168ff [file] [log] [blame]
Vikram S. Adve24132e82002-07-09 12:04:21 +00001#===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
Chris Lattner2f7c9632001-06-06 20:29:01 +00002#
3# This file is included by all of the LLVM makefiles. This file defines common
Misha Brukmana1f0c142003-08-21 22:02:18 +00004# rules to do things like compile a .cpp file or generate dependency info.
5# These are platform dependent, so this is the file used to specify these
6# system dependent operations.
Chris Lattner2f7c9632001-06-06 20:29:01 +00007#
Vikram S. Adve728de922002-08-29 23:28:46 +00008# The following functionality can be set by setting incoming variables.
9# The variable $(LEVEL) *must* be set:
Chris Lattner2f7c9632001-06-06 20:29:01 +000010#
11# 1. LEVEL - The level of the current subdirectory from the top of the
12# MagicStats view. This level should be expressed as a path, for
13# example, ../.. for two levels deep.
14#
15# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnerf3dd5f52002-09-18 03:22:27 +000016# so that each of the targets "all", "install", and "clean" each build
17# the subdirectories before the local target. DIRS are guaranteed to be
18# built in order.
Chris Lattner2f7c9632001-06-06 20:29:01 +000019#
Chris Lattnerf3dd5f52002-09-18 03:22:27 +000020# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21# built in any order. All DIRS are built in order before PARALLEL_DIRS are
22# built, which are then built in any order.
23#
24# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner2f7c9632001-06-06 20:29:01 +000025# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattneree6e1992001-10-18 01:48:09 +000026# in the current directory. Also, if you want to build files in addition
27# to the local files, you can use the ExtraSource variable
Chris Lattner2f7c9632001-06-06 20:29:01 +000028#
Chris Lattner021249f2003-05-15 21:28:55 +000029# 5. SourceDir - If specified, this specifies a directory that the source files
30# are in, if they are not in the current directory. This should include a
31# trailing / character.
32#
John Criswell3ef61af2003-06-30 21:59:07 +000033# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati55512b12003-05-29 21:49:00 +000034#
John Criswell3ef61af2003-06-30 21:59:07 +000035# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
36# and usually the source code too (unless SourceDir is set).
37#
38# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
39#
40# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
41#
42# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
43# placed.
44#
45# For building,
Chris Lattnerb42c1532003-08-21 22:23:49 +000046# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
Chris Lattner2e9fc94a2003-08-15 03:02:52 +000047#
Vikram S. Adve24132e82002-07-09 12:04:21 +000048#===-----------------------------------------------------------------------====
Chris Lattner2f7c9632001-06-06 20:29:01 +000049
John Criswell8224df92003-06-27 16:58:44 +000050#
John Criswell0a6e6aa2003-09-06 14:44:17 +000051# Set the VPATH so that we can find source files.
John Criswell0607d882003-06-11 13:55:44 +000052#
John Criswell1e8c7b72003-09-11 18:03:50 +000053VPATH=$(SourceDir)
John Criswell0607d882003-06-11 13:55:44 +000054
John Criswell3ef61af2003-06-30 21:59:07 +000055###########################################################################
56# Default Targets:
57# The following targets are the standard top level targets for
58# building.
59###########################################################################
Chris Lattnere5ad7bd2002-09-13 22:14:47 +000060
John Criswell06636c22003-10-07 14:16:44 +000061# Ensure people re-run configure when it gets updated
62all::$(LLVM_OBJ_ROOT)/include/Config/config.h
63
Chris Lattner570c6a62002-07-23 19:21:31 +000064ifdef SHARED_LIBRARY
65# if SHARED_LIBRARY is specified, the default is to build the dynamic lib
John Criswell3ef61af2003-06-30 21:59:07 +000066all:: dynamic
Chris Lattner570c6a62002-07-23 19:21:31 +000067endif
68
Chris Lattner23991d52003-08-14 21:10:25 +000069ifdef BYTECODE_LIBRARY
70# if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
71all:: bytecodelib
Chris Lattner0c4f4fe2003-08-15 02:18:35 +000072install:: bytecodelib-install
Chris Lattner23991d52003-08-14 21:10:25 +000073endif
74
Chris Lattner44601ba2001-06-29 05:20:16 +000075# Default Rule: Make sure it's also a :: rule
Chris Lattner2f7c9632001-06-06 20:29:01 +000076all ::
77
78# Default for install is to at least build everything...
79install ::
80
John Criswell0607d882003-06-11 13:55:44 +000081# Default rule for test. It ensures everything has a test rule
82test::
Dinakar Dhurjati41f77482003-05-29 16:18:20 +000083
Vikram S. Adve5fc4aee2003-07-10 19:25:29 +000084# Default rule for building only bytecode.
85bytecode::
86
John Criswell3ef61af2003-06-30 21:59:07 +000087# Print out the directories used for building
88prdirs::
Chris Lattnerb42c1532003-08-21 22:23:49 +000089 @echo "Build Source Root: " $(BUILD_SRC_ROOT)
90 @echo "Build Source Dir : " $(BUILD_SRC_DIR)
91 @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
92 @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
93 @echo "LLVM Source Root: " $(LLVM_SRC_ROOT)
94 @echo "LLVM Object Root: " $(LLVM_OBJ_ROOT)
John Criswell3ef61af2003-06-30 21:59:07 +000095
John Criswell816deb72003-08-20 15:18:41 +000096###########################################################################
97# Suffixes and implicit rules:
98# Empty out the list of suffixes, generate a list that is only
99# used by this Makefile, and cancel useless implicit rules. This
100# will hopefully speed up compilation a little bit.
101###########################################################################
102.SUFFIXES:
103.SUFFIXES: .c .cpp .h .hpp .y .l
John Criswellded98992003-09-09 20:57:03 +0000104.SUFFIXES: .lo .o .a .so .bc .td
John Criswell816deb72003-08-20 15:18:41 +0000105.SUFFIXES: .ps .dot .d
106
John Criswellaf4d1302003-07-16 20:26:06 +0000107#
108# Mark all of these targets as phony. This will hopefully speed up builds
109# slightly since GNU Make will not try to find implicit rules for targets
110# which are marked as Phony.
111#
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000112.PHONY: all dynamic bytecodelib bytecodelib-install
Chris Lattnera896edb2003-08-21 20:39:08 +0000113.PHONY: clean distclean install test bytecode prdirs
John Criswellaf4d1302003-07-16 20:26:06 +0000114
John Criswell3ef61af2003-06-30 21:59:07 +0000115###########################################################################
116# Miscellaneous paths and commands:
117# This section defines various configuration macros, such as where
118# to find burg, tblgen, and libtool.
119###########################################################################
120
Chris Lattner2f7c9632001-06-06 20:29:01 +0000121#--------------------------------------------------------------------
Vikram S. Adve728de922002-08-29 23:28:46 +0000122# Variables derived from configuration options...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000123#--------------------------------------------------------------------
124
125#BinInstDir=/usr/local/bin
John Criswell9cca31f2003-05-29 18:52:10 +0000126#LibInstDir=/usr/local/lib/xxx
Chris Lattner2f7c9632001-06-06 20:29:01 +0000127#DocInstDir=/usr/doc/xxx
128
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000129BURG_OPTS = -I
130
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000131ifdef ENABLE_PROFILING
132 ENABLE_OPTIMIZED = 1
133 CONFIGURATION := Profile
134else
135 ifdef ENABLE_OPTIMIZED
136 CONFIGURATION := Release
137 else
138 CONFIGURATION := Debug
139 endif
140endif
141
John Criswell3ef61af2003-06-30 21:59:07 +0000142#
143# Enable this for profiling support with 'gprof'
144# This automatically enables optimized builds.
145#
146ifdef ENABLE_PROFILING
147 PROFILE = -pg
148endif
149
John Criswell0607d882003-06-11 13:55:44 +0000150###########################################################################
John Criswell3ef61af2003-06-30 21:59:07 +0000151# Library Locations:
John Criswell0607d882003-06-11 13:55:44 +0000152# These variables describe various library locations:
153#
154# DEST* = Location of where libraries that are built will be placed.
155# LLVM* = Location of LLVM libraries used for linking.
156# PROJ* = Location of previously built libraries used for linking.
157###########################################################################
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000158
John Criswell0607d882003-06-11 13:55:44 +0000159# Libraries that are being built
160DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug
161DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release
162DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile
Chris Lattner2481a982003-09-10 19:37:51 +0000163DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
John Criswell0607d882003-06-11 13:55:44 +0000164DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000165
John Criswell0607d882003-06-11 13:55:44 +0000166# LLVM libraries used for linking
167LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug
168LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release
169LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile
170LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000171
John Criswell0607d882003-06-11 13:55:44 +0000172# Libraries that were built that will now be used for linking
173PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug
174PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release
175PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile
176PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000177
John Criswell0607d882003-06-11 13:55:44 +0000178###########################################################################
179# Tool Locations
180# These variables describe various tool locations:
181#
182# DEST* = Location of where tools that are built will be placed.
183# LLVM* = Location of LLVM tools used for building.
184# PROJ* = Location of previously built tools used for linking.
185###########################################################################
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000186
John Criswell0607d882003-06-11 13:55:44 +0000187DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
188DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
189DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
190DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
191
192LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug
193LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
194LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
195LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
196
197PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug
198PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
199PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
200PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000201
John Criswell3ef61af2003-06-30 21:59:07 +0000202#
203# Libtool is found in the current directory.
204#
John Criswell0a6e6aa2003-09-06 14:44:17 +0000205LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
John Criswell3ef61af2003-06-30 21:59:07 +0000206
207#
John Criswell3601f372003-07-31 20:58:51 +0000208# If we're not building a shared library, use the disable-shared tag with
209# libtool. This will disable the building of objects for shared libraries and
210# only generate static library objects.
211#
212# For dynamic libraries, we'll take the performance hit for now, since we
213# almost never build them.
214#
215# This should speed up compilation and require no modifications to future
216# versions of libtool.
217#
218ifndef SHARED_LIBRARY
Chris Lattner23991d52003-08-14 21:10:25 +0000219LIBTOOL += --tag=disable-shared
John Criswell3601f372003-07-31 20:58:51 +0000220endif
221
222#
Misha Brukman1326a7c2002-09-12 16:05:39 +0000223# Verbosity levels
John Criswell3ef61af2003-06-30 21:59:07 +0000224#
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000225ifndef VERBOSE
Misha Brukman1326a7c2002-09-12 16:05:39 +0000226VERB := @
Chris Lattner23991d52003-08-14 21:10:25 +0000227LIBTOOL += --silent
Misha Brukman1326a7c2002-09-12 16:05:39 +0000228endif
229
John Criswell3ef61af2003-06-30 21:59:07 +0000230###########################################################################
231# Miscellaneous paths and commands (part deux):
232# This section defines various configuration macros, such as where
233# to find burg, tblgen, and libtool.
234###########################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000235
John Criswell3ef61af2003-06-30 21:59:07 +0000236#--------------------------------------------------------------------------
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000237# Utilities used while building the LLVM tree, which live in the utils dir
238#
John Criswell0607d882003-06-11 13:55:44 +0000239BURG := $(LLVMTOOLCURRENT)/burg
Chris Lattnerc58930c2002-09-19 19:42:24 +0000240RunBurg := $(BURG) $(BURG_OPTS)
John Criswell0607d882003-06-11 13:55:44 +0000241TBLGEN := $(LLVMTOOLCURRENT)/tblgen
Vikram S. Adveca4a3822001-08-06 19:01:20 +0000242
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000243#--------------------------------------------------------------------------
244# The LLVM GCC front-end in C and C++ flavors
245#
Chris Lattner5c0b0ba2003-08-15 15:20:52 +0000246LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
Chris Lattnerbc9b0b92003-08-20 22:11:45 +0000247LCC1 := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
Chris Lattner5c0b0ba2003-08-15 15:20:52 +0000248LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
Chris Lattnerbc9b0b92003-08-20 22:11:45 +0000249LCC1XX := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000250
251#--------------------------------------------------------------------------
252# Some of the compiled LLVM tools which are used for compilation of runtime
253# libraries.
254#
Misha Brukmanfc8010c2003-08-28 21:45:08 +0000255LLVMAS := $(LLVMTOOLCURRENT)/llvm-as
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000256
Chris Lattner2f7c9632001-06-06 20:29:01 +0000257
John Criswell0607d882003-06-11 13:55:44 +0000258###########################################################################
259# Compile Time Flags
260###########################################################################
261
262#
John Criswell3ef61af2003-06-30 21:59:07 +0000263# Include both the project headers and the LLVM headers for compilation and
264# dependency computation.
John Criswell0607d882003-06-11 13:55:44 +0000265#
John Criswell0a6e6aa2003-09-06 14:44:17 +0000266# BUILD_OBJ_DIR : Files local to the particular object directory
267# (locallly generated header files).
268# BUILD_SRC_DIR : Files local to the particular source directory.
269# BUILD_SRC_ROOT/include : Files global to the project.
Chris Lattner218112d2003-09-15 01:07:32 +0000270# LLVM_OBJ_ROOT/include : config.h files generated by autoconf
John Criswell0a6e6aa2003-09-06 14:44:17 +0000271# LEVEL/include : config.h files for the project
272# LLVM_SRC_ROOT/include : Files global to LLVM.
John Criswell0a6e6aa2003-09-06 14:44:17 +0000273#
Chris Lattner6b6eadc2003-09-15 01:12:04 +0000274CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
275 -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
276 -I$(LLVM_SRC_ROOT)/include
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000277
Vikram S. Adved141c282002-09-18 11:55:13 +0000278# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000279ifndef KEEP_SYMBOLS
Chris Lattnerd119b562003-01-31 19:00:26 +0000280STRIP = $(PLATFORMSTRIPOPTS)
Misha Brukmanfd3e0af2003-07-10 16:52:41 +0000281STRIP_WARN_MSG = "(without symbols)"
Vikram S. Adved141c282002-09-18 11:55:13 +0000282endif
283
Chris Lattner2efcf432002-09-13 16:02:26 +0000284# Allow gnu extensions...
285CPPFLAGS += -D_GNU_SOURCE
286
Chris Lattner7c95d2f2003-08-27 18:26:44 +0000287CompileWarnings := -Wall -W -Wwrite-strings -Wno-unused
John Criswell0a6e6aa2003-09-06 14:44:17 +0000288CompileCommonOpts := $(CompileWarnings) -fshort-enums
Chris Lattner7c95d2f2003-08-27 18:26:44 +0000289CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
Chris Lattner2f7c9632001-06-06 20:29:01 +0000290
John Criswell3ef61af2003-06-30 21:59:07 +0000291#
292# Compile commands with libtool.
293#
294Compile := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
Chris Lattnerc38d7fa2003-08-23 15:56:38 +0000295CompileC := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
John Criswell3ef61af2003-06-30 21:59:07 +0000296
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000297# Compile a cpp file, don't link...
Chris Lattner01f68c62002-08-12 21:19:28 +0000298CompileG := $(Compile) -g -D_DEBUG
Chris Lattner4bb08062003-02-13 16:56:30 +0000299CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
300CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000301
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000302# Compile a c file, don't link...
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000303CompileCG := $(CompileC) -g -D_DEBUG
Chris Lattner61493ff2003-02-19 22:12:20 +0000304CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
305CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000306
John Criswell3ef61af2003-06-30 21:59:07 +0000307###########################################################################
308# Link Time Options
309###########################################################################
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000310
John Criswell3ef61af2003-06-30 21:59:07 +0000311#
Chris Lattner2f7c9632001-06-06 20:29:01 +0000312# Link final executable
John Criswell3ef61af2003-06-30 21:59:07 +0000313# (Note that we always link with the C++ compiler).
314#
John Criswell3ef61af2003-06-30 21:59:07 +0000315Link := $(LIBTOOL) --mode=link $(CXX)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000316
John Criswell3ef61af2003-06-30 21:59:07 +0000317# link both projlib and llvmlib libraries
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000318LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
319LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
320LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000321
Chris Lattner76d98ba2002-07-23 17:56:16 +0000322# Create one .o file from a bunch of .o files...
Chris Lattner23991d52003-08-14 21:10:25 +0000323Relink := ${LIBTOOL} --mode=link $(CXX)
John Criswell3ef61af2003-06-30 21:59:07 +0000324
325#
326# Configure where the item being compiled should go.
327#
328ifdef SHARED_LIBRARY
Chris Lattner23991d52003-08-14 21:10:25 +0000329Link += -rpath $(DESTLIBCURRENT)
John Criswell3ef61af2003-06-30 21:59:07 +0000330endif
331
332ifdef TOOLNAME
Chris Lattner23991d52003-08-14 21:10:25 +0000333Link += -rpath $(DESTTOOLCURRENT)
John Criswell3ef61af2003-06-30 21:59:07 +0000334endif
Chris Lattnere5ad7bd2002-09-13 22:14:47 +0000335
Misha Brukmana1f0c142003-08-21 22:02:18 +0000336# Create dependency file from CPP file, send to stdout.
John Criswell0607d882003-06-11 13:55:44 +0000337Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS)
338DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000339
340# Archive a bunch of .o files into a .a file...
John Criswell857ec182003-05-30 15:50:31 +0000341AR = ${AR_PATH} cq
Chris Lattner2f7c9632001-06-06 20:29:01 +0000342
343#----------------------------------------------------------
344
345# Source includes all of the cpp files, and objects are derived from the
346# source files...
Chris Lattneree6e1992001-10-18 01:48:09 +0000347# The local Makefile can list other Source files via ExtraSource = ...
Vikram S. Advebd9cae22001-10-17 12:33:55 +0000348#
Vikram S. Adve53738842002-10-14 16:40:04 +0000349ifndef Source
Chris Lattner6b6eadc2003-09-15 01:12:04 +0000350Source := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
351 $(SourceDir)/*.c $(SourceDir)/*.y $(SourceDir)/*.l))
Vikram S. Adve53738842002-10-14 16:40:04 +0000352endif
Vikram S. Advefe346892001-07-15 13:16:47 +0000353
John Criswell3601f372003-07-31 20:58:51 +0000354#
355# Libtool Objects
356#
John Criswellded98992003-09-09 20:57:03 +0000357Srcs := $(sort $(basename $(Source)))
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000358Objs := $(addsuffix .lo, $(Srcs))
John Criswell7320d2f2003-07-01 14:52:28 +0000359ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
360ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
361ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
Chris Lattner6721f0e2003-09-15 22:17:02 +0000362ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/BytecodeObj/,$(addsuffix .bc, $(Srcs)))
Chris Lattner76d98ba2002-07-23 17:56:16 +0000363
John Criswell3601f372003-07-31 20:58:51 +0000364#
365# The real objects underlying the libtool objects
366#
John Criswellded98992003-09-09 20:57:03 +0000367RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
John Criswell3601f372003-07-31 20:58:51 +0000368RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
369RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
370RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
371
Chris Lattner2f7c9632001-06-06 20:29:01 +0000372#---------------------------------------------------------
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000373# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner2f7c9632001-06-06 20:29:01 +0000374#---------------------------------------------------------
375
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000376ifdef DIRS
Chris Lattnera896edb2003-08-21 20:39:08 +0000377all install clean test bytecode ::
Chris Lattner59ded8e2002-09-17 23:45:34 +0000378 $(VERB) for dir in ${DIRS}; do \
Chris Lattner539a23c2002-09-17 23:35:02 +0000379 (cd $$dir; $(MAKE) $@) || exit 1; \
380 done
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000381endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000382
383# Handle PARALLEL_DIRS
384ifdef PARALLEL_DIRS
Vikram S. Adve5fc4aee2003-07-10 19:25:29 +0000385all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
386install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
387clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
388test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
389bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000390
Chris Lattnera896edb2003-08-21 20:39:08 +0000391%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000392 $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000393endif
394
John Criswell3ef61af2003-06-30 21:59:07 +0000395# Handle directories that may or may not exist
John Criswell8224df92003-06-27 16:58:44 +0000396ifdef OPTIONAL_DIRS
Chris Lattnera896edb2003-08-21 20:39:08 +0000397all install clean test bytecode ::
John Criswell8224df92003-06-27 16:58:44 +0000398 $(VERB) for dir in ${OPTIONAL_DIRS}; do \
399 if [ -d $$dir ]; \
400 then\
401 (cd $$dir; $(MAKE) $@) || exit 1; \
402 fi \
403 done
404endif
405
John Criswell3ef61af2003-06-30 21:59:07 +0000406###########################################################################
407# Library Build Rules:
408#
Chris Lattner2f7c9632001-06-06 20:29:01 +0000409#---------------------------------------------------------
410# Handle the LIBRARYNAME option - used when building libs...
411#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +0000412#
413# When libraries are built, they are allowed to optionally define the
414# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
415# from being built for the library. This .o files may then be linked to by a
416# tool if the tool does not need (or want) the semantics a .a file provides
417# (linking in only object files that are "needed"). If a library is never to
418# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
419# BUILD_ARCHIVE instead.
420#
421# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattnerd711a5e2002-07-31 21:32:05 +0000422# it's built as a .o file, then all of the constituent .o files in it will be
Chris Lattner76d98ba2002-07-23 17:56:16 +0000423# linked into tools (for example gccas) even if they only use one of the parts
424# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell3ef61af2003-06-30 21:59:07 +0000425###########################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000426
427ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000428
Chris Lattner0100eab2002-09-16 22:36:42 +0000429# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000430LIBRARYNAME := $(strip $(LIBRARYNAME))
431
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000432LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
433LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
434LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
435LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
436LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
437LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
438LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
439LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
440LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000441LIBNAME_BC := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
Chris Lattner2f7c9632001-06-06 20:29:01 +0000442
John Criswell3ef61af2003-06-30 21:59:07 +0000443#--------------------------------------------------------------------
444# Library Targets
445# Modify the top level targets to build the desired libraries.
446#--------------------------------------------------------------------
447
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000448# dynamic target builds a shared object version of the library...
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000449dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000450bytecodelib:: $(LIBNAME_BC)
451bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
452
453$(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
454 @echo ======= Installing $(LIBRARYNAME) bytecode library =======
455 cp $< $@
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +0000456
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000457# Does the library want a .o version built?
Chris Lattner76d98ba2002-07-23 17:56:16 +0000458ifndef DONT_BUILD_RELINKED
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000459all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
Chris Lattner76d98ba2002-07-23 17:56:16 +0000460endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000461
462# Does the library want an archive version built?
Chris Lattner76d98ba2002-07-23 17:56:16 +0000463ifdef BUILD_ARCHIVE
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000464all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
Chris Lattner76d98ba2002-07-23 17:56:16 +0000465endif
Chris Lattner76d98ba2002-07-23 17:56:16 +0000466
John Criswell3ef61af2003-06-30 21:59:07 +0000467#--------------------------------------------------------------------
468# Rules for building libraries
469#--------------------------------------------------------------------
Chris Lattner2f7c9632001-06-06 20:29:01 +0000470
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000471LinkBCLib := $(LLVMGCC) -shared
472ifdef EXPORTED_SYMBOL_LIST
473LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
474else
Chris Lattner65568e82003-09-15 15:06:54 +0000475 ifdef EXPORTED_SYMBOL_FILE
476LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
477 else
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000478LinkBCLib += -Xlinker -disable-internalize
Chris Lattner65568e82003-09-15 15:06:54 +0000479 endif
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000480endif
481
482
483# Rule for building bytecode libraries.
Chris Lattner2e9fc94a2003-08-15 03:02:52 +0000484$(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000485 @echo ======= Linking $(LIBRARYNAME) bytecode library =======
486 $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
John Criswell3ef61af2003-06-30 21:59:07 +0000487#
488# Rules for building dynamically linked libraries.
489#
John Criswell7320d2f2003-07-01 14:52:28 +0000490$(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000491 @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
Chris Lattner92fc9b02003-08-15 20:00:47 +0000492 $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
493 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000494
John Criswell7320d2f2003-07-01 14:52:28 +0000495$(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000496 @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
Chris Lattner92fc9b02003-08-15 20:00:47 +0000497 $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
498 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000499
John Criswell7320d2f2003-07-01 14:52:28 +0000500$(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000501 @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
Chris Lattner92fc9b02003-08-15 20:00:47 +0000502 $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
503 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
Vikram S. Advefe346892001-07-15 13:16:47 +0000504
John Criswell3ef61af2003-06-30 21:59:07 +0000505#
506# Rules for building static archive libraries.
507#
John Criswell7320d2f2003-07-01 14:52:28 +0000508$(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000509 @echo ======= Linking $(LIBRARYNAME) archive release library =======
510 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000511 $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000512
John Criswell7320d2f2003-07-01 14:52:28 +0000513$(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000514 @echo ======= Linking $(LIBRARYNAME) archive profile library =======
515 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000516 $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
Vikram S. Advefe346892001-07-15 13:16:47 +0000517
John Criswell7320d2f2003-07-01 14:52:28 +0000518$(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000519 @echo ======= Linking $(LIBRARYNAME) archive debug library =======
520 @$(RM) -f $@
John Criswell7320d2f2003-07-01 14:52:28 +0000521 $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
John Criswell3ef61af2003-06-30 21:59:07 +0000522
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000523
John Criswell3ef61af2003-06-30 21:59:07 +0000524#
525# Rules for building .o libraries.
526#
John Criswell3601f372003-07-31 20:58:51 +0000527# JTC:
528# Note that for this special case, we specify the actual object files
529# instead of their libtool counterparts. This is because libtool
530# doesn't want to generate a reloadable object file unless it is given
531# .o files explicitly.
532#
533# Note that we're making an assumption here: If we build a .lo file,
534# it's corresponding .o file will be placed in the same directory.
535#
536# I think that is safe.
537#
John Criswell7320d2f2003-07-01 14:52:28 +0000538$(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000539 @echo "Linking $@"
John Criswell3601f372003-07-31 20:58:51 +0000540 $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000541
John Criswell7320d2f2003-07-01 14:52:28 +0000542$(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000543 @echo "Linking $@"
John Criswell3601f372003-07-31 20:58:51 +0000544 $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000545
John Criswell7320d2f2003-07-01 14:52:28 +0000546$(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
Chris Lattner8d081dd2002-09-25 17:15:22 +0000547 @echo "Linking $@"
John Criswell3601f372003-07-31 20:58:51 +0000548 $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
Chris Lattner76d98ba2002-07-23 17:56:16 +0000549
Chris Lattner2f7c9632001-06-06 20:29:01 +0000550endif
551
Chris Lattner07c7c192001-09-07 22:57:58 +0000552#------------------------------------------------------------------------
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000553# Create a TAGS database for emacs
554#------------------------------------------------------------------------
555
John Criswell4ffb8442003-10-02 19:02:02 +0000556ifneq ($(ETAGS),false)
Vikram S. Advea0e99082001-10-13 12:26:59 +0000557ifeq ($(LEVEL), .)
John Criswell0a6e6aa2003-09-06 14:44:17 +0000558SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
Chris Lattner132c88d2003-08-21 21:53:38 +0000559
Vikram S. Advea0e99082001-10-13 12:26:59 +0000560tags:
Chris Lattner132c88d2003-08-21 21:53:38 +0000561 $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
Vikram S. Advea0e99082001-10-13 12:26:59 +0000562all:: tags
Vikram S. Advea0e99082001-10-13 12:26:59 +0000563endif
John Criswell3ef61af2003-06-30 21:59:07 +0000564else
565tags:
566 ${ECHO} "Cannot build $@: The program etags is not installed"
567endif
Vikram S. Advefa9dc582001-10-10 22:35:00 +0000568
569#------------------------------------------------------------------------
Chris Lattner07c7c192001-09-07 22:57:58 +0000570# Handle the TOOLNAME option - used when building tool executables...
571#------------------------------------------------------------------------
572#
573# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattner76d98ba2002-07-23 17:56:16 +0000574# libraries (and the order of the libs) that should be linked to the
575# tool. USEDLIBS should contain a list of library names (some with .a extension)
576# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner07c7c192001-09-07 22:57:58 +0000577#
578ifdef TOOLNAME
579
580# TOOLEXENAME* - These compute the output filenames to generate...
John Criswell0607d882003-06-11 13:55:44 +0000581TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
582TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
583TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
584TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME)
Chris Lattner07c7c192001-09-07 22:57:58 +0000585
586# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000587PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
588PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS))
589PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
590PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
591
592LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
593LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS))
594LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
595LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
596
597LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
Chris Lattnerf6791e52003-06-20 15:41:57 +0000598LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000599LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
600
Chris Lattner07c7c192001-09-07 22:57:58 +0000601# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
Chris Lattner76d98ba2002-07-23 17:56:16 +0000602# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
Misha Brukman7b14a192003-07-14 17:26:34 +0000603# files separately.
Chris Lattner07c7c192001-09-07 22:57:58 +0000604#
Chris Lattner76d98ba2002-07-23 17:56:16 +0000605STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000606USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
607USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
608USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
Chris Lattner07c7c192001-09-07 22:57:58 +0000609
John Criswell3ef61af2003-06-30 21:59:07 +0000610#
611# Libtool link options:
612# Ensure that all binaries have their symbols exported so that they can
613# by dlsym'ed.
614#
615LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
Chris Lattner3ecb7762003-01-22 16:13:31 +0000616
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000617
618
619
620
Chris Lattner3ecb7762003-01-22 16:13:31 +0000621# Tell make that we need to rebuild subdirectories before we can link the tool.
622# This affects things like LLI which has library subdirectories.
623$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
624 $(addsuffix /.makeall, $(PARALLEL_DIRS))
625
Chris Lattner1fd501f2001-10-13 05:10:29 +0000626all:: $(TOOLEXENAMES)
John Criswell8224df92003-06-27 16:58:44 +0000627
Chris Lattner07c7c192001-09-07 22:57:58 +0000628clean::
John Criswell3ef61af2003-06-30 21:59:07 +0000629 $(VERB) $(RM) -f $(TOOLEXENAMES)
Chris Lattner07c7c192001-09-07 22:57:58 +0000630
John Criswell7320d2f2003-07-01 14:52:28 +0000631$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
Misha Brukmanfd3e0af2003-07-10 16:52:41 +0000632 @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
John Criswell7320d2f2003-07-01 14:52:28 +0000633 $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000634
John Criswell7320d2f2003-07-01 14:52:28 +0000635$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
Chris Lattner500f0642002-09-12 17:02:40 +0000636 @echo ======= Linking $(TOOLNAME) release executable =======
John Criswell7320d2f2003-07-01 14:52:28 +0000637 $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
Chris Lattner07c7c192001-09-07 22:57:58 +0000638
John Criswell7320d2f2003-07-01 14:52:28 +0000639$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000640 @echo ======= Linking $(TOOLNAME) profile executable =======
John Criswell7320d2f2003-07-01 14:52:28 +0000641 $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000642
Chris Lattner07c7c192001-09-07 22:57:58 +0000643endif
644
645
Chris Lattner2f7c9632001-06-06 20:29:01 +0000646
647#---------------------------------------------------------
Chris Lattner6721f0e2003-09-15 22:17:02 +0000648.PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
John Criswell0607d882003-06-11 13:55:44 +0000649.PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
Chris Lattner2f7c9632001-06-06 20:29:01 +0000650
John Criswell3ef61af2003-06-30 21:59:07 +0000651# Create .lo files in the ObjectFiles directory from the .cpp and .c files...
John Criswellded98992003-09-09 20:57:03 +0000652$(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000653 @echo "Compiling $<"
654 $(VERB) $(CompileO) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000655
John Criswellded98992003-09-09 20:57:03 +0000656$(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000657 @echo "Compiling $<"
Chris Lattnerd3fcf422002-10-22 23:28:23 +0000658 $(VERB) $(CompileCO) $< -o $@
Vikram S. Advefe346892001-07-15 13:16:47 +0000659
John Criswellded98992003-09-09 20:57:03 +0000660$(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
Vikram S. Adve20aa62f2002-09-20 14:03:13 +0000661 @echo "Compiling $<"
662 $(VERB) $(CompileP) $< -o $@
663
John Criswellded98992003-09-09 20:57:03 +0000664$(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000665 @echo "Compiling $<"
666 $(VERB) $(CompileCP) $< -o $@
667
John Criswellded98992003-09-09 20:57:03 +0000668$(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
Misha Brukman1326a7c2002-09-12 16:05:39 +0000669 @echo "Compiling $<"
670 $(VERB) $(CompileG) $< -o $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000671
John Criswellded98992003-09-09 20:57:03 +0000672$(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000673 @echo "Compiling $<"
674 $(VERB) $(CompileCG) $< -o $@
675
Chris Lattner6721f0e2003-09-15 22:17:02 +0000676$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000677 @echo "Compiling $< to bytecode"
Chris Lattner7c95d2f2003-08-27 18:26:44 +0000678 $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000679
Chris Lattner6721f0e2003-09-15 22:17:02 +0000680$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000681 @echo "Compiling $< to bytecode"
Chris Lattner7c95d2f2003-08-27 18:26:44 +0000682 $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000683
Chris Lattner6721f0e2003-09-15 22:17:02 +0000684$(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000685 @echo "Compiling $< to bytecode"
686 $(VERB) $(LLVMAS) $< -f -o $@
687
688
Chris Lattnerdb644dd2003-01-16 22:44:19 +0000689#
690# Rules for building lex/yacc files
691#
692LEX_FILES = $(filter %.l, $(Source))
693LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
694YACC_FILES = $(filter %.y, $(Source))
695YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
696.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
697
Chris Lattner2f7c9632001-06-06 20:29:01 +0000698# Create a .cpp source file from a flex input file... this uses sed to cut down
699# on the warnings emited by GCC...
Chris Lattner9e461662003-01-23 16:33:10 +0000700#
701# The last line is a gross hack to work around flex aparently not being able to
702# resize the buffer on a large token input. Currently, for uninitialized string
703# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattner92fc9b02003-08-15 20:00:47 +0000704# FIXME. (f.e. char Buffer[10000] )
Chris Lattner9e461662003-01-23 16:33:10 +0000705#
Chris Lattner2f7c9632001-06-06 20:29:01 +0000706%.cpp: %.l
John Criswell73c5be42003-09-11 15:15:53 +0000707 @echo Flexing $<
Chris Lattnerb3aae612003-08-04 19:48:10 +0000708 $(VERB) $(FLEX) -t $< | \
709 $(SED) '/^find_rule/d' | \
710 $(SED) 's/void yyunput/inline void yyunput/' | \
John Criswell3ef61af2003-06-30 21:59:07 +0000711 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
Chris Lattner7d0adf72003-08-04 19:47:06 +0000712 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
713 > $@.tmp
John Criswell48ecca62003-08-12 18:51:51 +0000714 $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
Chris Lattner7d0adf72003-08-04 19:47:06 +0000715 @# remove the output of flex if it didn't get moved over...
716 @rm -f $@.tmp
Chris Lattner2f7c9632001-06-06 20:29:01 +0000717
718# Rule for building the bison parsers...
Chris Lattner021249f2003-05-15 21:28:55 +0000719%.c: %.y # Cancel built-in rules for yacc
720%.h: %.y # Cancel built-in rules for yacc
Chris Lattner2f7c9632001-06-06 20:29:01 +0000721%.cpp %.h : %.y
John Criswell73c5be42003-09-11 15:15:53 +0000722 @echo Bisoning $<
John Criswellded98992003-09-09 20:57:03 +0000723 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
John Criswell48ecca62003-08-12 18:51:51 +0000724 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
725 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || ${MV} -f $*.tab.h $*.h
Chris Lattner7d0adf72003-08-04 19:47:06 +0000726 @# If the files were not updated, don't leave them lying around...
727 @rm -f $*.tab.c $*.tab.h
Chris Lattner2f7c9632001-06-06 20:29:01 +0000728
729# To create the directories...
730%/.dir:
John Criswell3ef61af2003-06-30 21:59:07 +0000731 $(VERB) ${MKDIR} $* > /dev/null
732 @$(DATE) > $@
Chris Lattner2f7c9632001-06-06 20:29:01 +0000733
Chris Lattner23d47392003-01-16 21:06:18 +0000734# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +0000735ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +0000736%.ps: %.dot
John Criswell3ef61af2003-06-30 21:59:07 +0000737 ${DOT} -Tps < $< > $@
738else
739%.ps: %.dot
740 ${ECHO} "Cannot build $@: The program dot is not installed"
741endif
Chris Lattner23d47392003-01-16 21:06:18 +0000742
John Criswell0a6e6aa2003-09-06 14:44:17 +0000743#
744# This rules ensures that header files that are removed still have a rule for
745# which they can be "generated." This allows make to ignore them and
746# reproduce the dependency lists.
747#
John Criswella8391af2003-09-18 18:37:08 +0000748%.h:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +0000749
Chris Lattnera8ce09e2002-09-22 02:47:15 +0000750# 'make clean' nukes the tree
Chris Lattner2f7c9632001-06-06 20:29:01 +0000751clean::
Chris Lattner0c4f4fe2003-08-15 02:18:35 +0000752 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
753 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
Chris Lattner6721f0e2003-09-15 22:17:02 +0000754 $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
John Criswell3ef61af2003-06-30 21:59:07 +0000755 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
756 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
757
John Criswell3ef61af2003-06-30 21:59:07 +0000758###########################################################################
759# C/C++ Dependencies
760# Define variables and rules that generate header file dependencies
761# from C/C++ source files.
762###########################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000763
Chris Lattnere9d7d702003-08-22 14:10:16 +0000764ifndef DISABLE_AUTO_DEPENDENCIES
765
Chris Lattner021249f2003-05-15 21:28:55 +0000766# If dependencies were generated for the file that included this file,
Misha Brukmana1f0c142003-08-21 22:02:18 +0000767# include the dependencies now...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000768#
John Criswellded98992003-09-09 20:57:03 +0000769SourceBaseNames := $(basename $(Source))
John Criswell0607d882003-06-11 13:55:44 +0000770SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
Chris Lattner021249f2003-05-15 21:28:55 +0000771
772# Create dependencies for the *.cpp files...
John Criswellded98992003-09-09 20:57:03 +0000773$(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000774 $(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 Lattner021249f2003-05-15 21:28:55 +0000775
776# Create dependencies for the *.c files...
John Criswellded98992003-09-09 20:57:03 +0000777$(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
John Criswell3ef61af2003-06-30 21:59:07 +0000778 $(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 Lattner021249f2003-05-15 21:28:55 +0000779
John Criswell3ef61af2003-06-30 21:59:07 +0000780#
John Criswell06636c22003-10-07 14:16:44 +0000781# Autoconf Dependencies.
782#
783$(LLVM_OBJ_ROOT)/include/Config/config.h:: $(LLVM_SRC_ROOT)/configure
784 @${ECHO} "You need to re-run $(LLVM_SRC_ROOT)/configure"
785 @${ECHO} "inside the directory $(LLVM_OBJ_ROOT)"
786 $(VERB) exit 1
787
788#
John Criswell3ef61af2003-06-30 21:59:07 +0000789# Include dependencies generated from C/C++ source files, but not if we
790# are cleaning (this example taken from the GNU Make Manual).
791#
792ifneq ($(MAKECMDGOALS),clean)
John Criswell48ecca62003-08-12 18:51:51 +0000793ifneq ($(MAKECMDGOALS),distclean)
Chris Lattnerb0f858b2003-08-29 14:07:02 +0000794-include /dev/null $(SourceDepend)
John Criswell3ef61af2003-06-30 21:59:07 +0000795endif
John Criswell48ecca62003-08-12 18:51:51 +0000796endif
Chris Lattner598222b2003-08-18 17:27:40 +0000797
Chris Lattnere9d7d702003-08-22 14:10:16 +0000798endif # ifndef DISABLE_AUTO_DEPENDENCIES