blob: 8b2af1a56c33d414a7faccf6d6332864a454acc1 [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
Reid Spencere5487ba2004-10-24 07:53:21 +000030TOPLEV_TARGETS := dist dist-check dist-clean tags
31INTERNAL_TARGETS := preconditions \
32 install-config-dir install-shared-library install-bytecode-library \
33 install-archive-library install-relinked-library install-tool \
34 uninstall-config-dir uninstall-shared-library uninstall-bytecode-library \
35 uninstall-archive-library uninstall-relinked-library uninstall-tool
Reid Spencer3a561f52004-10-23 20:04:14 +000036
37#--------------------------------------------------------------------
38# Mark all of these targets as phony to avoid implicit rule search
39#--------------------------------------------------------------------
40.PHONY: $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOP_TARGETS) $(INTERNAL_TARGETS)
41
42#--------------------------------------------------------------------
43# Make sure all the user-target rules are double colon rules and that
44# the preconditions are run first.
45#--------------------------------------------------------------------
46
47all :: all-local
48check:: check-local
49clean:: clean-local
50install :: install-local
51uninstall :: uninstall-local
52
53all-local :: preconditions
54clean-local :: preconditions
55check-local :: all-local
56install-local :: all-local
57printvars :: preconditions
58uninstall-local :: preconditions
59
Reid Spencer3a561f52004-10-23 20:04:14 +000060###############################################################################
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; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000243 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 0; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000244 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 Spencere5487ba2004-10-24 07:53:21 +0000292install-local:: install-config-dir
Reid Spencer3a561f52004-10-23 20:04:14 +0000293
294install-config-dir: $(sysconfdir) $(CONFIG_FILES)
Reid Spencer37130d22004-10-04 07:05:07 +0000295 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
296 $(VERB)for file in $(CONFIG_FILES); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000297 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
Reid Spencerfc945082004-08-20 09:20:05 +0000298 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000299
Reid Spencere5487ba2004-10-24 07:53:21 +0000300uninstall-local:: uninstall-config-dir
301
302uninstall-config-dir:
303 $(VERB)$(ECHO) Uninstalling Configuration Files From $(sysconfdir)
304 $(VERB)for file in $(CONFIG_FILES); do \
305 $(RM) -f $(sysconfdir)/$${file} ; \
306 done
307
Reid Spencer3a561f52004-10-23 20:04:14 +0000308$(sysconfdir):
309 $(MKDIR) $(sysconfdir)
310
Reid Spencerfc945082004-08-20 09:20:05 +0000311endif
312
Reid Spencer3a561f52004-10-23 20:04:14 +0000313###############################################################################
314# Library Build Rules: Four ways to build a library
315###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000316
Brian Gaeke8abff792004-01-22 22:53:48 +0000317
Reid Spencer3a561f52004-10-23 20:04:14 +0000318# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000319ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000320
Chris Lattner2a548c52002-09-16 22:36:42 +0000321# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000322LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer4d71b662004-10-22 21:01:56 +0000323LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
324LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
325LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
326LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000327
Reid Spencer3a561f52004-10-23 20:04:14 +0000328#---------------------------------------------------------
329# Shared Library Targets:
330# If the user asked for a shared library to be built
331# with the SHARED_LIBRARY variable, then we provide
332# targets for building them.
333#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000334ifdef SHARED_LIBRARY
335
Reid Spencer3a561f52004-10-23 20:04:14 +0000336all-local:: $(LIBNAME_LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000337
338$(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
339 @$(ECHO) Linking shared library $(notdir $@)
340 $(VERB) $(Link) -o $@ $(ObjectsLO)
341 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
Reid Spencer3a561f52004-10-23 20:04:14 +0000342
343clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000344ifneq ($(strip $(LIBNAME_LA)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000345 $(VERB) $(RM) -f $(LIBNAME_LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000346endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000347
Reid Spencere5487ba2004-10-24 07:53:21 +0000348DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
349install-local:: install-shared-library
Reid Spencer4d71b662004-10-22 21:01:56 +0000350
Reid Spencere5487ba2004-10-24 07:53:21 +0000351install-shared-library: $(DestSharedLib)
352
353$(DestSharedLib): $(LIBNAME_LA)
354 @$(ECHO) Installing shared library $(DestSharedLib)
355 $(VERB) $(MKDIR) $(libdir)
356 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
357 $(VERB) $(LIBTOOL) --finish $(libdir)
358
359uninstall-local:: uninstall-shared-library
360
361uninstall-shared-library:
362 @$(ECHO) Uninstalling shared library $(DestSharedLib)
363 $(VERB) $(RM) -f $(DestSharedLib)
364
Reid Spencer4d71b662004-10-22 21:01:56 +0000365endif
366
Reid Spencer3a561f52004-10-23 20:04:14 +0000367#---------------------------------------------------------
368# Bytecode Library Targets:
369# If the user asked for a bytecode library to be built
370# with the BYTECODE_LIBRARY variable, then we provide
371# targets for building them.
372#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000373ifdef BYTECODE_LIBRARY
374
375ifdef EXPORTED_SYMBOL_LIST
376 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
377else
378 ifdef EXPORTED_SYMBOL_FILE
379 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
380 else
381 BCLinkLib += -Xlinker -disable-internalize
382 endif
383endif
384
Reid Spencer3a561f52004-10-23 20:04:14 +0000385all-local:: $(LIBNAME_BC)
Reid Spencer4d71b662004-10-22 21:01:56 +0000386
387$(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
388 @$(ECHO) Linking bytecode library $(notdir $@)
389 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
390
Reid Spencer3a561f52004-10-23 20:04:14 +0000391clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000392ifneq ($(strip $(LIBNAME_BC)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000393 $(VERB) $(RM) -f $(LIBNAME_BC)
Reid Spencere5487ba2004-10-24 07:53:21 +0000394endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000395
Reid Spencere5487ba2004-10-24 07:53:21 +0000396DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
397install-local:: install-bytecode-library
Chris Lattner481cc7c2003-08-15 02:18:35 +0000398
Reid Spencere5487ba2004-10-24 07:53:21 +0000399install-bytecode-library: $(DestBytecodeLib)
400
401$(DestBytecodeLib): $(LIBNAME_BC) $(bytecode_libdir)
402 @$(ECHO) Installing bytecode library $(DestBytecodeLib)
403 $(VERB) $(INSTALL) $< $@
404
405uninstall-local:: uninstall-bytecode-library
406
407uninstall-bytecode-library:
408 @$(ECHO) Uninstalling bytecode library $(DestBytecodeLib)
409 $(VERB) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000410
411endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000412
Chris Lattner760da062003-03-14 20:25:22 +0000413# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000414ifndef DONT_BUILD_RELINKED
Reid Spencer3a561f52004-10-23 20:04:14 +0000415all-local:: $(LIBNAME_O)
Reid Spencer4d71b662004-10-22 21:01:56 +0000416
417$(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencer3a561f52004-10-23 20:04:14 +0000418 @$(ECHO) Linking object library $(notdir $@)
Reid Spencer4d71b662004-10-22 21:01:56 +0000419 $(VERB) $(Relink) -o $@ $(ObjectsO)
420
Reid Spencer3a561f52004-10-23 20:04:14 +0000421clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000422ifneq ($(strip $(LIBNAME_O)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000423 $(VERB) $(RM) -f $(LIBNAME_O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000424endif
425
426DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
427
428install-local:: install-relinked-library
429
430install-relinked-library: $(DestRelinkedLib)
431
432$(DestRelinkedLib): $(LIBNAME_O)
433 @$(ECHO) Installing object library $(DestRelinkedLib)
434 $(VERB) $(MKDIR) $(libdir)
435 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
436
437uninstall-local:: uninstall-relinked-library
438
439uninstall-relinked-library:
440 @$(ECHO) Uninstalling object library $(DestRelinkedLib)
441 $(VERB) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000442
Chris Lattnere62dbe92002-07-23 17:56:16 +0000443endif
Chris Lattner760da062003-03-14 20:25:22 +0000444
445# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000446ifdef BUILD_ARCHIVE
Reid Spencer3a561f52004-10-23 20:04:14 +0000447all-local:: $(LIBNAME_A)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000448
Reid Spencer4d71b662004-10-22 21:01:56 +0000449$(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencer3a561f52004-10-23 20:04:14 +0000450 @$(ECHO) Building archive library $(notdir $@)
Reid Spencer37130d22004-10-04 07:05:07 +0000451 $(VERB)$(RM) -f $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000452 $(VERB) $(Archive) $@ $(ObjectsO)
453 $(VERB) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000454
Reid Spencer3a561f52004-10-23 20:04:14 +0000455clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000456ifneq ($(strip $(LIBNAME_A)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000457 $(VERB) $(RM) -f $(LIBNAME_A)
Chris Lattner00950542001-06-06 20:29:01 +0000458endif
459
Reid Spencere5487ba2004-10-24 07:53:21 +0000460DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
461
462install-local:: install-archive-library
463
464install-archive-library: $(DestArchiveLib)
465
466$(DestArchiveLib): $(LIBNAME_A)
467 @$(ECHO) Installing archive library $(DestArchiveLib)
468 $(VERB) $(MKDIR) $(libdir)
469 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
470
471uninstall-local:: install-archive-library
472
473uninstall-archive-library:
474 @$(ECHO) Uninstalling archive library $(DestArchiveLib)
475 $(VERB) $(RM) -f $(DestArchiveLib)
476
477endif
478
479# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000480endif
481
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000482#------------------------------------------------------------------------
483# Handle the TOOLNAME option - used when building tool executables...
484#------------------------------------------------------------------------
485#
486# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000487# libraries (and the order of the libs) that should be linked to the
488# tool. USEDLIBS should contain a list of library names (some with .a extension)
489# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000490#
491ifdef TOOLNAME
492
Reid Spencer4d71b662004-10-22 21:01:56 +0000493# TOOLLINKOPTSB to pass options to the linker like library search path etc
494# Note that this is different from TOOLLINKOPTS, these options
495# are passed to the linker *before* the USEDLIBS options are passed.
496# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
497ifdef TOOLLINKOPTSB
498Link += $(TOOLLINKOPTSB)
Reid Spencer37130d22004-10-04 07:05:07 +0000499endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000500
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000501# TOOLEXENAME* - These compute the output filenames to generate...
Reid Spencer4d71b662004-10-22 21:01:56 +0000502TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000503
504# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Reid Spencer4d71b662004-10-22 21:01:56 +0000505PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
506PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
507LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
508LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000509
Reid Spencer4d71b662004-10-22 21:01:56 +0000510PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
511LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
512PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
513LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000514
Reid Spencer4d71b662004-10-22 21:01:56 +0000515LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
John Criswellfe785bd2004-09-16 14:11:25 +0000516
John Criswell7a73b802003-06-30 21:59:07 +0000517#
518# Libtool link options:
519# Ensure that all binaries have their symbols exported so that they can
520# by dlsym'ed.
521#
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000522
Reid Spencer4d71b662004-10-22 21:01:56 +0000523# Handle compression libraries automatically
524ifeq ($(HAVE_BZIP2),1)
525LIBS += -lbz2
526endif
527ifeq ($(HAVE_ZLIB),1)
528LIBS += -lz
529endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000530
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000531# Tell make that we need to rebuild subdirectories before we can link the tool.
532# This affects things like LLI which has library subdirectories.
Reid Spencer4d71b662004-10-22 21:01:56 +0000533$(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000534
Reid Spencer3a561f52004-10-23 20:04:14 +0000535all-local:: $(TOOLEXENAME)
John Criswell2a6530f2003-06-27 16:58:44 +0000536
Reid Spencer3a561f52004-10-23 20:04:14 +0000537clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000538ifneq ($(strip $(TOOLEXENAME)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000539 $(VERB) $(RM) -f $(TOOLEXENAME)
Reid Spencere5487ba2004-10-24 07:53:21 +0000540endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000541
Reid Spencer4d71b662004-10-22 21:01:56 +0000542$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
543 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
544 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
545 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000546
Reid Spencere5487ba2004-10-24 07:53:21 +0000547install-local:: install-tool
548
549DestTool = $(bindir)/$(TOOLNAME)
550
551install-tool: $(DestTool)
552
553$(DestTool): $(TOOLEXENAME)
554 @$(ECHO) Installing $(DestTool)
555 $(VERB) $(INSTALL) $(TOOLEXENAME) $(bindir)
556
557uninstall-local:: uninstall-tool
558
559uninstall-tool:
560 @$(ECHO) Uninstalling $(DestTool)
561 $(VERB) $(RM) -f $(DestTool)
562
Reid Spencer4d71b662004-10-22 21:01:56 +0000563endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000564
Reid Spencer4d71b662004-10-22 21:01:56 +0000565ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000566
Reid Spencer4d71b662004-10-22 21:01:56 +0000567# Create .lo files in the OBJDIR directory from the .cpp and .c files...
Reid Spencer3a561f52004-10-23 20:04:14 +0000568ifdef SHARED_LIBRARY
569
570$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000571 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000572 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
573 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
574 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
575
576$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
577 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
578 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
579 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
580 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
581
582else
Reid Spencer4d71b662004-10-22 21:01:56 +0000583
584$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
585 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000586 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
587 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
588 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000589
590$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
591 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000592 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
593 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
594 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
595
596endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000597
598# Create .bc files in the OBJDIR directory from .cpp and .c files...
599$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
600 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000601 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
602 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
603 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000604
605$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
606 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000607 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
608 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
609 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000610
611else
612
Reid Spencer3a561f52004-10-23 20:04:14 +0000613ifdef SHARED_LIBRARY
614
615$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000616 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000617 $(LTCompile.CXX) $< -o $@
618
619$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
620 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
621 $(LTCompile.C) $< -o $@
622
623else
Reid Spencer4d71b662004-10-22 21:01:56 +0000624
625$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
626 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000627 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000628
629$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
630 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000631 $(Compile.C) $< -o $@
632endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000633
634# Create .bc files in the OBJDIR directory from .cpp and .c files...
635$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
636 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
637 $(BCCompileCPP) $< -o $@
638
639$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
640 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
641 $(BCCompileC) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000642
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000643endif
644
Reid Spencer4d71b662004-10-22 21:01:56 +0000645$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
646 @$(ECHO) "Compiling $*.ll To Bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000647 $(VERB) $(LLVMAS) $< -f -o $@
648
Reid Spencer4d71b662004-10-22 21:01:56 +0000649ifdef TARGET
650
Reid Spencerc64b2b32004-10-23 08:19:37 +0000651TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
Reid Spencer4d71b662004-10-22 21:01:56 +0000652
653$(BUILT_SOURCES): $(TDFILES)
654
655%GenRegisterNames.inc : %.td
656 @echo "Building $(<F) register names with tblgen"
657 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
658
659%GenRegisterInfo.h.inc : %.td
660 @echo "Building $(<F) register information header with tblgen"
661 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
662
663%GenRegisterInfo.inc : %.td
664 @echo "Building $(<F) register info implementation with tblgen"
665 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
666
667%GenInstrNames.inc : %.td
668 @echo "Building $(<F) instruction names with tblgen"
669 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
670
671%GenInstrInfo.inc : %.td
672 @echo "Building $(<F) instruction information with tblgen"
673 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
674
675%GenAsmWriter.inc : %.td
676 @echo "Building $(<F) assembly writer with tblgen"
677 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
678
679%GenATTAsmWriter.inc : %.td
680 @echo "Building $(<F) AT&T assembly writer with tblgen"
681 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
682
683%GenIntelAsmWriter.inc : %.td
684 @echo "Building $(<F) Intel assembly writer with tblgen"
685 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
686
687%GenInstrSelector.inc: %.td
688 @echo "Building $(<F) instruction selector with tblgen"
689 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
690
691%GenCodeEmitter.inc:: %.td
692 @echo "Building $(<F) code emitter with tblgen"
693 $(VERB) $(TableGen) -gen-emitter -o $@ $<
694
Reid Spencer3a561f52004-10-23 20:04:14 +0000695clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000696 $(VERB) rm -f *.inc
697
698endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000699
Chris Lattnere8996782003-01-16 22:44:19 +0000700#
701# Rules for building lex/yacc files
702#
Reid Spencer3a561f52004-10-23 20:04:14 +0000703LEX_FILES = $(filter %.l, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000704LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
Reid Spencer3a561f52004-10-23 20:04:14 +0000705YACC_FILES = $(filter %.y, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000706YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
707.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
708
Chris Lattner00950542001-06-06 20:29:01 +0000709# Create a .cpp source file from a flex input file... this uses sed to cut down
710# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000711#
712# The last line is a gross hack to work around flex aparently not being able to
713# resize the buffer on a large token input. Currently, for uninitialized string
714# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000715# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000716#
Chris Lattner00950542001-06-06 20:29:01 +0000717%.cpp: %.l
Reid Spencer4d71b662004-10-22 21:01:56 +0000718 @$(ECHO) Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000719 $(VERB) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000720 $(SED) '/^find_rule/d' | \
721 $(SED) 's/void yyunput/inline void yyunput/' | \
722 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
723 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
724 > $@.tmp
725 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000726 @# remove the output of flex if it didn't get moved over...
727 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000728
729# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000730%.c: %.y # Cancel built-in rules for yacc
731%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000732%.cpp %.h : %.y
Reid Spencer4d71b662004-10-22 21:01:56 +0000733 @$(ECHO) "Bisoning $*.y"
John Criswell410d1b52003-09-09 20:57:03 +0000734 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000735 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
736 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000737 @# If the files were not updated, don't leave them lying around...
738 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000739
740# To create the directories...
741%/.dir:
Reid Spencer4d71b662004-10-22 21:01:56 +0000742 $(VERB) $(MKDIR) $* > /dev/null
John Criswell7a73b802003-06-30 21:59:07 +0000743 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000744
Reid Spencer4d71b662004-10-22 21:01:56 +0000745.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
746.PRECIOUS: $(LLVMTOOLDIR)/.dir
747
Chris Lattner30440c62003-01-16 21:06:18 +0000748# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000749ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000750%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000751 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000752else
753%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000754 $(ECHO) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000755endif
Chris Lattner30440c62003-01-16 21:06:18 +0000756
John Criswell7f336952003-09-06 14:44:17 +0000757#
758# This rules ensures that header files that are removed still have a rule for
759# which they can be "generated." This allows make to ignore them and
760# reproduce the dependency lists.
761#
John Criswell4b6e5d12003-09-18 18:37:08 +0000762%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000763
Chris Lattner172b6482002-09-22 02:47:15 +0000764# 'make clean' nukes the tree
Reid Spencer3a561f52004-10-23 20:04:14 +0000765clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000766ifneq ($(strip $(OBJDIR)),)
Reid Spencer83cbcb92004-10-24 02:26:09 +0000767 $(VERB) $(RM) -rf $(OBJDIR)
Reid Spencere5487ba2004-10-24 07:53:21 +0000768endif
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000769 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
770ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
771 $(VERB) $(RM) -f *$(SHLIBEXT)
772endif
Reid Spencere5487ba2004-10-24 07:53:21 +0000773ifneq ($(strip $(LEX_OUTPUT)),)
774 $(VERB) $(RM) -f $(LEX_OUTPUT)
775endif
776ifneq ($(strip $(YACC_OUTPUT)),)
777 $(VERB) $(RM) -f $(YACC_OUTPUT)
778endif
John Criswell7a73b802003-06-30 21:59:07 +0000779
Reid Spencer3a561f52004-10-23 20:04:14 +0000780###############################################################################
781# DEPENDENCIES: Include the dependency files if we should
782###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +0000783ifndef DISABLE_AUTO_DEPENDENCIES
784
Reid Spencer3a561f52004-10-23 20:04:14 +0000785# If its not one of the cleaning targets
786ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000787
Reid Spencer3a561f52004-10-23 20:04:14 +0000788# Get the list of dependency files
789DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
790DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000791
Reid Spencer3a561f52004-10-23 20:04:14 +0000792-include /dev/null $(DependFiles)
793
John Criswelld741bcf2003-08-12 18:51:51 +0000794endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000795
Chris Lattner33ad24a2003-08-22 14:10:16 +0000796endif # ifndef DISABLE_AUTO_DEPENDENCIES
Reid Spencer4d71b662004-10-22 21:01:56 +0000797
Reid Spencer3a561f52004-10-23 20:04:14 +0000798################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000799# PRECONDITIONS - that which must be built/checked first
Reid Spencer3a561f52004-10-23 20:04:14 +0000800################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000801
802OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
803SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
804CONFIGURE := $(LLVM_SRC_ROOT)/configure
805CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
806MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
807MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
808
809#------------------------------------------------------------------------
810# List of the preconditions
Reid Spencer3a561f52004-10-23 20:04:14 +0000811#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000812preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
813
Reid Spencer3a561f52004-10-23 20:04:14 +0000814all all-local check check-local dist dist-check install:: $(BUILT_SOURCES)
Reid Spencer4d71b662004-10-22 21:01:56 +0000815
Reid Spencer3a561f52004-10-23 20:04:14 +0000816clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000817ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000818 $(VERB) $(RM) -f $(BUILT_SOURCES)
Reid Spencere5487ba2004-10-24 07:53:21 +0000819endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000820
821#------------------------------------------------------------------------
822# Make sure we're not using a stale configuration
Reid Spencer3a561f52004-10-23 20:04:14 +0000823#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000824.PRECIOUS: $(CONFIG_STATUS)
825$(CONFIG_STATUS): $(CONFIGURE)
826 @$(ECHO) Reconfiguring with $@
827 $(VERB) $(CONFIG_STATUS) --recheck
828
829#------------------------------------------------------------------------
830# Make sure the configuration makefile is up to date
Reid Spencer3a561f52004-10-23 20:04:14 +0000831#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000832$(MAKE_CONFIG): $(MAKE_CONFIG_IN)
833 @$(ECHO) Regenerating $@
834 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
Reid Spencerc64b2b32004-10-23 08:19:37 +0000835 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000836 @exit 0;
837
Reid Spencere5487ba2004-10-24 07:53:21 +0000838
Reid Spencer4d71b662004-10-22 21:01:56 +0000839#------------------------------------------------------------------------
840# If the Makefile in the source tree has been updated, copy it over into the
Reid Spencer3a561f52004-10-23 20:04:14 +0000841# build tree. But, only do this if the source and object makefiles differ
842#------------------------------------------------------------------------
Reid Spencere53e3972004-10-22 23:06:30 +0000843ifneq ($(OBJMKFILE),$(SRCMKFILE))
Reid Spencer4d71b662004-10-22 21:01:56 +0000844.PRECIOUS: $(OBJMKFILE)
845$(OBJMKFILE): $(SRCMKFILE)
846 @$(ECHO) "Updating Makefile from : $(dir $<)"
847 $(VERB) $(MKDIR) $(@D)
848 $(VERB) cp -f $< $@
Reid Spencerc64b2b32004-10-23 08:19:37 +0000849 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000850 @exit 0;
Reid Spencere53e3972004-10-22 23:06:30 +0000851endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000852
853###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +0000854# TOP LEVEL - targets only to apply at the top level directory
855###############################################################################
856
857ifeq ($(LEVEL),.)
858
859#------------------------------------------------------------------------
860# Handle construction of a distribution
861dist:: preconditions
862 @$(ECHO) Target dist is not implemented yet
863
864dist-check:: preconditions dist
865 @$(ECHO) Target dist-check is not implemented yet
866
867dist-clean:: preconditions
868 @$(ECHO) Target dist-clean is not implemented yet
869
870#------------------------------------------------------------------------
871# Install support for project's include files:
872#------------------------------------------------------------------------
873install-local::
874 @$(ECHO) Installing include files
875 $(VERB) $(MKDIR) $(includedir)
876 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
877 cd $(BUILD_SRC_ROOT)/include && \
878 find . -path '*/Internal' -prune -o '(' -type f \
879 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
880 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
881 fi
882
883uninstall-local::
884 @$(ECHO) Uninstalling include files
885 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
886 cd $(BUILD_SRC_ROOT)/include && \
887 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
888 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
889 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
890 fi
891
892#------------------------------------------------------------------------
893# Build tags database for Emacs/Xemacs:
894#------------------------------------------------------------------------
895TAGS: tags
896
897tags::
898 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
899
900dist-clean:: clean
901 $(VERB) $(RM) -rf $(LEVEL)/Makefile.config \
902 $(LEVEL)/include/llvm/Config/config.h \
903 $(LEVEL)/autoconf/autom4te.cache \
904 $(LEVEL)/config.log \
905 $(LEVEL)/TAGS
906endif
907
908###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000909# MISCELLANEOUS - utility targets
910###############################################################################
911
912#------------------------------------------------------------------------
913# Print out the directories used for building
Reid Spencer3a561f52004-10-23 20:04:14 +0000914printvars::
Reid Spencer4d71b662004-10-22 21:01:56 +0000915 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
916 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
917 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
918 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
919 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
920 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
921 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
922 @$(ECHO) "OBJDIR: " $(OBJDIR)
923 @$(ECHO) "LIBDIR: " $(LIBDIR)
924 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
925 @$(ECHO) "TDFILES:" '$(TDFILES)'
Reid Spencer3a561f52004-10-23 20:04:14 +0000926 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
927 @$(ECHO) "Compile.C: " '$(Compile.C)'
Reid Spencere5487ba2004-10-24 07:53:21 +0000928
929# This frivolous target provided for Resistor who requested that the makefiles
930# be hardened and that he get a "pony" after the makefiles (accidentally)
931# deleted his unix kernel.
932pony::
933 @wget -q \
934 http://search.cpan.org/src/ASAVIGE/Acme-EyeDrops-1.40/lib/Acme/EyeDrops/pony2.eye \
935 -O /tmp/resistor.pony
936 @cat /tmp/resistor.pony