blob: 410a1422a880760bf3a4f0ded8a4a9436cc9947d [file] [log] [blame]
Misha Brukman7426c892004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswell23e43fb2003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
Chris Lattner11cc8b32007-12-29 20:11:13 +00005# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
Misha Brukman2879c292009-01-08 02:11:55 +00007#
Misha Brukman7426c892004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner2f7c9632001-06-06 20:29:01 +00009#
Reid Spencer81cd0492004-10-23 20:04:14 +000010# This file is included by all of the LLVM makefiles. For details on how to use
11# it properly, please see the document MakefileGuide.html in the docs directory.
Chris Lattner2e9fc94a2003-08-15 03:02:52 +000012#
Chris Lattnerb8e7aa02006-02-14 04:27:15 +000013#===-----------------------------------------------------------------------====#
Chris Lattner2f7c9632001-06-06 20:29:01 +000014
Reid Spencerf88808a2004-10-30 09:19:36 +000015################################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencerf88808a2004-10-30 09:19:36 +000017################################################################################
John Criswell3ef61af2003-06-30 21:59:07 +000018
Chris Lattner2f7c9632001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Daniel Dunbar96ccc472009-09-13 22:39:27 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode \
23 unitcheck
Reid Spencer8b5ebe52004-12-06 05:35:13 +000024LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencerd4bd3752004-12-03 20:08:48 +000025 install-local printvars uninstall-local \
Daniel Dunbar96ccc472009-09-13 22:39:27 +000026 install-bytecode-local
Chris Lattnerd0382a82007-09-26 06:10:47 +000027TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
Bill Wendling8790e322009-01-04 23:12:21 +000028 dist-zip unittests
Reid Spencerf88808a2004-10-30 09:19:36 +000029UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30InternalTargets := preconditions distdir dist-hook
Reid Spencer81cd0492004-10-23 20:04:14 +000031
Reid Spencerf88808a2004-10-30 09:19:36 +000032################################################################################
Reid Spencer77a46d22004-10-26 22:26:33 +000033# INITIALIZATION: Basic things the makefile needs
Reid Spencerf88808a2004-10-30 09:19:36 +000034################################################################################
35
36#--------------------------------------------------------------------
37# Set the VPATH so that we can find source files.
38#--------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +000039VPATH=$(PROJ_SRC_DIR)
Reid Spencer77a46d22004-10-26 22:26:33 +000040
41#--------------------------------------------------------------------
Reid Spencer7214cfd2007-06-29 14:02:07 +000042# Reset the list of suffixes we know how to build.
Reid Spencer77a46d22004-10-26 22:26:33 +000043#--------------------------------------------------------------------
44.SUFFIXES:
Greg Claytonf9d17762010-07-13 18:47:09 +000045.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
Reid Spencerf88808a2004-10-30 09:19:36 +000046.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer77a46d22004-10-26 22:26:33 +000047
Reid Spencer81cd0492004-10-23 20:04:14 +000048#--------------------------------------------------------------------
49# Mark all of these targets as phony to avoid implicit rule search
50#--------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +000051.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer81cd0492004-10-23 20:04:14 +000052
53#--------------------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +000054# Make sure all the user-target rules are double colon rules and
Reid Spencer77a46d22004-10-26 22:26:33 +000055# they are defined first.
Reid Spencer81cd0492004-10-23 20:04:14 +000056#--------------------------------------------------------------------
57
Reid Spencerf88808a2004-10-30 09:19:36 +000058$(UserTargets)::
Reid Spencer100080c2004-10-25 08:27:37 +000059
Reid Spencer77a46d22004-10-26 22:26:33 +000060################################################################################
61# PRECONDITIONS: that which must be built/checked first
62################################################################################
63
Reid Spencerd4bd3752004-12-03 20:08:48 +000064SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencerba6a3db2005-01-16 02:20:54 +000065 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
66ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
67ConfigureScript := $(PROJ_SRC_ROOT)/configure
68ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
69MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
70MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
71MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
72MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
73PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
74ifneq ($(MakefileCommonIn),)
75PreConditions += $(MakefileCommon)
76endif
Chris Lattner68c97542006-09-04 05:23:20 +000077
Reid Spencerba6a3db2005-01-16 02:20:54 +000078ifneq ($(MakefileConfigIn),)
79PreConditions += $(MakefileConfig)
80endif
Reid Spencer77a46d22004-10-26 22:26:33 +000081
Reid Spencer53846bc2005-08-25 04:59:49 +000082preconditions: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +000083
84#------------------------------------------------------------------------
85# Make sure the BUILT_SOURCES are built first
86#------------------------------------------------------------------------
Reid Spencer97e40f12004-12-16 07:15:16 +000087$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000088
Reid Spencer48c74392007-02-07 19:13:19 +000089clean-all-local::
Reid Spencer77a46d22004-10-26 22:26:33 +000090ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +000091 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer77a46d22004-10-26 22:26:33 +000092endif
93
Reid Spencerba6a3db2005-01-16 02:20:54 +000094ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer55814372004-12-16 08:00:46 +000095spotless:
Reid Spencer55814372004-12-16 08:00:46 +000096 $(Verb) if test -x config.status ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +000097 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +000098 $(MKDIR) .spotless.save ; \
99 $(MV) config.status .spotless.save ; \
100 $(MV) mklib .spotless.save ; \
101 $(MV) projects .spotless.save ; \
Reid Spencer55814372004-12-16 08:00:46 +0000102 $(RM) -rf * ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000103 $(MV) .spotless.save/config.status . ; \
104 $(MV) .spotless.save/mklib . ; \
105 $(MV) .spotless.save/projects . ; \
106 $(RM) -rf .spotless.save ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000107 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer7ef8e662004-12-17 07:45:03 +0000108 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
109 $(ConfigStatusScript) ; \
Reid Spencer55814372004-12-16 08:00:46 +0000110 else \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000111 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer55814372004-12-16 08:00:46 +0000112 fi
Reid Spencerc49a8632005-12-21 23:17:06 +0000113else
114spotless:
115 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer55814372004-12-16 08:00:46 +0000116endif
117
Reid Spencerf88808a2004-10-30 09:19:36 +0000118$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencerb7f710a2004-10-28 00:41:43 +0000119
Reid Spencer77a46d22004-10-26 22:26:33 +0000120#------------------------------------------------------------------------
121# Make sure we're not using a stale configuration
122#------------------------------------------------------------------------
Reid Spencerafdc82c2004-12-16 18:26:53 +0000123reconfigure:
Reid Spencerba6a3db2005-01-16 02:20:54 +0000124 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
125 $(Verb) cd $(PROJ_OBJ_ROOT) && \
126 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
127 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000128 fi ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000129 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
130 $(ConfigStatusScript)
131
Reid Spencerf88808a2004-10-30 09:19:36 +0000132.PRECIOUS: $(ConfigStatusScript)
Jim Grosbachd4ee8452010-10-01 22:32:12 +0000133$(ConfigStatusScript): $(ConfigureScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000134 $(Echo) Reconfiguring with $<
Reid Spencerba6a3db2005-01-16 02:20:54 +0000135 $(Verb) cd $(PROJ_OBJ_ROOT) && \
136 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
137 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
Reid Spencer35655d62004-12-24 03:36:31 +0000138 fi ; \
Reid Spencer50f34872004-11-29 12:37:44 +0000139 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
140 $(ConfigStatusScript)
Reid Spencer77a46d22004-10-26 22:26:33 +0000141
Reid Spencer83bde552005-08-25 04:44:18 +0000142#------------------------------------------------------------------------
Reid Spencer77a46d22004-10-26 22:26:33 +0000143# Make sure the configuration makefile is up to date
144#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +0000145ifneq ($(MakefileConfigIn),)
146$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencerf88808a2004-10-30 09:19:36 +0000147 $(Echo) Regenerating $@
Reid Spencerba6a3db2005-01-16 02:20:54 +0000148 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
149endif
150
151ifneq ($(MakefileCommonIn),)
152$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
153 $(Echo) Regenerating $@
154 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
155endif
Reid Spencer77a46d22004-10-26 22:26:33 +0000156
157#------------------------------------------------------------------------
158# If the Makefile in the source tree has been updated, copy it over into the
159# build tree. But, only do this if the source and object makefiles differ
160#------------------------------------------------------------------------
Daniel Dunbar4c5301d2010-09-09 17:38:11 +0000161ifndef PROJ_MAKEFILE
162PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
163endif
164
Reid Spencerba6a3db2005-01-16 02:20:54 +0000165ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer77a46d22004-10-26 22:26:33 +0000166
Daniel Dunbar4c5301d2010-09-09 17:38:11 +0000167Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
Reid Spencerf88808a2004-10-30 09:19:36 +0000168 $(Echo) "Updating Makefile"
169 $(Verb) $(MKDIR) $(@D)
Reid Spencerafdc82c2004-12-16 18:26:53 +0000170 $(Verb) $(CP) -f $< $@
Reid Spencer77a46d22004-10-26 22:26:33 +0000171
172# Copy the Makefile.* files unless we're in the root directory which avoids
173# the copying of Makefile.config.in or other things that should be explicitly
174# taken care of.
Daniel Dunbar4c5301d2010-09-09 17:38:11 +0000175$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
Reid Spencerd94bb332004-10-26 23:10:00 +0000176 @case '$?' in \
177 *Makefile.rules) ;; \
178 *.in) ;; \
Gordon Henriksen04e38cf2008-03-10 15:58:40 +0000179 *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000180 $(MKDIR) $(@D) ; \
Reid Spencerafdc82c2004-12-16 18:26:53 +0000181 $(CP) -f $< $@ ;; \
Reid Spencerd94bb332004-10-26 23:10:00 +0000182 esac
Gabor Greifc848f9e2008-02-27 13:34:15 +0000183
Reid Spencer77a46d22004-10-26 22:26:33 +0000184endif
185
186#------------------------------------------------------------------------
187# Set up the basic dependencies
188#------------------------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +0000189$(UserTargets):: $(PreConditions)
Reid Spencer77a46d22004-10-26 22:26:33 +0000190
191all:: all-local
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000192clean:: clean-local
Reid Spencer9d0c1e02004-11-02 16:36:03 +0000193clean-all:: clean-local clean-all-local
Reid Spencer77a46d22004-10-26 22:26:33 +0000194install:: install-local
195uninstall:: uninstall-local
Misha Brukman2879c292009-01-08 02:11:55 +0000196install-local:: all-local
Reid Spencerd4bd3752004-12-03 20:08:48 +0000197install-bytecode:: install-bytecode-local
Reid Spencer81cd0492004-10-23 20:04:14 +0000198
199###############################################################################
Mikhail Glushenkov938e9762010-08-15 07:07:12 +0000200# LLVMC: Provide rules for compiling llvmc-based driver
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000201###############################################################################
202
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000203ifdef LLVMC_BASED_DRIVER
204
205TOOLNAME = $(LLVMC_BASED_DRIVER)
Mikhail Glushenkovd6c39ae2009-07-03 03:52:47 +0000206
Mikhail Glushenkov938e9762010-08-15 07:07:12 +0000207LLVMLIBS = CompilerDriver.a
208LINK_COMPONENTS = support system
Mikhail Glushenkov73da6262009-06-25 01:07:00 +0000209
210endif # LLVMC_BASED_DRIVER
211
Mikhail Glushenkov7cff8182009-03-02 09:04:13 +0000212###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +0000213# VARIABLES: Set up various variables based on configuration data
214###############################################################################
215
Daniel Dunbar78caa022008-10-03 19:11:19 +0000216# Variable for if this make is for a "cleaning" target
217ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
218 IS_CLEANING_TARGET=1
219endif
220
Reid Spencer81cd0492004-10-23 20:04:14 +0000221#--------------------------------------------------------------------
222# Variables derived from configuration we are building
Chris Lattner2f7c9632001-06-06 20:29:01 +0000223#--------------------------------------------------------------------
224
Reid Spencerfd8e6412007-07-10 07:19:53 +0000225CPP.Defines :=
David Greene80f48bd2009-04-17 14:49:22 +0000226ifeq ($(ENABLE_OPTIMIZED),1)
227 BuildMode := Release
228 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000229 ifneq ($(HOST_OS),FreeBSD)
230 ifneq ($(HOST_OS),Darwin)
David Greene80f48bd2009-04-17 14:49:22 +0000231 OmitFramePointer := -fomit-frame-pointer
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000232 endif
David Greene80f48bd2009-04-17 14:49:22 +0000233 endif
234
235 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Cheng57709502009-04-20 22:49:59 +0000236 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
237 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000238 #ifeq ($(HOST_OS),Darwin)
Evan Cheng40c52322009-04-20 22:16:40 +0000239 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
240 #endif
David Greene80f48bd2009-04-17 14:49:22 +0000241 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
242 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
243 LD.Flags += $(OPTIMIZE_OPTION)
Jeffrey Yasskinc3273dc2009-09-27 17:47:29 +0000244 ifdef DEBUG_SYMBOLS
Jeffrey Yasskindb281082009-09-25 16:46:09 +0000245 BuildMode := $(BuildMode)+Debug
246 CXX.Flags += -g
247 C.Flags += -g
248 LD.Flags += -g
249 KEEP_SYMBOLS := 1
250 endif
David Greene80f48bd2009-04-17 14:49:22 +0000251else
Daniel Dunbar08d4ab92009-11-16 22:37:52 +0000252 ifdef NO_DEBUG_SYMBOLS
253 BuildMode := Unoptimized
254 CXX.Flags +=
255 C.Flags +=
256 LD.Flags +=
257 KEEP_SYMBOLS := 1
258 else
259 BuildMode := Debug
260 CXX.Flags += -g
261 C.Flags += -g
262 LD.Flags += -g
263 KEEP_SYMBOLS := 1
264 endif
David Greene80f48bd2009-04-17 14:49:22 +0000265endif
266
267ifeq ($(ENABLE_PROFILING),1)
268 BuildMode := $(BuildMode)+Profile
269 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
270 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
271 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
272 KEEP_SYMBOLS := 1
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000273endif
274
Daniel Dunbar61e0a822008-09-02 17:35:16 +0000275#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
276# CXX.Flags += -fvisibility-inlines-hidden
277#endif
278
Chris Lattnerab8a7c42010-01-24 20:20:40 +0000279ifdef ENABLE_EXPENSIVE_CHECKS
280 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
281 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
282 REQUIRES_RTTI := 1
283endif
284
Reid Spencer51e6f682006-08-25 19:54:53 +0000285# IF REQUIRES_EH=1 is specified then don't disable exceptions
Reid Spencer0b6396c2006-08-25 20:56:59 +0000286ifndef REQUIRES_EH
287 CXX.Flags += -fno-exceptions
Chris Lattnerdb308fd2010-01-24 20:21:50 +0000288else
289 # If the library requires EH, it also requires RTTI.
290 REQUIRES_RTTI := 1
Reid Spencer0b6396c2006-08-25 20:56:59 +0000291endif
Reid Spencer51e6f682006-08-25 19:54:53 +0000292
Nicolas Geoffray43cce222009-08-19 22:04:44 +0000293ifdef REQUIRES_FRAME_POINTER
294 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
295 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
296 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
297endif
298
Daniel Dunbar24c00472009-09-11 15:47:24 +0000299# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
Chris Lattner823aed12010-01-24 20:43:08 +0000300ifneq ($(REQUIRES_RTTI), 1)
301 CXX.Flags += -fno-rtti
Reid Spencere6bc2062007-05-02 21:29:39 +0000302endif
303
Peter Collingbournea92b66e2010-10-22 12:54:34 +0000304ifeq ($(ENABLE_COVERAGE),1)
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000305 BuildMode := $(BuildMode)+Coverage
Chris Lattnereaae8d02009-06-16 23:00:42 +0000306 CXX.Flags += -ftest-coverage -fprofile-arcs
307 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000308endif
309
Reid Spencer15b85092006-04-10 16:46:04 +0000310# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
311# then disable assertions by defining the appropriate preprocessor symbols.
Peter Collingbournea92b66e2010-10-22 12:54:34 +0000312ifeq ($(DISABLE_ASSERTIONS),1)
313 CPP.Defines += -DNDEBUG
314else
Duncan Sands408bb192010-07-07 07:48:00 +0000315 BuildMode := $(BuildMode)+Asserts
Reid Spencerfd8e6412007-07-10 07:19:53 +0000316 CPP.Defines += -D_DEBUG
Chris Lattner98c79c32006-03-21 01:06:41 +0000317endif
318
Misha Brukman2879c292009-01-08 02:11:55 +0000319# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
320# configured), then enable expensive checks by defining the
David Greene869e4b52007-06-29 03:36:21 +0000321# appropriate preprocessor symbols.
Peter Collingbournea92b66e2010-10-22 12:54:34 +0000322ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
David Greenecbc8ddf2007-06-28 19:36:08 +0000323 BuildMode := $(BuildMode)+Checks
Duncan Sands445071c2008-12-09 21:33:20 +0000324 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
David Greenecbc8ddf2007-06-28 19:36:08 +0000325endif
326
Nick Lewycky28c62d22009-02-26 07:44:16 +0000327# LOADABLE_MODULE implies several other things so we force them to be
328# defined/on.
329ifdef LOADABLE_MODULE
330 SHARED_LIBRARY := 1
Nick Lewycky28c62d22009-02-26 07:44:16 +0000331 LINK_LIBS_IN_SHARED := 1
332endif
333
334ifdef SHARED_LIBRARY
335 ENABLE_PIC := 1
336 PIC_FLAG = "(PIC)"
337endif
338
Reid Spencer05a1fe52006-12-16 22:07:52 +0000339ifeq ($(ENABLE_PIC),1)
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000340 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000341 # Nothing. Win32 defaults to PIC and warns when given -fPIC
342 else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000343 ifeq ($(HOST_OS),Darwin)
Nick Lewycky28c62d22009-02-26 07:44:16 +0000344 # Common symbols not allowed in dylib files
Nick Lewycky9e5ed6d2009-02-21 08:41:09 +0000345 CXX.Flags += -fno-common
346 C.Flags += -fno-common
347 else
348 # Linux and others; pass -fPIC
349 CXX.Flags += -fPIC
350 C.Flags += -fPIC
351 endif
352 endif
Mike Stumpd1b46362009-05-08 23:08:58 +0000353else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000354 ifeq ($(HOST_OS),Darwin)
Mike Stumpd1b46362009-05-08 23:08:58 +0000355 CXX.Flags += -mdynamic-no-pic
356 C.Flags += -mdynamic-no-pic
357 endif
Reid Spencer05a1fe52006-12-16 22:07:52 +0000358endif
359
Daniel Dunbardac18242010-05-10 20:11:56 +0000360# Support makefile variable to disable any kind of timestamp/non-deterministic
361# info from being used in the build.
362ifeq ($(ENABLE_TIMESTAMPS),1)
363 DOTDIR_TIMESTAMP_COMMAND := $(DATE)
364else
365 DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
366endif
367
Anton Korobeynikov803c60c2010-01-16 14:06:58 +0000368ifeq ($(HOST_OS),MingW)
369 # Work around PR4957
370 CPP.Defines += -D__NO_CTYPE_INLINE
371 ifeq ($(LLVM_CROSS_COMPILING),1)
372 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
373 ifdef TOOLNAME
374 LD.Flags += -Wl,--allow-multiple-definition
375 endif
376 endif
377endif
378
Eric Christopher3fe69672009-08-18 03:23:40 +0000379CXX.Flags += -Woverloaded-virtual
David Greenecbc8ddf2007-06-28 19:36:08 +0000380CPP.BaseFlags += $(CPP.Defines)
Reid Spencer6f682b72006-03-22 15:59:55 +0000381AR.Flags := cru
Reid Spencer81cd0492004-10-23 20:04:14 +0000382
Chris Lattnerdc5a8962006-07-27 18:19:51 +0000383# Make Floating point IEEE compliant on Alpha.
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000384ifeq ($(ARCH),Alpha)
Reid Spencer05a1fe52006-12-16 22:07:52 +0000385 CXX.Flags += -mieee
386 CPP.BaseFlags += -mieee
387ifeq ($(ENABLE_PIC),0)
388 CXX.Flags += -fPIC
389 CPP.BaseFlags += -fPIC
390endif
Andrew Lenharth9a98def2005-02-13 03:41:10 +0000391
Andrew Lenharth0ad67b02007-01-26 13:34:50 +0000392 LD.Flags += -Wl,--no-relax
393endif
394
Reid Spencer81cd0492004-10-23 20:04:14 +0000395#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000396# Directory locations
Reid Spencer81cd0492004-10-23 20:04:14 +0000397#--------------------------------------------------------------------
Jim Grosbach009db892008-10-02 22:56:44 +0000398TargetMode :=
399ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000400 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbach009db892008-10-02 22:56:44 +0000401endif
402
403ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000404ObjDir := $(ObjRootDir)
405LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
406ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
407ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
408LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
409LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
410LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell3ef61af2003-06-30 21:59:07 +0000411
Reid Spencer81cd0492004-10-23 20:04:14 +0000412#--------------------------------------------------------------------
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000413# Locations of shared libraries
414#--------------------------------------------------------------------
415
416SharedPrefix := lib
417SharedLibDir := $(LibDir)
418LLVMSharedLibDir := $(LLVMLibDir)
419
420# Win32.DLL prefers to be located on the "PATH" of binaries.
421ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
422 SharedLibDir := $(ToolDir)
423 LLVMSharedLibDir := $(LLVMToolDir)
424
425 ifeq ($(HOST_OS),Cygwin)
426 SharedPrefix := cyg
427 else
428 SharedPrefix :=
429 endif
430endif
431
432#--------------------------------------------------------------------
Daniel Dunbar16a13532010-02-23 10:00:53 +0000433# LLVM Capable Compiler
434#--------------------------------------------------------------------
435
436ifeq ($(LLVMCC_OPTION),llvm-gcc)
437 LLVMCC := $(LLVMGCC)
438 LLVMCXX := $(LLVMGXX)
439else
440 ifeq ($(LLVMCC_OPTION),clang)
441 ifneq ($(CLANGPATH),)
442 LLVMCC := $(CLANGPATH)
443 LLVMCXX := $(CLANGXXPATH)
444 else
445 ifeq ($(ENABLE_BUILT_CLANG),1)
446 LLVMCC := $(LLVMToolDir)/clang
447 LLVMCXX := $(LLVMToolDir)/clang++
448 endif
449 endif
450 endif
451endif
452
453#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000454# Full Paths To Compiled Tools and Utilities
Reid Spencer81cd0492004-10-23 20:04:14 +0000455#--------------------------------------------------------------------
Reid Spencerb12e2902005-01-14 16:33:36 +0000456EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
457Echo = @$(EchoCmd)
Reid Spencerf88808a2004-10-30 09:19:36 +0000458ifndef LLVMAS
459LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
460endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000461ifndef TBLGEN
Reid Spencer0aa9d002006-07-26 21:14:56 +0000462 ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov8e58c522008-11-10 07:33:13 +0000463 TBLGEN := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Reid Spencer0aa9d002006-07-26 21:14:56 +0000464 else
465 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
466 endif
Reid Spencerf88808a2004-10-30 09:19:36 +0000467endif
Misha Brukman2879c292009-01-08 02:11:55 +0000468LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Reid Spencerb63d0c42007-02-09 15:52:07 +0000469ifndef LLVMLD
Reid Spencer7cec4f22007-02-09 17:09:14 +0000470LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
Reid Spencerf88808a2004-10-30 09:19:36 +0000471endif
Chris Lattner68c97542006-09-04 05:23:20 +0000472ifndef LLVMDIS
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000473LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
474endif
475ifndef LLI
476LLI := $(LLVMToolDir)/lli$(EXEEXT)
477endif
Alkis Evlogimenos24340582005-02-27 10:21:37 +0000478ifndef LLC
479LLC := $(LLVMToolDir)/llc$(EXEEXT)
480endif
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000481ifndef LOPT
Alkis Evlogimenos7c7705d2004-12-13 18:08:29 +0000482LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenosa20de022004-12-13 17:44:14 +0000483endif
Alkis Evlogimenos7c04a3d2005-02-02 00:40:15 +0000484ifndef LBUGPOINT
485LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
486endif
Reid Spencer9a6fc822006-12-03 21:01:45 +0000487
Reid Spencer81cd0492004-10-23 20:04:14 +0000488#--------------------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000489# Adjust to user's request
Reid Spencer81cd0492004-10-23 20:04:14 +0000490#--------------------------------------------------------------------
Dinakar Dhurjati41f77482003-05-29 16:18:20 +0000491
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000492ifeq ($(HOST_OS),Darwin)
Scott Michelb1a830a2009-03-12 21:03:53 +0000493 DARWIN_VERSION := `sw_vers -productVersion`
494 # Strip a number like 10.4.7 to 10.4
495 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
496 # Get "4" out of 10.4 for later pieces in the makefile.
497 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendlingf3ef2c72009-03-22 08:28:45 +0000498
Dan Gohman91f8ad72010-04-16 22:58:15 +0000499 SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined,suppress \
Evan Cheng57b14192009-09-08 18:52:20 +0000500 -dynamiclib
501 ifneq ($(ARCH),ARM)
502 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
503 endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000504else
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000505 SharedLinkOptions=-shared
Scott Michelb1a830a2009-03-12 21:03:53 +0000506endif
507
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000508ifeq ($(TARGET_OS),Darwin)
Evan Cheng57b14192009-09-08 18:52:20 +0000509 ifneq ($(ARCH),ARM)
510 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
511 endif
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000512endif
513
Reid Spencer87e645c2005-01-11 04:31:07 +0000514ifdef SHARED_LIBRARY
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000515ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Rafael Espindola9d2fe3c2010-05-16 03:05:14 +0000516ifneq ($(HOST_OS),Darwin)
517 LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
518else
Scott Michelb1a830a2009-03-12 21:03:53 +0000519ifneq ($(DARWIN_MAJVERS),4)
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000520 LD.Flags += $(RPATH) -Wl,$(SharedLibDir)
521endif
John Criswell3601f372003-07-31 20:58:51 +0000522endif
Scott Michelb1a830a2009-03-12 21:03:53 +0000523endif
Rafael Espindola9d2fe3c2010-05-16 03:05:14 +0000524endif
John Criswell3601f372003-07-31 20:58:51 +0000525
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000526ifdef TOOL_VERBOSE
527 C.Flags += -v
528 CXX.Flags += -v
529 LD.Flags += -v
Reid Spencerf8b4a8e2004-11-08 17:32:12 +0000530 VERBOSE := 1
531endif
532
Reid Spencer81cd0492004-10-23 20:04:14 +0000533# Adjust settings for verbose mode
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000534ifndef VERBOSE
Reid Spencerf88808a2004-10-30 09:19:36 +0000535 Verb := @
Reid Spencerfcd78152007-07-23 08:20:46 +0000536 AR.Flags += >/dev/null 2>/dev/null
Reid Spencerba6a3db2005-01-16 02:20:54 +0000537 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer100080c2004-10-25 08:27:37 +0000538else
Misha Brukman2879c292009-01-08 02:11:55 +0000539 ConfigureScriptFLAGS :=
Misha Brukman1326a7c2002-09-12 16:05:39 +0000540endif
541
Vikram S. Adved141c282002-09-18 11:55:13 +0000542# By default, strip symbol information from executable
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +0000543ifndef KEEP_SYMBOLS
Reid Spencerf88808a2004-10-30 09:19:36 +0000544 Strip := $(PLATFORMSTRIPOPTS)
545 StripWarnMsg := "(without symbols)"
Reid Spencer247a10e2005-02-24 07:12:43 +0000546 Install.StripFlag += -s
Vikram S. Adved141c282002-09-18 11:55:13 +0000547endif
548
Rafael Espindola6db28372010-10-15 00:58:12 +0000549ifdef TOOL_NO_EXPORTS
550 DynamicFlags :=
551else
552 DynamicFlag := $(RDYNAMIC)
553endif
554
Reid Spencer81cd0492004-10-23 20:04:14 +0000555# Adjust linker flags for building an executable
Nick Lewyckyadaf5172010-08-02 03:16:19 +0000556ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
557ifneq ($(HOST_OS), Darwin)
Reid Spencerf206bd72004-10-22 21:01:56 +0000558ifdef TOOLNAME
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000559 LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
560 ifdef EXAMPLE_TOOL
Rafael Espindola6db28372010-10-15 00:58:12 +0000561 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000562 else
Rafael Espindola6db28372010-10-15 00:58:12 +0000563 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000564 endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000565endif
Ted Kremenek34231222010-07-15 06:36:57 +0000566else
567ifneq ($(DARWIN_MAJVERS),4)
568 LD.Flags += $(RPATH) -Wl,@executable_path/../lib
Nick Lewycky28c62d22009-02-26 07:44:16 +0000569endif
Ted Kremenek34231222010-07-15 06:36:57 +0000570endif
Nick Lewyckyadaf5172010-08-02 03:16:19 +0000571endif
Ted Kremenek34231222010-07-15 06:36:57 +0000572
Dinakar Dhurjati3ac83a92003-10-29 14:28:35 +0000573
Reid Spencer81cd0492004-10-23 20:04:14 +0000574#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000575# Options To Invoke Tools
Reid Spencer81cd0492004-10-23 20:04:14 +0000576#----------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +0000577
Daniel Dunbar310511d2009-05-12 07:26:49 +0000578ifndef NO_PEDANTIC
Duncan Sandse532b552009-06-19 12:40:30 +0000579CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbar310511d2009-05-12 07:26:49 +0000580endif
Duncan Sandse532b552009-06-19 12:40:30 +0000581CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
582 $(EXTRA_OPTIONS)
Dan Gohman0557cd72010-04-19 18:33:28 +0000583# Enable cast-qual for C++; the workaround is to use const_cast.
584CXX.Flags += -Wcast-qual
Reid Spencerf206bd72004-10-22 21:01:56 +0000585
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000586ifeq ($(HOST_OS),HP-UX)
Duraid Madina1f898af2006-02-15 03:20:16 +0000587 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
Duraid Madina60c9a3c2005-05-16 06:38:09 +0000588endif
589
Chris Lattner11c25cf2006-05-30 16:38:06 +0000590# If we are building a universal binary on Mac OS/X, pass extra options. This
591# is useful to people that want to link the LLVM libraries into their universal
Chris Lattner65e28b32006-06-29 19:38:04 +0000592# apps.
593#
594# The following can be optionally specified:
595# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
596# For Mac OS/X 10.4 Intel machines, the traditional one is:
597# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
598# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
599# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
600# i386/ppc only.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000601ifdef UNIVERSAL
Chris Lattner65e28b32006-06-29 19:38:04 +0000602 ifndef UNIVERSAL_ARCH
603 UNIVERSAL_ARCH := i386 ppc
604 endif
605 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
606 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattner64e85f32006-06-16 21:47:59 +0000607 ifdef UNIVERSAL_SDK_PATH
608 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattner64e85f32006-06-16 21:47:59 +0000609 endif
610
611 # Building universal cannot compute dependencies automatically.
Chris Lattnerd81eba52006-04-06 06:30:15 +0000612 DISABLE_AUTO_DEPENDENCIES=1
Evan Cheng3807bb72009-03-09 18:28:37 +0000613else
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000614 ifeq ($(TARGET_OS),Darwin)
Bill Wendling207495d2009-03-12 04:10:09 +0000615 ifeq ($(ARCH),x86_64)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000616 TargetCommonOpts = -m64
Bill Wendling207495d2009-03-12 04:10:09 +0000617 else
618 ifeq ($(ARCH),x86)
Evan Cheng3138f7a2009-03-23 03:45:56 +0000619 TargetCommonOpts = -m32
Bill Wendling207495d2009-03-12 04:10:09 +0000620 endif
Evan Cheng3807bb72009-03-09 18:28:37 +0000621 endif
622 endif
Chris Lattnerd81eba52006-04-06 06:30:15 +0000623endif
624
Anton Korobeynikov90e17e72009-08-18 00:40:33 +0000625ifeq ($(HOST_OS),SunOS)
Chris Lattner01602a12008-06-24 17:44:42 +0000626CPP.BaseFlags += -include llvm/System/Solaris.h
627endif
628
Edward O'Callaghan4ae411e2009-10-14 05:55:03 +0000629ifeq ($(HOST_OS),AuroraUX)
630CPP.BaseFlags += -include llvm/System/Solaris.h
631endif # !HOST_OS - AuroraUX.
632
Misha Brukman2879c292009-01-08 02:11:55 +0000633LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Dan Gohmanca0546f2008-10-17 01:33:43 +0000634CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
Reid Spencer6f682b72006-03-22 15:59:55 +0000635# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands9f6f4d32008-01-28 17:38:30 +0000636CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
637 $(patsubst %,-I%/include,\
Chris Lattner6379fc62008-01-28 04:18:41 +0000638 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
639 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
640 $(CPP.BaseFlags)
Reid Spencerf206bd72004-10-22 21:01:56 +0000641
Daniel Dunbar5b86bf52009-03-13 20:59:41 +0000642ifeq ($(BUILD_COMPONENT), 1)
Eric Christopher3fe69672009-08-18 03:23:40 +0000643 Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000644 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000645 Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
646 $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000647 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000648 Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000649 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000650 Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
651 $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000652 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000653else
Eric Christopher3fe69672009-08-18 03:23:40 +0000654 Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000655 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000656 Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000657 $(TargetCommonOpts) $(CompileCommonOpts) -c
Eric Christopher3fe69672009-08-18 03:23:40 +0000658 Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
Chris Lattnereaae8d02009-06-16 23:00:42 +0000659 $(CompileCommonOpts) $(CXX.Flags) -E
Eric Christopherd604b252009-08-18 18:07:35 +0000660 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LDFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000661 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbach009db892008-10-02 22:56:44 +0000662endif
663
Daniel Dunbare615b5f2010-02-23 10:28:06 +0000664BCCompile.C = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000665 $(TargetCommonOpts) $(CompileCommonOpts)
Eric Christopher3fe69672009-08-18 03:23:40 +0000666Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000667 $(TargetCommonOpts) $(CompileCommonOpts) -E
Chris Lattnerbb087952005-10-05 00:28:41 +0000668
Daniel Dunbare615b5f2010-02-23 10:28:06 +0000669BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Cheng3138f7a2009-03-23 03:45:56 +0000670 $(TargetCommonOpts) $(CompileCommonOpts)
Chris Lattner008b2de2006-09-29 18:47:13 +0000671
Misha Brukman2879c292009-01-08 02:11:55 +0000672ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
673ScriptInstall = $(INSTALL) -m 0755
Reid Spencer247a10e2005-02-24 07:12:43 +0000674DataInstall = $(INSTALL) -m 0644
Chris Lattner50475362008-01-15 23:27:40 +0000675
676# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
677# paths. In this case, the SYSPATH function (defined in
678# Makefile.config) transforms Unix paths into Windows paths.
679TableGen = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkov726440d2009-01-09 16:31:01 +0000680 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner50475362008-01-15 23:27:40 +0000681 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
682 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
683
Reid Spencerf88808a2004-10-30 09:19:36 +0000684Archive = $(AR) $(AR.Flags)
Reid Spencer32f7e422004-12-02 09:28:21 +0000685LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencerf206bd72004-10-22 21:01:56 +0000686ifdef RANLIB
Reid Spencer81cd0492004-10-23 20:04:14 +0000687Ranlib = $(RANLIB)
Reid Spencerf206bd72004-10-22 21:01:56 +0000688else
Reid Spencer81cd0492004-10-23 20:04:14 +0000689Ranlib = ranlib
John Criswell3ef61af2003-06-30 21:59:07 +0000690endif
691
Daniel Dunbar0dd2b812009-11-19 00:14:53 +0000692AliasTool = ln -s
693
Chris Lattner2f7c9632001-06-06 20:29:01 +0000694#----------------------------------------------------------
Misha Brukman2879c292009-01-08 02:11:55 +0000695# Get the list of source files and compute object file
696# names from them.
Reid Spencer81cd0492004-10-23 20:04:14 +0000697#----------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000698
699ifndef SOURCES
700 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattner814d9ee2009-01-02 07:16:45 +0000701 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Reid Spencerf88808a2004-10-30 09:19:36 +0000702else
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000703 Sources := $(SOURCES)
Misha Brukman2879c292009-01-08 02:11:55 +0000704endif
Reid Spencerf206bd72004-10-22 21:01:56 +0000705
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000706ifdef BUILT_SOURCES
Chris Lattner814d9ee2009-01-02 07:16:45 +0000707Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Reid Spencer81546582004-12-04 22:34:09 +0000708endif
Reid Spencer81cd0492004-10-23 20:04:14 +0000709
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000710BaseNameSources := $(sort $(basename $(Sources)))
711
712ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +0000713ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
714
Reid Spencer81cd0492004-10-23 20:04:14 +0000715###############################################################################
716# DIRECTORIES: Handle recursive descent of directory structure
717###############################################################################
John Criswell3601f372003-07-31 20:58:51 +0000718
Chris Lattner2f7c9632001-06-06 20:29:01 +0000719#---------------------------------------------------------
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000720# Provide rules to make install dirs. This must be early
721# in the file so they get built before dependencies
722#---------------------------------------------------------
723
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000724$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
Mike Stumpf7a16e92009-01-22 03:24:22 +0000725 $(Verb) $(MKDIR) $@
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000726
Reid Spencerf88808a2004-10-30 09:19:36 +0000727# To create other directories, as needed, and timestamp their creation
728%/.dir:
729 $(Verb) $(MKDIR) $* > /dev/null
Daniel Dunbardac18242010-05-10 20:11:56 +0000730 $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
Reid Spencerf88808a2004-10-30 09:19:36 +0000731
Reid Spencer7e9e0b02004-11-18 10:03:46 +0000732.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
733.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencer9c7bfc92004-10-28 09:15:28 +0000734
735#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000736# Handle the DIRS options for sequential construction
Chris Lattner2f7c9632001-06-06 20:29:01 +0000737#---------------------------------------------------------
738
Misha Brukman2879c292009-01-08 02:11:55 +0000739SubDirs :=
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000740ifdef DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000741SubDirs += $(DIRS)
Chris Lattnerb9259612006-07-26 20:22:26 +0000742
743ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000744$(RecursiveTargets)::
745 $(Verb) for dir in $(DIRS); do \
Daniel Dunbar281d6bc2010-06-08 20:10:13 +0000746 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerc8cbcdd2010-06-18 00:35:32 +0000747 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000748 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000749 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencerf206bd72004-10-22 21:01:56 +0000750 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000751 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattner539a23c2002-09-17 23:35:02 +0000752 done
Chris Lattnerb9259612006-07-26 20:22:26 +0000753else
754$(RecursiveTargets)::
755 $(Verb) for dir in $(DIRS); do \
756 ($(MAKE) -C $$dir $@ ) || exit 1; \
757 done
758endif
759
Anand Shukla8c2a0ee2002-09-18 04:29:30 +0000760endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000761
Reid Spencer81cd0492004-10-23 20:04:14 +0000762#---------------------------------------------------------
763# Handle the EXPERIMENTAL_DIRS options ensuring success
764# after each directory is built.
765#---------------------------------------------------------
766ifdef EXPERIMENTAL_DIRS
Reid Spencerf88808a2004-10-30 09:19:36 +0000767$(RecursiveTargets)::
768 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Daniel Dunbar281d6bc2010-06-08 20:10:13 +0000769 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerc8cbcdd2010-06-18 00:35:32 +0000770 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer81cd0492004-10-23 20:04:14 +0000771 $(MKDIR) $$dir; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000772 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000773 fi; \
Reid Spencera22a5b32006-05-17 22:55:35 +0000774 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer81cd0492004-10-23 20:04:14 +0000775 done
776endif
Chris Lattnerf3dd5f52002-09-18 03:22:27 +0000777
Reid Spencerc49a8632005-12-21 23:17:06 +0000778#-----------------------------------------------------------
Mike Stump82221d62009-01-24 00:00:41 +0000779# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
780#-----------------------------------------------------------
781ifdef OPTIONAL_PARALLEL_DIRS
782 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
783endif
784
785#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000786# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencerc49a8632005-12-21 23:17:06 +0000787#-----------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +0000788ifdef PARALLEL_DIRS
789
Reid Spencerf88808a2004-10-30 09:19:36 +0000790SubDirs += $(PARALLEL_DIRS)
791
Reid Spencerd4bd3752004-12-03 20:08:48 +0000792# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencerf88808a2004-10-30 09:19:36 +0000793all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
794clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencer651dd3ad2004-11-02 16:56:15 +0000795clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencerf88808a2004-10-30 09:19:36 +0000796install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000797uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencerd4bd3752004-12-03 20:08:48 +0000798install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Daniel Dunbar96ccc472009-09-13 22:39:27 +0000799unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
Reid Spencer81cd0492004-10-23 20:04:14 +0000800
Reid Spencer81546582004-12-04 22:34:09 +0000801ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer81cd0492004-10-23 20:04:14 +0000802
Reid Spencer81546582004-12-04 22:34:09 +0000803$(ParallelTargets) :
Daniel Dunbar281d6bc2010-06-08 20:10:13 +0000804 $(Verb) if ([ ! -f $(@D)/Makefile ] || \
Chris Lattnerc8cbcdd2010-06-18 00:35:32 +0000805 command test $(@D)/Makefile -ot \
Chris Lattnerf9d8e172010-06-15 21:35:22 +0000806 $(PROJ_SRC_DIR)/$(@D)/Makefile ); then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000807 $(MKDIR) $(@D); \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000808 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswell6df35dd2003-11-25 19:32:22 +0000809 fi; \
Reid Spencer960cf7c2007-02-07 03:29:29 +0000810 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner2f7c9632001-06-06 20:29:01 +0000811endif
812
Reid Spencer81cd0492004-10-23 20:04:14 +0000813#---------------------------------------------------------
814# Handle the OPTIONAL_DIRS options for directores that may
815# or may not exist.
816#---------------------------------------------------------
John Criswell8224df92003-06-27 16:58:44 +0000817ifdef OPTIONAL_DIRS
Reid Spencer100080c2004-10-25 08:27:37 +0000818
Reid Spencerf88808a2004-10-30 09:19:36 +0000819SubDirs += $(OPTIONAL_DIRS)
Reid Spencer100080c2004-10-25 08:27:37 +0000820
Chris Lattnerb9259612006-07-26 20:22:26 +0000821ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerf88808a2004-10-30 09:19:36 +0000822$(RecursiveTargets)::
823 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000824 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Daniel Dunbar281d6bc2010-06-08 20:10:13 +0000825 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerc8cbcdd2010-06-18 00:35:32 +0000826 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencerf206bd72004-10-22 21:01:56 +0000827 $(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
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000852install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
853 $(Echo) Installing Configuration Files To $(DESTDIR)$(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 \
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000856 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +0000857 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000858 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(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::
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000865 $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
Reid Spencerf88808a2004-10-30 09:19:36 +0000866 $(Verb)for file in $(CONFIG_FILES); do \
Erick Tryzelaar444c0952010-03-04 20:56:19 +0000867 $(RM) -f $(DESTDIR)$(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###############################################################################
Eric Christopherb2c4a992010-06-21 23:49:08 +0000874# Set up variables for building libraries
Reid Spencera80f1672005-05-19 00:37:31 +0000875###############################################################################
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
NAKAMURA Takumi9c8a97ce02010-09-10 06:27:02 +0000898# Loadable module for Win32 requires all symbols resolved for linking.
899# Then all symbols in LLVM.dll will be available.
900ifeq ($(ENABLE_SHARED),1)
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000901 ifdef LOADABLE_MODULE
NAKAMURA Takumi9c8a97ce02010-09-10 06:27:02 +0000902 ifneq (,$(filter $(HOST_OS),Cygwin MingW))
903 LINK_COMPONENTS += all
904 endif
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000905 endif
906endif
907
Daniel Dunbar78caa022008-10-03 19:11:19 +0000908ifndef IS_CLEANING_TARGET
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000909ifdef LINK_COMPONENTS
Chris Lattner68c97542006-09-04 05:23:20 +0000910
911# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
912# clean in tools, then do a make in tools (instead of at the top level).
913$(LLVM_CONFIG):
914 @echo "*** llvm-config doesn't exist - rebuilding it."
915 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greifc848f9e2008-02-27 13:34:15 +0000916
Chris Lattner68c97542006-09-04 05:23:20 +0000917$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
918
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000919ifeq ($(ENABLE_SHARED), 1)
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000920# We can take the "auto-import" feature to get rid of using dllimport.
921ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
922LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
923 -L $(SharedLibDir)
924endif
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000925LLVMLibsOptions += -lLLVM-$(LLVMVersion)
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000926LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000927else
Chris Lattnerc19eaaa2010-09-01 16:11:17 +0000928
929ifndef NO_LLVM_CONFIG
930LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
931ifeq ($(LLVMConfigLibs),Error)
932$(error llvm-config --libs failed)
933endif
934LLVMLibsOptions += $(LLVMConfigLibs)
935LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
936ifeq ($(LLVMConfigLibfiles),Error)
937$(error llvm-config --libfiles failed)
938endif
939LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
940endif
941
Chris Lattnerf9ac33d2006-09-04 04:47:21 +0000942endif
Chris Lattner9a4a92e2006-09-04 04:50:10 +0000943endif
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +0000944endif
Reid Spencera80f1672005-05-19 00:37:31 +0000945
Dan Gohman473a53f2010-04-15 20:54:25 +0000946# Set up the library exports file.
947ifdef EXPORTED_SYMBOL_FILE
948
949# First, set up the native export file, which may differ from the source
950# export file.
951
NAKAMURA Takumib9699072010-10-04 02:32:21 +0000952# The option --version-script is not effective on GNU ld win32.
953ifneq (,$(filter $(HOST_OS),Cygwin MingW))
954 HAVE_LINK_VERSION_SCRIPT := 0
955endif
956
Dan Gohman473a53f2010-04-15 20:54:25 +0000957ifeq ($(HOST_OS),Darwin)
958# Darwin convention prefixes symbols with underscores.
Dan Gohmanff9ecb22010-04-15 23:08:00 +0000959NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
Dan Gohman16392652010-04-15 22:46:27 +0000960$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
Dan Gohman1ce7a552010-06-01 17:08:56 +0000961 $(Verb) sed -e 's/^/_/' < $< > $@
Dan Gohman473a53f2010-04-15 20:54:25 +0000962clean-local::
963 -$(Verb) $(RM) -f $(NativeExportsFile)
964else
Dan Gohmanb7edb422010-06-01 14:56:56 +0000965ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
966# Gold and BFD ld require a version script rather than a plain list.
967NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
968$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
969 $(Verb) echo "{" > $@
970 $(Verb) grep -q "\<" $< && echo " global:" >> $@ || :
Dan Gohman1ce7a552010-06-01 17:08:56 +0000971 $(Verb) sed -e 's/$$/;/' -e 's/^/ /' < $< >> $@
Dan Gohmanb7edb422010-06-01 14:56:56 +0000972 $(Verb) echo " local: *;" >> $@
973 $(Verb) echo "};" >> $@
974clean-local::
975 -$(Verb) $(RM) -f $(NativeExportsFile)
976else
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000977ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Dan Gohman02ab9a62010-09-03 17:29:33 +0000978# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000979NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000980$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
981 $(Echo) Generating $(notdir $@)
982 $(Verb) $(ECHO) "EXPORTS" > $@
983 $(Verb) $(CAT) $< >> $@
984clean-local::
985 -$(Verb) $(RM) -f $(NativeExportsFile)
986else
Dan Gohman02ab9a62010-09-03 17:29:33 +0000987# Default behavior: just use the exports file verbatim.
988NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
989endif
990endif
991endif
992
993# Now add the linker command-line options to use the native export file.
994
995# Darwin
996ifeq ($(HOST_OS),Darwin)
997LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
998endif
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +0000999
Dan Gohman91f8ad72010-04-16 22:58:15 +00001000# gold, bfd ld, etc.
Dan Gohmanb7edb422010-06-01 14:56:56 +00001001ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1002LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
Dan Gohman473a53f2010-04-15 20:54:25 +00001003endif
1004
Dan Gohman02ab9a62010-09-03 17:29:33 +00001005# Windows
1006ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1007# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1008SharedLinkOptions += $(NativeExportsFile)
Dan Gohman473a53f2010-04-15 20:54:25 +00001009endif
1010
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001011endif
1012
Reid Spencera80f1672005-05-19 00:37:31 +00001013###############################################################################
Reid Spencer81cd0492004-10-23 20:04:14 +00001014# Library Build Rules: Four ways to build a library
1015###############################################################################
Chris Lattner2f7c9632001-06-06 20:29:01 +00001016
Reid Spencerd78077d2004-12-05 05:17:22 +00001017#---------------------------------------------------------
1018# Bytecode Module Targets:
1019# If the user set MODULE_NAME then they want to build a
1020# bytecode module from the sources. We compile all the
1021# sources and link it together into a single bytecode
1022# module.
1023#---------------------------------------------------------
1024
1025ifdef MODULE_NAME
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001026ifeq ($(strip $(LLVMCC)),)
1027$(warning Modules require LLVM capable compiler but none is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +00001028else
Reid Spencerd78077d2004-12-05 05:17:22 +00001029
1030Module := $(LibDir)/$(MODULE_NAME).bc
Daniel Dunbar8657a022010-02-23 09:28:50 +00001031LinkModule := $(LLVMLD) -r
Reid Spencer78ede562006-04-12 18:21:35 +00001032
Reid Spencerd78077d2004-12-05 05:17:22 +00001033
1034ifdef EXPORTED_SYMBOL_FILE
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001035LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencerd78077d2004-12-05 05:17:22 +00001036endif
1037
Reid Spencerb63d0c42007-02-09 15:52:07 +00001038$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
Reid Spencer83745dd2005-05-13 18:32:54 +00001039 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencerd78077d2004-12-05 05:17:22 +00001040 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1041
1042all-local:: $(Module)
1043
1044clean-local::
1045ifneq ($(strip $(Module)),)
1046 -$(Verb) $(RM) -f $(Module)
1047endif
1048
Reid Spencerefe3a822004-12-13 07:38:07 +00001049ifdef BYTECODE_DESTINATION
1050ModuleDestDir := $(BYTECODE_DESTINATION)
1051else
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001052ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencerefe3a822004-12-13 07:38:07 +00001053endif
Reid Spencerd78077d2004-12-05 05:17:22 +00001054
Reid Spencera79819d2007-02-06 18:53:14 +00001055ifdef NO_INSTALL
1056install-local::
1057 $(Echo) Install circumvented with NO_INSTALL
1058uninstall-local::
1059 $(Echo) Uninstall circumvented with NO_INSTALL
1060else
Reid Spencerefe3a822004-12-13 07:38:07 +00001061DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1062
1063install-module:: $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +00001064install-local:: $(DestModule)
1065
Misha Brukman2879c292009-01-08 02:11:55 +00001066$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencerd78077d2004-12-05 05:17:22 +00001067 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencerd77a4c02005-02-24 21:30:37 +00001068 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencerd78077d2004-12-05 05:17:22 +00001069
1070uninstall-local::
1071 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1072 -$(Verb) $(RM) -f $(DestModule)
Reid Spencera79819d2007-02-06 18:53:14 +00001073endif
Reid Spencerd78077d2004-12-05 05:17:22 +00001074
1075endif
Reid Spencere9fa5442005-02-14 21:54:08 +00001076endif
Brian Gaekeecc92bf2004-01-22 22:53:48 +00001077
Reid Spencer81cd0492004-10-23 20:04:14 +00001078# if we're building a library ...
Chris Lattner2f7c9632001-06-06 20:29:01 +00001079ifdef LIBRARYNAME
Vikram S. Advefe346892001-07-15 13:16:47 +00001080
Misha Brukman5906bc12009-08-17 15:31:24 +00001081# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
Chris Lattnere6e193ca2002-09-16 22:34:56 +00001082LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer87e645c2005-01-11 04:31:07 +00001083ifdef LOADABLE_MODULE
Nick Lewycky28c62d22009-02-26 07:44:16 +00001084LibName.A := $(LibDir)/$(LIBRARYNAME).a
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001085LibName.SO := $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer87e645c2005-01-11 04:31:07 +00001086else
Reid Spencerf88808a2004-10-30 09:19:36 +00001087LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001088LibName.SO := $(SharedLibDir)/$(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001089endif
Reid Spencerf88808a2004-10-30 09:19:36 +00001090LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer32f7e422004-12-02 09:28:21 +00001091LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnere6e193ca2002-09-16 22:34:56 +00001092
Reid Spencer81cd0492004-10-23 20:04:14 +00001093#---------------------------------------------------------
1094# Shared Library Targets:
1095# If the user asked for a shared library to be built
1096# with the SHARED_LIBRARY variable, then we provide
1097# targets for building them.
1098#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001099ifdef SHARED_LIBRARY
1100
Nick Lewycky28c62d22009-02-26 07:44:16 +00001101all-local:: $(LibName.SO)
Reid Spencerf206bd72004-10-22 21:01:56 +00001102
Dan Gohman473a53f2010-04-15 20:54:25 +00001103ifdef EXPORTED_SYMBOL_FILE
1104$(LibName.SO): $(NativeExportsFile)
1105endif
1106
Reid Spencera80f1672005-05-19 00:37:31 +00001107ifdef LINK_LIBS_IN_SHARED
Reid Spencere6458c32006-08-07 23:12:15 +00001108ifdef LOADABLE_MODULE
Chris Lattner7cab3de2006-11-15 21:04:15 +00001109SharedLibKindMessage := "Loadable Module"
Reid Spencere6458c32006-08-07 23:12:15 +00001110else
1111SharedLibKindMessage := "Shared Library"
1112endif
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001113$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
Reid Spencere6458c32006-08-07 23:12:15 +00001114 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
Dan Gohman14e297e2010-07-26 20:15:47 +00001115 $(notdir $@)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001116 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Torok Edwin49db7382009-05-26 19:11:47 +00001117 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Reid Spencera80f1672005-05-19 00:37:31 +00001118else
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001119$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
Dan Gohman14e297e2010-07-26 20:15:47 +00001120 $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001121 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Reid Spencera80f1672005-05-19 00:37:31 +00001122endif
Reid Spencer81cd0492004-10-23 20:04:14 +00001123
1124clean-local::
Nick Lewycky28c62d22009-02-26 07:44:16 +00001125ifneq ($(strip $(LibName.SO)),)
1126 -$(Verb) $(RM) -f $(LibName.SO)
Reid Spencer12a3a052004-10-24 07:53:21 +00001127endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001128
Reid Spencera79819d2007-02-06 18:53:14 +00001129ifdef NO_INSTALL
1130install-local::
1131 $(Echo) Install circumvented with NO_INSTALL
1132uninstall-local::
1133 $(Echo) Uninstall circumvented with NO_INSTALL
1134else
Rafael Espindola0af68892010-05-16 03:13:23 +00001135
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001136# Win32.DLL prefers to be located on the "PATH" of binaries.
1137ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1138DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
Rafael Espindola0af68892010-05-16 03:13:23 +00001139else
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001140DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
Rafael Espindola0af68892010-05-16 03:13:23 +00001141endif
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001142DestSharedLib := $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencerf206bd72004-10-22 21:01:56 +00001143
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001144install-local:: $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001145
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001146$(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001147 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001148 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001149
Misha Brukman2879c292009-01-08 02:11:55 +00001150uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001151 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Anton Korobeynikov51b8b1d2010-08-17 19:03:03 +00001152 -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
Reid Spencera79819d2007-02-06 18:53:14 +00001153endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001154endif
1155
Reid Spencer81cd0492004-10-23 20:04:14 +00001156#---------------------------------------------------------
1157# Bytecode Library Targets:
1158# If the user asked for a bytecode library to be built
Misha Brukman2879c292009-01-08 02:11:55 +00001159# with the BYTECODE_LIBRARY variable, then we provide
Reid Spencer81cd0492004-10-23 20:04:14 +00001160# targets for building them.
1161#---------------------------------------------------------
Reid Spencerf206bd72004-10-22 21:01:56 +00001162ifdef BYTECODE_LIBRARY
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001163ifeq ($(strip $(LLVMCC)),)
1164$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
Reid Spencere9fa5442005-02-14 21:54:08 +00001165else
Reid Spencerf206bd72004-10-22 21:01:56 +00001166
Reid Spencer32f7e422004-12-02 09:28:21 +00001167all-local:: $(LibName.BCA)
1168
1169ifdef EXPORTED_SYMBOL_FILE
Daniel Dunbar8657a022010-02-23 09:28:50 +00001170BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer32f7e422004-12-02 09:28:21 +00001171
Reid Spencerb63d0c42007-02-09 15:52:07 +00001172$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001173 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001174 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1175 "(internalize)"
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001176 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001177 $(Verb) $(RM) -f $@
Daniel Dunbar8d799c52009-08-28 16:14:46 +00001178 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
Reid Spencerf206bd72004-10-22 21:01:56 +00001179else
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001180$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattnerc0bd4b12004-12-15 17:14:06 +00001181 $(LLVMToolDir)/llvm-ar
Reid Spencer32f7e422004-12-02 09:28:21 +00001182 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencer85d55ad2004-12-13 03:59:35 +00001183 $(Verb) $(RM) -f $@
Reid Spencer32f7e422004-12-02 09:28:21 +00001184 $(Verb) $(LArchive) $@ $(ObjectsBC)
1185
Reid Spencerf206bd72004-10-22 21:01:56 +00001186endif
1187
Reid Spencer81cd0492004-10-23 20:04:14 +00001188clean-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001189ifneq ($(strip $(LibName.BCA)),)
1190 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencer12a3a052004-10-24 07:53:21 +00001191endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001192
Reid Spencer65086be2004-12-13 07:28:21 +00001193ifdef BYTECODE_DESTINATION
1194BytecodeDestDir := $(BYTECODE_DESTINATION)
1195else
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001196BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencer65086be2004-12-13 07:28:21 +00001197endif
1198
Daniel Dunbarc25ba422009-05-12 05:35:40 +00001199DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Reid Spencer32f7e422004-12-02 09:28:21 +00001200
Reid Spencerd4bd3752004-12-03 20:08:48 +00001201install-bytecode-local:: $(DestBytecodeLib)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001202
Reid Spencera79819d2007-02-06 18:53:14 +00001203ifdef NO_INSTALL
1204install-local::
1205 $(Echo) Install circumvented with NO_INSTALL
1206uninstall-local::
1207 $(Echo) Uninstall circumvented with NO_INSTALL
1208else
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001209install-local:: $(DestBytecodeLib)
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001210
Mike Stump35f423e2009-02-12 23:45:11 +00001211$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Reid Spencer32f7e422004-12-02 09:28:21 +00001212 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerdcc53752005-02-24 21:36:32 +00001213 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001214
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001215uninstall-local::
Reid Spencer32f7e422004-12-02 09:28:21 +00001216 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001217 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001218endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001219endif
Reid Spencere9fa5442005-02-14 21:54:08 +00001220endif
Vikram S. Adve15bd3ad2002-08-02 18:34:12 +00001221
Reid Spencerf88808a2004-10-30 09:19:36 +00001222#---------------------------------------------------------
Chris Lattnereaae8d02009-06-16 23:00:42 +00001223# Library Targets:
1224# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1225# building an archive.
Reid Spencerf88808a2004-10-30 09:19:36 +00001226#---------------------------------------------------------
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +00001227ifndef NO_BUILD_ARCHIVE
Chris Lattner1b91cbd2005-10-24 02:21:45 +00001228ifndef BUILD_ARCHIVE
Chris Lattnereaae8d02009-06-16 23:00:42 +00001229ifndef LOADABLE_MODULE
1230BUILD_ARCHIVE = 1
Reid Spencera79819d2007-02-06 18:53:14 +00001231endif
Chris Lattner76d98ba2002-07-23 17:56:16 +00001232endif
Jeffrey Yasskin6b718f72010-02-25 06:34:33 +00001233endif
Chris Lattnerc2bd7cf2003-03-14 20:25:22 +00001234
Reid Spencerf88808a2004-10-30 09:19:36 +00001235#---------------------------------------------------------
1236# Archive Library Targets:
Misha Brukman2879c292009-01-08 02:11:55 +00001237# If the user wanted a regular archive library built,
Reid Spencerf88808a2004-10-30 09:19:36 +00001238# then we provide targets for building them.
1239#---------------------------------------------------------
Chris Lattner76d98ba2002-07-23 17:56:16 +00001240ifdef BUILD_ARCHIVE
Chris Lattner76d98ba2002-07-23 17:56:16 +00001241
Reid Spencerf88808a2004-10-30 09:19:36 +00001242all-local:: $(LibName.A)
1243
Reid Spenceraeea3cf2004-12-16 07:36:08 +00001244$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001245 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001246 -$(Verb) $(RM) -f $@
Bill Wendlingb2f724e2009-01-03 22:46:50 +00001247 $(Verb) $(Archive) $@ $(ObjectsO)
1248 $(Verb) $(Ranlib) $@
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001249
Reid Spencer81cd0492004-10-23 20:04:14 +00001250clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001251ifneq ($(strip $(LibName.A)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001252 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner2f7c9632001-06-06 20:29:01 +00001253endif
1254
Reid Spencera79819d2007-02-06 18:53:14 +00001255ifdef NO_INSTALL
1256install-local::
1257 $(Echo) Install circumvented with NO_INSTALL
1258uninstall-local::
1259 $(Echo) Uninstall circumvented with NO_INSTALL
Daniel Dunbar11328b72010-04-30 22:00:17 +00001260else
1261ifdef NO_INSTALL_ARCHIVES
Daniel Dunbar7d9ec412010-04-30 20:04:53 +00001262install-local::
1263 $(Echo) Install circumvented with NO_INSTALL
1264uninstall-local::
1265 $(Echo) Uninstall circumvented with NO_INSTALL
Reid Spencera79819d2007-02-06 18:53:14 +00001266else
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001267DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencer12a3a052004-10-24 07:53:21 +00001268
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001269install-local:: $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001270
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001271$(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001272 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001273 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001274 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Reid Spencer12a3a052004-10-24 07:53:21 +00001275
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001276uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001277 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001278 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencera79819d2007-02-06 18:53:14 +00001279endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001280endif
Daniel Dunbar11328b72010-04-30 22:00:17 +00001281endif
Reid Spencer12a3a052004-10-24 07:53:21 +00001282
1283# endif LIBRARYNAME
Misha Brukman2879c292009-01-08 02:11:55 +00001284endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001285
Reid Spencerdcba7782004-10-24 08:21:04 +00001286###############################################################################
1287# Tool Build Rules: Build executable tool based on TOOLNAME option
1288###############################################################################
1289
Chris Lattner07c7c192001-09-07 22:57:58 +00001290ifdef TOOLNAME
1291
Reid Spencerf88808a2004-10-30 09:19:36 +00001292#---------------------------------------------------------
1293# Set up variables for building a tool.
1294#---------------------------------------------------------
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001295TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001296ifdef EXAMPLE_TOOL
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001297ToolBuildPath := $(ExmplDir)/$(TOOLEXENAME)
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001298else
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001299ToolBuildPath := $(ToolDir)/$(TOOLEXENAME)
1300endif
1301
1302# TOOLALIAS is a name to symlink (or copy) the tool to.
1303ifdef TOOLALIAS
1304ifdef EXAMPLE_TOOL
1305ToolAliasBuildPath := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1306else
1307ToolAliasBuildPath := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1308endif
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001309endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001310
Reid Spencerf88808a2004-10-30 09:19:36 +00001311#---------------------------------------------------------
Chris Lattner0f1958092009-02-26 17:47:49 +00001312# Prune Exports
1313#---------------------------------------------------------
1314
1315# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1316# not exporting all of the weak symbols from the binary. This reduces dyld
1317# startup time by 4x on darwin in some cases.
1318ifdef TOOL_NO_EXPORTS
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001319ifeq ($(HOST_OS),Darwin)
Chris Lattner869b6bf2009-03-10 17:15:56 +00001320
1321# Tiger tools don't support this.
1322ifneq ($(DARWIN_MAJVERS),4)
Dan Gohman91f8ad72010-04-16 22:58:15 +00001323LD.Flags += -Wl,-exported_symbol,_main
Chris Lattner0f1958092009-02-26 17:47:49 +00001324endif
Chris Lattner869b6bf2009-03-10 17:15:56 +00001325endif
Chris Lattner0f1958092009-02-26 17:47:49 +00001326
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001327ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
Bruno Cardoso Lopes56129bd2010-07-20 08:44:20 +00001328ifneq ($(ARCH), Mips)
Nick Lewyckyefd3e902009-10-25 03:22:00 +00001329 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner0f1958092009-02-26 17:47:49 +00001330endif
1331endif
Bruno Cardoso Lopes56129bd2010-07-20 08:44:20 +00001332endif
Chris Lattner0f1958092009-02-26 17:47:49 +00001333
Devang Patelcedf9562010-07-15 20:57:09 +00001334#---------------------------------------------------------
Daniel Dunbar923e3ea2010-09-16 00:42:32 +00001335# Tool Order File Support
1336#---------------------------------------------------------
1337
1338ifeq ($(HOST_OS),Darwin)
1339ifdef TOOL_ORDER_FINE
1340
1341LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1342
1343endif
1344endif
1345
1346#---------------------------------------------------------
Devang Patelcedf9562010-07-15 20:57:09 +00001347# Tool Version Info Support
1348#---------------------------------------------------------
1349
1350ifeq ($(HOST_OS),Darwin)
1351ifdef TOOL_INFO_PLIST
1352
1353LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1354
1355$(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1356
Daniel Dunbar0a2f1ba2010-07-15 21:51:52 +00001357$(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
Devang Patelcedf9562010-07-15 20:57:09 +00001358 $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1359 $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1360 -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1361 -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1362 -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1363 $< > $@
1364
1365endif
1366endif
Chris Lattner0f1958092009-02-26 17:47:49 +00001367
1368#---------------------------------------------------------
Reid Spencerf88808a2004-10-30 09:19:36 +00001369# Provide targets for building the tools
1370#---------------------------------------------------------
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001371all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
John Criswell8224df92003-06-27 16:58:44 +00001372
Reid Spencer81cd0492004-10-23 20:04:14 +00001373clean-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00001374ifneq ($(strip $(ToolBuildPath)),)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001375 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencer12a3a052004-10-24 07:53:21 +00001376endif
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001377ifneq ($(strip $(ToolAliasBuildPath)),)
1378 -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1379endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001380
Reid Spencer7e9e0b02004-11-18 10:03:46 +00001381ifdef EXAMPLE_TOOL
1382$(ToolBuildPath): $(ExmplDir)/.dir
1383else
1384$(ToolBuildPath): $(ToolDir)/.dir
1385endif
1386
Chris Lattnera5d27b12006-09-04 06:39:52 +00001387$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001388 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001389 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencer10536582006-05-16 06:25:14 +00001390 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattnere2dcbe02006-02-14 04:25:54 +00001391 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukman2879c292009-01-08 02:11:55 +00001392 $(StripWarnMsg)
Reid Spencer12a3a052004-10-24 07:53:21 +00001393
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001394ifneq ($(strip $(ToolAliasBuildPath)),)
1395$(ToolAliasBuildPath): $(ToolBuildPath)
1396 $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1397 $(Verb) $(RM) -f $(ToolAliasBuildPath)
1398 $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
Dan Gohmana6103042010-08-18 01:35:53 +00001399 $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001400 $(StripWarnMsg)
1401endif
1402
Reid Spencera79819d2007-02-06 18:53:14 +00001403ifdef NO_INSTALL
1404install-local::
1405 $(Echo) Install circumvented with NO_INSTALL
1406uninstall-local::
1407 $(Echo) Uninstall circumvented with NO_INSTALL
1408else
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001409DestTool = $(DESTDIR)$(PROJ_bindir)/$(TOOLEXENAME)
Reid Spencer12a3a052004-10-24 07:53:21 +00001410
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001411install-local:: $(DestTool)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001412
Erick Tryzelaar444c0952010-03-04 20:56:19 +00001413$(DestTool): $(ToolBuildPath) $(DESTDIR)$(PROJ_bindir)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001414 $(Echo) Installing $(BuildMode) $(DestTool)
Reid Spencerc43b1d42005-02-24 03:56:32 +00001415 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencer12a3a052004-10-24 07:53:21 +00001416
Reid Spencerbe6a4e92004-10-28 07:57:28 +00001417uninstall-local::
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001418 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001419 -$(Verb) $(RM) -f $(DestTool)
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001420
1421# TOOLALIAS install.
1422ifdef TOOLALIAS
Chris Lattner0c48de02010-03-10 21:27:53 +00001423DestToolAlias = $(DESTDIR)$(PROJ_bindir)/$(TOOLALIAS)$(EXEEXT)
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001424
1425install-local:: $(DestToolAlias)
1426
Daniel Dunbar207014a92010-04-30 20:47:09 +00001427$(DestToolAlias): $(DestTool)
Daniel Dunbar0dd2b812009-11-19 00:14:53 +00001428 $(Echo) Installing $(BuildMode) $(DestToolAlias)
1429 $(Verb) $(RM) -f $(DestToolAlias)
1430 $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1431
1432uninstall-local::
1433 $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1434 -$(Verb) $(RM) -f $(DestToolAlias)
1435endif
1436
Reid Spencera79819d2007-02-06 18:53:14 +00001437endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001438endif
Chris Lattner07c7c192001-09-07 22:57:58 +00001439
Reid Spencerf88808a2004-10-30 09:19:36 +00001440###############################################################################
Misha Brukman2879c292009-01-08 02:11:55 +00001441# Object Build Rules: Build object files based on sources
Reid Spencerf88808a2004-10-30 09:19:36 +00001442###############################################################################
1443
Duraid Madinacbbc1842006-02-15 03:23:26 +00001444# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
Anton Korobeynikov90e17e72009-08-18 00:40:33 +00001445ifeq ($(HOST_OS),HP-UX)
Duraid Madinacbbc1842006-02-15 03:23:26 +00001446 DISABLE_AUTO_DEPENDENCIES=1
1447endif
1448
Reid Spencerf88808a2004-10-30 09:19:36 +00001449# Provide rule sets for when dependency generation is enabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001450ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve20aa62f2002-09-20 14:03:13 +00001451
Reid Spencerf88808a2004-10-30 09:19:36 +00001452#---------------------------------------------------------
Nick Lewycky28c62d22009-02-26 07:44:16 +00001453# Create .o files in the ObjDir directory from the .cpp and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001454#---------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00001455
Chris Lattnerc23e6352007-12-31 23:58:31 +00001456DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewycky28c62d22009-02-26 07:44:16 +00001457 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greifc848f9e2008-02-27 13:34:15 +00001458
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001459# If the build succeeded, move the dependency file over, otherwise
1460# remove it.
Chris Lattnerc23e6352007-12-31 23:58:31 +00001461DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1462 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1463
Daniel Dunbar4c5301d2010-09-09 17:38:11 +00001464$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Jakob Stoklund Olesenbefc8532009-10-04 17:54:36 +00001465 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001466 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001467 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001468
Daniel Dunbar4c5301d2010-09-09 17:38:11 +00001469$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Claytonf9d17762010-07-13 18:47:09 +00001470 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1471 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1472 $(DEPEND_MOVEFILE)
1473
Daniel Dunbar4c5301d2010-09-09 17:38:11 +00001474$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattner085c7152006-06-21 20:58:03 +00001475 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001476 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001477 $(DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001478
Daniel Dunbar4c5301d2010-09-09 17:38:11 +00001479$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattner085c7152006-06-21 20:58:03 +00001480 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001481 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnerc23e6352007-12-31 23:58:31 +00001482 $(DEPEND_MOVEFILE)
Reid Spencer81cd0492004-10-23 20:04:14 +00001483
Daniel Dunbar4c5301d2010-09-09 17:38:11 +00001484$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Claytonf9d17762010-07-13 18:47:09 +00001485 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1486 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1487 $(DEPEND_MOVEFILE)
1488
Reid Spencerf88808a2004-10-30 09:19:36 +00001489#---------------------------------------------------------
Chris Lattnerf60c1702005-02-04 21:28:50 +00001490# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencerf88808a2004-10-30 09:19:36 +00001491#---------------------------------------------------------
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001492
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001493BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1494 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1495
1496# If the build succeeded, move the dependency file over, otherwise
1497# remove it.
1498BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1499 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1500
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001501$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001502 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001503 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Duncan Sands1bc53032010-11-25 21:14:55 +00001504 $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001505 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001506
Greg Claytonf9d17762010-07-13 18:47:09 +00001507$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1508 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1509 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Duncan Sands1bc53032010-11-25 21:14:55 +00001510 $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
Greg Claytonf9d17762010-07-13 18:47:09 +00001511 $(BC_DEPEND_MOVEFILE)
1512
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001513$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001514 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001515 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Duncan Sands1bc53032010-11-25 21:14:55 +00001516 $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001517 $(BC_DEPEND_MOVEFILE)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001518
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001519$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001520 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001521 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Duncan Sands1bc53032010-11-25 21:14:55 +00001522 $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001523 $(BC_DEPEND_MOVEFILE)
Reid Spencerf206bd72004-10-22 21:01:56 +00001524
Greg Claytonf9d17762010-07-13 18:47:09 +00001525$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1526 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1527 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Duncan Sands1bc53032010-11-25 21:14:55 +00001528 $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
Greg Claytonf9d17762010-07-13 18:47:09 +00001529 $(BC_DEPEND_MOVEFILE)
1530
Reid Spencerf88808a2004-10-30 09:19:36 +00001531# Provide alternate rule sets if dependencies are disabled
Reid Spencerf206bd72004-10-22 21:01:56 +00001532else
1533
Nick Lewycky28c62d22009-02-26 07:44:16 +00001534$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001535 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001536 $(Compile.CXX) $< -o $@
Reid Spencer81cd0492004-10-23 20:04:14 +00001537
Greg Claytonf9d17762010-07-13 18:47:09 +00001538$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1539 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1540 $(Compile.CXX) $< -o $@
1541
Nick Lewycky28c62d22009-02-26 07:44:16 +00001542$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001543 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001544 $(Compile.CXX) $< -o $@
Chris Lattnerf60c1702005-02-04 21:28:50 +00001545
Nick Lewycky28c62d22009-02-26 07:44:16 +00001546$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner085c7152006-06-21 20:58:03 +00001547 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001548 $(Compile.C) $< -o $@
Reid Spencerf206bd72004-10-22 21:01:56 +00001549
Greg Claytonf9d17762010-07-13 18:47:09 +00001550$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1551 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1552 $(Compile.C) $< -o $@
1553
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001554$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001555 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Duncan Sands1bc53032010-11-25 21:14:55 +00001556 $(BCCompile.CXX) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
Reid Spencerf206bd72004-10-22 21:01:56 +00001557
Greg Claytonf9d17762010-07-13 18:47:09 +00001558$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1559 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
Duncan Sands1bc53032010-11-25 21:14:55 +00001560 $(BCCompile.CXX) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
Greg Claytonf9d17762010-07-13 18:47:09 +00001561
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001562$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001563 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Duncan Sands1bc53032010-11-25 21:14:55 +00001564 $(BCCompile.CXX) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
Chris Lattnerf60c1702005-02-04 21:28:50 +00001565
Daniel Dunbare615b5f2010-02-23 10:28:06 +00001566$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001567 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Duncan Sands1bc53032010-11-25 21:14:55 +00001568 $(BCCompile.C) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
Brian Gaeke0f148bc2003-12-10 00:26:28 +00001569
Greg Claytonf9d17762010-07-13 18:47:09 +00001570$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1571 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
Duncan Sands1bc53032010-11-25 21:14:55 +00001572 $(BCCompile.C) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
Greg Claytonf9d17762010-07-13 18:47:09 +00001573
Chris Lattner07c7c192001-09-07 22:57:58 +00001574endif
1575
Chris Lattner161a84e2006-06-21 21:01:20 +00001576
1577## Rules for building preprocessed (.i/.ii) outputs.
1578$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1579 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1580 $(Verb) $(Preprocess.CXX) $< -o $@
1581
Greg Claytonf9d17762010-07-13 18:47:09 +00001582$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1583 $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1584 $(Verb) $(Preprocess.CXX) $< -o $@
1585
Chris Lattner161a84e2006-06-21 21:01:20 +00001586$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1587 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1588 $(Verb) $(Preprocess.CXX) $< -o $@
1589
Reid Spencerbef61c52006-12-10 04:56:38 +00001590$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner161a84e2006-06-21 21:01:20 +00001591 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1592 $(Verb) $(Preprocess.C) $< -o $@
1593
Greg Claytonf9d17762010-07-13 18:47:09 +00001594$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1595 $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1596 $(Verb) $(Preprocess.C) $< -o $@
1597
Chris Lattner161a84e2006-06-21 21:01:20 +00001598
1599$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1600 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001601 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001602
Greg Claytonf9d17762010-07-13 18:47:09 +00001603$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1604 $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1605 $(Compile.CXX) $< -o $@ -S
1606
Chris Lattner161a84e2006-06-21 21:01:20 +00001607$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1608 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001609 $(Compile.CXX) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001610
1611$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1612 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky28c62d22009-02-26 07:44:16 +00001613 $(Compile.C) $< -o $@ -S
Chris Lattner161a84e2006-06-21 21:01:20 +00001614
Greg Claytonf9d17762010-07-13 18:47:09 +00001615$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1616 $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1617 $(Compile.C) $< -o $@ -S
1618
Reid Spencer4b8067f2006-11-17 03:32:33 +00001619
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001620# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer4b8067f2006-11-17 03:32:33 +00001621ifdef DEBUG_RUNTIME
Dan Gohman40d204f2009-09-08 15:52:56 +00001622$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Reid Spencer4b8067f2006-11-17 03:32:33 +00001623 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001624 $(Verb) $(LOPT) $< -std-compile-opts -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001625else
Dan Gohman40d204f2009-09-08 15:52:56 +00001626$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001627 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman40d204f2009-09-08 15:52:56 +00001628 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
Reid Spencer4b8067f2006-11-17 03:32:33 +00001629endif
1630
Chris Lattnerb3eb31f2006-01-27 22:13:12 +00001631
Reid Spencerf88808a2004-10-30 09:19:36 +00001632#---------------------------------------------------------
1633# Provide rule to build .bc files from .ll sources,
1634# regardless of dependencies
1635#---------------------------------------------------------
1636$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencerb5b92fb2004-11-01 07:50:27 +00001637 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencerf88808a2004-10-30 09:19:36 +00001638 $(Verb) $(LLVMAS) $< -f -o $@
1639
1640###############################################################################
1641# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1642###############################################################################
Chris Lattner0c4f4fe2003-08-15 02:18:35 +00001643
Reid Spencerf206bd72004-10-22 21:01:56 +00001644ifdef TARGET
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001645TABLEGEN_INC_FILES_COMMON = 1
1646endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001647
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001648ifdef LLVMC_BASED_DRIVER
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001649TABLEGEN_INC_FILES_COMMON = 1
1650endif
1651
1652ifdef TABLEGEN_INC_FILES_COMMON
1653
Reid Spencerf88808a2004-10-30 09:19:36 +00001654INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner2a023902004-12-16 17:28:50 +00001655INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1656.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001657
Misha Brukman2879c292009-01-08 02:11:55 +00001658# INCFiles rule: All of the tblgen generated files are emitted to
Chris Lattnerf86914d2004-12-16 17:38:56 +00001659# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1660# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbard395a172008-11-03 17:33:36 +00001661# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Chris Lattnerf86914d2004-12-16 17:38:56 +00001662# dependencies of the .inc files are, unless the contents of the .inc file
1663# changes.
1664$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerafdc82c2004-12-16 18:26:53 +00001665 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner2a023902004-12-16 17:28:50 +00001666
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001667endif # TABLEGEN_INC_FILES_COMMON
1668
1669ifdef TARGET
1670
1671TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1672 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1673 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1674 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1675 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1676 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1677 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1678
Rafael Espindola59e371a2009-03-10 17:58:54 +00001679# All of these files depend on tblgen and the .td files.
1680$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1681
Chris Lattner2a023902004-12-16 17:28:50 +00001682$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1683$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001684 $(Echo) "Building $(<F) register names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001685 $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001686
Chris Lattner2a023902004-12-16 17:28:50 +00001687$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1688$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001689 $(Echo) "Building $(<F) register information header with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001690 $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001691
Chris Lattner2a023902004-12-16 17:28:50 +00001692$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1693$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001694 $(Echo) "Building $(<F) register info implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001695 $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001696
Chris Lattner2a023902004-12-16 17:28:50 +00001697$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1698$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001699 $(Echo) "Building $(<F) instruction names with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001700 $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001701
Chris Lattner2a023902004-12-16 17:28:50 +00001702$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1703$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001704 $(Echo) "Building $(<F) instruction information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001705 $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001706
Chris Lattner2a023902004-12-16 17:28:50 +00001707$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1708$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001709 $(Echo) "Building $(<F) assembly writer with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001710 $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001711
Chris Lattner22f937a2004-12-16 17:34:04 +00001712$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1713$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1714 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Misha Brukman2879c292009-01-08 02:11:55 +00001715 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001716
Daniel Dunbar2841ea42009-07-13 18:35:35 +00001717$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1718$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
1719 $(Echo) "Building $(<F) assembly matcher with tblgen"
1720 $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1721
Jim Grosbachcd536df2010-11-03 23:46:01 +00001722$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
1723$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1724 $(Echo) "Building $(<F) MC code emitter with tblgen"
1725 $(Verb) $(TableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
1726
Chris Lattner2a023902004-12-16 17:28:50 +00001727$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1728$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
Reid Spencerf88808a2004-10-30 09:19:36 +00001729 $(Echo) "Building $(<F) code emitter with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001730 $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Reid Spencerf206bd72004-10-22 21:01:56 +00001731
Chris Lattner33f98bd2005-09-03 01:15:25 +00001732$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1733$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
Dan Gohmanb2226e22008-08-13 20:19:35 +00001734 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001735 $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001736
Daniel Dunbare8b8cce2009-11-25 04:46:58 +00001737$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1738$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir
1739 $(Echo) "Building $(<F) disassembly tables with tblgen"
1740 $(Verb) $(TableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1741
Sean Callanan82436d12010-01-29 00:21:04 +00001742$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1743$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir
1744 $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1745 $(Verb) $(TableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1746
Dan Gohmanb2226e22008-08-13 20:19:35 +00001747$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1748$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1749 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1750 $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1751
Jim Laskey9ed90322005-10-21 19:05:19 +00001752$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1753$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1754 $(Echo) "Building $(<F) subtarget information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001755 $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Chris Lattner33f98bd2005-09-03 01:15:25 +00001756
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001757$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1758$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1759 $(Echo) "Building $(<F) calling convention information with tblgen"
Chris Lattner50475362008-01-15 23:27:40 +00001760 $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Chris Lattneree0fe3b2007-02-27 20:44:12 +00001761
Dale Johannesenb842d522009-02-05 01:49:45 +00001762$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
Jakob Stoklund Olesen79843052009-10-15 18:48:47 +00001763$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir
1764 $(Echo) "Building $(<F) intrinsics information with tblgen"
Dale Johannesenb842d522009-02-05 01:49:45 +00001765 $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1766
Johnny Chen7b999ea2010-04-02 22:27:38 +00001767$(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir
1768 $(Echo) "Building $(<F) decoder tables with tblgen"
1769 $(Verb) $(TableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
1770
1771
Reid Spencer81cd0492004-10-23 20:04:14 +00001772clean-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001773 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencerf206bd72004-10-22 21:01:56 +00001774
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001775endif # TARGET
1776
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001777ifdef LLVMC_BASED_DRIVER
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001778
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001779TDSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1780 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001781
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001782TDCommon := $(strip $(wildcard \
1783 $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001784
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001785TDFiles := $(TDSrc) $(TDCommon)
1786
1787$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1788
1789$(ObjDir)/%.inc.tmp: %.td $(ObjDir)/.dir
1790 $(Echo) "Building LLVMC compilation graph description with tblgen"
Mikhail Glushenkovf4a68092010-10-23 07:32:53 +00001791 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001792
Mikhail Glushenkov938e9762010-08-15 07:07:12 +00001793clean-local::
1794 -$(Verb) $(RM) -f $(INCFiles)
1795
1796endif # LLVMC_BASED_DRIVER
Mikhail Glushenkovc6333bd2009-03-02 09:42:59 +00001797
Reid Spencerf88808a2004-10-30 09:19:36 +00001798###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001799# OTHER RULES: Other rules needed
1800###############################################################################
Reid Spencerf206bd72004-10-22 21:01:56 +00001801
Chris Lattner23d47392003-01-16 21:06:18 +00001802# To create postscript files from dot files...
John Criswell4ffb8442003-10-02 19:02:02 +00001803ifneq ($(DOT),false)
Chris Lattner23d47392003-01-16 21:06:18 +00001804%.ps: %.dot
Reid Spencerf206bd72004-10-22 21:01:56 +00001805 $(DOT) -Tps < $< > $@
John Criswell3ef61af2003-06-30 21:59:07 +00001806else
1807%.ps: %.dot
Reid Spencerf88808a2004-10-30 09:19:36 +00001808 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell3ef61af2003-06-30 21:59:07 +00001809endif
Chris Lattner23d47392003-01-16 21:06:18 +00001810
John Criswell0a6e6aa2003-09-06 14:44:17 +00001811# This rules ensures that header files that are removed still have a rule for
1812# which they can be "generated." This allows make to ignore them and
1813# reproduce the dependency lists.
John Criswella8391af2003-09-18 18:37:08 +00001814%.h:: ;
Chris Lattnerf60c1702005-02-04 21:28:50 +00001815%.hpp:: ;
John Criswell0a6e6aa2003-09-06 14:44:17 +00001816
Reid Spencerf88808a2004-10-30 09:19:36 +00001817# Define clean-local to clean the current directory. Note that this uses a
Misha Brukman2879c292009-01-08 02:11:55 +00001818# very conservative approach ensuring that empty variables do not cause
Reid Spencerf88808a2004-10-30 09:19:36 +00001819# errors or disastrous removal.
Reid Spencer81cd0492004-10-23 20:04:14 +00001820clean-local::
Jim Grosbach009db892008-10-02 22:56:44 +00001821ifneq ($(strip $(ObjRootDir)),)
1822 -$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencer12a3a052004-10-24 07:53:21 +00001823endif
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001824 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
Brian Gaeke8625f682004-01-21 19:53:11 +00001825ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001826 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke8625f682004-01-21 19:53:11 +00001827endif
John Criswell3ef61af2003-06-30 21:59:07 +00001828
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001829clean-all-local::
Reid Spencer651dd3ad2004-11-02 16:56:15 +00001830 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer9d0c1e02004-11-02 16:36:03 +00001831
Reid Spenceraee67e62004-11-12 02:27:36 +00001832
Reid Spencer81cd0492004-10-23 20:04:14 +00001833###############################################################################
1834# DEPENDENCIES: Include the dependency files if we should
1835###############################################################################
Chris Lattnere9d7d702003-08-22 14:10:16 +00001836ifndef DISABLE_AUTO_DEPENDENCIES
1837
Reid Spencer81cd0492004-10-23 20:04:14 +00001838# If its not one of the cleaning targets
Daniel Dunbar78caa022008-10-03 19:11:19 +00001839ifndef IS_CLEANING_TARGET
Reid Spencerf206bd72004-10-22 21:01:56 +00001840
Reid Spencer81cd0492004-10-23 20:04:14 +00001841# Get the list of dependency files
Greg Claytonf9d17762010-07-13 18:47:09 +00001842DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
Daniel Dunbar8a28e012009-05-12 06:35:50 +00001843DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1844
1845# Include bitcode dependency files if using bitcode libraries
1846ifdef BYTECODE_LIBRARY
1847DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1848endif
Misha Brukmanb891ffb2003-11-09 21:36:19 +00001849
Reid Spencerfcd78152007-07-23 08:20:46 +00001850-include $(DependFiles) ""
Reid Spencer81cd0492004-10-23 20:04:14 +00001851
John Criswell48ecca62003-08-12 18:51:51 +00001852endif
Chris Lattner598222b2003-08-18 17:27:40 +00001853
Misha Brukman2879c292009-01-08 02:11:55 +00001854endif
Reid Spencerf206bd72004-10-22 21:01:56 +00001855
Reid Spencer100080c2004-10-25 08:27:37 +00001856###############################################################################
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001857# CHECK: Running the test suite
1858###############################################################################
1859
Bill Wendlingf704f902009-04-09 18:26:57 +00001860check::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001861 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1862 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001863 $(EchoCmd) Running test suite ; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001864 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001865 TESTSUITE=$(TESTSUITE) ; \
1866 else \
1867 $(EchoCmd) No Makefile in test directory ; \
1868 fi ; \
1869 else \
1870 $(EchoCmd) No test directory ; \
1871 fi
1872
Daniel Dunbarb1af6052010-08-02 00:05:18 +00001873check-lit:: check
1874
1875check-dg::
Daniel Dunbar3eeddd22009-09-08 05:31:44 +00001876 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1877 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1878 $(EchoCmd) Running test suite ; \
Daniel Dunbarb1af6052010-08-02 00:05:18 +00001879 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
Daniel Dunbar3eeddd22009-09-08 05:31:44 +00001880 else \
1881 $(EchoCmd) No Makefile in test directory ; \
1882 fi ; \
1883 else \
1884 $(EchoCmd) No test directory ; \
1885 fi
1886
Daniel Dunbarf2719e62009-09-20 06:17:21 +00001887check-all::
1888 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1889 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1890 $(EchoCmd) Running test suite ; \
1891 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1892 else \
1893 $(EchoCmd) No Makefile in test directory ; \
1894 fi ; \
1895 else \
1896 $(EchoCmd) No test directory ; \
1897 fi
1898
Reid Spencer8b5ebe52004-12-06 05:35:13 +00001899###############################################################################
Bill Wendling8790e322009-01-04 23:12:21 +00001900# UNITTESTS: Running the unittests test suite
1901###############################################################################
1902
Bill Wendlingf704f902009-04-09 18:26:57 +00001903unittests::
Bill Wendling8790e322009-01-04 23:12:21 +00001904 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1905 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1906 $(EchoCmd) Running unittests test suite ; \
Daniel Dunbar96ccc472009-09-13 22:39:27 +00001907 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
Bill Wendling8790e322009-01-04 23:12:21 +00001908 else \
1909 $(EchoCmd) No Makefile in unittests directory ; \
1910 fi ; \
1911 else \
1912 $(EchoCmd) No unittests directory ; \
1913 fi
1914
1915###############################################################################
Reid Spencerf88808a2004-10-30 09:19:36 +00001916# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer100080c2004-10-25 08:27:37 +00001917###############################################################################
1918
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001919#------------------------------------------------------------------------
1920# Define distribution related variables
1921#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001922DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1923DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1924TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1925DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1926DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1927DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer100080c2004-10-25 08:27:37 +00001928DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1929 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001930 Makefile.config.in configure autoconf
1931DistOther := $(notdir $(wildcard \
Reid Spencerba6a3db2005-01-16 02:20:54 +00001932 $(PROJ_SRC_DIR)/*.h \
1933 $(PROJ_SRC_DIR)/*.td \
1934 $(PROJ_SRC_DIR)/*.def \
1935 $(PROJ_SRC_DIR)/*.ll \
1936 $(PROJ_SRC_DIR)/*.in))
Reid Spencerf88808a2004-10-30 09:19:36 +00001937DistSubDirs := $(SubDirs)
Reid Spencerfc66af42004-11-29 05:00:33 +00001938DistSources = $(Sources) $(EXTRA_DIST)
1939DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer100080c2004-10-25 08:27:37 +00001940
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001941#------------------------------------------------------------------------
1942# We MUST build distribution with OBJ_DIR != SRC_DIR
1943#------------------------------------------------------------------------
Reid Spencerba6a3db2005-01-16 02:20:54 +00001944ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001945dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerf88808a2004-10-30 09:19:36 +00001946 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001947
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001948else
1949
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001950#------------------------------------------------------------------------
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001951# Prevent attempt to run dist targets from anywhere but the top level
1952#------------------------------------------------------------------------
1953ifneq ($(LEVEL),.)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001954dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencerba6a3db2005-01-16 02:20:54 +00001955 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001956else
1957
1958#------------------------------------------------------------------------
1959# Provide the top level targets
1960#------------------------------------------------------------------------
1961
Reid Spencerf88808a2004-10-30 09:19:36 +00001962dist-gzip:: $(DistTarGZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001963
Reid Spencer81546582004-12-04 22:34:09 +00001964$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001965 $(Echo) Packing gzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001966 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001967 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001968
Reid Spencerf88808a2004-10-30 09:19:36 +00001969dist-bzip2:: $(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001970
Reid Spencer81546582004-12-04 22:34:09 +00001971$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001972 $(Echo) Packing bzipped distribution tar file.
Reid Spencerba6a3db2005-01-16 02:20:54 +00001973 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfc66af42004-11-29 05:00:33 +00001974 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001975
Reid Spencerf88808a2004-10-30 09:19:36 +00001976dist-zip:: $(DistZip)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001977
Reid Spencer81546582004-12-04 22:34:09 +00001978$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencerf88808a2004-10-30 09:19:36 +00001979 $(Echo) Packing zipped distribution file.
1980 $(Verb) rm -f $(DistZip)
Reid Spencerba6a3db2005-01-16 02:20:54 +00001981 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001982
Misha Brukman2879c292009-01-08 02:11:55 +00001983dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001984 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001985
Reid Spencer3a468752005-01-28 19:52:32 +00001986DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001987
Reid Spencer81546582004-12-04 22:34:09 +00001988dist-check:: $(DistTarGZip)
Reid Spencerf88808a2004-10-30 09:19:36 +00001989 $(Echo) Checking distribution tar file.
1990 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001991 $(RM) -rf $(DistCheckDir) ; \
1992 fi
Reid Spencerf88808a2004-10-30 09:19:36 +00001993 $(Verb) $(MKDIR) $(DistCheckDir)
1994 $(Verb) cd $(DistCheckDir) && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00001995 $(MKDIR) $(DistCheckDir)/build && \
1996 $(MKDIR) $(DistCheckDir)/install && \
1997 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1998 cd build && \
1999 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer13f51932005-05-24 02:33:20 +00002000 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer81546582004-12-04 22:34:09 +00002001 $(MAKE) all && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002002 $(MAKE) check && \
Bill Wendling8790e322009-01-04 23:12:21 +00002003 $(MAKE) unittests && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002004 $(MAKE) install && \
2005 $(MAKE) uninstall && \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002006 $(MAKE) dist-clean && \
Reid Spencerf88808a2004-10-30 09:19:36 +00002007 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002008
2009dist-clean::
Reid Spencerf88808a2004-10-30 09:19:36 +00002010 $(Echo) Cleaning distribution files
Reid Spencer81546582004-12-04 22:34:09 +00002011 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2012 $(DistCheckDir)
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002013
2014endif
2015
2016#------------------------------------------------------------------------
2017# Provide the recursive distdir target for building the distribution directory
2018#------------------------------------------------------------------------
Reid Spencer81546582004-12-04 22:34:09 +00002019distdir: $(DistDir)/.makedistdir
2020$(DistDir)/.makedistdir: $(DistSources)
Reid Spencerf88808a2004-10-30 09:19:36 +00002021 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002022 if test -d "$(DistDir)" ; then \
2023 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
2024 exit 1 ; \
2025 fi ; \
Reid Spencer81546582004-12-04 22:34:09 +00002026 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002027 $(RM) -rf $(DistDir); \
Reid Spencer8b5ebe52004-12-06 05:35:13 +00002028 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer15b85092006-04-10 16:46:04 +00002029 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002030 fi
Reid Spencerfc66af42004-11-29 05:00:33 +00002031 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukman2879c292009-01-08 02:11:55 +00002032 $(Verb) $(MKDIR) $(DistDir)
Reid Spencerba6a3db2005-01-16 02:20:54 +00002033 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2034 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer100080c2004-10-25 08:27:37 +00002035 for file in $(DistFiles) ; do \
2036 case "$$file" in \
Reid Spencerba6a3db2005-01-16 02:20:54 +00002037 $(PROJ_SRC_DIR)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00002038 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2039 ;; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00002040 $(PROJ_SRC_ROOT)/*) \
Reid Spencer81546582004-12-04 22:34:09 +00002041 file=`echo "$$file" | \
2042 sed "s#^$$srcrootstrip/##"` \
2043 ;; \
Reid Spencer100080c2004-10-25 08:27:37 +00002044 esac; \
Reid Spencerba6a3db2005-01-16 02:20:54 +00002045 if test -f "$(PROJ_SRC_DIR)/$$file" || \
2046 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2047 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer81546582004-12-04 22:34:09 +00002048 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00002049 from_dir=. ; \
Reid Spencer81546582004-12-04 22:34:09 +00002050 fi ; \
2051 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer100080c2004-10-25 08:27:37 +00002052 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2053 to_dir="$(DistDir)/$$dir"; \
2054 $(MKDIR) "$$to_dir" ; \
2055 else \
2056 to_dir="$(DistDir)"; \
2057 fi; \
2058 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2059 if test -n "$$mid_dir" ; then \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002060 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00002061 fi ; \
2062 if test -d "$$from_dir/$$file"; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00002063 if test -d "$(PROJ_SRC_DIR)/$$file" && \
2064 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00002065 cd $(PROJ_SRC_DIR) ; \
2066 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2067 ( cd $$to_dir ; $(TAR) xf - ) ; \
2068 cd $(PROJ_OBJ_DIR) ; \
2069 else \
2070 cd $$from_dir ; \
2071 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2072 ( cd $$to_dir ; $(TAR) xf - ) ; \
2073 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer100080c2004-10-25 08:27:37 +00002074 fi; \
Reid Spencer100080c2004-10-25 08:27:37 +00002075 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00002076 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00002077 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerafdc82c2004-12-16 18:26:53 +00002078 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00002079 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer81546582004-12-04 22:34:09 +00002080 $(EchoCmd) "===== WARNING: Distribution Source " \
2081 "$$from_dir/$$file Not Found!" ; \
Reid Spencerf88808a2004-10-30 09:19:36 +00002082 elif test "$(Verb)" != '@' ; then \
2083 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer100080c2004-10-25 08:27:37 +00002084 fi; \
2085 done
Reid Spencerf88808a2004-10-30 09:19:36 +00002086 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer100080c2004-10-25 08:27:37 +00002087 if test "$$subdir" \!= "." ; then \
Reid Spencer100080c2004-10-25 08:27:37 +00002088 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencer8da1b5d2004-10-26 07:09:33 +00002089 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer15b85092006-04-10 16:46:04 +00002090 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencer056f0222006-04-07 16:06:18 +00002091 DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer100080c2004-10-25 08:27:37 +00002092 fi; \
2093 done
Reid Spencer81546582004-12-04 22:34:09 +00002094 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer13f51932005-05-24 02:33:20 +00002095 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
Chris Lattnerb8e7aa02006-02-14 04:27:15 +00002096 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2097 -name .svn \) -print` ;\
Reid Spencer81546582004-12-04 22:34:09 +00002098 $(MAKE) dist-hook ; \
2099 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2100 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2101 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2102 -o ! -type d ! -perm -444 -exec \
2103 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2104 || chmod -R a+r $(DistDir) ; \
2105 fi
Reid Spencer100080c2004-10-25 08:27:37 +00002106
Reid Spencerf88808a2004-10-30 09:19:36 +00002107# This is invoked by distdir target, define it as a no-op to avoid errors if not
2108# defined by user.
Reid Spencer100080c2004-10-25 08:27:37 +00002109dist-hook::
2110
Reid Spencer23a70372004-10-22 23:06:30 +00002111endif
Reid Spencerf206bd72004-10-22 21:01:56 +00002112
2113###############################################################################
Reid Spencer12a3a052004-10-24 07:53:21 +00002114# TOP LEVEL - targets only to apply at the top level directory
2115###############################################################################
2116
2117ifeq ($(LEVEL),.)
2118
2119#------------------------------------------------------------------------
Reid Spencer8b5ebe52004-12-06 05:35:13 +00002120# Install support for the project's include files:
Reid Spencer12a3a052004-10-24 07:53:21 +00002121#------------------------------------------------------------------------
Reid Spencera79819d2007-02-06 18:53:14 +00002122ifdef NO_INSTALL
2123install-local::
2124 $(Echo) Install circumvented with NO_INSTALL
2125uninstall-local::
2126 $(Echo) Uninstall circumvented with NO_INSTALL
2127else
Reid Spencer12a3a052004-10-24 07:53:21 +00002128install-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00002129 $(Echo) Installing include files
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002130 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
Reid Spencerc43b1d42005-02-24 03:56:32 +00002131 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencerba6a3db2005-01-16 02:20:54 +00002132 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattner814d9ee2009-01-02 07:16:45 +00002133 for hdr in `find . -type f '!' '(' -name '*~' \
Reid Spencerc82c2cf2007-04-09 19:08:58 +00002134 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
2135 grep -v .svn` ; do \
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002136 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
Reid Spencerc43b1d42005-02-24 03:56:32 +00002137 if test \! -d "$$instdir" ; then \
2138 $(EchoCmd) Making install directory $$instdir ; \
2139 $(MKDIR) $$instdir ;\
2140 fi ; \
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002141 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00002142 done ; \
Reid Spencer12a3a052004-10-24 07:53:21 +00002143 fi
Reid Spencer528c9802005-12-23 22:27:56 +00002144ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencerc43b1d42005-02-24 03:56:32 +00002145 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer48a82f42005-02-16 15:54:03 +00002146 cd $(PROJ_OBJ_ROOT)/include && \
Reid Spencer528c9802005-12-23 22:27:56 +00002147 for hdr in `find . -type f -print | grep -v CVS` ; do \
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002148 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer48a82f42005-02-16 15:54:03 +00002149 done ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00002150 fi
Reid Spencer528c9802005-12-23 22:27:56 +00002151endif
Reid Spencer12a3a052004-10-24 07:53:21 +00002152
2153uninstall-local::
Reid Spencerf88808a2004-10-30 09:19:36 +00002154 $(Echo) Uninstalling include files
Reid Spencerba6a3db2005-01-16 02:20:54 +00002155 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2156 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencer12a3a052004-10-24 07:53:21 +00002157 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattner814d9ee2009-01-02 07:16:45 +00002158 '!' '(' -name '*~' -o -name '.#*' \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00002159 -o -name '*.in' ')' -print ')' | \
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002160 grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00002161 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnere2dcbe02006-02-14 04:25:54 +00002162 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
Erick Tryzelaar444c0952010-03-04 20:56:19 +00002163 -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattner81bfc9e2005-02-09 02:24:00 +00002164 fi
Reid Spencera79819d2007-02-06 18:53:14 +00002165endif
Reid Spencer12a3a052004-10-24 07:53:21 +00002166endif
2167
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00002168check-line-length:
Gabor Greif697e94c2008-05-15 10:04:30 +00002169 @echo searching for overlength lines in files: $(Sources)
2170 @echo
2171 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00002172 egrep -n '.{81}' $(Sources) /dev/null
Chris Lattnerf8adf7a2007-04-14 23:35:45 +00002173
Anton Korobeynikovfb801512007-04-16 18:10:23 +00002174check-for-tabs:
Gabor Greif697e94c2008-05-15 10:04:30 +00002175 @echo searching for tabs in files: $(Sources)
2176 @echo
2177 @echo
Gabor Greif2dd54ed2008-08-28 22:32:39 +00002178 egrep -n ' ' $(Sources) /dev/null
Gabor Greif697e94c2008-05-15 10:04:30 +00002179
Reid Spencere6bc2062007-05-02 21:29:39 +00002180check-footprint:
2181 @ls -l $(LibDir) | awk '\
2182 BEGIN { sum = 0; } \
2183 { sum += $$5; } \
2184 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2185 @ls -l $(ToolDir) | awk '\
2186 BEGIN { sum = 0; } \
2187 { sum += $$5; } \
2188 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
Reid Spencerf206bd72004-10-22 21:01:56 +00002189#------------------------------------------------------------------------
2190# Print out the directories used for building
Reid Spencerf88808a2004-10-30 09:19:36 +00002191#------------------------------------------------------------------------
Reid Spencer81cd0492004-10-23 20:04:14 +00002192printvars::
Reid Spencerba6a3db2005-01-16 02:20:54 +00002193 $(Echo) "BuildMode : " '$(BuildMode)'
2194 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2195 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2196 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2197 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2198 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2199 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2200 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
2201 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
2202 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
2203 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencerfe0a01e2005-02-16 16:13:02 +00002204 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00002205 $(Echo) "UserTargets : " '$(UserTargets)'
2206 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2207 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2208 $(Echo) "ObjDir : " '$(ObjDir)'
2209 $(Echo) "LibDir : " '$(LibDir)'
2210 $(Echo) "ToolDir : " '$(ToolDir)'
2211 $(Echo) "ExmplDir : " '$(ExmplDir)'
2212 $(Echo) "Sources : " '$(Sources)'
2213 $(Echo) "TDFiles : " '$(TDFiles)'
2214 $(Echo) "INCFiles : " '$(INCFiles)'
2215 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencerfefb9ea2005-03-01 16:27:06 +00002216 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencerba6a3db2005-01-16 02:20:54 +00002217 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
2218 $(Echo) "Compile.C : " '$(Compile.C)'
2219 $(Echo) "Archive : " '$(Archive)'
2220 $(Echo) "YaccFiles : " '$(YaccFiles)'
2221 $(Echo) "LexFiles : " '$(LexFiles)'
2222 $(Echo) "Module : " '$(Module)'
Reid Spencerb48e3f82005-08-24 10:43:10 +00002223 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
Reid Spencerece13582006-04-09 23:41:14 +00002224 $(Echo) "SubDirs : " '$(SubDirs)'
Reid Spencer200c6f92007-03-29 19:05:44 +00002225 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2226 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar0094e342009-02-21 20:42:39 +00002227
2228###
2229# Debugging
2230
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00002231# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar0094e342009-02-21 20:42:39 +00002232# definition, value and origin of XXX.
Daniel Dunbar3b3c3f02009-03-06 22:23:25 +00002233make-print-%:
Daniel Dunbar0094e342009-02-21 20:42:39 +00002234 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))