blob: 5f442d36f12b9bdbd5ca44101ea6d7bf6fff0c19 [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#--------------------------------------------------------------------
Chris Lattner661a7142004-12-03 21:05:57 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode
Reid Spencer8b5ebe52004-12-06 05:35:13 +000023LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencerd4bd3752004-12-03 20:08:48 +000024 install-local printvars uninstall-local \
Bill Wendling8790e322009-01-04 23:12:21 +000025 install-bytecode-local unittests
Chris Lattnerd0382a82007-09-26 06:10:47 +000026TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
Bill Wendling8790e322009-01-04 23:12:21 +000027 dist-zip unittests
Reid Spencerf88808a2004-10-30 09:19:36 +000028UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29InternalTargets := preconditions distdir dist-hook
Reid Spencer81cd0492004-10-23 20:04:14 +000030
Reid Spencerf88808a2004-10-30 09:19:36 +000031################################################################################
Reid Spencer77a46d22004-10-26 22:26:33 +000032# INITIALIZATION: Basic things the makefile needs
Reid Spencerf88808a2004-10-30 09:19:36 +000033################################################################################
34
35#--------------------------------------------------------------------
36# Set the VPATH so that we can find source files.
37#--------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +000038VPATH=$(PROJ_SRC_DIR)
Reid Spencer77a46d22004-10-26 22:26:33 +000039
40#--------------------------------------------------------------------
Reid Spencer7214cfd2007-06-29 14:02:07 +000041# Reset the list of suffixes we know how to build.
Reid Spencer77a46d22004-10-26 22:26:33 +000042#--------------------------------------------------------------------
43.SUFFIXES:
Nick Lewycky28c62d22009-02-26 07:44:16 +000044.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll
Reid Spencerf88808a2004-10-30 09:19:36 +000045.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer77a46d22004-10-26 22:26:33 +000046
Reid Spencer81cd0492004-10-23 20:04:14 +000047#--------------------------------------------------------------------
48# Mark all of these targets as phony to avoid implicit rule search
49#--------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +000050.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer81cd0492004-10-23 20:04:14 +000051
52#--------------------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +000053# Make sure all the user-target rules are double colon rules and
Reid Spencer77a46d22004-10-26 22:26:33 +000054# they are defined first.
Reid Spencer81cd0492004-10-23 20:04:14 +000055#--------------------------------------------------------------------
56
Reid Spencerf88808a2004-10-30 09:19:36 +000057$(UserTargets)::
Reid Spencer100080c2004-10-25 08:27:37 +000058
Reid Spencer77a46d22004-10-26 22:26:33 +000059################################################################################
60# PRECONDITIONS: that which must be built/checked first
61################################################################################
62
Reid Spencerd4bd3752004-12-03 20:08:48 +000063SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencerba6a3db2005-01-16 02:20:54 +000064 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66ConfigureScript := $(PROJ_SRC_ROOT)/configure
67ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
71MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
72PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
73ifneq ($(MakefileCommonIn),)
74PreConditions += $(MakefileCommon)
75endif
Chris Lattner68c97542006-09-04 05:23:20 +000076
Reid Spencerba6a3db2005-01-16 02:20:54 +000077ifneq ($(MakefileConfigIn),)
78PreConditions += $(MakefileConfig)
79endif
Reid Spencer77a46d22004-10-26 22:26:33 +000080
Reid Spencer53846bc2005-08-25 04:59:49 +000081preconditions: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +000082
83#------------------------------------------------------------------------
84# Make sure the BUILT_SOURCES are built first
85#------------------------------------------------------------------------
Reid Spencer97e40f12004-12-16 07:15:16 +000086$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000087
Reid Spencer48c74392007-02-07 19:13:19 +000088clean-all-local::
Reid Spencer77a46d22004-10-26 22:26:33 +000089ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +000090 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000091endif
92
Reid Spencerba6a3db2005-01-16 02:20:54 +000093ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer55814372004-12-16 08:00:46 +000094spotless:
Reid Spencer55814372004-12-16 08:00:46 +000095 $(Verb) if test -x config.status ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +000096 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +000097 $(MKDIR) .spotless.save ; \
98 $(MV) config.status .spotless.save ; \
99 $(MV) mklib .spotless.save ; \
100 $(MV) projects .spotless.save ; \
Reid Spencer55814372004-12-16 08:00:46 +0000101 $(RM) -rf * ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000102 $(MV) .spotless.save/config.status . ; \
103 $(MV) .spotless.save/mklib . ; \
104 $(MV) .spotless.save/projects . ; \
105 $(RM) -rf .spotless.save ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000106 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000107 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108 $(ConfigStatusScript) ; \
Reid Spencer55814372004-12-16 08:00:46 +0000109 else \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000110 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer55814372004-12-16 08:00:46 +0000111 fi
Reid Spencerc49a8632005-12-21 23:17:06 +0000112else
113spotless:
114 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer55814372004-12-16 08:00:46 +0000115endif
116
Reid Spencerf88808a2004-10-30 09:19:36 +0000117$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencerb7f710a2004-10-28 00:41:43 +0000118
Reid Spencer77a46d22004-10-26 22:26:33 +0000119#------------------------------------------------------------------------
120# Make sure we're not using a stale configuration
121#------------------------------------------------------------------------
Reid Spencerafdc82c2004-12-16 18:26:53 +0000122reconfigure:
Reid Spencerba6a3db2005-01-16 02:20:54 +0000123 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124 $(Verb) cd $(PROJ_OBJ_ROOT) && \
125 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000127 fi ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000128 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129 $(ConfigStatusScript)
130
Anton Korobeynikov28381c02009-08-14 18:53:19 +0000131# FIXME: The {PIC16,MSP430}/AsmPrinter line here is a hack to force a reconfigure to pick
Daniel Dunbard8186682009-08-13 17:22:49 +0000132# up AsmPrinter changes. Remove it after a reasonable delay from 2009-08-13.
133
Reid Spencerf88808a2004-10-30 09:19:36 +0000134.PRECIOUS: $(ConfigStatusScript)
Anton Korobeynikov28381c02009-08-14 18:53:19 +0000135$(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 +0000136 $(Echo) Reconfiguring with $<
Reid Spencerba6a3db2005-01-16 02:20:54 +0000137 $(Verb) cd $(PROJ_OBJ_ROOT) && \
138 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
139 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000140 fi ; \
Reid Spencer50f34872004-11-29 12:37:44 +0000141 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
142 $(ConfigStatusScript)
Reid Spencer77a46d22004-10-26 22:26:33 +0000143
Reid Spencer83bde552005-08-25 04:44:18 +0000144#------------------------------------------------------------------------
Reid Spencer77a46d22004-10-26 22:26:33 +0000145# Make sure the configuration makefile is up to date
146#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000147ifneq ($(MakefileConfigIn),)
148$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000149 $(Echo) Regenerating $@
Reid Spencerba6a3db2005-01-16 02:20:54 +0000150 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
151endif
152
153ifneq ($(MakefileCommonIn),)
154$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
155 $(Echo) Regenerating $@
156 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
157endif
Reid Spencer77a46d22004-10-26 22:26:33 +0000158
159#------------------------------------------------------------------------
160# If the Makefile in the source tree has been updated, copy it over into the
161# build tree. But, only do this if the source and object makefiles differ
162#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000163ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer77a46d22004-10-26 22:26:33 +0000164
Gordon Henriksen04e38cf2008-03-10 15:58:40 +0000165Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
Reid Spencerf88808a2004-10-30 09:19:36 +0000166 $(Echo) "Updating Makefile"
167 $(Verb) $(MKDIR) $(@D)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000168 $(Verb) $(CP) -f $< $@
Reid Spencer77a46d22004-10-26 22:26:33 +0000169
170# Copy the Makefile.* files unless we're in the root directory which avoids
171# the copying of Makefile.config.in or other things that should be explicitly
172# taken care of.
Reid Spencerba6a3db2005-01-16 02:20:54 +0000173$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
Reid Spencerd94bb332004-10-26 23:10:00 +0000174 @case '$?' in \
175 *Makefile.rules) ;; \
176 *.in) ;; \
Gordon Henriksen04e38cf2008-03-10 15:58:40 +0000177 *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000178 $(MKDIR) $(@D) ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000179 $(CP) -f $< $@ ;; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000180 esac
Gabor Greifc848f9e2008-02-27 13:34:15 +0000181
Reid Spencer77a46d22004-10-26 22:26:33 +0000182endif
183
184#------------------------------------------------------------------------
185# Set up the basic dependencies
186#------------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000187$(UserTargets):: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +0000188
189all:: all-local
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000190clean:: clean-local
Reid Spencer9d0c1e02004-11-02 16:36:03 +0000191clean-all:: clean-local clean-all-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000192install:: install-local
193uninstall:: uninstall-local
Misha Brukman2879c292009-01-08 02:11:55 +0000194install-local:: all-local
Reid Spencerd4bd3752004-12-03 20:08:48 +0000195install-bytecode:: install-bytecode-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000196
197###############################################################################
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000198# LLVMC: Provide rules for compiling llvmc plugins
199###############################################################################
200
201ifdef LLVMC_PLUGIN
202
203LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
Mikhail Glushenkov248c4142009-06-23 20:46:48 +0000204CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000205REQUIRES_EH := 1
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000206
207ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
208 LD.Flags += -lCompilerDriver
209endif
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000210
211# Build a dynamic library if the user runs `make` directly from the plugin
212# directory.
213ifndef LLVMC_BUILTIN_PLUGIN
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000214 LOADABLE_MODULE = 1
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000215endif
216
217# TableGen stuff...
218ifneq ($(BUILT_SOURCES),)
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000219 LLVMC_BUILD_AUTOGENERATED_INC=1
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000220endif
221
222endif # LLVMC_PLUGIN
223
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000224ifdef LLVMC_BASED_DRIVER
225
226TOOLNAME = $(LLVMC_BASED_DRIVER)
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000227
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000228REQUIRES_EH := 1
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000229
230ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
231 LD.Flags += -lCompilerDriver
232else
233 LLVMLIBS = CompilerDriver.a
234 LINK_COMPONENTS = support system
235endif
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000236
237# Preprocessor magic that generates references to static variables in built-in
238# plugins.
239ifneq ($(LLVMC_BUILTIN_PLUGINS),)
240
241USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
242
243LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
244LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
245LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
246LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
247LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
248
249ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
250CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
251endif
252
253ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
254CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
255endif
256
257ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
258CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
259endif
260
261ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
262CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
263endif
264
265ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
266CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
267endif
268
269endif
270
271endif # LLVMC_BASED_DRIVER
272
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000273###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000274# VARIABLES: Set up various variables based on configuration data
275###############################################################################
276
Daniel Dunbar78caa022008-10-03 19:11:19 +0000277# Variable for if this make is for a "cleaning" target
278ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
279 IS_CLEANING_TARGET=1
280endif
281
Reid Spencer81cd0492004-10-23 20:04:14 +0000282#--------------------------------------------------------------------
283# Variables derived from configuration we are building
Chris Lattner2f7c9632001-06-06 20:29:01 +0000284#--------------------------------------------------------------------
285
Reid Spencerfd8e6412007-07-10 07:19:53 +0000286CPP.Defines :=
Chris Lattner213a85b2006-05-24 23:02:40 +0000287# OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
288# this can be overridden on the make command line.
Evan Cheng40c52322009-04-20 22:16:40 +0000289ifndef OPTIMIZE_OPTION
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000290 ifneq ($(HOST_OS),MingW)
Evan Cheng40c52322009-04-20 22:16:40 +0000291 OPTIMIZE_OPTION := -O3
292 else
293 OPTIMIZE_OPTION := -O2
294 endif
Reid Spencer187b4ad2006-06-01 19:03:21 +0000295endif
Chris Lattner213a85b2006-05-24 23:02:40 +0000296
David Greene80f48bd2009-04-17 14:49:22 +0000297ifeq ($(ENABLE_OPTIMIZED),1)
298 BuildMode := Release
299 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000300 ifneq ($(HOST_OS),FreeBSD)
301 ifneq ($(HOST_OS),Darwin)
David Greene80f48bd2009-04-17 14:49:22 +0000302 OmitFramePointer := -fomit-frame-pointer
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000303 endif
David Greene80f48bd2009-04-17 14:49:22 +0000304 endif
305
306 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Cheng57709502009-04-20 22:49:59 +0000307 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
308 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000309 #ifeq ($(HOST_OS),Darwin)
Evan Cheng40c52322009-04-20 22:16:40 +0000310 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
311 #endif
David Greene80f48bd2009-04-17 14:49:22 +0000312 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
313 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
314 LD.Flags += $(OPTIMIZE_OPTION)
315else
316 BuildMode := Debug
317 CXX.Flags += -g
318 C.Flags += -g
319 LD.Flags += -g
320 KEEP_SYMBOLS := 1
321endif
322
323ifeq ($(ENABLE_PROFILING),1)
324 BuildMode := $(BuildMode)+Profile
325 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
326 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
327 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
328 KEEP_SYMBOLS := 1
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000329endif
330
Daniel Dunbar61e0a822008-09-02 17:35:16 +0000331#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
332# CXX.Flags += -fvisibility-inlines-hidden
333#endif
334
Reid Spencer51e6f682006-08-25 19:54:53 +0000335# IF REQUIRES_EH=1 is specified then don't disable exceptions
Reid Spencer0b6396c2006-08-25 20:56:59 +0000336ifndef REQUIRES_EH
337 CXX.Flags += -fno-exceptions
338endif
Reid Spencer51e6f682006-08-25 19:54:53 +0000339
Nicolas Geoffray43cce222009-08-19 22:04:44 +0000340ifdef REQUIRES_FRAME_POINTER
341 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
342 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
343 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
344endif
345
Reid Spencere6bc2062007-05-02 21:29:39 +0000346# IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
347ifndef REQUIRES_RTTI
Daniel Dunbar421bca32009-09-11 15:45:13 +0000348 CXX.Flags := $(filter-out -fno-rtti,$(CXX.Flags))
349 CXXFLAGS := $(filter-out -fno-rtti,$(CXXFLAGS))
Reid Spencere6bc2062007-05-02 21:29:39 +0000350endif
351
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000352ifdef ENABLE_COVERAGE
353 BuildMode := $(BuildMode)+Coverage
Chris Lattnereaae8d02009-06-16 23:00:42 +0000354 CXX.Flags += -ftest-coverage -fprofile-arcs
355 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000356endif
357
Reid Spencer15b85092006-04-10 16:46:04 +0000358# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
359# then disable assertions by defining the appropriate preprocessor symbols.
Reid Spencerece13582006-04-09 23:41:14 +0000360ifdef DISABLE_ASSERTIONS
Duncan Sands99d0b232009-03-27 11:35:00 +0000361 # Indicate that assertions are turned off using a minus sign
362 BuildMode := $(BuildMode)-Asserts
Reid Spencerfd8e6412007-07-10 07:19:53 +0000363 CPP.Defines += -DNDEBUG
Reid Spencerece13582006-04-09 23:41:14 +0000364else
Reid Spencerfd8e6412007-07-10 07:19:53 +0000365 CPP.Defines += -D_DEBUG
Chris Lattner98c79c32006-03-21 01:06:41 +0000366endif
367
Misha Brukman2879c292009-01-08 02:11:55 +0000368# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
369# configured), then enable expensive checks by defining the
David Greene869e4b52007-06-29 03:36:21 +0000370# appropriate preprocessor symbols.
David Greenecbc8ddf2007-06-28 19:36:08 +0000371ifdef ENABLE_EXPENSIVE_CHECKS
372 BuildMode := $(BuildMode)+Checks
Duncan Sands445071c2008-12-09 21:33:20 +0000373 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
David Greenecbc8ddf2007-06-28 19:36:08 +0000374endif
375
Nick Lewycky28c62d22009-02-26 07:44:16 +0000376# LOADABLE_MODULE implies several other things so we force them to be
377# defined/on.
378ifdef LOADABLE_MODULE
379 SHARED_LIBRARY := 1
Nick Lewycky28c62d22009-02-26 07:44:16 +0000380 LINK_LIBS_IN_SHARED := 1
381endif
382
383ifdef SHARED_LIBRARY
384 ENABLE_PIC := 1
385 PIC_FLAG = "(PIC)"
386endif
387
Reid Spencer05a1fe52006-12-16 22:07:52 +0000388ifeq ($(ENABLE_PIC),1)
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000389 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000390 # Nothing. Win32 defaults to PIC and warns when given -fPIC
391 else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000392 ifeq ($(HOST_OS),Darwin)
Nick Lewycky28c62d22009-02-26 07:44:16 +0000393 # Common symbols not allowed in dylib files
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000394 CXX.Flags += -fno-common
395 C.Flags += -fno-common
396 else
397 # Linux and others; pass -fPIC
398 CXX.Flags += -fPIC
399 C.Flags += -fPIC
400 endif
401 endif
Mike Stumpd1b46362009-05-08 23:08:58 +0000402else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000403 ifeq ($(HOST_OS),Darwin)
Mike Stumpd1b46362009-05-08 23:08:58 +0000404 CXX.Flags += -mdynamic-no-pic
405 C.Flags += -mdynamic-no-pic
406 endif
Reid Spencer05a1fe52006-12-16 22:07:52 +0000407endif
408
Eric Christopher3fe69672009-08-18 03:23:40 +0000409CXX.Flags += -Woverloaded-virtual
David Greenecbc8ddf2007-06-28 19:36:08 +0000410CPP.BaseFlags += $(CPP.Defines)
Reid Spencer6f682b72006-03-22 15:59:55 +0000411AR.Flags := cru
Reid Spencer81cd0492004-10-23 20:04:14 +0000412
Chris Lattnerdc5a8962006-07-27 18:19:51 +0000413# Make Floating point IEEE compliant on Alpha.
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000414ifeq ($(ARCH),Alpha)
Reid Spencer05a1fe52006-12-16 22:07:52 +0000415 CXX.Flags += -mieee
416 CPP.BaseFlags += -mieee
417ifeq ($(ENABLE_PIC),0)
418 CXX.Flags += -fPIC
419 CPP.BaseFlags += -fPIC
420endif
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000421endif
422
Andrew Lenharth0ad67b02007-01-26 13:34:50 +0000423ifeq ($(ARCH),Alpha)
424 LD.Flags += -Wl,--no-relax
425endif
426
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000427ifeq ($(HOST_OS),MingW)
Anton Korobeynikov0a0cc2d2009-05-04 10:25:30 +0000428 ifeq ($(LLVM_CROSS_COMPILING),1)
429 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
430 ifdef TOOLNAME
431 LD.Flags += -Wl,--allow-multiple-definition
432 endif
433 endif
434endif
435
Jay Foade609ab02009-05-15 18:13:31 +0000436ifdef ENABLE_EXPENSIVE_CHECKS
437 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
438 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
439 CXX.Flags := $(filter-out -fno-rtti,$(CXX.Flags))
Daniel Dunbar213f8f42009-09-03 08:41:19 +0000440 CXXFLAGS := $(filter-out -fno-rtti,$(CXXFLAGS))
Jay Foade609ab02009-05-15 18:13:31 +0000441endif
442
Reid Spencer81cd0492004-10-23 20:04:14 +0000443#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000444# Directory locations
Reid Spencer81cd0492004-10-23 20:04:14 +0000445#--------------------------------------------------------------------
Jim Grosbach009db892008-10-02 22:56:44 +0000446TargetMode :=
447ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000448 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbach009db892008-10-02 22:56:44 +0000449endif
450
451ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000452ObjDir := $(ObjRootDir)
453LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
454ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
455ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
456LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
457LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
458LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Reid Spencer2bba41c2004-12-22 05:57:21 +0000459CFERuntimeLibDir := $(LLVMGCCDIR)/lib
John Criswell3ef61af2003-06-30 21:59:07 +0000460
Reid Spencer81cd0492004-10-23 20:04:14 +0000461#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000462# Full Paths To Compiled Tools and Utilities
Reid Spencer81cd0492004-10-23 20:04:14 +0000463#--------------------------------------------------------------------
Reid Spencerb12e2902005-01-14 16:33:36 +0000464EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
465Echo = @$(EchoCmd)
Reid Spencerf88808a2004-10-30 09:19:36 +0000466ifndef LLVMAS
467LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
468endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000469ifndef TBLGEN
Reid Spencer0aa9d002006-07-26 21:14:56 +0000470 ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000471 TBLGEN := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Reid Spencer0aa9d002006-07-26 21:14:56 +0000472 else
473 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
474 endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000475endif
Misha Brukman2879c292009-01-08 02:11:55 +0000476LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Reid Spencerb63d0c42007-02-09 15:52:07 +0000477ifndef LLVMLD
Reid Spencer7cec4f22007-02-09 17:09:14 +0000478LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
Reid Spencerf88808a2004-10-30 09:19:36 +0000479endif
Chris Lattner68c97542006-09-04 05:23:20 +0000480ifndef LLVMDIS
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000481LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
482endif
483ifndef LLI
484LLI := $(LLVMToolDir)/lli$(EXEEXT)
485endif
Alkis Evlogimenos24340582005-02-27 10:21:37 +0000486ifndef LLC
487LLC := $(LLVMToolDir)/llc$(EXEEXT)
488endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000489ifndef LOPT
Alkis Evlogimenos7c7705d2004-12-13 18:08:29 +0000490LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000491endif
Alkis Evlogimenos7c04a3d2005-02-02 00:40:15 +0000492ifndef LBUGPOINT
493LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
494endif
Reid Spencer9a6fc822006-12-03 21:01:45 +0000495ifndef LUPGRADE
496LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
497endif
498ifeq ($(LLVMGCC_MAJVERS),3)
Reid Spencerbef61c52006-12-10 04:56:38 +0000499LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
500LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
Reid Spencer9a6fc822006-12-03 21:01:45 +0000501else
Reid Spencerbef61c52006-12-10 04:56:38 +0000502LLVMGCCWITHPATH := $(LLVMGCC)
503LLVMGXXWITHPATH := $(LLVMGXX)
Reid Spencer9a6fc822006-12-03 21:01:45 +0000504endif
505
Reid Spencer81cd0492004-10-23 20:04:14 +0000506#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000507# Adjust to user's request
Reid Spencer81cd0492004-10-23 20:04:14 +0000508#--------------------------------------------------------------------
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000509
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000510ifeq ($(HOST_OS),Darwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000511 DARWIN_VERSION := `sw_vers -productVersion`
512 # Strip a number like 10.4.7 to 10.4
513 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
514 # Get "4" out of 10.4 for later pieces in the makefile.
515 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendlingf3ef2c72009-03-22 08:28:45 +0000516
Julien Lerouge15833b92009-03-27 18:18:00 +0000517 SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
Evan Cheng57b14192009-09-08 18:52:20 +0000518 -dynamiclib
519 ifneq ($(ARCH),ARM)
520 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
521 endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000522else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000523 ifeq ($(HOST_OS),Cygwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000524 SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000525 -Wl,--enable-auto-import -Wl,--enable-auto-image-base
Scott Michelb1a830a2009-03-12 21:03:53 +0000526 else
527 SharedLinkOptions=-shared
528 endif
529endif
530
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000531ifeq ($(TARGET_OS),Darwin)
Evan Cheng57b14192009-09-08 18:52:20 +0000532 ifneq ($(ARCH),ARM)
533 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
534 endif
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000535endif
536
Nick Lewycky28c62d22009-02-26 07:44:16 +0000537# Adjust LD.Flags depending on the kind of library that is to be built. Note
538# that if LOADABLE_MODULE is specified then the resulting shared library can
539# be opened with dlopen.
Reid Spencere6458c32006-08-07 23:12:15 +0000540ifdef LOADABLE_MODULE
Reid Spencere6458c32006-08-07 23:12:15 +0000541 LD.Flags += -module
542endif
543
Reid Spencer87e645c2005-01-11 04:31:07 +0000544ifdef SHARED_LIBRARY
Scott Michelb1a830a2009-03-12 21:03:53 +0000545ifneq ($(DARWIN_MAJVERS),4)
Nick Lewycky7d01e392009-03-03 04:55:15 +0000546 LD.Flags += $(RPATH) -Wl,$(LibDir)
John Criswell3601f372003-07-31 20:58:51 +0000547endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000548endif
John Criswell3601f372003-07-31 20:58:51 +0000549
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000550ifdef TOOL_VERBOSE
551 C.Flags += -v
552 CXX.Flags += -v
553 LD.Flags += -v
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000554 VERBOSE := 1
555endif
556
Reid Spencer81cd0492004-10-23 20:04:14 +0000557# Adjust settings for verbose mode
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000558ifndef VERBOSE
Reid Spencerf88808a2004-10-30 09:19:36 +0000559 Verb := @
Reid Spencerfcd78152007-07-23 08:20:46 +0000560 AR.Flags += >/dev/null 2>/dev/null
Reid Spencerba6a3db2005-01-16 02:20:54 +0000561 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer100080c2004-10-25 08:27:37 +0000562else
Misha Brukman2879c292009-01-08 02:11:55 +0000563 ConfigureScriptFLAGS :=
Misha Brukman1326a7c2002-09-12 16:05:39 +0000564endif
565
Vikram S. Adved141c282002-09-18 11:55:13 +0000566# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000567ifndef KEEP_SYMBOLS
Reid Spencerf88808a2004-10-30 09:19:36 +0000568 Strip := $(PLATFORMSTRIPOPTS)
569 StripWarnMsg := "(without symbols)"
Reid Spencer247a10e2005-02-24 07:12:43 +0000570 Install.StripFlag += -s
Vikram S. Adved141c282002-09-18 11:55:13 +0000571endif
572
Reid Spencer81cd0492004-10-23 20:04:14 +0000573# Adjust linker flags for building an executable
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000574ifneq ($(HOST_OS),Darwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000575ifneq ($(DARWIN_MAJVERS),4)
Reid Spencerf206bd72004-10-22 21:01:56 +0000576ifdef TOOLNAME
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000577ifdef EXAMPLE_TOOL
Nick Lewyckyf653c2e2009-03-07 22:17:05 +0000578 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000579else
Nick Lewyckyf653c2e2009-03-07 22:17:05 +0000580 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000581endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000582endif
Nick Lewycky28c62d22009-02-26 07:44:16 +0000583endif
Nick Lewycky28c62d22009-02-26 07:44:16 +0000584endif
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000585
Reid Spencer81cd0492004-10-23 20:04:14 +0000586#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000587# Options To Invoke Tools
Reid Spencer81cd0492004-10-23 20:04:14 +0000588#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000589
Daniel Dunbar310511d2009-05-12 07:26:49 +0000590ifndef NO_PEDANTIC
Duncan Sandse532b552009-06-19 12:40:30 +0000591CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbar310511d2009-05-12 07:26:49 +0000592endif
Duncan Sandse532b552009-06-19 12:40:30 +0000593CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
594 $(EXTRA_OPTIONS)
Reid Spencerf206bd72004-10-22 21:01:56 +0000595
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000596ifeq ($(HOST_OS),HP-UX)
Duraid Madina1f898af2006-02-15 03:20:16 +0000597 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
Duraid Madina60c9a3c2005-05-16 06:38:09 +0000598endif
599
Chris Lattner11c25cf2006-05-30 16:38:06 +0000600# If we are building a universal binary on Mac OS/X, pass extra options. This
601# is useful to people that want to link the LLVM libraries into their universal
Chris Lattner65e28b32006-06-29 19:38:04 +0000602# apps.
603#
604# The following can be optionally specified:
605# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
606# For Mac OS/X 10.4 Intel machines, the traditional one is:
607# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
608# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
609# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
610# i386/ppc only.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000611ifdef UNIVERSAL
Chris Lattner65e28b32006-06-29 19:38:04 +0000612 ifndef UNIVERSAL_ARCH
613 UNIVERSAL_ARCH := i386 ppc
614 endif
615 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
616 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattner64e85f32006-06-16 21:47:59 +0000617 ifdef UNIVERSAL_SDK_PATH
618 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattner64e85f32006-06-16 21:47:59 +0000619 endif
620
621 # Building universal cannot compute dependencies automatically.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000622 DISABLE_AUTO_DEPENDENCIES=1
Evan Cheng3807bb72009-03-09 18:28:37 +0000623else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000624 ifeq ($(TARGET_OS),Darwin)
Bill Wendling207495d2009-03-12 04:10:09 +0000625 ifeq ($(ARCH),x86_64)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000626 TargetCommonOpts = -m64
Bill Wendling207495d2009-03-12 04:10:09 +0000627 else
628 ifeq ($(ARCH),x86)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000629 TargetCommonOpts = -m32
Bill Wendling207495d2009-03-12 04:10:09 +0000630 endif
Evan Cheng3807bb72009-03-09 18:28:37 +0000631 endif
632 endif
Chris Lattnerd81eba52006-04-06 06:30:15 +0000633endif
634
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000635ifeq ($(HOST_OS),SunOS)
Chris Lattner01602a12008-06-24 17:44:42 +0000636CPP.BaseFlags += -include llvm/System/Solaris.h
637endif
638
Misha Brukman2879c292009-01-08 02:11:55 +0000639LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Dan Gohmanca0546f2008-10-17 01:33:43 +0000640CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
Reid Spencer6f682b72006-03-22 15:59:55 +0000641# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands9f6f4d32008-01-28 17:38:30 +0000642CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
643 $(patsubst %,-I%/include,\
Chris Lattner6379fc62008-01-28 04:18:41 +0000644 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
645 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
646 $(CPP.BaseFlags)
Reid Spencerf206bd72004-10-22 21:01:56 +0000647
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000648ifeq ($(BUILD_COMPONENT), 1)
Eric Christopher3fe69672009-08-18 03:23:40 +0000649 Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000650 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000651 Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
652 $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000653 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000654 Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000655 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000656 Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
657 $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000658 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000659else
Eric Christopher3fe69672009-08-18 03:23:40 +0000660 Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000661 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000662 Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000663 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000664 Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000665 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000666 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000667 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000668endif
669
Eric Christopher3fe69672009-08-18 03:23:40 +0000670BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CFLAGS) \
671 $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000672 $(TargetCommonOpts) $(CompileCommonOpts)
Eric Christopher3fe69672009-08-18 03:23:40 +0000673Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000674 $(TargetCommonOpts) $(CompileCommonOpts) -E
Chris Lattnerbb087952005-10-05 00:28:41 +0000675
Eric Christopher3fe69672009-08-18 03:23:40 +0000676BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
677 $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000678 $(TargetCommonOpts) $(CompileCommonOpts)
Chris Lattner008b2de2006-09-29 18:47:13 +0000679
Misha Brukman2879c292009-01-08 02:11:55 +0000680ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
681ScriptInstall = $(INSTALL) -m 0755
Reid Spencer247a10e2005-02-24 07:12:43 +0000682DataInstall = $(INSTALL) -m 0644
Chris Lattner50475362008-01-15 23:27:40 +0000683
684# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
685# paths. In this case, the SYSPATH function (defined in
686# Makefile.config) transforms Unix paths into Windows paths.
687TableGen = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkov726440d2009-01-09 16:31:01 +0000688 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner50475362008-01-15 23:27:40 +0000689 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
690 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
691
Reid Spencerf88808a2004-10-30 09:19:36 +0000692Archive = $(AR) $(AR.Flags)
Reid Spencer32f7e422004-12-02 09:28:21 +0000693LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencerf206bd72004-10-22 21:01:56 +0000694ifdef RANLIB
Reid Spencer81cd0492004-10-23 20:04:14 +0000695Ranlib = $(RANLIB)
Reid Spencerf206bd72004-10-22 21:01:56 +0000696else
Reid Spencer81cd0492004-10-23 20:04:14 +0000697Ranlib = ranlib
John Criswell3ef61af2003-06-30 21:59:07 +0000698endif
699
Chris Lattner2f7c9632001-06-06 20:29:01 +0000700#----------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +0000701# Get the list of source files and compute object file
702# names from them.
Reid Spencer81cd0492004-10-23 20:04:14 +0000703#----------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000704
705ifndef SOURCES
706 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattner814d9ee2009-01-02 07:16:45 +0000707 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Reid Spencerf88808a2004-10-30 09:19:36 +0000708else
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000709 Sources := $(SOURCES)
Misha Brukman2879c292009-01-08 02:11:55 +0000710endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000711
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000712ifdef BUILT_SOURCES
Chris Lattner814d9ee2009-01-02 07:16:45 +0000713Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Reid Spencer81546582004-12-04 22:34:09 +0000714endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000715
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000716BaseNameSources := $(sort $(basename $(Sources)))
717
718ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000719ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
720
Reid Spencer81cd0492004-10-23 20:04:14 +0000721###############################################################################
722# DIRECTORIES: Handle recursive descent of directory structure
723###############################################################################
John Criswell3601f372003-07-31 20:58:51 +0000724
Chris Lattner2f7c9632001-06-06 20:29:01 +0000725#---------------------------------------------------------
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000726# Provide rules to make install dirs. This must be early
727# in the file so they get built before dependencies
728#---------------------------------------------------------
729
Mike Stump35f423e2009-02-12 23:45:11 +0000730$(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
Mike Stumpf7a16e92009-01-22 03:24:22 +0000731 $(Verb) $(MKDIR) $@
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000732
Reid Spencerf88808a2004-10-30 09:19:36 +0000733# To create other directories, as needed, and timestamp their creation
734%/.dir:
735 $(Verb) $(MKDIR) $* > /dev/null
Reid Spencerfc66af42004-11-29 05:00:33 +0000736 $(Verb) $(DATE) > $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000737
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000738.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
739.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000740
741#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000742# Handle the DIRS options for sequential construction
Chris Lattner2f7c9632001-06-06 20:29:01 +0000743#---------------------------------------------------------
744
Misha Brukman2879c292009-01-08 02:11:55 +0000745SubDirs :=
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000746ifdef DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000747SubDirs += $(DIRS)
Chris Lattnerb9259612006-07-26 20:22:26 +0000748
749ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000750$(RecursiveTargets)::
751 $(Verb) for dir in $(DIRS); do \
Reid Spencerf206bd72004-10-22 21:01:56 +0000752 if [ ! -f $$dir/Makefile ]; then \
753 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000754 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000755 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000756 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattner539a23c2002-09-17 23:35:02 +0000757 done
Chris Lattnerb9259612006-07-26 20:22:26 +0000758else
759$(RecursiveTargets)::
760 $(Verb) for dir in $(DIRS); do \
761 ($(MAKE) -C $$dir $@ ) || exit 1; \
762 done
763endif
764
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000765endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000766
Reid Spencer81cd0492004-10-23 20:04:14 +0000767#---------------------------------------------------------
768# Handle the EXPERIMENTAL_DIRS options ensuring success
769# after each directory is built.
770#---------------------------------------------------------
771ifdef EXPERIMENTAL_DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000772$(RecursiveTargets)::
773 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Reid Spencer81cd0492004-10-23 20:04:14 +0000774 if [ ! -f $$dir/Makefile ]; then \
775 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000776 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000777 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000778 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000779 done
780endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000781
Reid Spencerc49a8632005-12-21 23:17:06 +0000782#-----------------------------------------------------------
Mike Stump82221d62009-01-24 00:00:41 +0000783# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
784#-----------------------------------------------------------
785ifdef OPTIONAL_PARALLEL_DIRS
786 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
787endif
788
789#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000790# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencerc49a8632005-12-21 23:17:06 +0000791#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000792ifdef PARALLEL_DIRS
793
Reid Spencerf88808a2004-10-30 09:19:36 +0000794SubDirs += $(PARALLEL_DIRS)
795
Reid Spencerd4bd3752004-12-03 20:08:48 +0000796# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencerf88808a2004-10-30 09:19:36 +0000797all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
798clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000799clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencerf88808a2004-10-30 09:19:36 +0000800install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000801uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencerd4bd3752004-12-03 20:08:48 +0000802install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000803
Reid Spencer81546582004-12-04 22:34:09 +0000804ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer81cd0492004-10-23 20:04:14 +0000805
Reid Spencer81546582004-12-04 22:34:09 +0000806$(ParallelTargets) :
Reid Spencerf88808a2004-10-30 09:19:36 +0000807 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000808 $(MKDIR) $(@D); \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000809 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswell6df35dd2003-11-25 19:32:22 +0000810 fi; \
Reid Spencer960cf7c2007-02-07 03:29:29 +0000811 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000812endif
813
Reid Spencer81cd0492004-10-23 20:04:14 +0000814#---------------------------------------------------------
815# Handle the OPTIONAL_DIRS options for directores that may
816# or may not exist.
817#---------------------------------------------------------
John Criswell8224df92003-06-27 16:58:44 +0000818ifdef OPTIONAL_DIRS
Reid Spencer100080c2004-10-25 08:27:37 +0000819
Reid Spencerf88808a2004-10-30 09:19:36 +0000820SubDirs += $(OPTIONAL_DIRS)
Reid Spencer100080c2004-10-25 08:27:37 +0000821
Chris Lattnerb9259612006-07-26 20:22:26 +0000822ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000823$(RecursiveTargets)::
824 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000825 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Reid Spencerf206bd72004-10-22 21:01:56 +0000826 if [ ! -f $$dir/Makefile ]; then \
827 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000828 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000829 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000830 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000831 fi \
John Criswell8224df92003-06-27 16:58:44 +0000832 done
Chris Lattnerb9259612006-07-26 20:22:26 +0000833else
834$(RecursiveTargets)::
835 $(Verb) for dir in $(OPTIONAL_DIRS); do \
836 ($(MAKE) -C$$dir $@ ) || exit 1; \
837 done
838endif
John Criswell8224df92003-06-27 16:58:44 +0000839endif
840
Reid Spencercc51e7b2004-08-20 09:20:05 +0000841#---------------------------------------------------------
842# Handle the CONFIG_FILES options
843#---------------------------------------------------------
844ifdef CONFIG_FILES
Reid Spencercc51e7b2004-08-20 09:20:05 +0000845
Reid Spencera79819d2007-02-06 18:53:14 +0000846ifdef NO_INSTALL
847install-local::
848 $(Echo) Install circumvented with NO_INSTALL
849uninstall-local::
850 $(Echo) UnInstall circumvented with NO_INSTALL
851else
Reid Spencerba6a3db2005-01-16 02:20:54 +0000852install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
853 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000854 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000855 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000856 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000857 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Reid Spencerc43b1d42005-02-24 03:56:32 +0000858 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
Reid Spencer39d6a612004-11-23 05:59:53 +0000859 else \
860 $(ECHO) Error: cannot find config file $${file}. ; \
861 fi \
Reid Spencercc51e7b2004-08-20 09:20:05 +0000862 done
Reid Spencer81cd0492004-10-23 20:04:14 +0000863
Reid Spencerbe6a4e92004-10-28 07:57:28 +0000864uninstall-local::
Reid Spencerba6a3db2005-01-16 02:20:54 +0000865 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000866 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000867 $(RM) -f $(PROJ_etcdir)/$${file} ; \
Reid Spencer12a3a052004-10-24 07:53:21 +0000868 done
Reid Spencera79819d2007-02-06 18:53:14 +0000869endif
Reid Spencer12a3a052004-10-24 07:53:21 +0000870
Reid Spencercc51e7b2004-08-20 09:20:05 +0000871endif
872
Reid Spencer81cd0492004-10-23 20:04:14 +0000873###############################################################################
Reid Spencera80f1672005-05-19 00:37:31 +0000874# Set up variables for building libararies
875###############################################################################
876
877#---------------------------------------------------------
Reid Spencera80f1672005-05-19 00:37:31 +0000878# Define various command line options pertaining to the
Misha Brukman2879c292009-01-08 02:11:55 +0000879# libraries needed when linking. There are "Proj" libs
880# (defined by the user's project) and "LLVM" libs (defined
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000881# by the LLVM project).
Reid Spencera80f1672005-05-19 00:37:31 +0000882#---------------------------------------------------------
Andrew Lenharth6b62b472005-08-13 05:09:50 +0000883
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000884ifdef USEDLIBS
Reid Spencera80f1672005-05-19 00:37:31 +0000885ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
886ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000887ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
888ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
889endif
890
891ifdef LLVMLIBS
Reid Spencera80f1672005-05-19 00:37:31 +0000892LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
893LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
Reid Spencera80f1672005-05-19 00:37:31 +0000894LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
Reid Spencera80f1672005-05-19 00:37:31 +0000895LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000896endif
897
Daniel Dunbar78caa022008-10-03 19:11:19 +0000898ifndef IS_CLEANING_TARGET
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000899ifdef LINK_COMPONENTS
Chris Lattner68c97542006-09-04 05:23:20 +0000900
901# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
902# clean in tools, then do a make in tools (instead of at the top level).
903$(LLVM_CONFIG):
904 @echo "*** llvm-config doesn't exist - rebuilding it."
905 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greifc848f9e2008-02-27 13:34:15 +0000906
Chris Lattner68c97542006-09-04 05:23:20 +0000907$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
908
Mikhail Glushenkovab6f8de2009-03-03 10:03:27 +0000909LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
910LLVMLibsPaths += $(LLVM_CONFIG) \
Misha Brukman5906bc12009-08-17 15:31:24 +0000911 $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000912endif
Chris Lattner9a4a92e2006-09-04 04:50:10 +0000913endif
Reid Spencera80f1672005-05-19 00:37:31 +0000914
915###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000916# Library Build Rules: Four ways to build a library
917###############################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +0000918
Reid Spencerd78077d2004-12-05 05:17:22 +0000919#---------------------------------------------------------
920# Bytecode Module Targets:
921# If the user set MODULE_NAME then they want to build a
922# bytecode module from the sources. We compile all the
923# sources and link it together into a single bytecode
924# module.
925#---------------------------------------------------------
926
927ifdef MODULE_NAME
Reid Spencere9fa5442005-02-14 21:54:08 +0000928ifeq ($(strip $(LLVMGCC)),)
Reid Spencer83745dd2005-05-13 18:32:54 +0000929$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +0000930else
Reid Spencerd78077d2004-12-05 05:17:22 +0000931
932Module := $(LibDir)/$(MODULE_NAME).bc
Andrew Lenharthdddb68c2008-02-25 22:41:55 +0000933LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
Reid Spencer78ede562006-04-12 18:21:35 +0000934
Reid Spencerd78077d2004-12-05 05:17:22 +0000935
936ifdef EXPORTED_SYMBOL_FILE
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000937LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencerd78077d2004-12-05 05:17:22 +0000938endif
939
Reid Spencerb63d0c42007-02-09 15:52:07 +0000940$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
Reid Spencer83745dd2005-05-13 18:32:54 +0000941 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencerd78077d2004-12-05 05:17:22 +0000942 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
943
944all-local:: $(Module)
945
946clean-local::
947ifneq ($(strip $(Module)),)
948 -$(Verb) $(RM) -f $(Module)
949endif
950
Reid Spencerefe3a822004-12-13 07:38:07 +0000951ifdef BYTECODE_DESTINATION
952ModuleDestDir := $(BYTECODE_DESTINATION)
953else
Reid Spencerba6a3db2005-01-16 02:20:54 +0000954ModuleDestDir := $(PROJ_libdir)
Reid Spencerefe3a822004-12-13 07:38:07 +0000955endif
Reid Spencerd78077d2004-12-05 05:17:22 +0000956
Reid Spencera79819d2007-02-06 18:53:14 +0000957ifdef NO_INSTALL
958install-local::
959 $(Echo) Install circumvented with NO_INSTALL
960uninstall-local::
961 $(Echo) Uninstall circumvented with NO_INSTALL
962else
Reid Spencerefe3a822004-12-13 07:38:07 +0000963DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
964
965install-module:: $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +0000966install-local:: $(DestModule)
967
Misha Brukman2879c292009-01-08 02:11:55 +0000968$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencerd78077d2004-12-05 05:17:22 +0000969 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencerd77a4c02005-02-24 21:30:37 +0000970 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +0000971
972uninstall-local::
973 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
974 -$(Verb) $(RM) -f $(DestModule)
Reid Spencera79819d2007-02-06 18:53:14 +0000975endif
Reid Spencerd78077d2004-12-05 05:17:22 +0000976
977endif
Reid Spencere9fa5442005-02-14 21:54:08 +0000978endif
Brian Gaekeecc92bf2004-01-22 22:53:48 +0000979
Reid Spencer81cd0492004-10-23 20:04:14 +0000980# if we're building a library ...
Chris Lattner2f7c9632001-06-06 20:29:01 +0000981ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +0000982
Misha Brukman5906bc12009-08-17 15:31:24 +0000983# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000984LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer87e645c2005-01-11 04:31:07 +0000985ifdef LOADABLE_MODULE
Nick Lewycky28c62d22009-02-26 07:44:16 +0000986LibName.A := $(LibDir)/$(LIBRARYNAME).a
987LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer87e645c2005-01-11 04:31:07 +0000988else
Reid Spencerf88808a2004-10-30 09:19:36 +0000989LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
Nick Lewycky28c62d22009-02-26 07:44:16 +0000990LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
991endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000992LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer32f7e422004-12-02 09:28:21 +0000993LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnere6e193ca2002-09-16 22:34:56 +0000994
Reid Spencer81cd0492004-10-23 20:04:14 +0000995#---------------------------------------------------------
996# Shared Library Targets:
997# If the user asked for a shared library to be built
998# with the SHARED_LIBRARY variable, then we provide
999# targets for building them.
1000#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001001ifdef SHARED_LIBRARY
1002
Nick Lewycky28c62d22009-02-26 07:44:16 +00001003all-local:: $(LibName.SO)
Reid Spencerf206bd72004-10-22 21:01:56 +00001004
Reid Spencera80f1672005-05-19 00:37:31 +00001005ifdef LINK_LIBS_IN_SHARED
Reid Spencere6458c32006-08-07 23:12:15 +00001006ifdef LOADABLE_MODULE
Chris Lattner7cab3de2006-11-15 21:04:15 +00001007SharedLibKindMessage := "Loadable Module"
Reid Spencere6458c32006-08-07 23:12:15 +00001008else
1009SharedLibKindMessage := "Shared Library"
1010endif
Nick Lewycky28c62d22009-02-26 07:44:16 +00001011$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
Reid Spencere6458c32006-08-07 23:12:15 +00001012 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1013 $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001014 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Torok Edwin49db7382009-05-26 19:11:47 +00001015 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Reid Spencera80f1672005-05-19 00:37:31 +00001016else
Nick Lewycky28c62d22009-02-26 07:44:16 +00001017$(LibName.SO): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001018 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001019 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Reid Spencera80f1672005-05-19 00:37:31 +00001020endif
Reid Spencer81cd0492004-10-23 20:04:14 +00001021
1022clean-local::
Nick Lewycky28c62d22009-02-26 07:44:16 +00001023ifneq ($(strip $(LibName.SO)),)
1024 -$(Verb) $(RM) -f $(LibName.SO)
Reid Spencer12a3a052004-10-24 07:53:21 +00001025endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001026
Reid Spencera79819d2007-02-06 18:53:14 +00001027ifdef NO_INSTALL
1028install-local::
1029 $(Echo) Install circumvented with NO_INSTALL
1030uninstall-local::
1031 $(Echo) Uninstall circumvented with NO_INSTALL
1032else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001033DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf206bd72004-10-22 21:01:56 +00001034
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001035install-local:: $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001036
Nick Lewycky28c62d22009-02-26 07:44:16 +00001037$(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001038 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001039 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001040
Misha Brukman2879c292009-01-08 02:11:55 +00001041uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001042 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001043 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
Reid Spencera79819d2007-02-06 18:53:14 +00001044endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001045endif
1046
Reid Spencer81cd0492004-10-23 20:04:14 +00001047#---------------------------------------------------------
1048# Bytecode Library Targets:
1049# If the user asked for a bytecode library to be built
Misha Brukman2879c292009-01-08 02:11:55 +00001050# with the BYTECODE_LIBRARY variable, then we provide
Reid Spencer81cd0492004-10-23 20:04:14 +00001051# targets for building them.
1052#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001053ifdef BYTECODE_LIBRARY
Reid Spencere9fa5442005-02-14 21:54:08 +00001054ifeq ($(strip $(LLVMGCC)),)
Reid Spencer83745dd2005-05-13 18:32:54 +00001055$(warning Bytecode libraries require llvm-gcc which could not be found ****)
Reid Spencere9fa5442005-02-14 21:54:08 +00001056else
Reid Spencerf206bd72004-10-22 21:01:56 +00001057
Reid Spencer32f7e422004-12-02 09:28:21 +00001058all-local:: $(LibName.BCA)
1059
1060ifdef EXPORTED_SYMBOL_FILE
Reid Spencerb63d0c42007-02-09 15:52:07 +00001061BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
Chris Lattner11c25cf2006-05-30 16:38:06 +00001062 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer32f7e422004-12-02 09:28:21 +00001063
Reid Spencerb63d0c42007-02-09 15:52:07 +00001064$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001065 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001066 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1067 "(internalize)"
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001068 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001069 $(Verb) $(RM) -f $@
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001070 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
Reid Spencerf206bd72004-10-22 21:01:56 +00001071else
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001072$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001073 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001074 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001075 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +00001076 $(Verb) $(LArchive) $@ $(ObjectsBC)
1077
Reid Spencerf206bd72004-10-22 21:01:56 +00001078endif
1079
Reid Spencer81cd0492004-10-23 20:04:14 +00001080clean-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001081ifneq ($(strip $(LibName.BCA)),)
1082 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencer12a3a052004-10-24 07:53:21 +00001083endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001084
Reid Spencer65086be2004-12-13 07:28:21 +00001085ifdef BYTECODE_DESTINATION
1086BytecodeDestDir := $(BYTECODE_DESTINATION)
1087else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001088BytecodeDestDir := $(PROJ_libdir)
Reid Spencer65086be2004-12-13 07:28:21 +00001089endif
1090
Daniel Dunbarc25ba422009-05-12 05:35:40 +00001091DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Reid Spencer32f7e422004-12-02 09:28:21 +00001092
Reid Spencerd4bd3752004-12-03 20:08:48 +00001093install-bytecode-local:: $(DestBytecodeLib)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001094
Reid Spencera79819d2007-02-06 18:53:14 +00001095ifdef NO_INSTALL
1096install-local::
1097 $(Echo) Install circumvented with NO_INSTALL
1098uninstall-local::
1099 $(Echo) Uninstall circumvented with NO_INSTALL
1100else
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001101install-local:: $(DestBytecodeLib)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001102
Mike Stump35f423e2009-02-12 23:45:11 +00001103$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Reid Spencer32f7e422004-12-02 09:28:21 +00001104 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerdcc53752005-02-24 21:36:32 +00001105 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001106
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001107uninstall-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001108 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001109 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001110endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001111endif
Reid Spencere9fa5442005-02-14 21:54:08 +00001112endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +00001113
Reid Spencerf88808a2004-10-30 09:19:36 +00001114#---------------------------------------------------------
Chris Lattnereaae8d02009-06-16 23:00:42 +00001115# Library Targets:
1116# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1117# building an archive.
Reid Spencerf88808a2004-10-30 09:19:36 +00001118#---------------------------------------------------------
Chris Lattner1b91cbd2005-10-24 02:21:45 +00001119ifndef BUILD_ARCHIVE
Chris Lattnereaae8d02009-06-16 23:00:42 +00001120ifndef LOADABLE_MODULE
1121BUILD_ARCHIVE = 1
Reid Spencera79819d2007-02-06 18:53:14 +00001122endif
Chris Lattner76d98ba2002-07-23 17:56:16 +00001123endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +00001124
Reid Spencerf88808a2004-10-30 09:19:36 +00001125#---------------------------------------------------------
1126# Archive Library Targets:
Misha Brukman2879c292009-01-08 02:11:55 +00001127# If the user wanted a regular archive library built,
Reid Spencerf88808a2004-10-30 09:19:36 +00001128# then we provide targets for building them.
1129#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +00001130ifdef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +00001131
Reid Spencerf88808a2004-10-30 09:19:36 +00001132all-local:: $(LibName.A)
1133
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001134$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001135 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001136 -$(Verb) $(RM) -f $@
Bill Wendlingb2f724e2009-01-03 22:46:50 +00001137 $(Verb) $(Archive) $@ $(ObjectsO)
1138 $(Verb) $(Ranlib) $@
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001139
Reid Spencer81cd0492004-10-23 20:04:14 +00001140clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001141ifneq ($(strip $(LibName.A)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001142 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner2f7c9632001-06-06 20:29:01 +00001143endif
1144
Reid Spencera79819d2007-02-06 18:53:14 +00001145ifdef NO_INSTALL
1146install-local::
1147 $(Echo) Install circumvented with NO_INSTALL
1148uninstall-local::
1149 $(Echo) Uninstall circumvented with NO_INSTALL
1150else
Reid Spencerba6a3db2005-01-16 02:20:54 +00001151DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencer12a3a052004-10-24 07:53:21 +00001152
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001153install-local:: $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001154
Mike Stump35f423e2009-02-12 23:45:11 +00001155$(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001156 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001157 $(Verb) $(MKDIR) $(PROJ_libdir)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001158 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001159
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001160uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001161 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001162 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001163endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001164endif
1165
1166# endif LIBRARYNAME
Misha Brukman2879c292009-01-08 02:11:55 +00001167endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001168
Reid Spencerdcba7782004-10-24 08:21:04 +00001169###############################################################################
1170# Tool Build Rules: Build executable tool based on TOOLNAME option
1171###############################################################################
1172
Chris Lattner07c7c192001-09-07 22:57:58 +00001173ifdef TOOLNAME
1174
Reid Spencerf88808a2004-10-30 09:19:36 +00001175#---------------------------------------------------------
1176# Set up variables for building a tool.
1177#---------------------------------------------------------
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001178ifdef EXAMPLE_TOOL
Reid Spencer98a2d982005-05-19 21:03:11 +00001179ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001180else
Reid Spencer98a2d982005-05-19 21:03:11 +00001181ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001182endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001183
Reid Spencerf88808a2004-10-30 09:19:36 +00001184#---------------------------------------------------------
Chris Lattner0f1958092009-02-26 17:47:49 +00001185# Prune Exports
1186#---------------------------------------------------------
1187
1188# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1189# not exporting all of the weak symbols from the binary. This reduces dyld
1190# startup time by 4x on darwin in some cases.
1191ifdef TOOL_NO_EXPORTS
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001192ifeq ($(HOST_OS),Darwin)
Chris Lattner869b6bf2009-03-10 17:15:56 +00001193
1194# Tiger tools don't support this.
1195ifneq ($(DARWIN_MAJVERS),4)
Chris Lattner0f1958092009-02-26 17:47:49 +00001196LD.Flags += -Wl,-exported_symbol -Wl,_main
1197endif
Chris Lattner869b6bf2009-03-10 17:15:56 +00001198endif
Chris Lattner0f1958092009-02-26 17:47:49 +00001199
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001200ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
Chris Lattner75f9c4e2009-02-26 18:38:40 +00001201LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner0f1958092009-02-26 17:47:49 +00001202endif
1203endif
1204
1205
1206#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +00001207# Provide targets for building the tools
1208#---------------------------------------------------------
1209all-local:: $(ToolBuildPath)
John Criswell8224df92003-06-27 16:58:44 +00001210
Reid Spencer81cd0492004-10-23 20:04:14 +00001211clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001212ifneq ($(strip $(ToolBuildPath)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001213 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencer12a3a052004-10-24 07:53:21 +00001214endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001215
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001216ifdef EXAMPLE_TOOL
1217$(ToolBuildPath): $(ExmplDir)/.dir
1218else
1219$(ToolBuildPath): $(ToolDir)/.dir
1220endif
1221
Chris Lattnera5d27b12006-09-04 06:39:52 +00001222$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001223 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001224 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencer10536582006-05-16 06:25:14 +00001225 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001226 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukman2879c292009-01-08 02:11:55 +00001227 $(StripWarnMsg)
Reid Spencer12a3a052004-10-24 07:53:21 +00001228
Reid Spencera79819d2007-02-06 18:53:14 +00001229ifdef NO_INSTALL
1230install-local::
1231 $(Echo) Install circumvented with NO_INSTALL
1232uninstall-local::
1233 $(Echo) Uninstall circumvented with NO_INSTALL
1234else
Anton Korobeynikov1bb812e2009-08-05 09:37:43 +00001235DestTool = $(PROJ_bindir)/$(TOOLNAME)$(EXEEXT)
Reid Spencer12a3a052004-10-24 07:53:21 +00001236
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001237install-local:: $(DestTool)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001238
Mike Stump35f423e2009-02-12 23:45:11 +00001239$(DestTool): $(ToolBuildPath) $(PROJ_bindir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001240 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001241 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +00001242
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001243uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001244 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001245 -$(Verb) $(RM) -f $(DestTool)
Reid Spencera79819d2007-02-06 18:53:14 +00001246endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001247endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001248
Reid Spencerf88808a2004-10-30 09:19:36 +00001249###############################################################################
Misha Brukman2879c292009-01-08 02:11:55 +00001250# Object Build Rules: Build object files based on sources
Reid Spencerf88808a2004-10-30 09:19:36 +00001251###############################################################################
1252
Duraid Madinacbbc1842006-02-15 03:23:26 +00001253# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001254ifeq ($(HOST_OS),HP-UX)
Duraid Madinacbbc1842006-02-15 03:23:26 +00001255 DISABLE_AUTO_DEPENDENCIES=1
1256endif
1257
Reid Spencerf88808a2004-10-30 09:19:36 +00001258# Provide rule sets for when dependency generation is enabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001259ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001260
Reid Spencerf88808a2004-10-30 09:19:36 +00001261#---------------------------------------------------------
Nick Lewycky28c62d22009-02-26 07:44:16 +00001262# Create .o files in the ObjDir directory from the .cpp and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001263#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001264
Chris Lattnerc23e6352007-12-31 23:58:31 +00001265DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewycky28c62d22009-02-26 07:44:16 +00001266 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greifc848f9e2008-02-27 13:34:15 +00001267
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001268# If the build succeeded, move the dependency file over, otherwise
1269# remove it.
Chris Lattnerc23e6352007-12-31 23:58:31 +00001270DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1271 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1272
Nick Lewycky28c62d22009-02-26 07:44:16 +00001273$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001274 $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001275 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001276 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001277
Nick Lewycky28c62d22009-02-26 07:44:16 +00001278$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001279 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001280 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001281 $(DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001282
Nick Lewycky28c62d22009-02-26 07:44:16 +00001283$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001284 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001285 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001286 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001287
Reid Spencerf88808a2004-10-30 09:19:36 +00001288#---------------------------------------------------------
Chris Lattnerf60c1702005-02-04 21:28:50 +00001289# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001290#---------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001291
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001292BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1293 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1294
1295# If the build succeeded, move the dependency file over, otherwise
1296# remove it.
1297BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1298 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1299
Reid Spencer96edbd52006-12-30 16:31:02 +00001300$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001301 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001302 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1303 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1304 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001305
Reid Spencer96edbd52006-12-30 16:31:02 +00001306$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001307 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001308 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1309 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1310 $(BC_DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001311
Reid Spencer96edbd52006-12-30 16:31:02 +00001312$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001313 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001314 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1315 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1316 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001317
Reid Spencerf88808a2004-10-30 09:19:36 +00001318# Provide alternate rule sets if dependencies are disabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001319else
1320
Nick Lewycky28c62d22009-02-26 07:44:16 +00001321$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001322 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001323 $(Compile.CXX) $< -o $@
Reid Spencer81cd0492004-10-23 20:04:14 +00001324
Nick Lewycky28c62d22009-02-26 07:44:16 +00001325$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001326 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001327 $(Compile.CXX) $< -o $@
Chris Lattnerf60c1702005-02-04 21:28:50 +00001328
Nick Lewycky28c62d22009-02-26 07:44:16 +00001329$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001330 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001331 $(Compile.C) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +00001332
Reid Spencer96edbd52006-12-30 16:31:02 +00001333$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001334 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001335 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Reid Spencerf206bd72004-10-22 21:01:56 +00001336
Reid Spencer96edbd52006-12-30 16:31:02 +00001337$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001338 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001339 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Chris Lattnerf60c1702005-02-04 21:28:50 +00001340
Reid Spencer96edbd52006-12-30 16:31:02 +00001341$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001342 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001343 $(BCCompile.C) $< -o $@ -S -emit-llvm
Brian Gaeke0f148bc2003-12-10 00:26:28 +00001344
Chris Lattner07c7c192001-09-07 22:57:58 +00001345endif
1346
Chris Lattner161a84e2006-06-21 21:01:20 +00001347
1348## Rules for building preprocessed (.i/.ii) outputs.
1349$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1350 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1351 $(Verb) $(Preprocess.CXX) $< -o $@
1352
1353$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1354 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1355 $(Verb) $(Preprocess.CXX) $< -o $@
1356
Reid Spencerbef61c52006-12-10 04:56:38 +00001357$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner161a84e2006-06-21 21:01:20 +00001358 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1359 $(Verb) $(Preprocess.C) $< -o $@
1360
1361
1362$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1363 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001364 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001365
1366$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1367 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001368 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001369
1370$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1371 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001372 $(Compile.C) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001373
Reid Spencer4b8067f2006-11-17 03:32:33 +00001374
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001375# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer4b8067f2006-11-17 03:32:33 +00001376ifdef DEBUG_RUNTIME
Dan Gohman40d204f2009-09-08 15:52:56 +00001377$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Reid Spencer4b8067f2006-11-17 03:32:33 +00001378 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001379 $(Verb) $(LOPT) $< -std-compile-opts -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001380else
Dan Gohman40d204f2009-09-08 15:52:56 +00001381$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001382 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001383 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001384endif
1385
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001386
Reid Spencerf88808a2004-10-30 09:19:36 +00001387#---------------------------------------------------------
1388# Provide rule to build .bc files from .ll sources,
1389# regardless of dependencies
1390#---------------------------------------------------------
1391$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001392 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001393 $(Verb) $(LLVMAS) $< -f -o $@
1394
1395###############################################################################
1396# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1397###############################################################################
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001398
Reid Spencerf206bd72004-10-22 21:01:56 +00001399ifdef TARGET
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001400TABLEGEN_INC_FILES_COMMON = 1
1401endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001402
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001403ifdef LLVMC_BUILD_AUTOGENERATED_INC
1404TABLEGEN_INC_FILES_COMMON = 1
1405endif
1406
1407ifdef TABLEGEN_INC_FILES_COMMON
1408
Reid Spencerf88808a2004-10-30 09:19:36 +00001409INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner2a023902004-12-16 17:28:50 +00001410INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1411.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001412
Misha Brukman2879c292009-01-08 02:11:55 +00001413# INCFiles rule: All of the tblgen generated files are emitted to
Chris Lattnerf86914d2004-12-16 17:38:56 +00001414# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1415# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbard395a172008-11-03 17:33:36 +00001416# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Chris Lattnerf86914d2004-12-16 17:38:56 +00001417# dependencies of the .inc files are, unless the contents of the .inc file
1418# changes.
1419$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerafdc82c2004-12-16 18:26:53 +00001420 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner2a023902004-12-16 17:28:50 +00001421
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001422endif # TABLEGEN_INC_FILES_COMMON
1423
1424ifdef TARGET
1425
1426TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1427 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1428 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1429 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1430 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1431 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1432 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1433
Rafael Espindola59e371a2009-03-10 17:58:54 +00001434# All of these files depend on tblgen and the .td files.
1435$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1436
Chris Lattner2a023902004-12-16 17:28:50 +00001437$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1438$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001439 $(Echo) "Building $(<F) register names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001440 $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001441
Chris Lattner2a023902004-12-16 17:28:50 +00001442$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1443$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001444 $(Echo) "Building $(<F) register information header with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001445 $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001446
Chris Lattner2a023902004-12-16 17:28:50 +00001447$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1448$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001449 $(Echo) "Building $(<F) register info implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001450 $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001451
Chris Lattner2a023902004-12-16 17:28:50 +00001452$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1453$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001454 $(Echo) "Building $(<F) instruction names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001455 $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001456
Chris Lattner2a023902004-12-16 17:28:50 +00001457$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1458$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001459 $(Echo) "Building $(<F) instruction information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001460 $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001461
Chris Lattner2a023902004-12-16 17:28:50 +00001462$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1463$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001464 $(Echo) "Building $(<F) assembly writer with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001465 $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001466
Chris Lattner22f937a2004-12-16 17:34:04 +00001467$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1468$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1469 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Misha Brukman2879c292009-01-08 02:11:55 +00001470 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001471
Daniel Dunbar2841ea42009-07-13 18:35:35 +00001472$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1473$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
1474 $(Echo) "Building $(<F) assembly matcher with tblgen"
1475 $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1476
Chris Lattner2a023902004-12-16 17:28:50 +00001477$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1478$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001479 $(Echo) "Building $(<F) code emitter with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001480 $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001481
Chris Lattner33f98bd2005-09-03 01:15:25 +00001482$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1483$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
Dan Gohmanb2226e22008-08-13 20:19:35 +00001484 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001485 $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001486
Dan Gohmanb2226e22008-08-13 20:19:35 +00001487$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1488$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1489 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1490 $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1491
Jim Laskey9ed90322005-10-21 19:05:19 +00001492$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1493$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1494 $(Echo) "Building $(<F) subtarget information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001495 $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001496
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001497$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1498$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1499 $(Echo) "Building $(<F) calling convention information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001500 $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001501
Dale Johannesenb842d522009-02-05 01:49:45 +00001502$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1503$(ObjDir)/%GenIntrinsics.inc.tmp : Intrinsics%.td $(ObjDir)/.dir
1504 $(Echo) "Building $(<F) calling convention information with tblgen"
1505 $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1506
Reid Spencer81cd0492004-10-23 20:04:14 +00001507clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001508 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001509
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001510endif # TARGET
1511
1512ifdef LLVMC_BUILD_AUTOGENERATED_INC
1513
Mikhail Glushenkov2c332fe2009-04-21 19:46:10 +00001514LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1515 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001516
1517TDFiles := $(LLVMCPluginSrc) \
1518 $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1519
1520$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1521 $(TBLGEN) $(TD_COMMON)
1522 $(Echo) "Building LLVMC configuration library with tblgen"
1523 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1524
1525endif # LLVMC_BUILD_AUTOGENERATED_INC
1526
Reid Spencerf88808a2004-10-30 09:19:36 +00001527###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001528# OTHER RULES: Other rules needed
1529###############################################################################
Reid Spencerf206bd72004-10-22 21:01:56 +00001530
Chris Lattner23d47392003-01-16 21:06:18 +00001531# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +00001532ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +00001533%.ps: %.dot
Reid Spencerf206bd72004-10-22 21:01:56 +00001534 $(DOT) -Tps < $< > $@
John Criswell3ef61af2003-06-30 21:59:07 +00001535else
1536%.ps: %.dot
Reid Spencerf88808a2004-10-30 09:19:36 +00001537 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell3ef61af2003-06-30 21:59:07 +00001538endif
Chris Lattner23d47392003-01-16 21:06:18 +00001539
John Criswell0a6e6aa2003-09-06 14:44:17 +00001540# This rules ensures that header files that are removed still have a rule for
1541# which they can be "generated." This allows make to ignore them and
1542# reproduce the dependency lists.
John Criswella8391af2003-09-18 18:37:08 +00001543%.h:: ;
Chris Lattnerf60c1702005-02-04 21:28:50 +00001544%.hpp:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +00001545
Reid Spencerf88808a2004-10-30 09:19:36 +00001546# Define clean-local to clean the current directory. Note that this uses a
Misha Brukman2879c292009-01-08 02:11:55 +00001547# very conservative approach ensuring that empty variables do not cause
Reid Spencerf88808a2004-10-30 09:19:36 +00001548# errors or disastrous removal.
Reid Spencer81cd0492004-10-23 20:04:14 +00001549clean-local::
Jim Grosbach009db892008-10-02 22:56:44 +00001550ifneq ($(strip $(ObjRootDir)),)
1551 -$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencer12a3a052004-10-24 07:53:21 +00001552endif
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001553 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke8625f682004-01-21 19:53:11 +00001554ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001555 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke8625f682004-01-21 19:53:11 +00001556endif
John Criswell3ef61af2003-06-30 21:59:07 +00001557
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001558clean-all-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001559 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001560
Reid Spenceraee67e62004-11-12 02:27:36 +00001561
Reid Spencer81cd0492004-10-23 20:04:14 +00001562###############################################################################
1563# DEPENDENCIES: Include the dependency files if we should
1564###############################################################################
Chris Lattnere9d7d702003-08-22 14:10:16 +00001565ifndef DISABLE_AUTO_DEPENDENCIES
1566
Reid Spencer81cd0492004-10-23 20:04:14 +00001567# If its not one of the cleaning targets
Daniel Dunbar78caa022008-10-03 19:11:19 +00001568ifndef IS_CLEANING_TARGET
Reid Spencerf206bd72004-10-22 21:01:56 +00001569
Reid Spencer81cd0492004-10-23 20:04:14 +00001570# Get the list of dependency files
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001571DependSourceFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1572DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1573
1574# Include bitcode dependency files if using bitcode libraries
1575ifdef BYTECODE_LIBRARY
1576DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1577endif
Misha Brukmanb891ffb2003-11-09 21:36:19 +00001578
Reid Spencerfcd78152007-07-23 08:20:46 +00001579-include $(DependFiles) ""
Reid Spencer81cd0492004-10-23 20:04:14 +00001580
John Criswell48ecca62003-08-12 18:51:51 +00001581endif
Chris Lattner598222b2003-08-18 17:27:40 +00001582
Misha Brukman2879c292009-01-08 02:11:55 +00001583endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001584
Reid Spencer100080c2004-10-25 08:27:37 +00001585###############################################################################
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001586# CHECK: Running the test suite
1587###############################################################################
1588
Bill Wendlingf704f902009-04-09 18:26:57 +00001589check::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001590 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1591 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001592 $(EchoCmd) Running test suite ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001593 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001594 TESTSUITE=$(TESTSUITE) ; \
1595 else \
1596 $(EchoCmd) No Makefile in test directory ; \
1597 fi ; \
1598 else \
1599 $(EchoCmd) No test directory ; \
1600 fi
1601
Daniel Dunbar3eeddd22009-09-08 05:31:44 +00001602check-lit::
1603 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1604 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1605 $(EchoCmd) Running test suite ; \
1606 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-lit ; \
1607 else \
1608 $(EchoCmd) No Makefile in test directory ; \
1609 fi ; \
1610 else \
1611 $(EchoCmd) No test directory ; \
1612 fi
1613
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001614###############################################################################
Bill Wendling8790e322009-01-04 23:12:21 +00001615# UNITTESTS: Running the unittests test suite
1616###############################################################################
1617
Bill Wendlingf704f902009-04-09 18:26:57 +00001618unittests::
Bill Wendling8790e322009-01-04 23:12:21 +00001619 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1620 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1621 $(EchoCmd) Running unittests test suite ; \
1622 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests ; \
1623 else \
1624 $(EchoCmd) No Makefile in unittests directory ; \
1625 fi ; \
1626 else \
1627 $(EchoCmd) No unittests directory ; \
1628 fi
1629
1630###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001631# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer100080c2004-10-25 08:27:37 +00001632###############################################################################
1633
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001634#------------------------------------------------------------------------
1635# Define distribution related variables
1636#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001637DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1638DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1639TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1640DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1641DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1642DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer100080c2004-10-25 08:27:37 +00001643DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1644 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001645 Makefile.config.in configure autoconf
1646DistOther := $(notdir $(wildcard \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001647 $(PROJ_SRC_DIR)/*.h \
1648 $(PROJ_SRC_DIR)/*.td \
1649 $(PROJ_SRC_DIR)/*.def \
1650 $(PROJ_SRC_DIR)/*.ll \
1651 $(PROJ_SRC_DIR)/*.in))
Reid Spencerf88808a2004-10-30 09:19:36 +00001652DistSubDirs := $(SubDirs)
Reid Spencerfc66af42004-11-29 05:00:33 +00001653DistSources = $(Sources) $(EXTRA_DIST)
1654DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer100080c2004-10-25 08:27:37 +00001655
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001656#------------------------------------------------------------------------
1657# We MUST build distribution with OBJ_DIR != SRC_DIR
1658#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001659ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001660dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001661 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001662
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001663else
1664
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001665#------------------------------------------------------------------------
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001666# Prevent attempt to run dist targets from anywhere but the top level
1667#------------------------------------------------------------------------
1668ifneq ($(LEVEL),.)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001669dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001670 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001671else
1672
1673#------------------------------------------------------------------------
1674# Provide the top level targets
1675#------------------------------------------------------------------------
1676
Reid Spencerf88808a2004-10-30 09:19:36 +00001677dist-gzip:: $(DistTarGZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001678
Reid Spencer81546582004-12-04 22:34:09 +00001679$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001680 $(Echo) Packing gzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001681 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001682 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001683
Reid Spencerf88808a2004-10-30 09:19:36 +00001684dist-bzip2:: $(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001685
Reid Spencer81546582004-12-04 22:34:09 +00001686$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001687 $(Echo) Packing bzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001688 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001689 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001690
Reid Spencerf88808a2004-10-30 09:19:36 +00001691dist-zip:: $(DistZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001692
Reid Spencer81546582004-12-04 22:34:09 +00001693$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001694 $(Echo) Packing zipped distribution file.
1695 $(Verb) rm -f $(DistZip)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001696 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001697
Misha Brukman2879c292009-01-08 02:11:55 +00001698dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001699 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001700
Reid Spencer3a468752005-01-28 19:52:32 +00001701DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001702
Reid Spencer81546582004-12-04 22:34:09 +00001703dist-check:: $(DistTarGZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001704 $(Echo) Checking distribution tar file.
1705 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001706 $(RM) -rf $(DistCheckDir) ; \
1707 fi
Reid Spencerf88808a2004-10-30 09:19:36 +00001708 $(Verb) $(MKDIR) $(DistCheckDir)
1709 $(Verb) cd $(DistCheckDir) && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001710 $(MKDIR) $(DistCheckDir)/build && \
1711 $(MKDIR) $(DistCheckDir)/install && \
1712 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1713 cd build && \
1714 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer13f51932005-05-24 02:33:20 +00001715 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer81546582004-12-04 22:34:09 +00001716 $(MAKE) all && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001717 $(MAKE) check && \
Bill Wendling8790e322009-01-04 23:12:21 +00001718 $(MAKE) unittests && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001719 $(MAKE) install && \
1720 $(MAKE) uninstall && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001721 $(MAKE) dist-clean && \
Reid Spencerf88808a2004-10-30 09:19:36 +00001722 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001723
1724dist-clean::
Reid Spencerf88808a2004-10-30 09:19:36 +00001725 $(Echo) Cleaning distribution files
Reid Spencer81546582004-12-04 22:34:09 +00001726 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1727 $(DistCheckDir)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001728
1729endif
1730
1731#------------------------------------------------------------------------
1732# Provide the recursive distdir target for building the distribution directory
1733#------------------------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +00001734distdir: $(DistDir)/.makedistdir
1735$(DistDir)/.makedistdir: $(DistSources)
Reid Spencerf88808a2004-10-30 09:19:36 +00001736 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001737 if test -d "$(DistDir)" ; then \
1738 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1739 exit 1 ; \
1740 fi ; \
Reid Spencer81546582004-12-04 22:34:09 +00001741 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001742 $(RM) -rf $(DistDir); \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001743 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer15b85092006-04-10 16:46:04 +00001744 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001745 fi
Reid Spencerfc66af42004-11-29 05:00:33 +00001746 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukman2879c292009-01-08 02:11:55 +00001747 $(Verb) $(MKDIR) $(DistDir)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001748 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1749 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer100080c2004-10-25 08:27:37 +00001750 for file in $(DistFiles) ; do \
1751 case "$$file" in \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001752 $(PROJ_SRC_DIR)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001753 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1754 ;; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001755 $(PROJ_SRC_ROOT)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00001756 file=`echo "$$file" | \
1757 sed "s#^$$srcrootstrip/##"` \
1758 ;; \
Reid Spencer100080c2004-10-25 08:27:37 +00001759 esac; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001760 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1761 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1762 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer81546582004-12-04 22:34:09 +00001763 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001764 from_dir=. ; \
Reid Spencer81546582004-12-04 22:34:09 +00001765 fi ; \
1766 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001767 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1768 to_dir="$(DistDir)/$$dir"; \
1769 $(MKDIR) "$$to_dir" ; \
1770 else \
1771 to_dir="$(DistDir)"; \
1772 fi; \
1773 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1774 if test -n "$$mid_dir" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001775 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001776 fi ; \
1777 if test -d "$$from_dir/$$file"; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001778 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1779 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001780 cd $(PROJ_SRC_DIR) ; \
1781 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1782 ( cd $$to_dir ; $(TAR) xf - ) ; \
1783 cd $(PROJ_OBJ_DIR) ; \
1784 else \
1785 cd $$from_dir ; \
1786 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1787 ( cd $$to_dir ; $(TAR) xf - ) ; \
1788 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001789 fi; \
Reid Spencer100080c2004-10-25 08:27:37 +00001790 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001791 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001792 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00001793 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001794 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer81546582004-12-04 22:34:09 +00001795 $(EchoCmd) "===== WARNING: Distribution Source " \
1796 "$$from_dir/$$file Not Found!" ; \
Reid Spencerf88808a2004-10-30 09:19:36 +00001797 elif test "$(Verb)" != '@' ; then \
1798 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer100080c2004-10-25 08:27:37 +00001799 fi; \
1800 done
Reid Spencerf88808a2004-10-30 09:19:36 +00001801 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer100080c2004-10-25 08:27:37 +00001802 if test "$$subdir" \!= "." ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00001803 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001804 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer15b85092006-04-10 16:46:04 +00001805 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencer056f0222006-04-07 16:06:18 +00001806 DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00001807 fi; \
1808 done
Reid Spencer81546582004-12-04 22:34:09 +00001809 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00001810 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
Chris Lattnerb8e7aa02006-02-14 04:27:15 +00001811 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1812 -name .svn \) -print` ;\
Reid Spencer81546582004-12-04 22:34:09 +00001813 $(MAKE) dist-hook ; \
1814 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1815 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1816 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1817 -o ! -type d ! -perm -444 -exec \
1818 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1819 || chmod -R a+r $(DistDir) ; \
1820 fi
Reid Spencer100080c2004-10-25 08:27:37 +00001821
Reid Spencerf88808a2004-10-30 09:19:36 +00001822# This is invoked by distdir target, define it as a no-op to avoid errors if not
1823# defined by user.
Reid Spencer100080c2004-10-25 08:27:37 +00001824dist-hook::
1825
Reid Spencer23a70372004-10-22 23:06:30 +00001826endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001827
1828###############################################################################
Reid Spencer12a3a052004-10-24 07:53:21 +00001829# TOP LEVEL - targets only to apply at the top level directory
1830###############################################################################
1831
1832ifeq ($(LEVEL),.)
1833
1834#------------------------------------------------------------------------
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001835# Install support for the project's include files:
Reid Spencer12a3a052004-10-24 07:53:21 +00001836#------------------------------------------------------------------------
Reid Spencera79819d2007-02-06 18:53:14 +00001837ifdef NO_INSTALL
1838install-local::
1839 $(Echo) Install circumvented with NO_INSTALL
1840uninstall-local::
1841 $(Echo) Uninstall circumvented with NO_INSTALL
1842else
Reid Spencer12a3a052004-10-24 07:53:21 +00001843install-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001844 $(Echo) Installing include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001845 $(Verb) $(MKDIR) $(PROJ_includedir)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001846 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001847 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattner814d9ee2009-01-02 07:16:45 +00001848 for hdr in `find . -type f '!' '(' -name '*~' \
Reid Spencerc82c2cf2007-04-09 19:08:58 +00001849 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1850 grep -v .svn` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001851 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1852 if test \! -d "$$instdir" ; then \
1853 $(EchoCmd) Making install directory $$instdir ; \
1854 $(MKDIR) $$instdir ;\
1855 fi ; \
1856 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001857 done ; \
Reid Spencer12a3a052004-10-24 07:53:21 +00001858 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001859ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerc43b1d42005-02-24 03:56:32 +00001860 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer48a82f42005-02-16 15:54:03 +00001861 cd $(PROJ_OBJ_ROOT)/include && \
Reid Spencer528c9802005-12-23 22:27:56 +00001862 for hdr in `find . -type f -print | grep -v CVS` ; do \
Reid Spencerc43b1d42005-02-24 03:56:32 +00001863 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00001864 done ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001865 fi
Reid Spencer528c9802005-12-23 22:27:56 +00001866endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001867
1868uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001869 $(Echo) Uninstalling include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00001870 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1871 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer12a3a052004-10-24 07:53:21 +00001872 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattner814d9ee2009-01-02 07:16:45 +00001873 '!' '(' -name '*~' -o -name '.#*' \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001874 -o -name '*.in' ')' -print ')' | \
1875 grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001876 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001877 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1878 -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00001879 fi
Reid Spencera79819d2007-02-06 18:53:14 +00001880endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001881endif
1882
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00001883check-line-length:
Gabor Greif697e94c2008-05-15 10:04:30 +00001884 @echo searching for overlength lines in files: $(Sources)
1885 @echo
1886 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00001887 egrep -n '.{81}' $(Sources) /dev/null
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00001888
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001889check-for-tabs:
Gabor Greif697e94c2008-05-15 10:04:30 +00001890 @echo searching for tabs in files: $(Sources)
1891 @echo
1892 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00001893 egrep -n ' ' $(Sources) /dev/null
Gabor Greif697e94c2008-05-15 10:04:30 +00001894
Reid Spencere6bc2062007-05-02 21:29:39 +00001895check-footprint:
1896 @ls -l $(LibDir) | awk '\
1897 BEGIN { sum = 0; } \
1898 { sum += $$5; } \
1899 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1900 @ls -l $(ToolDir) | awk '\
1901 BEGIN { sum = 0; } \
1902 { sum += $$5; } \
1903 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
Reid Spencerf206bd72004-10-22 21:01:56 +00001904#------------------------------------------------------------------------
1905# Print out the directories used for building
Reid Spencerf88808a2004-10-30 09:19:36 +00001906#------------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001907printvars::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001908 $(Echo) "BuildMode : " '$(BuildMode)'
1909 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1910 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1911 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1912 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1913 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1914 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1915 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1916 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1917 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1918 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencerfe0a01e2005-02-16 16:13:02 +00001919 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00001920 $(Echo) "UserTargets : " '$(UserTargets)'
1921 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1922 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1923 $(Echo) "ObjDir : " '$(ObjDir)'
1924 $(Echo) "LibDir : " '$(LibDir)'
1925 $(Echo) "ToolDir : " '$(ToolDir)'
1926 $(Echo) "ExmplDir : " '$(ExmplDir)'
1927 $(Echo) "Sources : " '$(Sources)'
1928 $(Echo) "TDFiles : " '$(TDFiles)'
1929 $(Echo) "INCFiles : " '$(INCFiles)'
1930 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencerfefb9ea2005-03-01 16:27:06 +00001931 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00001932 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1933 $(Echo) "Compile.C : " '$(Compile.C)'
1934 $(Echo) "Archive : " '$(Archive)'
1935 $(Echo) "YaccFiles : " '$(YaccFiles)'
1936 $(Echo) "LexFiles : " '$(LexFiles)'
1937 $(Echo) "Module : " '$(Module)'
Reid Spencerb48e3f82005-08-24 10:43:10 +00001938 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
Reid Spencerece13582006-04-09 23:41:14 +00001939 $(Echo) "SubDirs : " '$(SubDirs)'
Reid Spencer200c6f92007-03-29 19:05:44 +00001940 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1941 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar0094e342009-02-21 20:42:39 +00001942
1943###
1944# Debugging
1945
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00001946# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar0094e342009-02-21 20:42:39 +00001947# definition, value and origin of XXX.
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00001948make-print-%:
Daniel Dunbar0094e342009-02-21 20:42:39 +00001949 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))