blob: 009db2b383433880dfe91eaf24bf7ca91bbca444 [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
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000471uninstall-local:: uninstall-archive-library
Reid Spencere5487ba2004-10-24 07:53:21 +0000472
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
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000482###############################################################################
483# Tool Build Rules: Build executable tool based on TOOLNAME option
484###############################################################################
485
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000486ifdef TOOLNAME
487
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000488#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000489# TOOLLINKOPTSB to pass options to the linker like library search path etc
490# Note that this is different from TOOLLINKOPTS, these options
491# are passed to the linker *before* the USEDLIBS options are passed.
492# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000493#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000494ifdef TOOLLINKOPTSB
495Link += $(TOOLLINKOPTSB)
Reid Spencer37130d22004-10-04 07:05:07 +0000496endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000497
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000498# TOOLEXENAME - This is the output filenames to generate
Reid Spencer4d71b662004-10-22 21:01:56 +0000499TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000500
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000501# LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
Reid Spencer4d71b662004-10-22 21:01:56 +0000502PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
503PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
504LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
505LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000506
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000507# USED_LIBS/LIBS_PATHS - Compute dependent library file paths
Reid Spencer4d71b662004-10-22 21:01:56 +0000508PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
509LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
510PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
511LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000512
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000513# Concatenate all the optoins
Reid Spencer4d71b662004-10-22 21:01:56 +0000514LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
John Criswellfe785bd2004-09-16 14:11:25 +0000515
Reid Spencer4d71b662004-10-22 21:01:56 +0000516# Handle compression libraries automatically
517ifeq ($(HAVE_BZIP2),1)
518LIBS += -lbz2
519endif
520ifeq ($(HAVE_ZLIB),1)
521LIBS += -lz
522endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000523
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000524# Tell make that we need to rebuild subdirectories before we can link the tool.
525# This affects things like LLI which has library subdirectories.
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000526$(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000527
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000528all-local:: $(TOOLEXENAME)
John Criswell2a6530f2003-06-27 16:58:44 +0000529
Reid Spencer3a561f52004-10-23 20:04:14 +0000530clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000531ifneq ($(strip $(TOOLEXENAME)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000532 $(VERB) $(RM) -f $(TOOLEXENAME)
Reid Spencere5487ba2004-10-24 07:53:21 +0000533endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000534
Reid Spencer4d71b662004-10-22 21:01:56 +0000535$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
536 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
537 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
538 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000539
Reid Spencere5487ba2004-10-24 07:53:21 +0000540install-local:: install-tool
541
542DestTool = $(bindir)/$(TOOLNAME)
543
544install-tool: $(DestTool)
545
546$(DestTool): $(TOOLEXENAME)
547 @$(ECHO) Installing $(DestTool)
548 $(VERB) $(INSTALL) $(TOOLEXENAME) $(bindir)
549
550uninstall-local:: uninstall-tool
551
552uninstall-tool:
553 @$(ECHO) Uninstalling $(DestTool)
554 $(VERB) $(RM) -f $(DestTool)
555
Reid Spencer4d71b662004-10-22 21:01:56 +0000556endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000557
Reid Spencer4d71b662004-10-22 21:01:56 +0000558ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000559
Reid Spencer4d71b662004-10-22 21:01:56 +0000560# Create .lo files in the OBJDIR directory from the .cpp and .c files...
Reid Spencer3a561f52004-10-23 20:04:14 +0000561ifdef SHARED_LIBRARY
562
563$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000564 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000565 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
566 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
567 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
568
569$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
570 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
571 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
572 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
573 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
574
575else
Reid Spencer4d71b662004-10-22 21:01:56 +0000576
577$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
578 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000579 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
580 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
581 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000582
583$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
584 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000585 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
586 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
587 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
588
589endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000590
591# Create .bc files in the OBJDIR directory from .cpp and .c files...
592$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
593 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000594 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
595 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
596 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000597
598$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
599 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
Reid Spencer3a561f52004-10-23 20:04:14 +0000600 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
601 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
602 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000603
604else
605
Reid Spencer3a561f52004-10-23 20:04:14 +0000606ifdef SHARED_LIBRARY
607
608$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencer4d71b662004-10-22 21:01:56 +0000609 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
Reid Spencer3a561f52004-10-23 20:04:14 +0000610 $(LTCompile.CXX) $< -o $@
611
612$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
613 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
614 $(LTCompile.C) $< -o $@
615
616else
Reid Spencer4d71b662004-10-22 21:01:56 +0000617
618$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
619 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000620 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000621
622$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
623 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
Reid Spencer3a561f52004-10-23 20:04:14 +0000624 $(Compile.C) $< -o $@
625endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000626
627# Create .bc files in the OBJDIR directory from .cpp and .c files...
628$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
629 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
630 $(BCCompileCPP) $< -o $@
631
632$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
633 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
634 $(BCCompileC) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000635
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000636endif
637
Reid Spencer4d71b662004-10-22 21:01:56 +0000638$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
639 @$(ECHO) "Compiling $*.ll To Bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000640 $(VERB) $(LLVMAS) $< -f -o $@
641
Reid Spencer4d71b662004-10-22 21:01:56 +0000642ifdef TARGET
643
Reid Spencerc64b2b32004-10-23 08:19:37 +0000644TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
Reid Spencer4d71b662004-10-22 21:01:56 +0000645
646$(BUILT_SOURCES): $(TDFILES)
647
648%GenRegisterNames.inc : %.td
649 @echo "Building $(<F) register names with tblgen"
650 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
651
652%GenRegisterInfo.h.inc : %.td
653 @echo "Building $(<F) register information header with tblgen"
654 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
655
656%GenRegisterInfo.inc : %.td
657 @echo "Building $(<F) register info implementation with tblgen"
658 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
659
660%GenInstrNames.inc : %.td
661 @echo "Building $(<F) instruction names with tblgen"
662 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
663
664%GenInstrInfo.inc : %.td
665 @echo "Building $(<F) instruction information with tblgen"
666 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
667
668%GenAsmWriter.inc : %.td
669 @echo "Building $(<F) assembly writer with tblgen"
670 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
671
672%GenATTAsmWriter.inc : %.td
673 @echo "Building $(<F) AT&T assembly writer with tblgen"
674 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
675
676%GenIntelAsmWriter.inc : %.td
677 @echo "Building $(<F) Intel assembly writer with tblgen"
678 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
679
680%GenInstrSelector.inc: %.td
681 @echo "Building $(<F) instruction selector with tblgen"
682 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
683
684%GenCodeEmitter.inc:: %.td
685 @echo "Building $(<F) code emitter with tblgen"
686 $(VERB) $(TableGen) -gen-emitter -o $@ $<
687
Reid Spencer3a561f52004-10-23 20:04:14 +0000688clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000689 $(VERB) rm -f *.inc
690
691endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000692
Chris Lattnere8996782003-01-16 22:44:19 +0000693#
694# Rules for building lex/yacc files
695#
Reid Spencer3a561f52004-10-23 20:04:14 +0000696LEX_FILES = $(filter %.l, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000697LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
Reid Spencer3a561f52004-10-23 20:04:14 +0000698YACC_FILES = $(filter %.y, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000699YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
700.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
701
Chris Lattner00950542001-06-06 20:29:01 +0000702# Create a .cpp source file from a flex input file... this uses sed to cut down
703# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000704#
705# The last line is a gross hack to work around flex aparently not being able to
706# resize the buffer on a large token input. Currently, for uninitialized string
707# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000708# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000709#
Chris Lattner00950542001-06-06 20:29:01 +0000710%.cpp: %.l
Reid Spencer4d71b662004-10-22 21:01:56 +0000711 @$(ECHO) Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000712 $(VERB) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000713 $(SED) '/^find_rule/d' | \
714 $(SED) 's/void yyunput/inline void yyunput/' | \
715 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
716 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
717 > $@.tmp
718 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000719 @# remove the output of flex if it didn't get moved over...
720 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000721
722# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000723%.c: %.y # Cancel built-in rules for yacc
724%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000725%.cpp %.h : %.y
Reid Spencer4d71b662004-10-22 21:01:56 +0000726 @$(ECHO) "Bisoning $*.y"
John Criswell410d1b52003-09-09 20:57:03 +0000727 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000728 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
729 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000730 @# If the files were not updated, don't leave them lying around...
731 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000732
733# To create the directories...
734%/.dir:
Reid Spencer4d71b662004-10-22 21:01:56 +0000735 $(VERB) $(MKDIR) $* > /dev/null
John Criswell7a73b802003-06-30 21:59:07 +0000736 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000737
Reid Spencer4d71b662004-10-22 21:01:56 +0000738.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
739.PRECIOUS: $(LLVMTOOLDIR)/.dir
740
Chris Lattner30440c62003-01-16 21:06:18 +0000741# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000742ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000743%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000744 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000745else
746%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000747 $(ECHO) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000748endif
Chris Lattner30440c62003-01-16 21:06:18 +0000749
John Criswell7f336952003-09-06 14:44:17 +0000750#
751# This rules ensures that header files that are removed still have a rule for
752# which they can be "generated." This allows make to ignore them and
753# reproduce the dependency lists.
754#
John Criswell4b6e5d12003-09-18 18:37:08 +0000755%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000756
Chris Lattner172b6482002-09-22 02:47:15 +0000757# 'make clean' nukes the tree
Reid Spencer3a561f52004-10-23 20:04:14 +0000758clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000759ifneq ($(strip $(OBJDIR)),)
Reid Spencer83cbcb92004-10-24 02:26:09 +0000760 $(VERB) $(RM) -rf $(OBJDIR)
Reid Spencere5487ba2004-10-24 07:53:21 +0000761endif
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000762 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
763ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
764 $(VERB) $(RM) -f *$(SHLIBEXT)
765endif
Reid Spencere5487ba2004-10-24 07:53:21 +0000766ifneq ($(strip $(LEX_OUTPUT)),)
767 $(VERB) $(RM) -f $(LEX_OUTPUT)
768endif
769ifneq ($(strip $(YACC_OUTPUT)),)
770 $(VERB) $(RM) -f $(YACC_OUTPUT)
771endif
John Criswell7a73b802003-06-30 21:59:07 +0000772
Reid Spencer3a561f52004-10-23 20:04:14 +0000773###############################################################################
774# DEPENDENCIES: Include the dependency files if we should
775###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +0000776ifndef DISABLE_AUTO_DEPENDENCIES
777
Reid Spencer3a561f52004-10-23 20:04:14 +0000778# If its not one of the cleaning targets
779ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000780
Reid Spencer3a561f52004-10-23 20:04:14 +0000781# Get the list of dependency files
782DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
783DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000784
Reid Spencer3a561f52004-10-23 20:04:14 +0000785-include /dev/null $(DependFiles)
786
John Criswelld741bcf2003-08-12 18:51:51 +0000787endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000788
Chris Lattner33ad24a2003-08-22 14:10:16 +0000789endif # ifndef DISABLE_AUTO_DEPENDENCIES
Reid Spencer4d71b662004-10-22 21:01:56 +0000790
Reid Spencer3a561f52004-10-23 20:04:14 +0000791################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000792# PRECONDITIONS - that which must be built/checked first
Reid Spencer3a561f52004-10-23 20:04:14 +0000793################################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000794
795OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
796SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
797CONFIGURE := $(LLVM_SRC_ROOT)/configure
798CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
799MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
800MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
801
802#------------------------------------------------------------------------
803# List of the preconditions
Reid Spencer3a561f52004-10-23 20:04:14 +0000804#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000805preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
806
Reid Spencer3a561f52004-10-23 20:04:14 +0000807all all-local check check-local dist dist-check install:: $(BUILT_SOURCES)
Reid Spencer4d71b662004-10-22 21:01:56 +0000808
Reid Spencer3a561f52004-10-23 20:04:14 +0000809clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000810ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000811 $(VERB) $(RM) -f $(BUILT_SOURCES)
Reid Spencere5487ba2004-10-24 07:53:21 +0000812endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000813
814#------------------------------------------------------------------------
815# Make sure we're not using a stale configuration
Reid Spencer3a561f52004-10-23 20:04:14 +0000816#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000817.PRECIOUS: $(CONFIG_STATUS)
818$(CONFIG_STATUS): $(CONFIGURE)
819 @$(ECHO) Reconfiguring with $@
820 $(VERB) $(CONFIG_STATUS) --recheck
821
822#------------------------------------------------------------------------
823# Make sure the configuration makefile is up to date
Reid Spencer3a561f52004-10-23 20:04:14 +0000824#------------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000825$(MAKE_CONFIG): $(MAKE_CONFIG_IN)
826 @$(ECHO) Regenerating $@
827 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
Reid Spencerc64b2b32004-10-23 08:19:37 +0000828 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000829 @exit 0;
830
Reid Spencere5487ba2004-10-24 07:53:21 +0000831
Reid Spencer4d71b662004-10-22 21:01:56 +0000832#------------------------------------------------------------------------
833# If the Makefile in the source tree has been updated, copy it over into the
Reid Spencer3a561f52004-10-23 20:04:14 +0000834# build tree. But, only do this if the source and object makefiles differ
835#------------------------------------------------------------------------
Reid Spencere53e3972004-10-22 23:06:30 +0000836ifneq ($(OBJMKFILE),$(SRCMKFILE))
Reid Spencer4d71b662004-10-22 21:01:56 +0000837.PRECIOUS: $(OBJMKFILE)
838$(OBJMKFILE): $(SRCMKFILE)
839 @$(ECHO) "Updating Makefile from : $(dir $<)"
840 $(VERB) $(MKDIR) $(@D)
841 $(VERB) cp -f $< $@
Reid Spencerc64b2b32004-10-23 08:19:37 +0000842 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000843 @exit 0;
Reid Spencere53e3972004-10-22 23:06:30 +0000844endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000845
846###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +0000847# TOP LEVEL - targets only to apply at the top level directory
848###############################################################################
849
850ifeq ($(LEVEL),.)
851
852#------------------------------------------------------------------------
853# Handle construction of a distribution
854dist:: preconditions
855 @$(ECHO) Target dist is not implemented yet
856
857dist-check:: preconditions dist
858 @$(ECHO) Target dist-check is not implemented yet
859
860dist-clean:: preconditions
861 @$(ECHO) Target dist-clean is not implemented yet
862
863#------------------------------------------------------------------------
864# Install support for project's include files:
865#------------------------------------------------------------------------
866install-local::
867 @$(ECHO) Installing include files
868 $(VERB) $(MKDIR) $(includedir)
869 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
870 cd $(BUILD_SRC_ROOT)/include && \
871 find . -path '*/Internal' -prune -o '(' -type f \
872 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
873 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
874 fi
875
876uninstall-local::
877 @$(ECHO) Uninstalling include files
878 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
879 cd $(BUILD_SRC_ROOT)/include && \
880 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
881 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
882 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
883 fi
884
885#------------------------------------------------------------------------
886# Build tags database for Emacs/Xemacs:
887#------------------------------------------------------------------------
888TAGS: tags
889
890tags::
891 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
892
893dist-clean:: clean
894 $(VERB) $(RM) -rf $(LEVEL)/Makefile.config \
895 $(LEVEL)/include/llvm/Config/config.h \
896 $(LEVEL)/autoconf/autom4te.cache \
897 $(LEVEL)/config.log \
898 $(LEVEL)/TAGS
899endif
900
901###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +0000902# MISCELLANEOUS - utility targets
903###############################################################################
904
905#------------------------------------------------------------------------
906# Print out the directories used for building
Reid Spencer3a561f52004-10-23 20:04:14 +0000907printvars::
Reid Spencer4d71b662004-10-22 21:01:56 +0000908 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
909 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
910 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
911 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
912 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
913 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
914 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
915 @$(ECHO) "OBJDIR: " $(OBJDIR)
916 @$(ECHO) "LIBDIR: " $(LIBDIR)
917 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
918 @$(ECHO) "TDFILES:" '$(TDFILES)'
Reid Spencer3a561f52004-10-23 20:04:14 +0000919 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
920 @$(ECHO) "Compile.C: " '$(Compile.C)'
Reid Spencere5487ba2004-10-24 07:53:21 +0000921
922# This frivolous target provided for Resistor who requested that the makefiles
923# be hardened and that he get a "pony" after the makefiles (accidentally)
924# deleted his unix kernel.
925pony::
926 @wget -q \
927 http://search.cpan.org/src/ASAVIGE/Acme-EyeDrops-1.40/lib/Acme/EyeDrops/pony2.eye \
928 -O /tmp/resistor.pony
929 @cat /tmp/resistor.pony