blob: db52985179fd13e0948cb9fab375824c38a0ceb2 [file] [log] [blame]
Misha Brukman7426c892004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswell23e43fb2003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
Chris Lattner11cc8b32007-12-29 20:11:13 +00005# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
Misha Brukman2879c292009-01-08 02:11:55 +00007#
Misha Brukman7426c892004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner2f7c9632001-06-06 20:29:01 +00009#
Reid Spencer81cd0492004-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 Lattner2e9fc94a2003-08-15 03:02:52 +000012#
Chris Lattnerb8e7aa02006-02-14 04:27:15 +000013#===-----------------------------------------------------------------------====#
Chris Lattner2f7c9632001-06-06 20:29:01 +000014
Reid Spencerf88808a2004-10-30 09:19:36 +000015################################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencerf88808a2004-10-30 09:19:36 +000017################################################################################
John Criswell3ef61af2003-06-30 21:59:07 +000018
Chris Lattner2f7c9632001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Daniel Dunbar96ccc472009-09-13 22:39:27 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode \
23 unitcheck
Reid Spencer8b5ebe52004-12-06 05:35:13 +000024LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencerd4bd3752004-12-03 20:08:48 +000025 install-local printvars uninstall-local \
Daniel Dunbar96ccc472009-09-13 22:39:27 +000026 install-bytecode-local
Chris Lattnerd0382a82007-09-26 06:10:47 +000027TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
Bill Wendling8790e322009-01-04 23:12:21 +000028 dist-zip unittests
Reid Spencerf88808a2004-10-30 09:19:36 +000029UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30InternalTargets := preconditions distdir dist-hook
Reid Spencer81cd0492004-10-23 20:04:14 +000031
Reid Spencerf88808a2004-10-30 09:19:36 +000032################################################################################
Reid Spencer77a46d22004-10-26 22:26:33 +000033# INITIALIZATION: Basic things the makefile needs
Reid Spencerf88808a2004-10-30 09:19:36 +000034################################################################################
35
36#--------------------------------------------------------------------
37# Set the VPATH so that we can find source files.
38#--------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +000039VPATH=$(PROJ_SRC_DIR)
Reid Spencer77a46d22004-10-26 22:26:33 +000040
41#--------------------------------------------------------------------
Reid Spencer7214cfd2007-06-29 14:02:07 +000042# Reset the list of suffixes we know how to build.
Reid Spencer77a46d22004-10-26 22:26:33 +000043#--------------------------------------------------------------------
44.SUFFIXES:
Nick Lewycky28c62d22009-02-26 07:44:16 +000045.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll
Reid Spencerf88808a2004-10-30 09:19:36 +000046.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer77a46d22004-10-26 22:26:33 +000047
Reid Spencer81cd0492004-10-23 20:04:14 +000048#--------------------------------------------------------------------
49# Mark all of these targets as phony to avoid implicit rule search
50#--------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +000051.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer81cd0492004-10-23 20:04:14 +000052
53#--------------------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +000054# Make sure all the user-target rules are double colon rules and
Reid Spencer77a46d22004-10-26 22:26:33 +000055# they are defined first.
Reid Spencer81cd0492004-10-23 20:04:14 +000056#--------------------------------------------------------------------
57
Reid Spencerf88808a2004-10-30 09:19:36 +000058$(UserTargets)::
Reid Spencer100080c2004-10-25 08:27:37 +000059
Reid Spencer77a46d22004-10-26 22:26:33 +000060################################################################################
61# PRECONDITIONS: that which must be built/checked first
62################################################################################
63
Reid Spencerd4bd3752004-12-03 20:08:48 +000064SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencerba6a3db2005-01-16 02:20:54 +000065 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
66ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
67ConfigureScript := $(PROJ_SRC_ROOT)/configure
68ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
69MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
70MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
71MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
72MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
73PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
74ifneq ($(MakefileCommonIn),)
75PreConditions += $(MakefileCommon)
76endif
Chris Lattner68c97542006-09-04 05:23:20 +000077
Reid Spencerba6a3db2005-01-16 02:20:54 +000078ifneq ($(MakefileConfigIn),)
79PreConditions += $(MakefileConfig)
80endif
Reid Spencer77a46d22004-10-26 22:26:33 +000081
Reid Spencer53846bc2005-08-25 04:59:49 +000082preconditions: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +000083
84#------------------------------------------------------------------------
85# Make sure the BUILT_SOURCES are built first
86#------------------------------------------------------------------------
Reid Spencer97e40f12004-12-16 07:15:16 +000087$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000088
Reid Spencer48c74392007-02-07 19:13:19 +000089clean-all-local::
Reid Spencer77a46d22004-10-26 22:26:33 +000090ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +000091 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000092endif
93
Reid Spencerba6a3db2005-01-16 02:20:54 +000094ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer55814372004-12-16 08:00:46 +000095spotless:
Reid Spencer55814372004-12-16 08:00:46 +000096 $(Verb) if test -x config.status ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +000097 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +000098 $(MKDIR) .spotless.save ; \
99 $(MV) config.status .spotless.save ; \
100 $(MV) mklib .spotless.save ; \
101 $(MV) projects .spotless.save ; \
Reid Spencer55814372004-12-16 08:00:46 +0000102 $(RM) -rf * ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000103 $(MV) .spotless.save/config.status . ; \
104 $(MV) .spotless.save/mklib . ; \
105 $(MV) .spotless.save/projects . ; \
106 $(RM) -rf .spotless.save ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000107 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000108 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
109 $(ConfigStatusScript) ; \
Reid Spencer55814372004-12-16 08:00:46 +0000110 else \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000111 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer55814372004-12-16 08:00:46 +0000112 fi
Reid Spencerc49a8632005-12-21 23:17:06 +0000113else
114spotless:
115 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer55814372004-12-16 08:00:46 +0000116endif
117
Reid Spencerf88808a2004-10-30 09:19:36 +0000118$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencerb7f710a2004-10-28 00:41:43 +0000119
Reid Spencer77a46d22004-10-26 22:26:33 +0000120#------------------------------------------------------------------------
121# Make sure we're not using a stale configuration
122#------------------------------------------------------------------------
Reid Spencerafdc82c2004-12-16 18:26:53 +0000123reconfigure:
Reid Spencerba6a3db2005-01-16 02:20:54 +0000124 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
125 $(Verb) cd $(PROJ_OBJ_ROOT) && \
126 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
127 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000128 fi ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000129 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
130 $(ConfigStatusScript)
131
Anton Korobeynikov28381c02009-08-14 18:53:19 +0000132# FIXME: The {PIC16,MSP430}/AsmPrinter line here is a hack to force a reconfigure to pick
Daniel Dunbard8186682009-08-13 17:22:49 +0000133# up AsmPrinter changes. Remove it after a reasonable delay from 2009-08-13.
134
Reid Spencerf88808a2004-10-30 09:19:36 +0000135.PRECIOUS: $(ConfigStatusScript)
Anton Korobeynikov28381c02009-08-14 18:53:19 +0000136$(ConfigStatusScript): $(ConfigureScript) $(LLVM_SRC_ROOT)/lib/Target/PIC16/AsmPrinter/Makefile $(LLVM_SRC_ROOT)/lib/Target/MSP430/AsmPrinter/Makefile
Reid Spencerf88808a2004-10-30 09:19:36 +0000137 $(Echo) Reconfiguring with $<
Reid Spencerba6a3db2005-01-16 02:20:54 +0000138 $(Verb) cd $(PROJ_OBJ_ROOT) && \
139 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
140 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000141 fi ; \
Reid Spencer50f34872004-11-29 12:37:44 +0000142 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
143 $(ConfigStatusScript)
Reid Spencer77a46d22004-10-26 22:26:33 +0000144
Reid Spencer83bde552005-08-25 04:44:18 +0000145#------------------------------------------------------------------------
Reid Spencer77a46d22004-10-26 22:26:33 +0000146# Make sure the configuration makefile is up to date
147#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000148ifneq ($(MakefileConfigIn),)
149$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000150 $(Echo) Regenerating $@
Reid Spencerba6a3db2005-01-16 02:20:54 +0000151 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
152endif
153
154ifneq ($(MakefileCommonIn),)
155$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
156 $(Echo) Regenerating $@
157 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
158endif
Reid Spencer77a46d22004-10-26 22:26:33 +0000159
160#------------------------------------------------------------------------
161# If the Makefile in the source tree has been updated, copy it over into the
162# build tree. But, only do this if the source and object makefiles differ
163#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000164ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer77a46d22004-10-26 22:26:33 +0000165
Gordon Henriksen04e38cf2008-03-10 15:58:40 +0000166Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
Reid Spencerf88808a2004-10-30 09:19:36 +0000167 $(Echo) "Updating Makefile"
168 $(Verb) $(MKDIR) $(@D)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000169 $(Verb) $(CP) -f $< $@
Reid Spencer77a46d22004-10-26 22:26:33 +0000170
171# Copy the Makefile.* files unless we're in the root directory which avoids
172# the copying of Makefile.config.in or other things that should be explicitly
173# taken care of.
Reid Spencerba6a3db2005-01-16 02:20:54 +0000174$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
Reid Spencerd94bb332004-10-26 23:10:00 +0000175 @case '$?' in \
176 *Makefile.rules) ;; \
177 *.in) ;; \
Gordon Henriksen04e38cf2008-03-10 15:58:40 +0000178 *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000179 $(MKDIR) $(@D) ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000180 $(CP) -f $< $@ ;; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000181 esac
Gabor Greifc848f9e2008-02-27 13:34:15 +0000182
Reid Spencer77a46d22004-10-26 22:26:33 +0000183endif
184
185#------------------------------------------------------------------------
186# Set up the basic dependencies
187#------------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000188$(UserTargets):: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +0000189
190all:: all-local
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000191clean:: clean-local
Reid Spencer9d0c1e02004-11-02 16:36:03 +0000192clean-all:: clean-local clean-all-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000193install:: install-local
194uninstall:: uninstall-local
Misha Brukman2879c292009-01-08 02:11:55 +0000195install-local:: all-local
Reid Spencerd4bd3752004-12-03 20:08:48 +0000196install-bytecode:: install-bytecode-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000197
198###############################################################################
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000199# LLVMC: Provide rules for compiling llvmc plugins
200###############################################################################
201
202ifdef LLVMC_PLUGIN
203
204LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
Mikhail Glushenkov248c4142009-06-23 20:46:48 +0000205CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000206REQUIRES_EH := 1
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000207
208ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
209 LD.Flags += -lCompilerDriver
210endif
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000211
212# Build a dynamic library if the user runs `make` directly from the plugin
213# directory.
214ifndef LLVMC_BUILTIN_PLUGIN
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000215 LOADABLE_MODULE = 1
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000216endif
217
218# TableGen stuff...
219ifneq ($(BUILT_SOURCES),)
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000220 LLVMC_BUILD_AUTOGENERATED_INC=1
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000221endif
222
223endif # LLVMC_PLUGIN
224
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000225ifdef LLVMC_BASED_DRIVER
226
227TOOLNAME = $(LLVMC_BASED_DRIVER)
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000228
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000229REQUIRES_EH := 1
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000230
231ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
232 LD.Flags += -lCompilerDriver
233else
234 LLVMLIBS = CompilerDriver.a
235 LINK_COMPONENTS = support system
236endif
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000237
238# Preprocessor magic that generates references to static variables in built-in
239# plugins.
240ifneq ($(LLVMC_BUILTIN_PLUGINS),)
241
242USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
243
244LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
245LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
246LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
247LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
248LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
Mikhail Glushenkovfc8809d2009-10-09 04:15:52 +0000249LLVMC_BUILTIN_PLUGIN_6 = $(word 6, $(LLVMC_BUILTIN_PLUGINS))
250LLVMC_BUILTIN_PLUGIN_7 = $(word 7, $(LLVMC_BUILTIN_PLUGINS))
251LLVMC_BUILTIN_PLUGIN_8 = $(word 8, $(LLVMC_BUILTIN_PLUGINS))
252LLVMC_BUILTIN_PLUGIN_9 = $(word 9, $(LLVMC_BUILTIN_PLUGINS))
253LLVMC_BUILTIN_PLUGIN_10 = $(word 10, $(LLVMC_BUILTIN_PLUGINS))
254
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000255
256ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
257CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
258endif
259
260ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
261CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
262endif
263
264ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
265CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
266endif
267
268ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
269CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
270endif
271
272ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
273CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
274endif
275
Mikhail Glushenkovfc8809d2009-10-09 04:15:52 +0000276ifneq ($(LLVMC_BUILTIN_PLUGIN_6),)
277CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_6)
278endif
279
280ifneq ($(LLVMC_BUILTIN_PLUGIN_7),)
281CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_7)
282endif
283
284ifneq ($(LLVMC_BUILTIN_PLUGIN_8),)
285CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_8)
286endif
287
288ifneq ($(LLVMC_BUILTIN_PLUGIN_9),)
289CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_9)
290endif
291
292ifneq ($(LLVMC_BUILTIN_PLUGIN_10),)
293CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_10)
294endif
295
296
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000297endif
298
299endif # LLVMC_BASED_DRIVER
300
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000301###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000302# VARIABLES: Set up various variables based on configuration data
303###############################################################################
304
Daniel Dunbar78caa022008-10-03 19:11:19 +0000305# Variable for if this make is for a "cleaning" target
306ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
307 IS_CLEANING_TARGET=1
308endif
309
Reid Spencer81cd0492004-10-23 20:04:14 +0000310#--------------------------------------------------------------------
311# Variables derived from configuration we are building
Chris Lattner2f7c9632001-06-06 20:29:01 +0000312#--------------------------------------------------------------------
313
Reid Spencerfd8e6412007-07-10 07:19:53 +0000314CPP.Defines :=
David Greene80f48bd2009-04-17 14:49:22 +0000315ifeq ($(ENABLE_OPTIMIZED),1)
316 BuildMode := Release
317 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000318 ifneq ($(HOST_OS),FreeBSD)
319 ifneq ($(HOST_OS),Darwin)
David Greene80f48bd2009-04-17 14:49:22 +0000320 OmitFramePointer := -fomit-frame-pointer
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000321 endif
David Greene80f48bd2009-04-17 14:49:22 +0000322 endif
323
324 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Cheng57709502009-04-20 22:49:59 +0000325 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
326 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000327 #ifeq ($(HOST_OS),Darwin)
Evan Cheng40c52322009-04-20 22:16:40 +0000328 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
329 #endif
David Greene80f48bd2009-04-17 14:49:22 +0000330 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
331 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
332 LD.Flags += $(OPTIMIZE_OPTION)
Jeffrey Yasskinc3273dc2009-09-27 17:47:29 +0000333 ifdef DEBUG_SYMBOLS
Jeffrey Yasskindb281082009-09-25 16:46:09 +0000334 BuildMode := $(BuildMode)+Debug
335 CXX.Flags += -g
336 C.Flags += -g
337 LD.Flags += -g
338 KEEP_SYMBOLS := 1
339 endif
David Greene80f48bd2009-04-17 14:49:22 +0000340else
Daniel Dunbar08d4ab92009-11-16 22:37:52 +0000341 ifdef NO_DEBUG_SYMBOLS
342 BuildMode := Unoptimized
343 CXX.Flags +=
344 C.Flags +=
345 LD.Flags +=
346 KEEP_SYMBOLS := 1
347 else
348 BuildMode := Debug
349 CXX.Flags += -g
350 C.Flags += -g
351 LD.Flags += -g
352 KEEP_SYMBOLS := 1
353 endif
David Greene80f48bd2009-04-17 14:49:22 +0000354endif
355
356ifeq ($(ENABLE_PROFILING),1)
357 BuildMode := $(BuildMode)+Profile
358 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
359 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
360 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
361 KEEP_SYMBOLS := 1
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000362endif
363
Daniel Dunbar61e0a822008-09-02 17:35:16 +0000364#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
365# CXX.Flags += -fvisibility-inlines-hidden
366#endif
367
Chris Lattnerab8a7c42010-01-24 20:20:40 +0000368ifdef ENABLE_EXPENSIVE_CHECKS
369 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
370 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
371 REQUIRES_RTTI := 1
372endif
373
Reid Spencer51e6f682006-08-25 19:54:53 +0000374# IF REQUIRES_EH=1 is specified then don't disable exceptions
Reid Spencer0b6396c2006-08-25 20:56:59 +0000375ifndef REQUIRES_EH
376 CXX.Flags += -fno-exceptions
Chris Lattnerdb308fd2010-01-24 20:21:50 +0000377else
378 # If the library requires EH, it also requires RTTI.
379 REQUIRES_RTTI := 1
Reid Spencer0b6396c2006-08-25 20:56:59 +0000380endif
Reid Spencer51e6f682006-08-25 19:54:53 +0000381
Nicolas Geoffray43cce222009-08-19 22:04:44 +0000382ifdef REQUIRES_FRAME_POINTER
383 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
384 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
385 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
386endif
387
Daniel Dunbar24c00472009-09-11 15:47:24 +0000388# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
Chris Lattner823aed12010-01-24 20:43:08 +0000389ifneq ($(REQUIRES_RTTI), 1)
390 CXX.Flags += -fno-rtti
391 CXXFLAGS += -fno-rtti
Reid Spencere6bc2062007-05-02 21:29:39 +0000392endif
393
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000394ifdef ENABLE_COVERAGE
395 BuildMode := $(BuildMode)+Coverage
Chris Lattnereaae8d02009-06-16 23:00:42 +0000396 CXX.Flags += -ftest-coverage -fprofile-arcs
397 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000398endif
399
Reid Spencer15b85092006-04-10 16:46:04 +0000400# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
401# then disable assertions by defining the appropriate preprocessor symbols.
Reid Spencerece13582006-04-09 23:41:14 +0000402ifdef DISABLE_ASSERTIONS
Duncan Sands99d0b232009-03-27 11:35:00 +0000403 # Indicate that assertions are turned off using a minus sign
404 BuildMode := $(BuildMode)-Asserts
Reid Spencerfd8e6412007-07-10 07:19:53 +0000405 CPP.Defines += -DNDEBUG
Reid Spencerece13582006-04-09 23:41:14 +0000406else
Reid Spencerfd8e6412007-07-10 07:19:53 +0000407 CPP.Defines += -D_DEBUG
Chris Lattner98c79c32006-03-21 01:06:41 +0000408endif
409
Misha Brukman2879c292009-01-08 02:11:55 +0000410# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
411# configured), then enable expensive checks by defining the
David Greene869e4b52007-06-29 03:36:21 +0000412# appropriate preprocessor symbols.
David Greenecbc8ddf2007-06-28 19:36:08 +0000413ifdef ENABLE_EXPENSIVE_CHECKS
414 BuildMode := $(BuildMode)+Checks
Duncan Sands445071c2008-12-09 21:33:20 +0000415 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
David Greenecbc8ddf2007-06-28 19:36:08 +0000416endif
417
Nick Lewycky28c62d22009-02-26 07:44:16 +0000418# LOADABLE_MODULE implies several other things so we force them to be
419# defined/on.
420ifdef LOADABLE_MODULE
421 SHARED_LIBRARY := 1
Nick Lewycky28c62d22009-02-26 07:44:16 +0000422 LINK_LIBS_IN_SHARED := 1
423endif
424
425ifdef SHARED_LIBRARY
426 ENABLE_PIC := 1
427 PIC_FLAG = "(PIC)"
428endif
429
Reid Spencer05a1fe52006-12-16 22:07:52 +0000430ifeq ($(ENABLE_PIC),1)
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000431 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000432 # Nothing. Win32 defaults to PIC and warns when given -fPIC
433 else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000434 ifeq ($(HOST_OS),Darwin)
Nick Lewycky28c62d22009-02-26 07:44:16 +0000435 # Common symbols not allowed in dylib files
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000436 CXX.Flags += -fno-common
437 C.Flags += -fno-common
438 else
439 # Linux and others; pass -fPIC
440 CXX.Flags += -fPIC
441 C.Flags += -fPIC
442 endif
443 endif
Mike Stumpd1b46362009-05-08 23:08:58 +0000444else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000445 ifeq ($(HOST_OS),Darwin)
Mike Stumpd1b46362009-05-08 23:08:58 +0000446 CXX.Flags += -mdynamic-no-pic
447 C.Flags += -mdynamic-no-pic
448 endif
Reid Spencer05a1fe52006-12-16 22:07:52 +0000449endif
450
Anton Korobeynikov803c60c2010-01-16 14:06:58 +0000451ifeq ($(HOST_OS),MingW)
452 # Work around PR4957
453 CPP.Defines += -D__NO_CTYPE_INLINE
454 ifeq ($(LLVM_CROSS_COMPILING),1)
455 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
456 ifdef TOOLNAME
457 LD.Flags += -Wl,--allow-multiple-definition
458 endif
459 endif
460endif
461
Eric Christopher3fe69672009-08-18 03:23:40 +0000462CXX.Flags += -Woverloaded-virtual
David Greenecbc8ddf2007-06-28 19:36:08 +0000463CPP.BaseFlags += $(CPP.Defines)
Reid Spencer6f682b72006-03-22 15:59:55 +0000464AR.Flags := cru
Reid Spencer81cd0492004-10-23 20:04:14 +0000465
Chris Lattnerdc5a8962006-07-27 18:19:51 +0000466# Make Floating point IEEE compliant on Alpha.
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000467ifeq ($(ARCH),Alpha)
Reid Spencer05a1fe52006-12-16 22:07:52 +0000468 CXX.Flags += -mieee
469 CPP.BaseFlags += -mieee
470ifeq ($(ENABLE_PIC),0)
471 CXX.Flags += -fPIC
472 CPP.BaseFlags += -fPIC
473endif
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000474endif
475
Andrew Lenharth0ad67b02007-01-26 13:34:50 +0000476ifeq ($(ARCH),Alpha)
477 LD.Flags += -Wl,--no-relax
478endif
479
Reid Spencer81cd0492004-10-23 20:04:14 +0000480#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000481# Directory locations
Reid Spencer81cd0492004-10-23 20:04:14 +0000482#--------------------------------------------------------------------
Jim Grosbach009db892008-10-02 22:56:44 +0000483TargetMode :=
484ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000485 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbach009db892008-10-02 22:56:44 +0000486endif
487
488ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000489ObjDir := $(ObjRootDir)
490LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
491ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
492ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
493LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
494LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
495LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell3ef61af2003-06-30 21:59:07 +0000496
Reid Spencer81cd0492004-10-23 20:04:14 +0000497#--------------------------------------------------------------------
Daniel Dunbar16a13532010-02-23 10:00:53 +0000498# LLVM Capable Compiler
499#--------------------------------------------------------------------
500
501ifeq ($(LLVMCC_OPTION),llvm-gcc)
502 LLVMCC := $(LLVMGCC)
503 LLVMCXX := $(LLVMGXX)
504else
505 ifeq ($(LLVMCC_OPTION),clang)
506 ifneq ($(CLANGPATH),)
507 LLVMCC := $(CLANGPATH)
508 LLVMCXX := $(CLANGXXPATH)
509 else
510 ifeq ($(ENABLE_BUILT_CLANG),1)
511 LLVMCC := $(LLVMToolDir)/clang
512 LLVMCXX := $(LLVMToolDir)/clang++
513 endif
514 endif
515 endif
516endif
517
518#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000519# Full Paths To Compiled Tools and Utilities
Reid Spencer81cd0492004-10-23 20:04:14 +0000520#--------------------------------------------------------------------
Reid Spencerb12e2902005-01-14 16:33:36 +0000521EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
522Echo = @$(EchoCmd)
Reid Spencerf88808a2004-10-30 09:19:36 +0000523ifndef LLVMAS
524LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
525endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000526ifndef TBLGEN
Reid Spencer0aa9d002006-07-26 21:14:56 +0000527 ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000528 TBLGEN := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Reid Spencer0aa9d002006-07-26 21:14:56 +0000529 else
530 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
531 endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000532endif
Misha Brukman2879c292009-01-08 02:11:55 +0000533LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Reid Spencerb63d0c42007-02-09 15:52:07 +0000534ifndef LLVMLD
Reid Spencer7cec4f22007-02-09 17:09:14 +0000535LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
Reid Spencerf88808a2004-10-30 09:19:36 +0000536endif
Chris Lattner68c97542006-09-04 05:23:20 +0000537ifndef LLVMDIS
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000538LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
539endif
540ifndef LLI
541LLI := $(LLVMToolDir)/lli$(EXEEXT)
542endif
Alkis Evlogimenos24340582005-02-27 10:21:37 +0000543ifndef LLC
544LLC := $(LLVMToolDir)/llc$(EXEEXT)
545endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000546ifndef LOPT
Alkis Evlogimenos7c7705d2004-12-13 18:08:29 +0000547LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000548endif
Alkis Evlogimenos7c04a3d2005-02-02 00:40:15 +0000549ifndef LBUGPOINT
550LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
551endif
Reid Spencer9a6fc822006-12-03 21:01:45 +0000552
Reid Spencer81cd0492004-10-23 20:04:14 +0000553#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000554# Adjust to user's request
Reid Spencer81cd0492004-10-23 20:04:14 +0000555#--------------------------------------------------------------------
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000556
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000557ifeq ($(HOST_OS),Darwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000558 DARWIN_VERSION := `sw_vers -productVersion`
559 # Strip a number like 10.4.7 to 10.4
560 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
561 # Get "4" out of 10.4 for later pieces in the makefile.
562 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendlingf3ef2c72009-03-22 08:28:45 +0000563
Julien Lerouge15833b92009-03-27 18:18:00 +0000564 SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
Evan Cheng57b14192009-09-08 18:52:20 +0000565 -dynamiclib
566 ifneq ($(ARCH),ARM)
567 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
568 endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000569else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000570 ifeq ($(HOST_OS),Cygwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000571 SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000572 -Wl,--enable-auto-import -Wl,--enable-auto-image-base
Scott Michelb1a830a2009-03-12 21:03:53 +0000573 else
574 SharedLinkOptions=-shared
575 endif
576endif
577
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000578ifeq ($(TARGET_OS),Darwin)
Evan Cheng57b14192009-09-08 18:52:20 +0000579 ifneq ($(ARCH),ARM)
580 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
Jim Grosbach95e6e932009-10-30 21:33:05 +0000581 else
582 TargetCommonOpts += -marm
Evan Cheng57b14192009-09-08 18:52:20 +0000583 endif
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000584endif
585
Nick Lewycky28c62d22009-02-26 07:44:16 +0000586# Adjust LD.Flags depending on the kind of library that is to be built. Note
587# that if LOADABLE_MODULE is specified then the resulting shared library can
588# be opened with dlopen.
Reid Spencere6458c32006-08-07 23:12:15 +0000589ifdef LOADABLE_MODULE
Reid Spencere6458c32006-08-07 23:12:15 +0000590 LD.Flags += -module
591endif
592
Reid Spencer87e645c2005-01-11 04:31:07 +0000593ifdef SHARED_LIBRARY
Scott Michelb1a830a2009-03-12 21:03:53 +0000594ifneq ($(DARWIN_MAJVERS),4)
Nick Lewycky7d01e392009-03-03 04:55:15 +0000595 LD.Flags += $(RPATH) -Wl,$(LibDir)
John Criswell3601f372003-07-31 20:58:51 +0000596endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000597endif
John Criswell3601f372003-07-31 20:58:51 +0000598
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000599ifdef TOOL_VERBOSE
600 C.Flags += -v
601 CXX.Flags += -v
602 LD.Flags += -v
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000603 VERBOSE := 1
604endif
605
Reid Spencer81cd0492004-10-23 20:04:14 +0000606# Adjust settings for verbose mode
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000607ifndef VERBOSE
Reid Spencerf88808a2004-10-30 09:19:36 +0000608 Verb := @
Reid Spencerfcd78152007-07-23 08:20:46 +0000609 AR.Flags += >/dev/null 2>/dev/null
Reid Spencerba6a3db2005-01-16 02:20:54 +0000610 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer100080c2004-10-25 08:27:37 +0000611else
Misha Brukman2879c292009-01-08 02:11:55 +0000612 ConfigureScriptFLAGS :=
Misha Brukman1326a7c2002-09-12 16:05:39 +0000613endif
614
Vikram S. Adved141c282002-09-18 11:55:13 +0000615# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000616ifndef KEEP_SYMBOLS
Reid Spencerf88808a2004-10-30 09:19:36 +0000617 Strip := $(PLATFORMSTRIPOPTS)
618 StripWarnMsg := "(without symbols)"
Reid Spencer247a10e2005-02-24 07:12:43 +0000619 Install.StripFlag += -s
Vikram S. Adved141c282002-09-18 11:55:13 +0000620endif
621
Reid Spencer81cd0492004-10-23 20:04:14 +0000622# Adjust linker flags for building an executable
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000623ifneq ($(HOST_OS),Darwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000624ifneq ($(DARWIN_MAJVERS),4)
Reid Spencerf206bd72004-10-22 21:01:56 +0000625ifdef TOOLNAME
Jeffrey Yasskinc4510272010-02-18 04:43:02 +0000626ifdef EXAMPLE_TOOL
627 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
628else
629 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
630endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000631endif
Nick Lewycky28c62d22009-02-26 07:44:16 +0000632endif
Nick Lewycky28c62d22009-02-26 07:44:16 +0000633endif
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000634
Reid Spencer81cd0492004-10-23 20:04:14 +0000635#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000636# Options To Invoke Tools
Reid Spencer81cd0492004-10-23 20:04:14 +0000637#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000638
Daniel Dunbar310511d2009-05-12 07:26:49 +0000639ifndef NO_PEDANTIC
Duncan Sandse532b552009-06-19 12:40:30 +0000640CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbar310511d2009-05-12 07:26:49 +0000641endif
Duncan Sandse532b552009-06-19 12:40:30 +0000642CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
643 $(EXTRA_OPTIONS)
Reid Spencerf206bd72004-10-22 21:01:56 +0000644
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000645ifeq ($(HOST_OS),HP-UX)
Duraid Madina1f898af2006-02-15 03:20:16 +0000646 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
Duraid Madina60c9a3c2005-05-16 06:38:09 +0000647endif
648
Chris Lattner11c25cf2006-05-30 16:38:06 +0000649# If we are building a universal binary on Mac OS/X, pass extra options. This
650# is useful to people that want to link the LLVM libraries into their universal
Chris Lattner65e28b32006-06-29 19:38:04 +0000651# apps.
652#
653# The following can be optionally specified:
654# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
655# For Mac OS/X 10.4 Intel machines, the traditional one is:
656# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
657# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
658# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
659# i386/ppc only.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000660ifdef UNIVERSAL
Chris Lattner65e28b32006-06-29 19:38:04 +0000661 ifndef UNIVERSAL_ARCH
662 UNIVERSAL_ARCH := i386 ppc
663 endif
664 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
665 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattner64e85f32006-06-16 21:47:59 +0000666 ifdef UNIVERSAL_SDK_PATH
667 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattner64e85f32006-06-16 21:47:59 +0000668 endif
669
670 # Building universal cannot compute dependencies automatically.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000671 DISABLE_AUTO_DEPENDENCIES=1
Evan Cheng3807bb72009-03-09 18:28:37 +0000672else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000673 ifeq ($(TARGET_OS),Darwin)
Bill Wendling207495d2009-03-12 04:10:09 +0000674 ifeq ($(ARCH),x86_64)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000675 TargetCommonOpts = -m64
Bill Wendling207495d2009-03-12 04:10:09 +0000676 else
677 ifeq ($(ARCH),x86)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000678 TargetCommonOpts = -m32
Bill Wendling207495d2009-03-12 04:10:09 +0000679 endif
Evan Cheng3807bb72009-03-09 18:28:37 +0000680 endif
681 endif
Chris Lattnerd81eba52006-04-06 06:30:15 +0000682endif
683
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000684ifeq ($(HOST_OS),SunOS)
Chris Lattner01602a12008-06-24 17:44:42 +0000685CPP.BaseFlags += -include llvm/System/Solaris.h
686endif
687
Edward O'Callaghan4ae411e2009-10-14 05:55:03 +0000688ifeq ($(HOST_OS),AuroraUX)
689CPP.BaseFlags += -include llvm/System/Solaris.h
690endif # !HOST_OS - AuroraUX.
691
Misha Brukman2879c292009-01-08 02:11:55 +0000692LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Dan Gohmanca0546f2008-10-17 01:33:43 +0000693CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
Reid Spencer6f682b72006-03-22 15:59:55 +0000694# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands9f6f4d32008-01-28 17:38:30 +0000695CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
696 $(patsubst %,-I%/include,\
Chris Lattner6379fc62008-01-28 04:18:41 +0000697 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
698 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
699 $(CPP.BaseFlags)
Reid Spencerf206bd72004-10-22 21:01:56 +0000700
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000701ifeq ($(BUILD_COMPONENT), 1)
Eric Christopher3fe69672009-08-18 03:23:40 +0000702 Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000703 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000704 Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
705 $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000706 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000707 Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000708 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000709 Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
710 $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000711 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000712else
Eric Christopher3fe69672009-08-18 03:23:40 +0000713 Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000714 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000715 Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000716 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000717 Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000718 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000719 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000720 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000721endif
722
Daniel Dunbare615b5f2010-02-23 10:28:06 +0000723BCCompile.C = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000724 $(TargetCommonOpts) $(CompileCommonOpts)
Eric Christopher3fe69672009-08-18 03:23:40 +0000725Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000726 $(TargetCommonOpts) $(CompileCommonOpts) -E
Chris Lattnerbb087952005-10-05 00:28:41 +0000727
Daniel Dunbare615b5f2010-02-23 10:28:06 +0000728BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000729 $(TargetCommonOpts) $(CompileCommonOpts)
Chris Lattner008b2de2006-09-29 18:47:13 +0000730
Misha Brukman2879c292009-01-08 02:11:55 +0000731ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
732ScriptInstall = $(INSTALL) -m 0755
Reid Spencer247a10e2005-02-24 07:12:43 +0000733DataInstall = $(INSTALL) -m 0644
Chris Lattner50475362008-01-15 23:27:40 +0000734
735# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
736# paths. In this case, the SYSPATH function (defined in
737# Makefile.config) transforms Unix paths into Windows paths.
738TableGen = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkov726440d2009-01-09 16:31:01 +0000739 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner50475362008-01-15 23:27:40 +0000740 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
741 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
742
Reid Spencerf88808a2004-10-30 09:19:36 +0000743Archive = $(AR) $(AR.Flags)
Reid Spencer32f7e422004-12-02 09:28:21 +0000744LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencerf206bd72004-10-22 21:01:56 +0000745ifdef RANLIB
Reid Spencer81cd0492004-10-23 20:04:14 +0000746Ranlib = $(RANLIB)
Reid Spencerf206bd72004-10-22 21:01:56 +0000747else
Reid Spencer81cd0492004-10-23 20:04:14 +0000748Ranlib = ranlib
John Criswell3ef61af2003-06-30 21:59:07 +0000749endif
750
Daniel Dunbar0dd2b812009-11-19 00:14:53 +0000751AliasTool = ln -s
752
Chris Lattner2f7c9632001-06-06 20:29:01 +0000753#----------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +0000754# Get the list of source files and compute object file
755# names from them.
Reid Spencer81cd0492004-10-23 20:04:14 +0000756#----------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000757
758ifndef SOURCES
759 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattner814d9ee2009-01-02 07:16:45 +0000760 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Reid Spencerf88808a2004-10-30 09:19:36 +0000761else
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000762 Sources := $(SOURCES)
Misha Brukman2879c292009-01-08 02:11:55 +0000763endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000764
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000765ifdef BUILT_SOURCES
Chris Lattner814d9ee2009-01-02 07:16:45 +0000766Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Reid Spencer81546582004-12-04 22:34:09 +0000767endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000768
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000769BaseNameSources := $(sort $(basename $(Sources)))
770
771ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000772ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
773
Reid Spencer81cd0492004-10-23 20:04:14 +0000774###############################################################################
775# DIRECTORIES: Handle recursive descent of directory structure
776###############################################################################
John Criswell3601f372003-07-31 20:58:51 +0000777
Chris Lattner2f7c9632001-06-06 20:29:01 +0000778#---------------------------------------------------------
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000779# Provide rules to make install dirs. This must be early
780# in the file so they get built before dependencies
781#---------------------------------------------------------
782
Mike Stump35f423e2009-02-12 23:45:11 +0000783$(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
Mike Stumpf7a16e92009-01-22 03:24:22 +0000784 $(Verb) $(MKDIR) $@
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000785
Reid Spencerf88808a2004-10-30 09:19:36 +0000786# To create other directories, as needed, and timestamp their creation
787%/.dir:
788 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfc66af42004-11-29 05:00:33 +0000789 $(Verb) $(DATE) > $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000790
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000791.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
792.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000793
794#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000795# Handle the DIRS options for sequential construction
Chris Lattner2f7c9632001-06-06 20:29:01 +0000796#---------------------------------------------------------
797
Misha Brukman2879c292009-01-08 02:11:55 +0000798SubDirs :=
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000799ifdef DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000800SubDirs += $(DIRS)
Chris Lattnerb9259612006-07-26 20:22:26 +0000801
802ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000803$(RecursiveTargets)::
804 $(Verb) for dir in $(DIRS); do \
Reid Spencerf206bd72004-10-22 21:01:56 +0000805 if [ ! -f $$dir/Makefile ]; then \
806 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000807 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000808 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000809 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattner539a23c2002-09-17 23:35:02 +0000810 done
Chris Lattnerb9259612006-07-26 20:22:26 +0000811else
812$(RecursiveTargets)::
813 $(Verb) for dir in $(DIRS); do \
814 ($(MAKE) -C $$dir $@ ) || exit 1; \
815 done
816endif
817
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000818endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000819
Reid Spencer81cd0492004-10-23 20:04:14 +0000820#---------------------------------------------------------
821# Handle the EXPERIMENTAL_DIRS options ensuring success
822# after each directory is built.
823#---------------------------------------------------------
824ifdef EXPERIMENTAL_DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000825$(RecursiveTargets)::
826 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer81cd0492004-10-23 20:04:14 +0000827 if [ ! -f $$dir/Makefile ]; then \
828 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000829 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000830 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000831 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000832 done
833endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000834
Reid Spencerc49a8632005-12-21 23:17:06 +0000835#-----------------------------------------------------------
Mike Stump82221d62009-01-24 00:00:41 +0000836# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
837#-----------------------------------------------------------
838ifdef OPTIONAL_PARALLEL_DIRS
839 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
840endif
841
842#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000843# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencerc49a8632005-12-21 23:17:06 +0000844#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000845ifdef PARALLEL_DIRS
846
Reid Spencerf88808a2004-10-30 09:19:36 +0000847SubDirs += $(PARALLEL_DIRS)
848
Reid Spencerd4bd3752004-12-03 20:08:48 +0000849# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencerf88808a2004-10-30 09:19:36 +0000850all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
851clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000852clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencerf88808a2004-10-30 09:19:36 +0000853install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000854uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencerd4bd3752004-12-03 20:08:48 +0000855install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Daniel Dunbar96ccc472009-09-13 22:39:27 +0000856unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000857
Reid Spencer81546582004-12-04 22:34:09 +0000858ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer81cd0492004-10-23 20:04:14 +0000859
Reid Spencer81546582004-12-04 22:34:09 +0000860$(ParallelTargets) :
Reid Spencerf88808a2004-10-30 09:19:36 +0000861 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000862 $(MKDIR) $(@D); \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000863 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswell6df35dd2003-11-25 19:32:22 +0000864 fi; \
Reid Spencer960cf7c2007-02-07 03:29:29 +0000865 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000866endif
867
Reid Spencer81cd0492004-10-23 20:04:14 +0000868#---------------------------------------------------------
869# Handle the OPTIONAL_DIRS options for directores that may
870# or may not exist.
871#---------------------------------------------------------
John Criswell8224df92003-06-27 16:58:44 +0000872ifdef OPTIONAL_DIRS
Reid Spencer100080c2004-10-25 08:27:37 +0000873
Reid Spencerf88808a2004-10-30 09:19:36 +0000874SubDirs += $(OPTIONAL_DIRS)
Reid Spencer100080c2004-10-25 08:27:37 +0000875
Chris Lattnerb9259612006-07-26 20:22:26 +0000876ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000877$(RecursiveTargets)::
878 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000879 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Reid Spencerf206bd72004-10-22 21:01:56 +0000880 if [ ! -f $$dir/Makefile ]; then \
881 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000882 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000883 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000884 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000885 fi \
John Criswell8224df92003-06-27 16:58:44 +0000886 done
Chris Lattnerb9259612006-07-26 20:22:26 +0000887else
888$(RecursiveTargets)::
889 $(Verb) for dir in $(OPTIONAL_DIRS); do \
890 ($(MAKE) -C$$dir $@ ) || exit 1; \
891 done
892endif
John Criswell8224df92003-06-27 16:58:44 +0000893endif
894
Reid Spencercc51e7b2004-08-20 09:20:05 +0000895#---------------------------------------------------------
896# Handle the CONFIG_FILES options
897#---------------------------------------------------------
898ifdef CONFIG_FILES
Reid Spencercc51e7b2004-08-20 09:20:05 +0000899
Reid Spencera79819d2007-02-06 18:53:14 +0000900ifdef NO_INSTALL
901install-local::
902 $(Echo) Install circumvented with NO_INSTALL
903uninstall-local::
904 $(Echo) UnInstall circumvented with NO_INSTALL
905else
Reid Spencerba6a3db2005-01-16 02:20:54 +0000906install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
907 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000908 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000909 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000910 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000911 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000912 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencer39d6a612004-11-23 05:59:53 +0000913 else \
914 $(ECHO) Error: cannot find config file $${file}. ; \
915 fi \
Reid Spencercc51e7b2004-08-20 09:20:05 +0000916 done
Reid Spencer81cd0492004-10-23 20:04:14 +0000917
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000918uninstall-local::
Reid Spencerba6a3db2005-01-16 02:20:54 +0000919 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000920 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000921 $(RM) -f $(PROJ_etcdir)/$${file} ; \
Reid Spencer12a3a052004-10-24 07:53:21 +0000922 done
Reid Spencera79819d2007-02-06 18:53:14 +0000923endif
Reid Spencer12a3a052004-10-24 07:53:21 +0000924
Reid Spencercc51e7b2004-08-20 09:20:05 +0000925endif
926
Reid Spencer81cd0492004-10-23 20:04:14 +0000927###############################################################################
Reid Spencera80f1672005-05-19 00:37:31 +0000928# Set up variables for building libararies
929###############################################################################
930
931#---------------------------------------------------------
Reid Spencera80f1672005-05-19 00:37:31 +0000932# Define various command line options pertaining to the
Misha Brukman2879c292009-01-08 02:11:55 +0000933# libraries needed when linking. There are "Proj" libs
934# (defined by the user's project) and "LLVM" libs (defined
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000935# by the LLVM project).
Reid Spencera80f1672005-05-19 00:37:31 +0000936#---------------------------------------------------------
Andrew Lenharth6b62b472005-08-13 05:09:50 +0000937
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000938ifdef USEDLIBS
Reid Spencera80f1672005-05-19 00:37:31 +0000939ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
940ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000941ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
942ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
943endif
944
945ifdef LLVMLIBS
Reid Spencera80f1672005-05-19 00:37:31 +0000946LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
947LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
Reid Spencera80f1672005-05-19 00:37:31 +0000948LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
Reid Spencera80f1672005-05-19 00:37:31 +0000949LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000950endif
951
Daniel Dunbar78caa022008-10-03 19:11:19 +0000952ifndef IS_CLEANING_TARGET
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000953ifdef LINK_COMPONENTS
Chris Lattner68c97542006-09-04 05:23:20 +0000954
955# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
956# clean in tools, then do a make in tools (instead of at the top level).
957$(LLVM_CONFIG):
958 @echo "*** llvm-config doesn't exist - rebuilding it."
959 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greifc848f9e2008-02-27 13:34:15 +0000960
Chris Lattner68c97542006-09-04 05:23:20 +0000961$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
962
Mikhail Glushenkovab6f8de2009-03-03 10:03:27 +0000963LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
964LLVMLibsPaths += $(LLVM_CONFIG) \
Misha Brukman5906bc12009-08-17 15:31:24 +0000965 $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000966endif
Chris Lattner9a4a92e2006-09-04 04:50:10 +0000967endif
Reid Spencera80f1672005-05-19 00:37:31 +0000968
969###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000970# Library Build Rules: Four ways to build a library
971###############################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000972
Reid Spencerd78077d2004-12-05 05:17:22 +0000973#---------------------------------------------------------
974# Bytecode Module Targets:
975# If the user set MODULE_NAME then they want to build a
976# bytecode module from the sources. We compile all the
977# sources and link it together into a single bytecode
978# module.
979#---------------------------------------------------------
980
981ifdef MODULE_NAME
Daniel Dunbare615b5f2010-02-23 10:28:06 +0000982ifeq ($(strip $(LLVMCC)),)
983$(warning Modules require LLVM capable compiler but none is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +0000984else
Reid Spencerd78077d2004-12-05 05:17:22 +0000985
986Module := $(LibDir)/$(MODULE_NAME).bc
Daniel Dunbar8657a022010-02-23 09:28:50 +0000987LinkModule := $(LLVMLD) -r
Reid Spencer78ede562006-04-12 18:21:35 +0000988
Reid Spencerd78077d2004-12-05 05:17:22 +0000989
990ifdef EXPORTED_SYMBOL_FILE
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000991LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencerd78077d2004-12-05 05:17:22 +0000992endif
993
Reid Spencerb63d0c42007-02-09 15:52:07 +0000994$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
Reid Spencer83745dd2005-05-13 18:32:54 +0000995 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencerd78077d2004-12-05 05:17:22 +0000996 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
997
998all-local:: $(Module)
999
1000clean-local::
1001ifneq ($(strip $(Module)),)
1002 -$(Verb) $(RM) -f $(Module)
1003endif
1004
Reid Spencerefe3a822004-12-13 07:38:07 +00001005ifdef BYTECODE_DESTINATION
1006ModuleDestDir := $(BYTECODE_DESTINATION)
1007else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001008ModuleDestDir := $(PROJ_libdir)
Reid Spencerefe3a822004-12-13 07:38:07 +00001009endif
Reid Spencerd78077d2004-12-05 05:17:22 +00001010
Reid Spencera79819d2007-02-06 18:53:14 +00001011ifdef NO_INSTALL
1012install-local::
1013 $(Echo) Install circumvented with NO_INSTALL
1014uninstall-local::
1015 $(Echo) Uninstall circumvented with NO_INSTALL
1016else
Reid Spencerefe3a822004-12-13 07:38:07 +00001017DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1018
1019install-module:: $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +00001020install-local:: $(DestModule)
1021
Misha Brukman2879c292009-01-08 02:11:55 +00001022$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencerd78077d2004-12-05 05:17:22 +00001023 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencerd77a4c02005-02-24 21:30:37 +00001024 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +00001025
1026uninstall-local::
1027 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1028 -$(Verb) $(RM) -f $(DestModule)
Reid Spencera79819d2007-02-06 18:53:14 +00001029endif
Reid Spencerd78077d2004-12-05 05:17:22 +00001030
1031endif
Reid Spencere9fa5442005-02-14 21:54:08 +00001032endif
Brian Gaekeecc92bf2004-01-22 22:53:48 +00001033
Reid Spencer81cd0492004-10-23 20:04:14 +00001034# if we're building a library ...
Chris Lattner2f7c9632001-06-06 20:29:01 +00001035ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +00001036
Misha Brukman5906bc12009-08-17 15:31:24 +00001037# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +00001038LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer87e645c2005-01-11 04:31:07 +00001039ifdef LOADABLE_MODULE
Nick Lewycky28c62d22009-02-26 07:44:16 +00001040LibName.A := $(LibDir)/$(LIBRARYNAME).a
1041LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer87e645c2005-01-11 04:31:07 +00001042else
Reid Spencerf88808a2004-10-30 09:19:36 +00001043LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
Nick Lewycky28c62d22009-02-26 07:44:16 +00001044LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
1045endif
Reid Spencerf88808a2004-10-30 09:19:36 +00001046LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer32f7e422004-12-02 09:28:21 +00001047LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnere6e193ca2002-09-16 22:34:56 +00001048
Reid Spencer81cd0492004-10-23 20:04:14 +00001049#---------------------------------------------------------
1050# Shared Library Targets:
1051# If the user asked for a shared library to be built
1052# with the SHARED_LIBRARY variable, then we provide
1053# targets for building them.
1054#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001055ifdef SHARED_LIBRARY
1056
Nick Lewycky28c62d22009-02-26 07:44:16 +00001057all-local:: $(LibName.SO)
Reid Spencerf206bd72004-10-22 21:01:56 +00001058
Reid Spencera80f1672005-05-19 00:37:31 +00001059ifdef LINK_LIBS_IN_SHARED
Reid Spencere6458c32006-08-07 23:12:15 +00001060ifdef LOADABLE_MODULE
Chris Lattner7cab3de2006-11-15 21:04:15 +00001061SharedLibKindMessage := "Loadable Module"
Reid Spencere6458c32006-08-07 23:12:15 +00001062else
1063SharedLibKindMessage := "Shared Library"
1064endif
Nick Lewycky28c62d22009-02-26 07:44:16 +00001065$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
Reid Spencere6458c32006-08-07 23:12:15 +00001066 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1067 $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001068 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Torok Edwin49db7382009-05-26 19:11:47 +00001069 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Reid Spencera80f1672005-05-19 00:37:31 +00001070else
Nick Lewycky28c62d22009-02-26 07:44:16 +00001071$(LibName.SO): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001072 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001073 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Reid Spencera80f1672005-05-19 00:37:31 +00001074endif
Reid Spencer81cd0492004-10-23 20:04:14 +00001075
1076clean-local::
Nick Lewycky28c62d22009-02-26 07:44:16 +00001077ifneq ($(strip $(LibName.SO)),)
1078 -$(Verb) $(RM) -f $(LibName.SO)
Reid Spencer12a3a052004-10-24 07:53:21 +00001079endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001080
Reid Spencera79819d2007-02-06 18:53:14 +00001081ifdef NO_INSTALL
1082install-local::
1083 $(Echo) Install circumvented with NO_INSTALL
1084uninstall-local::
1085 $(Echo) Uninstall circumvented with NO_INSTALL
1086else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001087DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf206bd72004-10-22 21:01:56 +00001088
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001089install-local:: $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001090
Nick Lewycky28c62d22009-02-26 07:44:16 +00001091$(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001092 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001093 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001094
Misha Brukman2879c292009-01-08 02:11:55 +00001095uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001096 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001097 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
Reid Spencera79819d2007-02-06 18:53:14 +00001098endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001099endif
1100
Reid Spencer81cd0492004-10-23 20:04:14 +00001101#---------------------------------------------------------
1102# Bytecode Library Targets:
1103# If the user asked for a bytecode library to be built
Misha Brukman2879c292009-01-08 02:11:55 +00001104# with the BYTECODE_LIBRARY variable, then we provide
Reid Spencer81cd0492004-10-23 20:04:14 +00001105# targets for building them.
1106#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001107ifdef BYTECODE_LIBRARY
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001108ifeq ($(strip $(LLVMCC)),)
1109$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +00001110else
Reid Spencerf206bd72004-10-22 21:01:56 +00001111
Reid Spencer32f7e422004-12-02 09:28:21 +00001112all-local:: $(LibName.BCA)
1113
1114ifdef EXPORTED_SYMBOL_FILE
Daniel Dunbar8657a022010-02-23 09:28:50 +00001115BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer32f7e422004-12-02 09:28:21 +00001116
Reid Spencerb63d0c42007-02-09 15:52:07 +00001117$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001118 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001119 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1120 "(internalize)"
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001121 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001122 $(Verb) $(RM) -f $@
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001123 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
Reid Spencerf206bd72004-10-22 21:01:56 +00001124else
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001125$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001126 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001127 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001128 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +00001129 $(Verb) $(LArchive) $@ $(ObjectsBC)
1130
Reid Spencerf206bd72004-10-22 21:01:56 +00001131endif
1132
Reid Spencer81cd0492004-10-23 20:04:14 +00001133clean-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001134ifneq ($(strip $(LibName.BCA)),)
1135 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencer12a3a052004-10-24 07:53:21 +00001136endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001137
Reid Spencer65086be2004-12-13 07:28:21 +00001138ifdef BYTECODE_DESTINATION
1139BytecodeDestDir := $(BYTECODE_DESTINATION)
1140else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001141BytecodeDestDir := $(PROJ_libdir)
Reid Spencer65086be2004-12-13 07:28:21 +00001142endif
1143
Daniel Dunbarc25ba422009-05-12 05:35:40 +00001144DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Reid Spencer32f7e422004-12-02 09:28:21 +00001145
Reid Spencerd4bd3752004-12-03 20:08:48 +00001146install-bytecode-local:: $(DestBytecodeLib)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001147
Reid Spencera79819d2007-02-06 18:53:14 +00001148ifdef NO_INSTALL
1149install-local::
1150 $(Echo) Install circumvented with NO_INSTALL
1151uninstall-local::
1152 $(Echo) Uninstall circumvented with NO_INSTALL
1153else
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001154install-local:: $(DestBytecodeLib)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001155
Mike Stump35f423e2009-02-12 23:45:11 +00001156$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Reid Spencer32f7e422004-12-02 09:28:21 +00001157 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerdcc53752005-02-24 21:36:32 +00001158 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001159
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001160uninstall-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001161 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001162 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001163endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001164endif
Reid Spencere9fa5442005-02-14 21:54:08 +00001165endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +00001166
Reid Spencerf88808a2004-10-30 09:19:36 +00001167#---------------------------------------------------------
Chris Lattnereaae8d02009-06-16 23:00:42 +00001168# Library Targets:
1169# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1170# building an archive.
Reid Spencerf88808a2004-10-30 09:19:36 +00001171#---------------------------------------------------------
Chris Lattner1b91cbd2005-10-24 02:21:45 +00001172ifndef BUILD_ARCHIVE
Chris Lattnereaae8d02009-06-16 23:00:42 +00001173ifndef LOADABLE_MODULE
1174BUILD_ARCHIVE = 1
Reid Spencera79819d2007-02-06 18:53:14 +00001175endif
Chris Lattner76d98ba2002-07-23 17:56:16 +00001176endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +00001177
Reid Spencerf88808a2004-10-30 09:19:36 +00001178#---------------------------------------------------------
1179# Archive Library Targets:
Misha Brukman2879c292009-01-08 02:11:55 +00001180# If the user wanted a regular archive library built,
Reid Spencerf88808a2004-10-30 09:19:36 +00001181# then we provide targets for building them.
1182#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +00001183ifdef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +00001184
Reid Spencerf88808a2004-10-30 09:19:36 +00001185all-local:: $(LibName.A)
1186
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001187$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001188 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001189 -$(Verb) $(RM) -f $@
Bill Wendlingb2f724e2009-01-03 22:46:50 +00001190 $(Verb) $(Archive) $@ $(ObjectsO)
1191 $(Verb) $(Ranlib) $@
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001192
Reid Spencer81cd0492004-10-23 20:04:14 +00001193clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001194ifneq ($(strip $(LibName.A)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001195 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner2f7c9632001-06-06 20:29:01 +00001196endif
1197
Reid Spencera79819d2007-02-06 18:53:14 +00001198ifdef NO_INSTALL
1199install-local::
1200 $(Echo) Install circumvented with NO_INSTALL
1201uninstall-local::
1202 $(Echo) Uninstall circumvented with NO_INSTALL
1203else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001204DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencer12a3a052004-10-24 07:53:21 +00001205
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001206install-local:: $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001207
Mike Stump35f423e2009-02-12 23:45:11 +00001208$(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001209 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001210 $(Verb) $(MKDIR) $(PROJ_libdir)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001211 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001212
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001213uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001214 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001215 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001216endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001217endif
1218
1219# endif LIBRARYNAME
Misha Brukman2879c292009-01-08 02:11:55 +00001220endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001221
Reid Spencerdcba7782004-10-24 08:21:04 +00001222###############################################################################
1223# Tool Build Rules: Build executable tool based on TOOLNAME option
1224###############################################################################
1225
Chris Lattner07c7c192001-09-07 22:57:58 +00001226ifdef TOOLNAME
1227
Reid Spencerf88808a2004-10-30 09:19:36 +00001228#---------------------------------------------------------
1229# Set up variables for building a tool.
1230#---------------------------------------------------------
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001231TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001232ifdef EXAMPLE_TOOL
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001233ToolBuildPath := $(ExmplDir)/$(TOOLEXENAME)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001234else
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001235ToolBuildPath := $(ToolDir)/$(TOOLEXENAME)
1236endif
1237
1238# TOOLALIAS is a name to symlink (or copy) the tool to.
1239ifdef TOOLALIAS
1240ifdef EXAMPLE_TOOL
1241ToolAliasBuildPath := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1242else
1243ToolAliasBuildPath := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1244endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001245endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001246
Reid Spencerf88808a2004-10-30 09:19:36 +00001247#---------------------------------------------------------
Chris Lattner0f1958092009-02-26 17:47:49 +00001248# Prune Exports
1249#---------------------------------------------------------
1250
1251# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1252# not exporting all of the weak symbols from the binary. This reduces dyld
1253# startup time by 4x on darwin in some cases.
1254ifdef TOOL_NO_EXPORTS
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001255ifeq ($(HOST_OS),Darwin)
Chris Lattner869b6bf2009-03-10 17:15:56 +00001256
1257# Tiger tools don't support this.
1258ifneq ($(DARWIN_MAJVERS),4)
Chris Lattner0f1958092009-02-26 17:47:49 +00001259LD.Flags += -Wl,-exported_symbol -Wl,_main
1260endif
Chris Lattner869b6bf2009-03-10 17:15:56 +00001261endif
Chris Lattner0f1958092009-02-26 17:47:49 +00001262
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001263ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
Nick Lewyckyefd3e902009-10-25 03:22:00 +00001264 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner0f1958092009-02-26 17:47:49 +00001265endif
1266endif
1267
1268
1269#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +00001270# Provide targets for building the tools
1271#---------------------------------------------------------
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001272all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
John Criswell8224df92003-06-27 16:58:44 +00001273
Reid Spencer81cd0492004-10-23 20:04:14 +00001274clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001275ifneq ($(strip $(ToolBuildPath)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001276 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencer12a3a052004-10-24 07:53:21 +00001277endif
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001278ifneq ($(strip $(ToolAliasBuildPath)),)
1279 -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1280endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001281
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001282ifdef EXAMPLE_TOOL
1283$(ToolBuildPath): $(ExmplDir)/.dir
1284else
1285$(ToolBuildPath): $(ToolDir)/.dir
1286endif
1287
Chris Lattnera5d27b12006-09-04 06:39:52 +00001288$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001289 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001290 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencer10536582006-05-16 06:25:14 +00001291 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001292 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukman2879c292009-01-08 02:11:55 +00001293 $(StripWarnMsg)
Reid Spencer12a3a052004-10-24 07:53:21 +00001294
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001295ifneq ($(strip $(ToolAliasBuildPath)),)
1296$(ToolAliasBuildPath): $(ToolBuildPath)
1297 $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1298 $(Verb) $(RM) -f $(ToolAliasBuildPath)
1299 $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
1300 $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLNAME) \
1301 $(StripWarnMsg)
1302endif
1303
Reid Spencera79819d2007-02-06 18:53:14 +00001304ifdef NO_INSTALL
1305install-local::
1306 $(Echo) Install circumvented with NO_INSTALL
1307uninstall-local::
1308 $(Echo) Uninstall circumvented with NO_INSTALL
1309else
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001310DestTool = $(PROJ_bindir)/$(TOOLEXENAME)
Reid Spencer12a3a052004-10-24 07:53:21 +00001311
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001312install-local:: $(DestTool)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001313
Mike Stump35f423e2009-02-12 23:45:11 +00001314$(DestTool): $(ToolBuildPath) $(PROJ_bindir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001315 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001316 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +00001317
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001318uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001319 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001320 -$(Verb) $(RM) -f $(DestTool)
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001321
1322# TOOLALIAS install.
1323ifdef TOOLALIAS
1324DestToolAlias = $(PROJ_bindir)/$(TOOLALIAS)$(EXEEXT)
1325
1326install-local:: $(DestToolAlias)
1327
1328$(DestToolAlias): $(DestTool) $(PROJ_bindir)
1329 $(Echo) Installing $(BuildMode) $(DestToolAlias)
1330 $(Verb) $(RM) -f $(DestToolAlias)
1331 $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1332
1333uninstall-local::
1334 $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1335 -$(Verb) $(RM) -f $(DestToolAlias)
1336endif
1337
Reid Spencera79819d2007-02-06 18:53:14 +00001338endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001339endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001340
Reid Spencerf88808a2004-10-30 09:19:36 +00001341###############################################################################
Misha Brukman2879c292009-01-08 02:11:55 +00001342# Object Build Rules: Build object files based on sources
Reid Spencerf88808a2004-10-30 09:19:36 +00001343###############################################################################
1344
Duraid Madinacbbc1842006-02-15 03:23:26 +00001345# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001346ifeq ($(HOST_OS),HP-UX)
Duraid Madinacbbc1842006-02-15 03:23:26 +00001347 DISABLE_AUTO_DEPENDENCIES=1
1348endif
1349
Reid Spencerf88808a2004-10-30 09:19:36 +00001350# Provide rule sets for when dependency generation is enabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001351ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001352
Reid Spencerf88808a2004-10-30 09:19:36 +00001353#---------------------------------------------------------
Nick Lewycky28c62d22009-02-26 07:44:16 +00001354# Create .o files in the ObjDir directory from the .cpp and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001355#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001356
Chris Lattnerc23e6352007-12-31 23:58:31 +00001357DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewycky28c62d22009-02-26 07:44:16 +00001358 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greifc848f9e2008-02-27 13:34:15 +00001359
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001360# If the build succeeded, move the dependency file over, otherwise
1361# remove it.
Chris Lattnerc23e6352007-12-31 23:58:31 +00001362DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1363 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1364
Daniel Dunbar99ab0e02010-01-22 18:10:54 +00001365$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
Jakob Stoklund Olesenbefc8532009-10-04 17:54:36 +00001366 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001367 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001368 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001369
Daniel Dunbar99ab0e02010-01-22 18:10:54 +00001370$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
Chris Lattner085c7152006-06-21 20:58:03 +00001371 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001372 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001373 $(DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001374
Daniel Dunbar99ab0e02010-01-22 18:10:54 +00001375$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
Chris Lattner085c7152006-06-21 20:58:03 +00001376 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001377 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001378 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001379
Reid Spencerf88808a2004-10-30 09:19:36 +00001380#---------------------------------------------------------
Chris Lattnerf60c1702005-02-04 21:28:50 +00001381# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001382#---------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001383
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001384BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1385 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1386
1387# If the build succeeded, move the dependency file over, otherwise
1388# remove it.
1389BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1390 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1391
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001392$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001393 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001394 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1395 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1396 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001397
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001398$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001399 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001400 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1401 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1402 $(BC_DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001403
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001404$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001405 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001406 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1407 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1408 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001409
Reid Spencerf88808a2004-10-30 09:19:36 +00001410# Provide alternate rule sets if dependencies are disabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001411else
1412
Nick Lewycky28c62d22009-02-26 07:44:16 +00001413$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001414 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001415 $(Compile.CXX) $< -o $@
Reid Spencer81cd0492004-10-23 20:04:14 +00001416
Nick Lewycky28c62d22009-02-26 07:44:16 +00001417$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001418 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001419 $(Compile.CXX) $< -o $@
Chris Lattnerf60c1702005-02-04 21:28:50 +00001420
Nick Lewycky28c62d22009-02-26 07:44:16 +00001421$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001422 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001423 $(Compile.C) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +00001424
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001425$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001426 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001427 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Reid Spencerf206bd72004-10-22 21:01:56 +00001428
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001429$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001430 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001431 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Chris Lattnerf60c1702005-02-04 21:28:50 +00001432
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001433$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001434 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001435 $(BCCompile.C) $< -o $@ -S -emit-llvm
Brian Gaeke0f148bc2003-12-10 00:26:28 +00001436
Chris Lattner07c7c192001-09-07 22:57:58 +00001437endif
1438
Chris Lattner161a84e2006-06-21 21:01:20 +00001439
1440## Rules for building preprocessed (.i/.ii) outputs.
1441$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1442 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1443 $(Verb) $(Preprocess.CXX) $< -o $@
1444
1445$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1446 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1447 $(Verb) $(Preprocess.CXX) $< -o $@
1448
Reid Spencerbef61c52006-12-10 04:56:38 +00001449$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner161a84e2006-06-21 21:01:20 +00001450 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1451 $(Verb) $(Preprocess.C) $< -o $@
1452
1453
1454$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1455 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001456 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001457
1458$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1459 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001460 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001461
1462$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1463 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001464 $(Compile.C) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001465
Reid Spencer4b8067f2006-11-17 03:32:33 +00001466
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001467# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer4b8067f2006-11-17 03:32:33 +00001468ifdef DEBUG_RUNTIME
Dan Gohman40d204f2009-09-08 15:52:56 +00001469$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Reid Spencer4b8067f2006-11-17 03:32:33 +00001470 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001471 $(Verb) $(LOPT) $< -std-compile-opts -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001472else
Dan Gohman40d204f2009-09-08 15:52:56 +00001473$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001474 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001475 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001476endif
1477
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001478
Reid Spencerf88808a2004-10-30 09:19:36 +00001479#---------------------------------------------------------
1480# Provide rule to build .bc files from .ll sources,
1481# regardless of dependencies
1482#---------------------------------------------------------
1483$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001484 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001485 $(Verb) $(LLVMAS) $< -f -o $@
1486
1487###############################################################################
1488# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1489###############################################################################
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001490
Reid Spencerf206bd72004-10-22 21:01:56 +00001491ifdef TARGET
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001492TABLEGEN_INC_FILES_COMMON = 1
1493endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001494
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001495ifdef LLVMC_BUILD_AUTOGENERATED_INC
1496TABLEGEN_INC_FILES_COMMON = 1
1497endif
1498
1499ifdef TABLEGEN_INC_FILES_COMMON
1500
Reid Spencerf88808a2004-10-30 09:19:36 +00001501INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner2a023902004-12-16 17:28:50 +00001502INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1503.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001504
Misha Brukman2879c292009-01-08 02:11:55 +00001505# INCFiles rule: All of the tblgen generated files are emitted to
Chris Lattnerf86914d2004-12-16 17:38:56 +00001506# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1507# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbard395a172008-11-03 17:33:36 +00001508# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Chris Lattnerf86914d2004-12-16 17:38:56 +00001509# dependencies of the .inc files are, unless the contents of the .inc file
1510# changes.
1511$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerafdc82c2004-12-16 18:26:53 +00001512 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner2a023902004-12-16 17:28:50 +00001513
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001514endif # TABLEGEN_INC_FILES_COMMON
1515
1516ifdef TARGET
1517
1518TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1519 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1520 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1521 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1522 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1523 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1524 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1525
Rafael Espindola59e371a2009-03-10 17:58:54 +00001526# All of these files depend on tblgen and the .td files.
1527$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1528
Chris Lattner2a023902004-12-16 17:28:50 +00001529$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1530$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001531 $(Echo) "Building $(<F) register names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001532 $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001533
Chris Lattner2a023902004-12-16 17:28:50 +00001534$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1535$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001536 $(Echo) "Building $(<F) register information header with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001537 $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001538
Chris Lattner2a023902004-12-16 17:28:50 +00001539$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1540$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001541 $(Echo) "Building $(<F) register info implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001542 $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001543
Chris Lattner2a023902004-12-16 17:28:50 +00001544$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1545$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001546 $(Echo) "Building $(<F) instruction names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001547 $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001548
Chris Lattner2a023902004-12-16 17:28:50 +00001549$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1550$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001551 $(Echo) "Building $(<F) instruction information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001552 $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001553
Chris Lattner2a023902004-12-16 17:28:50 +00001554$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1555$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001556 $(Echo) "Building $(<F) assembly writer with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001557 $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001558
Chris Lattner22f937a2004-12-16 17:34:04 +00001559$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1560$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1561 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Misha Brukman2879c292009-01-08 02:11:55 +00001562 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001563
Daniel Dunbar2841ea42009-07-13 18:35:35 +00001564$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1565$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
1566 $(Echo) "Building $(<F) assembly matcher with tblgen"
1567 $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1568
Chris Lattner2a023902004-12-16 17:28:50 +00001569$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1570$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001571 $(Echo) "Building $(<F) code emitter with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001572 $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001573
Chris Lattner33f98bd2005-09-03 01:15:25 +00001574$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1575$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
Dan Gohmanb2226e22008-08-13 20:19:35 +00001576 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001577 $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001578
Daniel Dunbare8b8cce2009-11-25 04:46:58 +00001579$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1580$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir
1581 $(Echo) "Building $(<F) disassembly tables with tblgen"
1582 $(Verb) $(TableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1583
Sean Callanan82436d12010-01-29 00:21:04 +00001584$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1585$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir
1586 $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1587 $(Verb) $(TableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1588
Dan Gohmanb2226e22008-08-13 20:19:35 +00001589$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1590$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1591 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1592 $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1593
Jim Laskey9ed90322005-10-21 19:05:19 +00001594$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1595$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1596 $(Echo) "Building $(<F) subtarget information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001597 $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001598
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001599$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1600$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1601 $(Echo) "Building $(<F) calling convention information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001602 $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001603
Dale Johannesenb842d522009-02-05 01:49:45 +00001604$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
Jakob Stoklund Olesen79843052009-10-15 18:48:47 +00001605$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir
1606 $(Echo) "Building $(<F) intrinsics information with tblgen"
Dale Johannesenb842d522009-02-05 01:49:45 +00001607 $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1608
Reid Spencer81cd0492004-10-23 20:04:14 +00001609clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001610 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001611
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001612endif # TARGET
1613
1614ifdef LLVMC_BUILD_AUTOGENERATED_INC
1615
Mikhail Glushenkov2c332fe2009-04-21 19:46:10 +00001616LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1617 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001618
1619TDFiles := $(LLVMCPluginSrc) \
1620 $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1621
1622$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1623 $(TBLGEN) $(TD_COMMON)
1624 $(Echo) "Building LLVMC configuration library with tblgen"
1625 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1626
1627endif # LLVMC_BUILD_AUTOGENERATED_INC
1628
Reid Spencerf88808a2004-10-30 09:19:36 +00001629###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001630# OTHER RULES: Other rules needed
1631###############################################################################
Reid Spencerf206bd72004-10-22 21:01:56 +00001632
Chris Lattner23d47392003-01-16 21:06:18 +00001633# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +00001634ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +00001635%.ps: %.dot
Reid Spencerf206bd72004-10-22 21:01:56 +00001636 $(DOT) -Tps < $< > $@
John Criswell3ef61af2003-06-30 21:59:07 +00001637else
1638%.ps: %.dot
Reid Spencerf88808a2004-10-30 09:19:36 +00001639 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell3ef61af2003-06-30 21:59:07 +00001640endif
Chris Lattner23d47392003-01-16 21:06:18 +00001641
John Criswell0a6e6aa2003-09-06 14:44:17 +00001642# This rules ensures that header files that are removed still have a rule for
1643# which they can be "generated." This allows make to ignore them and
1644# reproduce the dependency lists.
John Criswella8391af2003-09-18 18:37:08 +00001645%.h:: ;
Chris Lattnerf60c1702005-02-04 21:28:50 +00001646%.hpp:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +00001647
Reid Spencerf88808a2004-10-30 09:19:36 +00001648# Define clean-local to clean the current directory. Note that this uses a
Misha Brukman2879c292009-01-08 02:11:55 +00001649# very conservative approach ensuring that empty variables do not cause
Reid Spencerf88808a2004-10-30 09:19:36 +00001650# errors or disastrous removal.
Reid Spencer81cd0492004-10-23 20:04:14 +00001651clean-local::
Jim Grosbach009db892008-10-02 22:56:44 +00001652ifneq ($(strip $(ObjRootDir)),)
1653 -$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencer12a3a052004-10-24 07:53:21 +00001654endif
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001655 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke8625f682004-01-21 19:53:11 +00001656ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001657 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke8625f682004-01-21 19:53:11 +00001658endif
John Criswell3ef61af2003-06-30 21:59:07 +00001659
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001660clean-all-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001661 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001662
Reid Spenceraee67e62004-11-12 02:27:36 +00001663
Reid Spencer81cd0492004-10-23 20:04:14 +00001664###############################################################################
1665# DEPENDENCIES: Include the dependency files if we should
1666###############################################################################
Chris Lattnere9d7d702003-08-22 14:10:16 +00001667ifndef DISABLE_AUTO_DEPENDENCIES
1668
Reid Spencer81cd0492004-10-23 20:04:14 +00001669# If its not one of the cleaning targets
Daniel Dunbar78caa022008-10-03 19:11:19 +00001670ifndef IS_CLEANING_TARGET
Reid Spencerf206bd72004-10-22 21:01:56 +00001671
Reid Spencer81cd0492004-10-23 20:04:14 +00001672# Get the list of dependency files
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001673DependSourceFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1674DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1675
1676# Include bitcode dependency files if using bitcode libraries
1677ifdef BYTECODE_LIBRARY
1678DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1679endif
Misha Brukmanb891ffb2003-11-09 21:36:19 +00001680
Reid Spencerfcd78152007-07-23 08:20:46 +00001681-include $(DependFiles) ""
Reid Spencer81cd0492004-10-23 20:04:14 +00001682
John Criswell48ecca62003-08-12 18:51:51 +00001683endif
Chris Lattner598222b2003-08-18 17:27:40 +00001684
Misha Brukman2879c292009-01-08 02:11:55 +00001685endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001686
Reid Spencer100080c2004-10-25 08:27:37 +00001687###############################################################################
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001688# CHECK: Running the test suite
1689###############################################################################
1690
Bill Wendlingf704f902009-04-09 18:26:57 +00001691check::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001692 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1693 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001694 $(EchoCmd) Running test suite ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001695 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001696 TESTSUITE=$(TESTSUITE) ; \
1697 else \
1698 $(EchoCmd) No Makefile in test directory ; \
1699 fi ; \
1700 else \
1701 $(EchoCmd) No test directory ; \
1702 fi
1703
Daniel Dunbar3eeddd22009-09-08 05:31:44 +00001704check-lit::
1705 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1706 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1707 $(EchoCmd) Running test suite ; \
1708 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-lit ; \
1709 else \
1710 $(EchoCmd) No Makefile in test directory ; \
1711 fi ; \
1712 else \
1713 $(EchoCmd) No test directory ; \
1714 fi
1715
Daniel Dunbarf2719e62009-09-20 06:17:21 +00001716check-all::
1717 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1718 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1719 $(EchoCmd) Running test suite ; \
1720 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1721 else \
1722 $(EchoCmd) No Makefile in test directory ; \
1723 fi ; \
1724 else \
1725 $(EchoCmd) No test directory ; \
1726 fi
1727
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001728###############################################################################
Bill Wendling8790e322009-01-04 23:12:21 +00001729# UNITTESTS: Running the unittests test suite
1730###############################################################################
1731
Bill Wendlingf704f902009-04-09 18:26:57 +00001732unittests::
Bill Wendling8790e322009-01-04 23:12:21 +00001733 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1734 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1735 $(EchoCmd) Running unittests test suite ; \
Daniel Dunbar96ccc472009-09-13 22:39:27 +00001736 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
Bill Wendling8790e322009-01-04 23:12:21 +00001737 else \
1738 $(EchoCmd) No Makefile in unittests directory ; \
1739 fi ; \
1740 else \
1741 $(EchoCmd) No unittests directory ; \
1742 fi
1743
1744###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001745# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer100080c2004-10-25 08:27:37 +00001746###############################################################################
1747
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001748#------------------------------------------------------------------------
1749# Define distribution related variables
1750#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001751DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1752DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1753TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1754DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1755DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1756DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer100080c2004-10-25 08:27:37 +00001757DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1758 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001759 Makefile.config.in configure autoconf
1760DistOther := $(notdir $(wildcard \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001761 $(PROJ_SRC_DIR)/*.h \
1762 $(PROJ_SRC_DIR)/*.td \
1763 $(PROJ_SRC_DIR)/*.def \
1764 $(PROJ_SRC_DIR)/*.ll \
1765 $(PROJ_SRC_DIR)/*.in))
Reid Spencerf88808a2004-10-30 09:19:36 +00001766DistSubDirs := $(SubDirs)
Reid Spencerfc66af42004-11-29 05:00:33 +00001767DistSources = $(Sources) $(EXTRA_DIST)
1768DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer100080c2004-10-25 08:27:37 +00001769
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001770#------------------------------------------------------------------------
1771# We MUST build distribution with OBJ_DIR != SRC_DIR
1772#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001773ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001774dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001775 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001776
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001777else
1778
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001779#------------------------------------------------------------------------
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001780# Prevent attempt to run dist targets from anywhere but the top level
1781#------------------------------------------------------------------------
1782ifneq ($(LEVEL),.)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001783dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001784 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001785else
1786
1787#------------------------------------------------------------------------
1788# Provide the top level targets
1789#------------------------------------------------------------------------
1790
Reid Spencerf88808a2004-10-30 09:19:36 +00001791dist-gzip:: $(DistTarGZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001792
Reid Spencer81546582004-12-04 22:34:09 +00001793$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001794 $(Echo) Packing gzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001795 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001796 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001797
Reid Spencerf88808a2004-10-30 09:19:36 +00001798dist-bzip2:: $(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001799
Reid Spencer81546582004-12-04 22:34:09 +00001800$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001801 $(Echo) Packing bzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001802 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001803 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001804
Reid Spencerf88808a2004-10-30 09:19:36 +00001805dist-zip:: $(DistZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001806
Reid Spencer81546582004-12-04 22:34:09 +00001807$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001808 $(Echo) Packing zipped distribution file.
1809 $(Verb) rm -f $(DistZip)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001810 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001811
Misha Brukman2879c292009-01-08 02:11:55 +00001812dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001813 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001814
Reid Spencer3a468752005-01-28 19:52:32 +00001815DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001816
Reid Spencer81546582004-12-04 22:34:09 +00001817dist-check:: $(DistTarGZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001818 $(Echo) Checking distribution tar file.
1819 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001820 $(RM) -rf $(DistCheckDir) ; \
1821 fi
Reid Spencerf88808a2004-10-30 09:19:36 +00001822 $(Verb) $(MKDIR) $(DistCheckDir)
1823 $(Verb) cd $(DistCheckDir) && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001824 $(MKDIR) $(DistCheckDir)/build && \
1825 $(MKDIR) $(DistCheckDir)/install && \
1826 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1827 cd build && \
1828 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer13f51932005-05-24 02:33:20 +00001829 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer81546582004-12-04 22:34:09 +00001830 $(MAKE) all && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001831 $(MAKE) check && \
Bill Wendling8790e322009-01-04 23:12:21 +00001832 $(MAKE) unittests && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001833 $(MAKE) install && \
1834 $(MAKE) uninstall && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001835 $(MAKE) dist-clean && \
Reid Spencerf88808a2004-10-30 09:19:36 +00001836 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001837
1838dist-clean::
Reid Spencerf88808a2004-10-30 09:19:36 +00001839 $(Echo) Cleaning distribution files
Reid Spencer81546582004-12-04 22:34:09 +00001840 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1841 $(DistCheckDir)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001842
1843endif
1844
1845#------------------------------------------------------------------------
1846# Provide the recursive distdir target for building the distribution directory
1847#------------------------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +00001848distdir: $(DistDir)/.makedistdir
1849$(DistDir)/.makedistdir: $(DistSources)
Reid Spencerf88808a2004-10-30 09:19:36 +00001850 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001851 if test -d "$(DistDir)" ; then \
1852 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1853 exit 1 ; \
1854 fi ; \
Reid Spencer81546582004-12-04 22:34:09 +00001855 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001856 $(RM) -rf $(DistDir); \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001857 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer15b85092006-04-10 16:46:04 +00001858 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001859 fi
Reid Spencerfc66af42004-11-29 05:00:33 +00001860 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukman2879c292009-01-08 02:11:55 +00001861 $(Verb) $(MKDIR) $(DistDir)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001862 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1863 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer100080c2004-10-25 08:27:37 +00001864 for file in $(DistFiles) ; do \
1865 case "$$file" in \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001866 $(PROJ_SRC_DIR)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001867 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1868 ;; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001869 $(PROJ_SRC_ROOT)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001870 file=`echo "$$file" | \
1871 sed "s#^$$srcrootstrip/##"` \
1872 ;; \
Reid Spencer100080c2004-10-25 08:27:37 +00001873 esac; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001874 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1875 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1876 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer81546582004-12-04 22:34:09 +00001877 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001878 from_dir=. ; \
Reid Spencer81546582004-12-04 22:34:09 +00001879 fi ; \
1880 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001881 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1882 to_dir="$(DistDir)/$$dir"; \
1883 $(MKDIR) "$$to_dir" ; \
1884 else \
1885 to_dir="$(DistDir)"; \
1886 fi; \
1887 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1888 if test -n "$$mid_dir" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001889 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001890 fi ; \
1891 if test -d "$$from_dir/$$file"; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001892 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1893 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001894 cd $(PROJ_SRC_DIR) ; \
1895 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1896 ( cd $$to_dir ; $(TAR) xf - ) ; \
1897 cd $(PROJ_OBJ_DIR) ; \
1898 else \
1899 cd $$from_dir ; \
1900 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1901 ( cd $$to_dir ; $(TAR) xf - ) ; \
1902 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001903 fi; \
Reid Spencer100080c2004-10-25 08:27:37 +00001904 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001905 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001906 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001907 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001908 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer81546582004-12-04 22:34:09 +00001909 $(EchoCmd) "===== WARNING: Distribution Source " \
1910 "$$from_dir/$$file Not Found!" ; \
Reid Spencerf88808a2004-10-30 09:19:36 +00001911 elif test "$(Verb)" != '@' ; then \
1912 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001913 fi; \
1914 done
Reid Spencerf88808a2004-10-30 09:19:36 +00001915 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer100080c2004-10-25 08:27:37 +00001916 if test "$$subdir" \!= "." ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001917 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001918 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer15b85092006-04-10 16:46:04 +00001919 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencer056f0222006-04-07 16:06:18 +00001920 DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001921 fi; \
1922 done
Reid Spencer81546582004-12-04 22:34:09 +00001923 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001924 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
Chris Lattnerb8e7aa02006-02-14 04:27:15 +00001925 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1926 -name .svn \) -print` ;\
Reid Spencer81546582004-12-04 22:34:09 +00001927 $(MAKE) dist-hook ; \
1928 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1929 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1930 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1931 -o ! -type d ! -perm -444 -exec \
1932 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1933 || chmod -R a+r $(DistDir) ; \
1934 fi
Reid Spencer100080c2004-10-25 08:27:37 +00001935
Reid Spencerf88808a2004-10-30 09:19:36 +00001936# This is invoked by distdir target, define it as a no-op to avoid errors if not
1937# defined by user.
Reid Spencer100080c2004-10-25 08:27:37 +00001938dist-hook::
1939
Reid Spencer23a70372004-10-22 23:06:30 +00001940endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001941
1942###############################################################################
Reid Spencer12a3a052004-10-24 07:53:21 +00001943# TOP LEVEL - targets only to apply at the top level directory
1944###############################################################################
1945
1946ifeq ($(LEVEL),.)
1947
1948#------------------------------------------------------------------------
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001949# Install support for the project's include files:
Reid Spencer12a3a052004-10-24 07:53:21 +00001950#------------------------------------------------------------------------
Reid Spencera79819d2007-02-06 18:53:14 +00001951ifdef NO_INSTALL
1952install-local::
1953 $(Echo) Install circumvented with NO_INSTALL
1954uninstall-local::
1955 $(Echo) Uninstall circumvented with NO_INSTALL
1956else
Reid Spencer12a3a052004-10-24 07:53:21 +00001957install-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001958 $(Echo) Installing include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001959 $(Verb) $(MKDIR) $(PROJ_includedir)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001960 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001961 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattner814d9ee2009-01-02 07:16:45 +00001962 for hdr in `find . -type f '!' '(' -name '*~' \
Reid Spencerc82c2cf2007-04-09 19:08:58 +00001963 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1964 grep -v .svn` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001965 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1966 if test \! -d "$$instdir" ; then \
1967 $(EchoCmd) Making install directory $$instdir ; \
1968 $(MKDIR) $$instdir ;\
1969 fi ; \
1970 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001971 done ; \
Reid Spencer12a3a052004-10-24 07:53:21 +00001972 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001973ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerc43b1d42005-02-24 03:56:32 +00001974 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer48a82f42005-02-16 15:54:03 +00001975 cd $(PROJ_OBJ_ROOT)/include && \
Reid Spencer528c9802005-12-23 22:27:56 +00001976 for hdr in `find . -type f -print | grep -v CVS` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001977 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001978 done ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001979 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001980endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001981
1982uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001983 $(Echo) Uninstalling include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001984 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1985 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer12a3a052004-10-24 07:53:21 +00001986 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattner814d9ee2009-01-02 07:16:45 +00001987 '!' '(' -name '*~' -o -name '.#*' \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001988 -o -name '*.in' ')' -print ')' | \
1989 grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001990 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001991 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1992 -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001993 fi
Reid Spencera79819d2007-02-06 18:53:14 +00001994endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001995endif
1996
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00001997check-line-length:
Gabor Greif697e94c2008-05-15 10:04:30 +00001998 @echo searching for overlength lines in files: $(Sources)
1999 @echo
2000 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00002001 egrep -n '.{81}' $(Sources) /dev/null
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00002002
Anton Korobeynikovfb801512007-04-16 18:10:23 +00002003check-for-tabs:
Gabor Greif697e94c2008-05-15 10:04:30 +00002004 @echo searching for tabs in files: $(Sources)
2005 @echo
2006 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00002007 egrep -n ' ' $(Sources) /dev/null
Gabor Greif697e94c2008-05-15 10:04:30 +00002008
Reid Spencere6bc2062007-05-02 21:29:39 +00002009check-footprint:
2010 @ls -l $(LibDir) | awk '\
2011 BEGIN { sum = 0; } \
2012 { sum += $$5; } \
2013 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2014 @ls -l $(ToolDir) | awk '\
2015 BEGIN { sum = 0; } \
2016 { sum += $$5; } \
2017 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
Reid Spencerf206bd72004-10-22 21:01:56 +00002018#------------------------------------------------------------------------
2019# Print out the directories used for building
Reid Spencerf88808a2004-10-30 09:19:36 +00002020#------------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00002021printvars::
Reid Spencerba6a3db2005-01-16 02:20:54 +00002022 $(Echo) "BuildMode : " '$(BuildMode)'
2023 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2024 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2025 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2026 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2027 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2028 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2029 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
2030 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
2031 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
2032 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencerfe0a01e2005-02-16 16:13:02 +00002033 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00002034 $(Echo) "UserTargets : " '$(UserTargets)'
2035 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2036 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2037 $(Echo) "ObjDir : " '$(ObjDir)'
2038 $(Echo) "LibDir : " '$(LibDir)'
2039 $(Echo) "ToolDir : " '$(ToolDir)'
2040 $(Echo) "ExmplDir : " '$(ExmplDir)'
2041 $(Echo) "Sources : " '$(Sources)'
2042 $(Echo) "TDFiles : " '$(TDFiles)'
2043 $(Echo) "INCFiles : " '$(INCFiles)'
2044 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencerfefb9ea2005-03-01 16:27:06 +00002045 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00002046 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
2047 $(Echo) "Compile.C : " '$(Compile.C)'
2048 $(Echo) "Archive : " '$(Archive)'
2049 $(Echo) "YaccFiles : " '$(YaccFiles)'
2050 $(Echo) "LexFiles : " '$(LexFiles)'
2051 $(Echo) "Module : " '$(Module)'
Reid Spencerb48e3f82005-08-24 10:43:10 +00002052 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
Reid Spencerece13582006-04-09 23:41:14 +00002053 $(Echo) "SubDirs : " '$(SubDirs)'
Reid Spencer200c6f92007-03-29 19:05:44 +00002054 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2055 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar0094e342009-02-21 20:42:39 +00002056
2057###
2058# Debugging
2059
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00002060# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar0094e342009-02-21 20:42:39 +00002061# definition, value and origin of XXX.
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00002062make-print-%:
Daniel Dunbar0094e342009-02-21 20:42:39 +00002063 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))