blob: cd82e139582a8b4e0b2f366e89a3f5177270db8c [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#
10# This file is included by all of the LLVM makefiles. This file defines common
Misha Brukman36bc6422003-08-21 22:02:18 +000011# rules to do things like compile a .cpp file or generate dependency info.
12# These are platform dependent, so this is the file used to specify these
13# system dependent operations.
Chris Lattner00950542001-06-06 20:29:01 +000014#
Vikram S. Advec214e712002-08-29 23:28:46 +000015# The following functionality can be set by setting incoming variables.
16# The variable $(LEVEL) *must* be set:
Chris Lattner00950542001-06-06 20:29:01 +000017#
18# 1. LEVEL - The level of the current subdirectory from the top of the
19# MagicStats view. This level should be expressed as a path, for
20# example, ../.. for two levels deep.
21#
22# 2. DIRS - A list of subdirectories to be built. Fake targets are set up
Chris Lattnera8abc222002-09-18 03:22:27 +000023# so that each of the targets "all", "install", and "clean" each build
24# the subdirectories before the local target. DIRS are guaranteed to be
25# built in order.
Chris Lattner00950542001-06-06 20:29:01 +000026#
Chris Lattnera8abc222002-09-18 03:22:27 +000027# 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
28# built in any order. All DIRS are built in order before PARALLEL_DIRS are
29# built, which are then built in any order.
30#
31# 4. Source - If specified, this sets the source code filenames. If this
Chris Lattner00950542001-06-06 20:29:01 +000032# is not set, it defaults to be all of the .cpp, .c, .y, and .l files
Chris Lattnere0010592001-10-18 01:48:09 +000033# in the current directory. Also, if you want to build files in addition
Reid Spencer4d71b662004-10-22 21:01:56 +000034# to the local files, you can use the BUILT_SOURCES variable
Chris Lattner694c5df2003-05-15 21:28:55 +000035#
John Criswell7a73b802003-06-30 21:59:07 +000036# 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
Dinakar Dhurjati584dd182003-05-29 21:49:00 +000037#
John Criswell7a73b802003-06-30 21:59:07 +000038# 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39# and usually the source code too (unless SourceDir is set).
40#
41# 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
42#
43# 10. BUILD_OBJ_DIR - The directory where object code should be placed.
44#
45# 11. BUILD_OBJ_ROOT - The root directory for where object code should be
46# placed.
47#
48# For building,
Chris Lattnere430a1e2003-08-21 22:23:49 +000049# LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
Chris Lattneraf06a082003-08-15 03:02:52 +000050#
Vikram S. Adved60aede2002-07-09 12:04:21 +000051#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000052
John Criswell2a6530f2003-06-27 16:58:44 +000053#
John Criswell7f336952003-09-06 14:44:17 +000054# Set the VPATH so that we can find source files.
John Criswell8bff5092003-06-11 13:55:44 +000055#
Reid Spencer4d71b662004-10-22 21:01:56 +000056VPATH=$(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +000057
John Criswell7a73b802003-06-30 21:59:07 +000058###########################################################################
59# Default Targets:
60# The following targets are the standard top level targets for
61# building.
62###########################################################################
Chris Lattner4bb13b82002-09-13 22:14:47 +000063
John Criswellbd082802003-10-07 14:16:44 +000064
Reid Spencer4d71b662004-10-22 21:01:56 +000065# Ensure all preconditions are met
66all:: preconditions
Chris Lattneredf1f232002-07-23 19:21:31 +000067
Reid Spencer4d71b662004-10-22 21:01:56 +000068# Make sure all the user-target rules are double colon rules
69all :: preconditions
70clean:: preconditions
71install :: preconditions
72uninstall :: preconditions
73check:: preconditions
74dist:: preconditions
75distcheck:: preconditions
76distclean:: preconditions
Chris Lattner95cc1b32003-08-14 21:10:25 +000077
John Criswell7a73b802003-06-30 21:59:07 +000078
John Criswell9621a2b2003-08-20 15:18:41 +000079###########################################################################
80# Suffixes and implicit rules:
81# Empty out the list of suffixes, generate a list that is only
82# used by this Makefile, and cancel useless implicit rules. This
83# will hopefully speed up compilation a little bit.
84###########################################################################
85.SUFFIXES:
86.SUFFIXES: .c .cpp .h .hpp .y .l
Brian Gaeked65ed3f2004-01-21 19:59:19 +000087.SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
John Criswell9621a2b2003-08-20 15:18:41 +000088.SUFFIXES: .ps .dot .d
89
John Criswell96914392003-07-16 20:26:06 +000090#
91# Mark all of these targets as phony. This will hopefully speed up builds
92# slightly since GNU Make will not try to find implicit rules for targets
93# which are marked as Phony.
94#
Reid Spencer4d71b662004-10-22 21:01:56 +000095ALL_TARGETS= all dynamic bytecodelib install-bytecode-library clean distclean install test bytecode prdirs
96.PHONY: $(ALL_TARGETS) preconditions
John Criswell96914392003-07-16 20:26:06 +000097
John Criswell7a73b802003-06-30 21:59:07 +000098###########################################################################
99# Miscellaneous paths and commands:
100# This section defines various configuration macros, such as where
101# to find burg, tblgen, and libtool.
102###########################################################################
103
Chris Lattner00950542001-06-06 20:29:01 +0000104#--------------------------------------------------------------------
Vikram S. Advec214e712002-08-29 23:28:46 +0000105# Variables derived from configuration options...
Chris Lattner00950542001-06-06 20:29:01 +0000106#--------------------------------------------------------------------
107
Chris Lattner760da062003-03-14 20:25:22 +0000108ifdef ENABLE_PROFILING
Chris Lattner760da062003-03-14 20:25:22 +0000109 CONFIGURATION := Profile
Reid Spencer4d71b662004-10-22 21:01:56 +0000110 CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
111 CFLAGS += -O3 -DNDEBUG -pg
112 LDFLAGS += -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000113else
114 ifdef ENABLE_OPTIMIZED
115 CONFIGURATION := Release
Reid Spencer4d71b662004-10-22 21:01:56 +0000116 CXXFLAGS += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
117 CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
118 LDFLAGS += -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000119 else
120 CONFIGURATION := Debug
Reid Spencer4d71b662004-10-22 21:01:56 +0000121 CXXFLAGS += -g -D_DEBUG
122 CFLAGS += -g -D_DEBUG
123 LDFLAGS += -g -D_DEBUG
124 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000125 endif
126endif
127
Reid Spencer4d71b662004-10-22 21:01:56 +0000128ARFLAGS := cru
129#------------------------------------------------------------------------------
130# Directory locations
131OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
132LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
133TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
134LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
135LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
John Criswell7a73b802003-06-30 21:59:07 +0000136
Reid Spencer4d71b662004-10-22 21:01:56 +0000137#------------------------------------------------------------------------------
138# Full Paths To Compiled Tools and Utilities
139LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
140LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
141BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
142TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
143GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
144LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
145LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000146
Reid Spencer4d71b662004-10-22 21:01:56 +0000147# Need a better way to compute this.
148LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000149
Reid Spencer4d71b662004-10-22 21:01:56 +0000150#------------------------------------------------------------------------------
151# Adjust to user's request
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000152
John Criswell82f4a5a2003-07-31 20:58:51 +0000153ifndef SHARED_LIBRARY
Reid Spencer4d71b662004-10-22 21:01:56 +0000154 LIBTOOL += --tag=disable-shared
155else
156 LDFLAGS += -rpath $(LIBDIR)
John Criswell82f4a5a2003-07-31 20:58:51 +0000157endif
158
159#
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000160# Verbosity levels
John Criswell7a73b802003-06-30 21:59:07 +0000161#
Chris Lattner760da062003-03-14 20:25:22 +0000162ifndef VERBOSE
Reid Spencer4d71b662004-10-22 21:01:56 +0000163 VERB := @
164 LIBTOOL += --silent
165 AR += >/dev/null 2>/dev/null
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000166endif
167
Vikram S. Advefeeae582002-09-18 11:55:13 +0000168# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000169ifndef KEEP_SYMBOLS
Reid Spencer4d71b662004-10-22 21:01:56 +0000170 STRIP = $(PLATFORMSTRIPOPTS)
171 STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000172endif
173
Reid Spencer4d71b662004-10-22 21:01:56 +0000174ifdef TOOLNAME
175 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
176endif
Chris Lattner00950542001-06-06 20:29:01 +0000177
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000178# TOOLLINKOPTSB to pass options to the linker like library search path etc
179# Note that this is different from TOOLLINKOPTS, these options
180# are passed to the linker *before* the USEDLIBS options are passed.
181# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
182ifdef TOOLLINKOPTSB
Reid Spencer4d71b662004-10-22 21:01:56 +0000183LDFLAGS += $(TOOLLINKOPTSB)
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000184endif
185
Reid Spencer4d71b662004-10-22 21:01:56 +0000186LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
John Criswell7a73b802003-06-30 21:59:07 +0000187
Reid Spencer4d71b662004-10-22 21:01:56 +0000188#------------------------------------------------------------------------------
189# Options To Invoke Tools
190
191CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
192
193CPPFLAGS += -I$(BUILD_OBJ_DIR) \
194 -I$(BUILD_SRC_DIR) \
195 -I$(BUILD_SRC_ROOT)/include \
196 -I$(BUILD_OBJ_ROOT)/include \
197 -I$(LLVM_OBJ_ROOT)/include \
198 -I$(LLVM_SRC_ROOT)/include \
199 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
200
201CXXCompile := $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
202LTCXXCompile := $(LIBTOOL) --tag=CXX --mode=compile $(CXXCompile)
203CCompile := $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
204LTCCompile := $(LIBTOOL) --mode=compile $(CCompile)
205BCCXXCompile := $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
206BCCCompile := $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
207Link := $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
208Relink := $(LIBTOOL) --tag=CXX --mode=link $(CXX)
209BCLinkLib := $(LLVMGCC) -shared -nostdlib
210Burg := $(BURG) -I $(BUILD_SRC_DIR)
211TableGen := $(TBLGEN) -I $(BUILD_SRC_DIR)
212Archive := $(AR) $(ARFLAGS)
213ifdef RANLIB
214Ranlib := $(RANLIB)
215else
216Ranlib := ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000217endif
218
Chris Lattner00950542001-06-06 20:29:01 +0000219#----------------------------------------------------------
Chris Lattner00950542001-06-06 20:29:01 +0000220# Source includes all of the cpp files, and objects are derived from the
221# source files...
Reid Spencer4d71b662004-10-22 21:01:56 +0000222# The local Makefile can list other Source files via BUILT_SOURCES = ...
Vikram S. Advec4bed342001-10-17 12:33:55 +0000223#
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000224ifndef Source
Reid Spencer4d71b662004-10-22 21:01:56 +0000225
226Source := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
227 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
228 $(BUILD_SRC_DIR)/*.l))
229endif
230
231ifdef BUILT_SOURCES
232Source += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000233endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000234
John Criswell82f4a5a2003-07-31 20:58:51 +0000235#
236# Libtool Objects
237#
John Criswell410d1b52003-09-09 20:57:03 +0000238Srcs := $(sort $(basename $(Source)))
Reid Spencer4d71b662004-10-22 21:01:56 +0000239ObjectsO := $(Srcs:%=$(OBJDIR)/%.o)
240ObjectsLO := $(Srcs:%=$(OBJDIR)/%.lo)
241ObjectsBC := $(Srcs:%=$(OBJDIR)/%.bc)
John Criswell82f4a5a2003-07-31 20:58:51 +0000242
Chris Lattner00950542001-06-06 20:29:01 +0000243#---------------------------------------------------------
Chris Lattnera8abc222002-09-18 03:22:27 +0000244# Handle the DIRS and PARALLEL_DIRS options
Chris Lattner00950542001-06-06 20:29:01 +0000245#---------------------------------------------------------
246
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000247ifdef DIRS
Reid Spencer4d71b662004-10-22 21:01:56 +0000248$(ALL_TARGETS)::
249 $(VERB) for dir in $(DIRS); do \
250 if [ ! -f $$dir/Makefile ]; then \
251 $(MKDIR) $$dir; \
252 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
253 fi; \
254 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000255 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000256endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000257
258# Handle PARALLEL_DIRS
259ifdef PARALLEL_DIRS
Vikram S. Adve6edfe272003-07-10 19:25:29 +0000260all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
261install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
262clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
263test :: $(addsuffix /.maketest , $(PARALLEL_DIRS))
264bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
Chris Lattnera8df7bd2003-12-01 07:28:25 +0000265stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
Brian Gaekef313ea72004-03-10 17:38:01 +0000266install-bytecode :: $(addsuffix /.makeinstall-bytecode, $(PARALLEL_DIRS))
Chris Lattnera8abc222002-09-18 03:22:27 +0000267
Brian Gaekef313ea72004-03-10 17:38:01 +0000268%/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode %/.makeinstall-bytecode:
Reid Spencer4d71b662004-10-22 21:01:56 +0000269 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
270 $(MKDIR) $(@D); \
271 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000272 fi; \
Misha Brukman694b3ff2004-05-21 23:21:11 +0000273 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
Chris Lattner00950542001-06-06 20:29:01 +0000274endif
275
John Criswell7a73b802003-06-30 21:59:07 +0000276# Handle directories that may or may not exist
John Criswell2a6530f2003-06-27 16:58:44 +0000277ifdef OPTIONAL_DIRS
Reid Spencer4d71b662004-10-22 21:01:56 +0000278$(ALL_TARGETS)::
279 $(VERB) for dir in $(OPTIONAL_DIRS); do \
280 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
281 if [ ! -f $$dir/Makefile ]; then \
282 $(MKDIR) $$dir; \
283 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
284 fi; \
285 ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 1; \
286 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000287 done
288endif
289
Reid Spencerfc945082004-08-20 09:20:05 +0000290#---------------------------------------------------------
291# Handle the CONFIG_FILES options
292#---------------------------------------------------------
293ifdef CONFIG_FILES
Reid Spencer05e90a02004-08-20 09:32:32 +0000294install:: install-config-files
Reid Spencerfc945082004-08-20 09:20:05 +0000295
296$(sysconfdir):
297 $(MKDIR) $(sysconfdir)
298
Reid Spencer05e90a02004-08-20 09:32:32 +0000299install-config-files: $(sysconfdir) $(CONFIG_FILES)
Reid Spencer37130d22004-10-04 07:05:07 +0000300 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
301 $(VERB)for file in $(CONFIG_FILES); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000302 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
Reid Spencerfc945082004-08-20 09:20:05 +0000303 done
304endif
305
John Criswell7a73b802003-06-30 21:59:07 +0000306###########################################################################
307# Library Build Rules:
308#
Chris Lattner00950542001-06-06 20:29:01 +0000309#---------------------------------------------------------
310# Handle the LIBRARYNAME option - used when building libs...
311#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +0000312#
313# When libraries are built, they are allowed to optionally define the
314# DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
315# from being built for the library. This .o files may then be linked to by a
316# tool if the tool does not need (or want) the semantics a .a file provides
317# (linking in only object files that are "needed"). If a library is never to
318# be used in this way, it is better to define DONT_BUILD_RELINKED, and define
319# BUILD_ARCHIVE instead.
320#
321# Some libraries must be built as .a files (libscalar for example) because if
Chris Lattner1917e952002-07-31 21:32:05 +0000322# it's built as a .o file, then all of the constituent .o files in it will be
Chris Lattnere62dbe92002-07-23 17:56:16 +0000323# linked into tools (for example gccas) even if they only use one of the parts
324# of it. For this reason, sometimes it's useful to use libraries as .a files.
John Criswell7a73b802003-06-30 21:59:07 +0000325###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000326
Brian Gaeke8abff792004-01-22 22:53:48 +0000327# Install rule for making bytecode library directory if it does not exist.
328# Trigger this by making libraries that need to be installed here depend on it.
329$(DESTDIR)$(bytecode_libdir):
330 $(MKDIR) $@
331
Chris Lattner00950542001-06-06 20:29:01 +0000332ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000333
Chris Lattner2a548c52002-09-16 22:36:42 +0000334# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000335LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer4d71b662004-10-22 21:01:56 +0000336LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
337LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
338LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
339LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000340
Reid Spencer4d71b662004-10-22 21:01:56 +0000341#-------------------------------------------------------------------------------
342# Shared Library Targets
John Criswell7a73b802003-06-30 21:59:07 +0000343# Modify the top level targets to build the desired libraries.
Reid Spencer4d71b662004-10-22 21:01:56 +0000344#-------------------------------------------------------------------------------
John Criswell7a73b802003-06-30 21:59:07 +0000345
Reid Spencer4d71b662004-10-22 21:01:56 +0000346# Does the library want a shared library version built?
347ifdef SHARED_LIBRARY
348
349all:: $(LIBNAME_LA)
350
351$(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
352 @$(ECHO) Linking shared library $(notdir $@)
353 $(VERB) $(Link) -o $@ $(ObjectsLO)
354 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
355 @$(ECHO) Finished linking shared library $(LIBRARYNAME).la
356clean::
357 $(VERB) $(RM) -f $(LIBNAME_LA)
358
359install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
360
361$(DESTDIR)/lib/lib$(LIBRARYNAME)$(SHLIBEXT): $(LIBNAME_LA)
362 @$(ECHO) Installing shared library $(notdir $@)
363 $(VERB) $(MKDIR) $(DESTDIR)
364 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
365 $(VERB) $(LIBTOOL) --finish $(DESTDIR)$(libdir)
366endif
367
368# Does the library want a bytecode version built?
369ifdef BYTECODE_LIBRARY
370
371ifdef EXPORTED_SYMBOL_LIST
372 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
373else
374 ifdef EXPORTED_SYMBOL_FILE
375 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
376 else
377 BCLinkLib += -Xlinker -disable-internalize
378 endif
379endif
380
381all:: $(LIBNAME_BC)
382
383$(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
384 @$(ECHO) Linking bytecode library $(notdir $@)
385 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
386
387clean::
388 $(VERB) $(RM) -f $(LIBNAME_BC)
389
390install:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
Chris Lattner481cc7c2003-08-15 02:18:35 +0000391
Brian Gaeke13f99322004-01-21 23:57:21 +0000392$(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
Reid Spencer4d71b662004-10-22 21:01:56 +0000393 @$(ECHO) Installing bytecode library $(notdir $@)
394 $(VERB)$(INSTALL) $< $@
395
396endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000397
Chris Lattner760da062003-03-14 20:25:22 +0000398# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000399ifndef DONT_BUILD_RELINKED
Reid Spencer4d71b662004-10-22 21:01:56 +0000400all:: $(LIBNAME_O)
401
402$(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
403 @$(ECHO) Linking object $(notdir $@)
404 $(VERB) $(Relink) -o $@ $(ObjectsO)
405
406install:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
407
408$(DESTDIR)$(libdir)/$(LIBRARYNAME).o: $(LIBNAME_O)
409 @$(ECHO) Installing object library $(notdir $@)
410 $(VERB) $(MKDIR) $(DESTDIR)$(libdir)
411 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
412
413clean::
414 $(VERB) $(RM) -f $(LIBNAME_O)
415
Chris Lattnere62dbe92002-07-23 17:56:16 +0000416endif
Chris Lattner760da062003-03-14 20:25:22 +0000417
418# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000419ifdef BUILD_ARCHIVE
Reid Spencer4d71b662004-10-22 21:01:56 +0000420all:: $(LIBNAME_A)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000421
Reid Spencer4d71b662004-10-22 21:01:56 +0000422$(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
423 @$(ECHO) Linking archive $(notdir $@) library
Reid Spencer37130d22004-10-04 07:05:07 +0000424 $(VERB)$(RM) -f $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000425 $(VERB) $(Archive) $@ $(ObjectsO)
426 $(VERB) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000427
Reid Spencer4d71b662004-10-22 21:01:56 +0000428clean::
429 $(VERB) $(RM) -f $(LIBNAME_A)
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000430
Reid Spencer4d71b662004-10-22 21:01:56 +0000431install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
John Criswell7a73b802003-06-30 21:59:07 +0000432
Reid Spencer4d71b662004-10-22 21:01:56 +0000433$(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a: $(LIBNAME_A)
Brian Gaeke6c096962004-02-09 17:38:52 +0000434 $(MKDIR) $(DESTDIR)$(libdir)
Reid Spencer4d71b662004-10-22 21:01:56 +0000435 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
Chris Lattner00950542001-06-06 20:29:01 +0000436endif
437
Reid Spencer4d71b662004-10-22 21:01:56 +0000438# if LIBRARYNAME
439endif
440
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000441#------------------------------------------------------------------------
442# Handle the TOOLNAME option - used when building tool executables...
443#------------------------------------------------------------------------
444#
445# The TOOLNAME option should be used with a USEDLIBS variable that tells the
Chris Lattnere62dbe92002-07-23 17:56:16 +0000446# libraries (and the order of the libs) that should be linked to the
447# tool. USEDLIBS should contain a list of library names (some with .a extension)
448# that are automatically linked in as .o files unless the .a suffix is added.
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000449#
450ifdef TOOLNAME
451
Reid Spencer4d71b662004-10-22 21:01:56 +0000452# TOOLLINKOPTSB to pass options to the linker like library search path etc
453# Note that this is different from TOOLLINKOPTS, these options
454# are passed to the linker *before* the USEDLIBS options are passed.
455# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
456ifdef TOOLLINKOPTSB
457Link += $(TOOLLINKOPTSB)
Reid Spencer37130d22004-10-04 07:05:07 +0000458endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000459
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000460# TOOLEXENAME* - These compute the output filenames to generate...
Reid Spencer4d71b662004-10-22 21:01:56 +0000461TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000462
463# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
Reid Spencer4d71b662004-10-22 21:01:56 +0000464PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
465PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
466LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
467LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000468
Reid Spencer4d71b662004-10-22 21:01:56 +0000469PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
470LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
471PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
472LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000473
Reid Spencer4d71b662004-10-22 21:01:56 +0000474LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
John Criswellfe785bd2004-09-16 14:11:25 +0000475
John Criswell7a73b802003-06-30 21:59:07 +0000476#
477# Libtool link options:
478# Ensure that all binaries have their symbols exported so that they can
479# by dlsym'ed.
480#
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000481
Reid Spencer4d71b662004-10-22 21:01:56 +0000482# Handle compression libraries automatically
483ifeq ($(HAVE_BZIP2),1)
484LIBS += -lbz2
485endif
486ifeq ($(HAVE_ZLIB),1)
487LIBS += -lz
488endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000489
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000490# Tell make that we need to rebuild subdirectories before we can link the tool.
491# This affects things like LLI which has library subdirectories.
Reid Spencer4d71b662004-10-22 21:01:56 +0000492$(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000493
Reid Spencer4d71b662004-10-22 21:01:56 +0000494all:: $(TOOLEXENAME)
John Criswell2a6530f2003-06-27 16:58:44 +0000495
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000496clean::
Reid Spencer4d71b662004-10-22 21:01:56 +0000497 $(VERB) $(RM) -f $(TOOLEXENAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000498
Reid Spencer4d71b662004-10-22 21:01:56 +0000499$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
500 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
501 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
502 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000503
Reid Spencer4d71b662004-10-22 21:01:56 +0000504install:: $(TOOLEXENAME)
505 @$(ECHO) Installing $(TOOLNAME)
506 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
507endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000508
Reid Spencer4d71b662004-10-22 21:01:56 +0000509ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000510
Reid Spencer4d71b662004-10-22 21:01:56 +0000511# Create .lo files in the OBJDIR directory from the .cpp and .c files...
512$(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
513 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
514 $(VERB) if $(LTCXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
515 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
516
517$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
518 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
519 $(VERB) if $(CXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
520 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
521
522$(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
523 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
524 $(VERB) if $(LTCCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
525 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
526
527$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
528 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
529 $(VERB) if $(CCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
530 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
531
532# Create .bc files in the OBJDIR directory from .cpp and .c files...
533$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
534 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
535 $(VERB) if $(BCCXXCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
536 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
537
538$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
539 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
540 $(VERB) if $(BCCCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
541 then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Tpo"; exit 1; fi
542
543else
544
545$(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
546 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
547 $(LTCXXCompile) $< -o $@
548
549$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
550 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
551 $(CXXCompile) $< -o $@
552
553$(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir
554 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
555 $(LTCCompile) $< -o $@
556
557$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
558 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
559 $(CCompile) $< -o $@
560
561# Create .bc files in the OBJDIR directory from .cpp and .c files...
562$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
563 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
564 $(BCCompileCPP) $< -o $@
565
566$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
567 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
568 $(BCCompileC) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000569
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000570endif
571
Reid Spencer4d71b662004-10-22 21:01:56 +0000572$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
573 @$(ECHO) "Compiling $*.ll To Bytecode"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000574 $(VERB) $(LLVMAS) $< -f -o $@
575
Reid Spencer4d71b662004-10-22 21:01:56 +0000576ifdef TARGET
577
Misha Brukman8567ccf2004-10-22 22:18:27 +0000578TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(BUILD_SRC_ROOT)/lib/Target/Target.td)
Reid Spencer4d71b662004-10-22 21:01:56 +0000579
580$(BUILT_SOURCES): $(TDFILES)
581
582%GenRegisterNames.inc : %.td
583 @echo "Building $(<F) register names with tblgen"
584 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
585
586%GenRegisterInfo.h.inc : %.td
587 @echo "Building $(<F) register information header with tblgen"
588 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
589
590%GenRegisterInfo.inc : %.td
591 @echo "Building $(<F) register info implementation with tblgen"
592 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
593
594%GenInstrNames.inc : %.td
595 @echo "Building $(<F) instruction names with tblgen"
596 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
597
598%GenInstrInfo.inc : %.td
599 @echo "Building $(<F) instruction information with tblgen"
600 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
601
602%GenAsmWriter.inc : %.td
603 @echo "Building $(<F) assembly writer with tblgen"
604 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
605
606%GenATTAsmWriter.inc : %.td
607 @echo "Building $(<F) AT&T assembly writer with tblgen"
608 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
609
610%GenIntelAsmWriter.inc : %.td
611 @echo "Building $(<F) Intel assembly writer with tblgen"
612 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
613
614%GenInstrSelector.inc: %.td
615 @echo "Building $(<F) instruction selector with tblgen"
616 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
617
618%GenCodeEmitter.inc:: %.td
619 @echo "Building $(<F) code emitter with tblgen"
620 $(VERB) $(TableGen) -gen-emitter -o $@ $<
621
622clean::
623 $(VERB) rm -f *.inc
624
625endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000626
Chris Lattnere8996782003-01-16 22:44:19 +0000627#
628# Rules for building lex/yacc files
629#
630LEX_FILES = $(filter %.l, $(Source))
631LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
632YACC_FILES = $(filter %.y, $(Source))
633YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
634.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
635
Chris Lattner00950542001-06-06 20:29:01 +0000636# Create a .cpp source file from a flex input file... this uses sed to cut down
637# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000638#
639# The last line is a gross hack to work around flex aparently not being able to
640# resize the buffer on a large token input. Currently, for uninitialized string
641# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000642# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000643#
Chris Lattner00950542001-06-06 20:29:01 +0000644%.cpp: %.l
Reid Spencer4d71b662004-10-22 21:01:56 +0000645 @$(ECHO) Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000646 $(VERB) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000647 $(SED) '/^find_rule/d' | \
648 $(SED) 's/void yyunput/inline void yyunput/' | \
649 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
650 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
651 > $@.tmp
652 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
Chris Lattnera328f882003-08-04 19:47:06 +0000653 @# remove the output of flex if it didn't get moved over...
654 @rm -f $@.tmp
Chris Lattner00950542001-06-06 20:29:01 +0000655
656# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000657%.c: %.y # Cancel built-in rules for yacc
658%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000659%.cpp %.h : %.y
Reid Spencer4d71b662004-10-22 21:01:56 +0000660 @$(ECHO) "Bisoning $*.y"
John Criswell410d1b52003-09-09 20:57:03 +0000661 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
Reid Spencer4d71b662004-10-22 21:01:56 +0000662 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
663 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
Chris Lattnera328f882003-08-04 19:47:06 +0000664 @# If the files were not updated, don't leave them lying around...
665 @rm -f $*.tab.c $*.tab.h
Chris Lattner00950542001-06-06 20:29:01 +0000666
667# To create the directories...
668%/.dir:
Reid Spencer4d71b662004-10-22 21:01:56 +0000669 $(VERB) $(MKDIR) $* > /dev/null
John Criswell7a73b802003-06-30 21:59:07 +0000670 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000671
Reid Spencer4d71b662004-10-22 21:01:56 +0000672.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
673.PRECIOUS: $(LLVMTOOLDIR)/.dir
674
Chris Lattner30440c62003-01-16 21:06:18 +0000675# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000676ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000677%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000678 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000679else
680%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000681 $(ECHO) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000682endif
Chris Lattner30440c62003-01-16 21:06:18 +0000683
John Criswell7f336952003-09-06 14:44:17 +0000684#
685# This rules ensures that header files that are removed still have a rule for
686# which they can be "generated." This allows make to ignore them and
687# reproduce the dependency lists.
688#
John Criswell4b6e5d12003-09-18 18:37:08 +0000689%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000690
Chris Lattner172b6482002-09-22 02:47:15 +0000691# 'make clean' nukes the tree
Chris Lattner00950542001-06-06 20:29:01 +0000692clean::
Reid Spencer4d71b662004-10-22 21:01:56 +0000693 $(VERB) $(RM) -rf $(OBJDIR)
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000694 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
695ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
696 $(VERB) $(RM) -f *$(SHLIBEXT)
697endif
John Criswell7a73b802003-06-30 21:59:07 +0000698 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
699
John Criswell7a73b802003-06-30 21:59:07 +0000700###########################################################################
701# C/C++ Dependencies
702# Define variables and rules that generate header file dependencies
703# from C/C++ source files.
704###########################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000705
Chris Lattner33ad24a2003-08-22 14:10:16 +0000706ifndef DISABLE_AUTO_DEPENDENCIES
707
Chris Lattner694c5df2003-05-15 21:28:55 +0000708# If dependencies were generated for the file that included this file,
Misha Brukman36bc6422003-08-21 22:02:18 +0000709# include the dependencies now...
Chris Lattner00950542001-06-06 20:29:01 +0000710#
Reid Spencer4d71b662004-10-22 21:01:56 +0000711
John Criswell410d1b52003-09-09 20:57:03 +0000712SourceBaseNames := $(basename $(Source))
Reid Spencer4d71b662004-10-22 21:01:56 +0000713SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d)
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000714
John Criswellbd082802003-10-07 14:16:44 +0000715#
John Criswell7a73b802003-06-30 21:59:07 +0000716# Include dependencies generated from C/C++ source files, but not if we
717# are cleaning (this example taken from the GNU Make Manual).
718#
719ifneq ($(MAKECMDGOALS),clean)
John Criswelld741bcf2003-08-12 18:51:51 +0000720ifneq ($(MAKECMDGOALS),distclean)
Chris Lattner15444a92003-08-29 14:07:02 +0000721-include /dev/null $(SourceDepend)
John Criswell7a73b802003-06-30 21:59:07 +0000722endif
John Criswelld741bcf2003-08-12 18:51:51 +0000723endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000724
Chris Lattner33ad24a2003-08-22 14:10:16 +0000725endif # ifndef DISABLE_AUTO_DEPENDENCIES
Reid Spencer4d71b662004-10-22 21:01:56 +0000726
727###############################################################################
728# PRECONDITIONS - that which must be built/checked first
729###############################################################################
730
731OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
732SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
733CONFIGURE := $(LLVM_SRC_ROOT)/configure
734CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
735MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
736MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
737
738#------------------------------------------------------------------------
739# List of the preconditions
740preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
741
742all dist distcheck install:: $(BUILT_SOURCES)
743
744clean::
745 $(VERB) $(RM) -f $(BUILT_SOURCES)
746
747#------------------------------------------------------------------------
748# Make sure we're not using a stale configuration
749.PRECIOUS: $(CONFIG_STATUS)
750$(CONFIG_STATUS): $(CONFIGURE)
751 @$(ECHO) Reconfiguring with $@
752 $(VERB) $(CONFIG_STATUS) --recheck
753
754#------------------------------------------------------------------------
755# Make sure the configuration makefile is up to date
756$(MAKE_CONFIG): $(MAKE_CONFIG_IN)
757 @$(ECHO) Regenerating $@
758 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
759 $(VERB) $(MAKE) $(MAKEFLAGS) $(MAKECMDGOALS)
760 @exit 0;
761
762#------------------------------------------------------------------------
763# If the Makefile in the source tree has been updated, copy it over into the
764# build tree.
Reid Spencere53e3972004-10-22 23:06:30 +0000765ifneq ($(OBJMKFILE),$(SRCMKFILE))
Reid Spencer4d71b662004-10-22 21:01:56 +0000766.PRECIOUS: $(OBJMKFILE)
767$(OBJMKFILE): $(SRCMKFILE)
768 @$(ECHO) "Updating Makefile from : $(dir $<)"
769 $(VERB) $(MKDIR) $(@D)
770 $(VERB) cp -f $< $@
771 $(VERB) $(MAKE) $(MAKEFLAGS) $(MAKECMDGOALS)
772 @exit 0;
Reid Spencere53e3972004-10-22 23:06:30 +0000773endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000774
775###############################################################################
776# MISCELLANEOUS - utility targets
777###############################################################################
778
779#------------------------------------------------------------------------
780# Print out the directories used for building
781printvars:
782 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
783 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
784 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
785 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
786 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
787 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
788 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
789 @$(ECHO) "OBJDIR: " $(OBJDIR)
790 @$(ECHO) "LIBDIR: " $(LIBDIR)
791 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
792 @$(ECHO) "TDFILES:" '$(TDFILES)'
793 @$(ECHO) "CXXCompile: " '$(CXXCompile)'
794 @$(ECHO) "CCompile: " '$(CCompile)'