blob: 94b53bcb189ec109f02adee2b95f81cefd5e0ad0 [file] [log] [blame]
Misha Brukman6d5ab862004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswelld8846c12003-10-21 14:33:46 +00003# 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#
Misha Brukman6d5ab862004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner00950542001-06-06 20:29:01 +00009#
Reid Spencer3a561f52004-10-23 20:04:14 +000010# This file is included by all of the LLVM makefiles. For details on how to use
11# it properly, please see the document MakefileGuide.html in the docs directory.
Chris Lattneraf06a082003-08-15 03:02:52 +000012#
Vikram S. Adved60aede2002-07-09 12:04:21 +000013#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000014
John Criswell2a6530f2003-06-27 16:58:44 +000015#
John Criswell7f336952003-09-06 14:44:17 +000016# Set the VPATH so that we can find source files.
John Criswell8bff5092003-06-11 13:55:44 +000017#
Reid Spencer4d71b662004-10-22 21:01:56 +000018VPATH=$(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +000019
Reid Spencer3a561f52004-10-23 20:04:14 +000020###############################################################################
21# TARGETS: Define standard targets that can be invoked
22###############################################################################
John Criswell7a73b802003-06-30 21:59:07 +000023
Chris Lattner00950542001-06-06 20:29:01 +000024#--------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +000025# Define the various target sets
26#--------------------------------------------------------------------
27RECURSIVE_TARGETS := all clean check install uninstall
28LOCAL_TARGETS := all-local clean-local check-local install-local printvars\
29 uninstall-local
30TOPLEV_TARGETS := dist dist-check dist-clean
31INTERNAL_TARGETS := preconditions
32
33#--------------------------------------------------------------------
34# Mark all of these targets as phony to avoid implicit rule search
35#--------------------------------------------------------------------
36.PHONY: $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOP_TARGETS) $(INTERNAL_TARGETS)
37
38#--------------------------------------------------------------------
39# Make sure all the user-target rules are double colon rules and that
40# the preconditions are run first.
41#--------------------------------------------------------------------
42
43all :: all-local
44check:: check-local
45clean:: clean-local
46install :: install-local
47uninstall :: uninstall-local
48
49all-local :: preconditions
50clean-local :: preconditions
51check-local :: all-local
52install-local :: all-local
53printvars :: preconditions
54uninstall-local :: preconditions
55
56dist:: preconditions
57dist-check:: preconditions
58dist-clean:: preconditions
59
60###############################################################################
61# SUFFIXES: Reset the list of suffixes we know how to build
62###############################################################################
63.SUFFIXES:
64.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
65
66###############################################################################
67# VARIABLES: Set up various variables based on configuration data
68###############################################################################
69
70#--------------------------------------------------------------------
71# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +000072#--------------------------------------------------------------------
73
Chris Lattner760da062003-03-14 20:25:22 +000074ifdef ENABLE_PROFILING
Chris Lattner760da062003-03-14 20:25:22 +000075 CONFIGURATION := Profile
Reid Spencer4d71b662004-10-22 21:01:56 +000076 CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
77 CFLAGS += -O3 -DNDEBUG -pg
78 LDFLAGS += -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +000079else
80 ifdef ENABLE_OPTIMIZED
81 CONFIGURATION := Release
Reid Spencer4d71b662004-10-22 21:01:56 +000082 CXXFLAGS += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
83 CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
84 LDFLAGS += -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +000085 else
86 CONFIGURATION := Debug
Reid Spencer4d71b662004-10-22 21:01:56 +000087 CXXFLAGS += -g -D_DEBUG
88 CFLAGS += -g -D_DEBUG
89 LDFLAGS += -g -D_DEBUG
90 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +000091 endif
92endif
93
Reid Spencer4d71b662004-10-22 21:01:56 +000094ARFLAGS := cru
Reid Spencer3a561f52004-10-23 20:04:14 +000095
96#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +000097# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +000098#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +000099OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
100LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
101TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
102LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
103LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
John Criswell7a73b802003-06-30 21:59:07 +0000104
Reid Spencer3a561f52004-10-23 20:04:14 +0000105#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000106# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000107#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000108LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
109LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
110BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
111TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
112GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
113LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
114LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000115
Reid Spencer4d71b662004-10-22 21:01:56 +0000116# Need a better way to compute this.
117LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000118
Reid Spencer3a561f52004-10-23 20:04:14 +0000119#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000120# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000121#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000122
Reid Spencer3a561f52004-10-23 20:04:14 +0000123# Adjust LIBTOOL options for shared libraries, or not.
John Criswell82f4a5a2003-07-31 20:58:51 +0000124ifndef SHARED_LIBRARY
Reid Spencer4d71b662004-10-22 21:01:56 +0000125 LIBTOOL += --tag=disable-shared
126else
127 LDFLAGS += -rpath $(LIBDIR)
John Criswell82f4a5a2003-07-31 20:58:51 +0000128endif
129
Reid Spencer3a561f52004-10-23 20:04:14 +0000130# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000131ifndef VERBOSE
Reid Spencer4d71b662004-10-22 21:01:56 +0000132 VERB := @
133 LIBTOOL += --silent
134 AR += >/dev/null 2>/dev/null
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000135endif
136
Vikram S. Advefeeae582002-09-18 11:55:13 +0000137# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000138ifndef KEEP_SYMBOLS
Reid Spencer4d71b662004-10-22 21:01:56 +0000139 STRIP = $(PLATFORMSTRIPOPTS)
140 STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000141endif
142
Reid Spencer3a561f52004-10-23 20:04:14 +0000143# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000144ifdef TOOLNAME
145 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
146endif
Chris Lattner00950542001-06-06 20:29:01 +0000147
Reid Spencer3a561f52004-10-23 20:04:14 +0000148# Use TOOLLINKOPTSB to pass options to the linker like library search
149# path etc.
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000150# Note that this is different from TOOLLINKOPTS, these options
151# are passed to the linker *before* the USEDLIBS options are passed.
152# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
153ifdef TOOLLINKOPTSB
Reid Spencer4d71b662004-10-22 21:01:56 +0000154LDFLAGS += $(TOOLLINKOPTSB)
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000155endif
156
Reid Spencer3a561f52004-10-23 20:04:14 +0000157#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000158# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000159#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000160
161CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
162
Reid Spencer3a561f52004-10-23 20:04:14 +0000163LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
Reid Spencer4d71b662004-10-22 21:01:56 +0000164CPPFLAGS += -I$(BUILD_OBJ_DIR) \
165 -I$(BUILD_SRC_DIR) \
166 -I$(BUILD_SRC_ROOT)/include \
167 -I$(BUILD_OBJ_ROOT)/include \
168 -I$(LLVM_OBJ_ROOT)/include \
169 -I$(LLVM_SRC_ROOT)/include \
170 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
171
Reid Spencer3a561f52004-10-23 20:04:14 +0000172Compile.C = $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
173Compile.CXX = $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
174LTCompile.C = $(LIBTOOL) --mode=compile $(Compile.C)
175LTCompile.CXX = $(LIBTOOL) --tag=CXX --mode=compile $(Compile.CXX)
176BCCompile.CXX = $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
177BCCompile.C = $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
178Link = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) \
179 $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
180Relink = $(LIBTOOL) --tag=CXX --mode=link $(CXX)
181BCLinkLib = $(LLVMGCC) -shared -nostdlib
182Burg = $(BURG) -I $(BUILD_SRC_DIR)
183TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
184Archive = $(AR) $(ARFLAGS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000185ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000186Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000187else
Reid Spencer3a561f52004-10-23 20:04:14 +0000188Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000189endif
190
Chris Lattner00950542001-06-06 20:29:01 +0000191#----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000192# Get the list of source files
193#----------------------------------------------------------
194ifndef SOURCES
195SOURCES := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
196 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
197 $(BUILD_SRC_DIR)/*.l))
Reid Spencer4d71b662004-10-22 21:01:56 +0000198endif
199
200ifdef BUILT_SOURCES
Reid Spencer3a561f52004-10-23 20:04:14 +0000201SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000202endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000203
Reid Spencer3a561f52004-10-23 20:04:14 +0000204#----------------------------------------------------------
205# Types of objects that can be built from sources
206#----------------------------------------------------------
207BASENAME_SOURCES := $(sort $(basename $(SOURCES)))
208ObjectsO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.o)
209ObjectsLO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.lo)
210ObjectsBC := $(BASENAME_SOURCES:%=$(OBJDIR)/%.bc)
211
212
213###############################################################################
214# DIRECTORIES: Handle recursive descent of directory structure
215###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000216
Chris Lattner00950542001-06-06 20:29:01 +0000217#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000218# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000219#---------------------------------------------------------
220
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000221ifdef DIRS
Reid Spencer3a561f52004-10-23 20:04:14 +0000222$(RECURSIVE_TARGETS)::
Reid Spencer4d71b662004-10-22 21:01:56 +0000223 $(VERB) for dir in $(DIRS); do \
224 if [ ! -f $$dir/Makefile ]; then \
225 $(MKDIR) $$dir; \
226 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
227 fi; \
228 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000229 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000230endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000231
Reid Spencer3a561f52004-10-23 20:04:14 +0000232#---------------------------------------------------------
233# Handle the EXPERIMENTAL_DIRS options ensuring success
234# after each directory is built.
235#---------------------------------------------------------
236ifdef EXPERIMENTAL_DIRS
237$(RECURSIVE_TARGETS)::
238 $(VERB) for dir in $(EXPERIMENTAL_DIRS); do \
239 if [ ! -f $$dir/Makefile ]; then \
240 $(MKDIR) $$dir; \
241 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
242 fi; \
243 $(MAKE) -C $$dir $@ $(MFLAGS) || exit 0; \
244 done
245endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000246
Reid Spencer3a561f52004-10-23 20:04:14 +0000247#---------------------------------------------------------
248# Handle the PARALLEL_DIRS options for parallel construction
249#---------------------------------------------------------
250ifdef PARALLEL_DIRS
251
252# Unfortunately, this list must be maintained if new
253# recursive targets are added.
254all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
255clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
256check :: $(addsuffix /.makecheck , $(PARALLEL_DIRS))
257install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
258uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
259
260Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
261
262$(Parallel_Targets) :
Reid Spencer4d71b662004-10-22 21:01:56 +0000263 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
264 $(MKDIR) $(@D); \
265 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000266 fi; \
Misha Brukman694b3ff2004-05-21 23:21:11 +0000267 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000268endif
269
Reid Spencer3a561f52004-10-23 20:04:14 +0000270#---------------------------------------------------------
271# Handle the OPTIONAL_DIRS options for directores that may
272# or may not exist.
273#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000274ifdef OPTIONAL_DIRS
Reid Spencer3a561f52004-10-23 20:04:14 +0000275$(RECURSIVE_TARGETS)::
Reid Spencer4d71b662004-10-22 21:01:56 +0000276 $(VERB) for dir in $(OPTIONAL_DIRS); do \
277 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
278 if [ ! -f $$dir/Makefile ]; then \
279 $(MKDIR) $$dir; \
280 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
281 fi; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000282 ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 1; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000283 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000284 done
285endif
286
Reid Spencerfc945082004-08-20 09:20:05 +0000287#---------------------------------------------------------
288# Handle the CONFIG_FILES options
289#---------------------------------------------------------
290ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000291
Reid Spencer3a561f52004-10-23 20:04:14 +0000292.PHONY: install-config-dir
Reid Spencerfc945082004-08-20 09:20:05 +0000293
Reid Spencer3a561f52004-10-23 20:04:14 +0000294install:: install-config-dir
295
296install-config-dir: $(sysconfdir) $(CONFIG_FILES)
Reid Spencer37130d22004-10-04 07:05:07 +0000297 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
298 $(VERB)for file in $(CONFIG_FILES); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000299 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
Reid Spencerfc945082004-08-20 09:20:05 +0000300 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000301
302$(sysconfdir):
303 $(MKDIR) $(sysconfdir)
304
Reid Spencerfc945082004-08-20 09:20:05 +0000305endif
306
Reid Spencer3a561f52004-10-23 20:04:14 +0000307###############################################################################
308# Library Build Rules: Four ways to build a library
309###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000310
Brian Gaeke8abff792004-01-22 22:53:48 +0000311
Reid Spencer3a561f52004-10-23 20:04:14 +0000312# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000313ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000314
Chris Lattner2a548c52002-09-16 22:36:42 +0000315# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000316LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer4d71b662004-10-22 21:01:56 +0000317LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
318LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
319LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
320LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000321
Reid Spencer3a561f52004-10-23 20:04:14 +0000322#---------------------------------------------------------
323# Shared Library Targets:
324# If the user asked for a shared library to be built
325# with the SHARED_LIBRARY variable, then we provide
326# targets for building them.
327#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000328ifdef SHARED_LIBRARY
329
Reid Spencer3a561f52004-10-23 20:04:14 +0000330all-local:: $(LIBNAME_LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000331
332$(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
333 @$(ECHO) Linking shared library $(notdir $@)
334 $(VERB) $(Link) -o $@ $(ObjectsLO)
335 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
Reid Spencer3a561f52004-10-23 20:04:14 +0000336
337clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000338 $(VERB) $(RM) -f $(LIBNAME_LA)
339
Reid Spencer3a561f52004-10-23 20:04:14 +0000340install-local:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000341
342$(DESTDIR)/lib/lib$(LIBRARYNAME)$(SHLIBEXT): $(LIBNAME_LA)
343 @$(ECHO) Installing shared library $(notdir $@)
344 $(VERB) $(MKDIR) $(DESTDIR)
345 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
346 $(VERB) $(LIBTOOL) --finish $(DESTDIR)$(libdir)
347endif
348
Reid Spencer3a561f52004-10-23 20:04:14 +0000349#---------------------------------------------------------
350# Bytecode Library Targets:
351# If the user asked for a bytecode library to be built
352# with the BYTECODE_LIBRARY variable, then we provide
353# targets for building them.
354#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000355ifdef BYTECODE_LIBRARY
356
357ifdef EXPORTED_SYMBOL_LIST
358 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
359else
360 ifdef EXPORTED_SYMBOL_FILE
361 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
362 else
363 BCLinkLib += -Xlinker -disable-internalize
364 endif
365endif
366
Reid Spencer3a561f52004-10-23 20:04:14 +0000367all-local:: $(LIBNAME_BC)
Reid Spencer4d71b662004-10-22 21:01:56 +0000368
369$(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
370 @$(ECHO) Linking bytecode library $(notdir $@)
371 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
372
Reid Spencer3a561f52004-10-23 20:04:14 +0000373clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000374 $(VERB) $(RM) -f $(LIBNAME_BC)
375
Reid Spencer3a561f52004-10-23 20:04:14 +0000376install-local:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
Chris Lattner481cc7c2003-08-15 02:18:35 +0000377
Brian Gaeke13f99322004-01-21 23:57:21 +0000378$(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
Reid Spencer4d71b662004-10-22 21:01:56 +0000379 @$(ECHO) Installing bytecode library $(notdir $@)
380 $(VERB)$(INSTALL) $< $@
381
382endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000383
Chris Lattner760da062003-03-14 20:25:22 +0000384# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000385ifndef DONT_BUILD_RELINKED
Reid Spencer3a561f52004-10-23 20:04:14 +0000386all-local:: $(LIBNAME_O)
Reid Spencer4d71b662004-10-22 21:01:56 +0000387
388$(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencer3a561f52004-10-23 20:04:14 +0000389 @$(ECHO) Linking object library $(notdir $@)
Reid Spencer4d71b662004-10-22 21:01:56 +0000390 $(VERB) $(Relink) -o $@ $(ObjectsO)
391
Reid Spencer3a561f52004-10-23 20:04:14 +0000392install-local:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
Reid Spencer4d71b662004-10-22 21:01:56 +0000393
394$(DESTDIR)$(libdir)/$(LIBRARYNAME).o: $(LIBNAME_O)
395 @$(ECHO) Installing object library $(notdir $@)
396 $(VERB) $(MKDIR) $(DESTDIR)$(libdir)
397 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
398
Reid Spencer3a561f52004-10-23 20:04:14 +0000399clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000400 $(VERB) $(RM) -f $(LIBNAME_O)
401
Chris Lattnere62dbe92002-07-23 17:56:16 +0000402endif
Chris Lattner760da062003-03-14 20:25:22 +0000403
404# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000405ifdef BUILD_ARCHIVE
Reid Spencer3a561f52004-10-23 20:04:14 +0000406all-local:: $(LIBNAME_A)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000407
Reid Spencer4d71b662004-10-22 21:01:56 +0000408$(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencer3a561f52004-10-23 20:04:14 +0000409 @$(ECHO) Building archive library $(notdir $@)
Reid Spencer37130d22004-10-04 07:05:07 +0000410 $(VERB)$(RM) -f $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000411 $(VERB) $(Archive) $@ $(ObjectsO)
412 $(VERB) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000413
Reid Spencer3a561f52004-10-23 20:04:14 +0000414clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000415 $(VERB) $(RM) -f $(LIBNAME_A)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000416
Reid Spencer3a561f52004-10-23 20:04:14 +0000417install-local:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
John Criswell7a73b802003-06-30 21:59:07 +0000418
Reid Spencer4d71b662004-10-22 21:01:56 +0000419$(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a: $(LIBNAME_A)
Reid Spencer3a561f52004-10-23 20:04:14 +0000420 @$(ECHO) Installing archive library $(notdir $@)
Brian Gaeke6c096962004-02-09 17:38:52 +0000421 $(MKDIR) $(DESTDIR)$(libdir)
Reid Spencer4d71b662004-10-22 21:01:56 +0000422 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000423endif
424
Reid Spencer4d71b662004-10-22 21:01:56 +0000425# if LIBRARYNAME
426endif
427
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000428#------------------------------------------------------------------------
429# Handle the TOOLNAME option - used when building tool executables...
430#------------------------------------------------------------------------
431#
432# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000433# libraries (and the order of the libs) that should be linked to the
434# tool. USEDLIBS should contain a list of library names (some with .a extension)
435# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000436#
437ifdef TOOLNAME
438
Reid Spencer4d71b662004-10-22 21:01:56 +0000439# TOOLLINKOPTSB to pass options to the linker like library search path etc
440# Note that this is different from TOOLLINKOPTS, these options
441# are passed to the linker *before* the USEDLIBS options are passed.
442# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
443ifdef TOOLLINKOPTSB
444Link += $(TOOLLINKOPTSB)
Reid Spencer37130d22004-10-04 07:05:07 +0000445endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000446
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000447# TOOLEXENAME* - These compute the output filenames to generate...
Reid Spencer4d71b662004-10-22 21:01:56 +0000448TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000449
450# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Reid Spencer4d71b662004-10-22 21:01:56 +0000451PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
452PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
453LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
454LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000455
Reid Spencer4d71b662004-10-22 21:01:56 +0000456PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
457LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
458PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
459LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000460
Reid Spencer4d71b662004-10-22 21:01:56 +0000461LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
John Criswellfe785bd2004-09-16 14:11:25 +0000462
John Criswell7a73b802003-06-30 21:59:07 +0000463#
464# Libtool link options:
465# Ensure that all binaries have their symbols exported so that they can
466# by dlsym'ed.
467#
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000468
Reid Spencer4d71b662004-10-22 21:01:56 +0000469# Handle compression libraries automatically
470ifeq ($(HAVE_BZIP2),1)
471LIBS += -lbz2
472endif
473ifeq ($(HAVE_ZLIB),1)
474LIBS += -lz
475endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000476
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000477# Tell make that we need to rebuild subdirectories before we can link the tool.
478# This affects things like LLI which has library subdirectories.
Reid Spencer4d71b662004-10-22 21:01:56 +0000479$(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000480
Reid Spencer3a561f52004-10-23 20:04:14 +0000481all-local:: $(TOOLEXENAME)
John Criswell2a6530f2003-06-27 16:58:44 +0000482
Reid Spencer3a561f52004-10-23 20:04:14 +0000483clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000484 $(VERB) $(RM) -f $(TOOLEXENAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000485
Reid Spencer4d71b662004-10-22 21:01:56 +0000486$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
487 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
488 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
489 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000490
Reid Spencer3a561f52004-10-23 20:04:14 +0000491install-local:: $(TOOLEXENAME)
Reid Spencer4d71b662004-10-22 21:01:56 +0000492 @$(ECHO) Installing $(TOOLNAME)
493 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
494endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000495
Reid Spencer4d71b662004-10-22 21:01:56 +0000496ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000497
Reid Spencer4d71b662004-10-22 21:01:56 +0000498# Create .lo files in the OBJDIR directory from the .cpp and .c files...
Reid Spencer3a561f52004-10-23 20:04:14 +0000499ifdef SHARED_LIBRARY
500
501$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000502 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000503 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
504 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
505 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
506
507$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
508 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
509 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
510 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
511 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
512
513else
Reid Spencer4d71b662004-10-22 21:01:56 +0000514
515$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
516 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000517 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
518 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
519 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000520
521$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
522 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000523 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
524 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
525 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
526
527endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000528
529# Create .bc files in the OBJDIR directory from .cpp and .c files...
530$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
531 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000532 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
533 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
534 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000535
536$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
537 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000538 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
539 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
540 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000541
542else
543
Reid Spencer3a561f52004-10-23 20:04:14 +0000544ifdef SHARED_LIBRARY
545
546$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000547 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000548 $(LTCompile.CXX) $< -o $@
549
550$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
551 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
552 $(LTCompile.C) $< -o $@
553
554else
Reid Spencer4d71b662004-10-22 21:01:56 +0000555
556$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
557 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000558 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000559
560$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
561 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000562 $(Compile.C) $< -o $@
563endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000564
565# Create .bc files in the OBJDIR directory from .cpp and .c files...
566$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
567 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
568 $(BCCompileCPP) $< -o $@
569
570$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
571 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
572 $(BCCompileC) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000573
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000574endif
575
Reid Spencer4d71b662004-10-22 21:01:56 +0000576$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
577 @$(ECHO) "Compiling $*.ll To Bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000578 $(VERB) $(LLVMAS) $< -f -o $@
579
Reid Spencer4d71b662004-10-22 21:01:56 +0000580ifdef TARGET
581
Reid Spencerc64b2b32004-10-23 08:19:37 +0000582TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
Reid Spencer4d71b662004-10-22 21:01:56 +0000583
584$(BUILT_SOURCES): $(TDFILES)
585
586%GenRegisterNames.inc : %.td
587 @echo "Building $(<F) register names with tblgen"
588 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
589
590%GenRegisterInfo.h.inc : %.td
591 @echo "Building $(<F) register information header with tblgen"
592 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
593
594%GenRegisterInfo.inc : %.td
595 @echo "Building $(<F) register info implementation with tblgen"
596 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
597
598%GenInstrNames.inc : %.td
599 @echo "Building $(<F) instruction names with tblgen"
600 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
601
602%GenInstrInfo.inc : %.td
603 @echo "Building $(<F) instruction information with tblgen"
604 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
605
606%GenAsmWriter.inc : %.td
607 @echo "Building $(<F) assembly writer with tblgen"
608 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
609
610%GenATTAsmWriter.inc : %.td
611 @echo "Building $(<F) AT&T assembly writer with tblgen"
612 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
613
614%GenIntelAsmWriter.inc : %.td
615 @echo "Building $(<F) Intel assembly writer with tblgen"
616 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
617
618%GenInstrSelector.inc: %.td
619 @echo "Building $(<F) instruction selector with tblgen"
620 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
621
622%GenCodeEmitter.inc:: %.td
623 @echo "Building $(<F) code emitter with tblgen"
624 $(VERB) $(TableGen) -gen-emitter -o $@ $<
625
Reid Spencer3a561f52004-10-23 20:04:14 +0000626clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000627 $(VERB) rm -f *.inc
628
629endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000630
Chris Lattnere8996782003-01-16 22:44:19 +0000631#
632# Rules for building lex/yacc files
633#
Reid Spencer3a561f52004-10-23 20:04:14 +0000634LEX_FILES = $(filter %.l, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000635LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
Reid Spencer3a561f52004-10-23 20:04:14 +0000636YACC_FILES = $(filter %.y, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000637YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
638.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
639
Chris Lattner00950542001-06-06 20:29:01 +0000640# Create a .cpp source file from a flex input file... this uses sed to cut down
641# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000642#
643# The last line is a gross hack to work around flex aparently not being able to
644# resize the buffer on a large token input. Currently, for uninitialized string
645# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000646# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000647#
Chris Lattner00950542001-06-06 20:29:01 +0000648%.cpp: %.l
Reid Spencer4d71b662004-10-22 21:01:56 +0000649 @$(ECHO) Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000650 $(VERB) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000651 $(SED) '/^find_rule/d' | \
652 $(SED) 's/void yyunput/inline void yyunput/' | \
653 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
654 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
655 > $@.tmp
656 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000657 @# remove the output of flex if it didn't get moved over...
658 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000659
660# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000661%.c: %.y # Cancel built-in rules for yacc
662%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000663%.cpp %.h : %.y
Reid Spencer4d71b662004-10-22 21:01:56 +0000664 @$(ECHO) "Bisoning $*.y"
John Criswell410d1b52003-09-09 20:57:03 +0000665 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000666 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
667 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000668 @# If the files were not updated, don't leave them lying around...
669 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000670
671# To create the directories...
672%/.dir:
Reid Spencer4d71b662004-10-22 21:01:56 +0000673 $(VERB) $(MKDIR) $* > /dev/null
John Criswell7a73b802003-06-30 21:59:07 +0000674 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000675
Reid Spencer4d71b662004-10-22 21:01:56 +0000676.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
677.PRECIOUS: $(LLVMTOOLDIR)/.dir
678
Chris Lattner30440c62003-01-16 21:06:18 +0000679# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000680ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000681%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000682 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000683else
684%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000685 $(ECHO) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000686endif
Chris Lattner30440c62003-01-16 21:06:18 +0000687
John Criswell7f336952003-09-06 14:44:17 +0000688#
689# This rules ensures that header files that are removed still have a rule for
690# which they can be "generated." This allows make to ignore them and
691# reproduce the dependency lists.
692#
John Criswell4b6e5d12003-09-18 18:37:08 +0000693%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000694
Chris Lattner172b6482002-09-22 02:47:15 +0000695# 'make clean' nukes the tree
Reid Spencer3a561f52004-10-23 20:04:14 +0000696clean-local::
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000697 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
698ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
699 $(VERB) $(RM) -f *$(SHLIBEXT)
700endif
John Criswell7a73b802003-06-30 21:59:07 +0000701 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
702
Reid Spencer3a561f52004-10-23 20:04:14 +0000703###############################################################################
704# DEPENDENCIES: Include the dependency files if we should
705###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +0000706ifndef DISABLE_AUTO_DEPENDENCIES
707
Reid Spencer3a561f52004-10-23 20:04:14 +0000708# If its not one of the cleaning targets
709ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000710
Reid Spencer3a561f52004-10-23 20:04:14 +0000711# Get the list of dependency files
712DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
713DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000714
Reid Spencer3a561f52004-10-23 20:04:14 +0000715-include /dev/null $(DependFiles)
716
John Criswelld741bcf2003-08-12 18:51:51 +0000717endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000718
Chris Lattner33ad24a2003-08-22 14:10:16 +0000719endif # ifndef DISABLE_AUTO_DEPENDENCIES
Reid Spencer4d71b662004-10-22 21:01:56 +0000720
Reid Spencer3a561f52004-10-23 20:04:14 +0000721################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000722# PRECONDITIONS - that which must be built/checked first
Reid Spencer3a561f52004-10-23 20:04:14 +0000723################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000724
725OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
726SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
727CONFIGURE := $(LLVM_SRC_ROOT)/configure
728CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
729MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
730MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
731
732#------------------------------------------------------------------------
733# List of the preconditions
Reid Spencer3a561f52004-10-23 20:04:14 +0000734#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000735preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
736
Reid Spencer3a561f52004-10-23 20:04:14 +0000737all all-local check check-local dist dist-check install:: $(BUILT_SOURCES)
Reid Spencer4d71b662004-10-22 21:01:56 +0000738
Reid Spencer3a561f52004-10-23 20:04:14 +0000739clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000740 $(VERB) $(RM) -f $(BUILT_SOURCES)
741
742#------------------------------------------------------------------------
743# Make sure we're not using a stale configuration
Reid Spencer3a561f52004-10-23 20:04:14 +0000744#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000745.PRECIOUS: $(CONFIG_STATUS)
746$(CONFIG_STATUS): $(CONFIGURE)
747 @$(ECHO) Reconfiguring with $@
748 $(VERB) $(CONFIG_STATUS) --recheck
749
750#------------------------------------------------------------------------
751# Make sure the configuration makefile is up to date
Reid Spencer3a561f52004-10-23 20:04:14 +0000752#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000753$(MAKE_CONFIG): $(MAKE_CONFIG_IN)
754 @$(ECHO) Regenerating $@
755 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
Reid Spencerc64b2b32004-10-23 08:19:37 +0000756 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000757 @exit 0;
758
759#------------------------------------------------------------------------
760# If the Makefile in the source tree has been updated, copy it over into the
Reid Spencer3a561f52004-10-23 20:04:14 +0000761# build tree. But, only do this if the source and object makefiles differ
762#------------------------------------------------------------------------
Reid Spencere53e3972004-10-22 23:06:30 +0000763ifneq ($(OBJMKFILE),$(SRCMKFILE))
Reid Spencer4d71b662004-10-22 21:01:56 +0000764.PRECIOUS: $(OBJMKFILE)
765$(OBJMKFILE): $(SRCMKFILE)
766 @$(ECHO) "Updating Makefile from : $(dir $<)"
767 $(VERB) $(MKDIR) $(@D)
768 $(VERB) cp -f $< $@
Reid Spencerc64b2b32004-10-23 08:19:37 +0000769 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000770 @exit 0;
Reid Spencere53e3972004-10-22 23:06:30 +0000771endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000772
773###############################################################################
774# MISCELLANEOUS - utility targets
775###############################################################################
776
777#------------------------------------------------------------------------
778# Print out the directories used for building
Reid Spencer3a561f52004-10-23 20:04:14 +0000779printvars::
Reid Spencer4d71b662004-10-22 21:01:56 +0000780 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
781 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
782 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
783 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
784 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
785 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
786 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
787 @$(ECHO) "OBJDIR: " $(OBJDIR)
788 @$(ECHO) "LIBDIR: " $(LIBDIR)
789 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
790 @$(ECHO) "TDFILES:" '$(TDFILES)'
Reid Spencer3a561f52004-10-23 20:04:14 +0000791 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
792 @$(ECHO) "Compile.C: " '$(Compile.C)'