blob: 6ab6e959b4259c2decd23c89add16b2903ecc072 [file] [log] [blame]
Misha Brukman6d5ab862004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswelld8846c12003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
Chris Lattner57360d12007-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 Brukmanef5dc702009-01-08 02:11:55 +00007#
Misha Brukman6d5ab862004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner00950542001-06-06 20:29:01 +00009#
Reid Spencer3a561f52004-10-23 20:04:14 +000010# This file is included by all of the LLVM makefiles. For details on how to use
11# it properly, please see the document MakefileGuide.html in the docs directory.
Chris Lattneraf06a082003-08-15 03:02:52 +000012#
Chris Lattner77efe272006-02-14 04:27:15 +000013#===-----------------------------------------------------------------------====#
Chris Lattner00950542001-06-06 20:29:01 +000014
Reid Spencercc2d1e22004-10-30 09:19:36 +000015################################################################################
Reid Spencer3a561f52004-10-23 20:04:14 +000016# TARGETS: Define standard targets that can be invoked
Reid Spencercc2d1e22004-10-30 09:19:36 +000017################################################################################
John Criswell7a73b802003-06-30 21:59:07 +000018
Chris Lattner00950542001-06-06 20:29:01 +000019#--------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +000020# Define the various target sets
21#--------------------------------------------------------------------
Daniel Dunbar7f068f42009-09-13 22:39:27 +000022RecursiveTargets := all clean clean-all install uninstall install-bytecode \
23 unitcheck
Reid Spencer9e8d54a2004-12-06 05:35:13 +000024LocalTargets := all-local clean-local clean-all-local check-local \
Reid Spencer44cb1b32004-12-03 20:08:48 +000025 install-local printvars uninstall-local \
Daniel Dunbar7f068f42009-09-13 22:39:27 +000026 install-bytecode-local
Chris Lattner72e46332007-09-26 06:10:47 +000027TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
Bill Wendling4113bd12009-01-04 23:12:21 +000028 dist-zip unittests
Reid Spencercc2d1e22004-10-30 09:19:36 +000029UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30InternalTargets := preconditions distdir dist-hook
Reid Spencer3a561f52004-10-23 20:04:14 +000031
Reid Spencercc2d1e22004-10-30 09:19:36 +000032################################################################################
Reid Spencer9411c642004-10-26 22:26:33 +000033# INITIALIZATION: Basic things the makefile needs
Reid Spencercc2d1e22004-10-30 09:19:36 +000034################################################################################
35
36#--------------------------------------------------------------------
37# Set the VPATH so that we can find source files.
38#--------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +000039VPATH=$(PROJ_SRC_DIR)
Reid Spencer9411c642004-10-26 22:26:33 +000040
41#--------------------------------------------------------------------
Reid Spencer1abd46d2007-06-29 14:02:07 +000042# Reset the list of suffixes we know how to build.
Reid Spencer9411c642004-10-26 22:26:33 +000043#--------------------------------------------------------------------
44.SUFFIXES:
Greg Clayton43bc79a2010-07-13 18:47:09 +000045.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
Reid Spencercc2d1e22004-10-30 09:19:36 +000046.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
Reid Spencer9411c642004-10-26 22:26:33 +000047
Reid Spencer3a561f52004-10-23 20:04:14 +000048#--------------------------------------------------------------------
49# Mark all of these targets as phony to avoid implicit rule search
50#--------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +000051.PHONY: $(UserTargets) $(InternalTargets)
Reid Spencer3a561f52004-10-23 20:04:14 +000052
53#--------------------------------------------------------------------
Misha Brukmanef5dc702009-01-08 02:11:55 +000054# Make sure all the user-target rules are double colon rules and
Reid Spencer9411c642004-10-26 22:26:33 +000055# they are defined first.
Reid Spencer3a561f52004-10-23 20:04:14 +000056#--------------------------------------------------------------------
57
Reid Spencercc2d1e22004-10-30 09:19:36 +000058$(UserTargets)::
Reid Spencer151f8ba2004-10-25 08:27:37 +000059
Daniel Dunbare29c3162011-11-03 22:46:21 +000060#------------------------------------------------------------------------
61# LLVMBuild Integration
62#------------------------------------------------------------------------
63#
64# We use llvm-build to generate all the data required by the Makefile based
65# build system in one swoop:
66#
67# - We generate a file (a Makefile fragment) in the object root which contains
68# all the definitions that are required by Makefiles across the entire
69# project.
70#
71# - We generate the library table used by llvm-config.
72#
73# - We generate the dependencies for the Makefile fragment, so that we will
74# automatically reconfigure outselves.
75
76# The path to the llvm-build tool itself.
77LLVMBuildTool := $(PROJ_SRC_ROOT)/utils/llvm-build/llvm-build
78
79# The files we are going to generate using llvm-build.
80LLVMBuildMakeFrag := $(PROJ_OBJ_ROOT)/Makefile.llvmbuild
81LLVMConfigLibraryDependenciesInc := \
Daniel Dunbarcb497b82011-12-01 20:18:09 +000082 $(PROJ_OBJ_ROOT)/tools/llvm-config/LibraryDependencies.inc
Daniel Dunbare29c3162011-11-03 22:46:21 +000083
Daniel Dunbara7de1d62011-11-12 00:18:02 +000084# This is for temporary backwards compatibility.
85ifndef TARGET_NATIVE_ARCH
86TARGET_NATIVE_ARCH := $(ARCH)
87endif
88
Daniel Dunbare29c3162011-11-03 22:46:21 +000089# The rule to create the LLVMBuild Makefile fragment as well as the llvm-config
90# library table.
91#
92# Note that this target gets its real dependencies generated for us by
93# llvm-build.
Daniel Dunbar28088532011-11-09 18:48:22 +000094#
95# We include a dependency on this Makefile to ensure that changes to the
96# generation command get picked up.
97$(LLVMBuildMakeFrag): $(PROJ_SRC_ROOT)/Makefile.rules
Daniel Dunbard5574f62011-11-03 23:01:50 +000098 $(Echo) Constructing LLVMBuild project information.
99 $(Verb) $(LLVMBuildTool) \
Daniel Dunbara7de1d62011-11-12 00:18:02 +0000100 --native-target "$(TARGET_NATIVE_ARCH)" \
Daniel Dunbar83337302011-11-10 01:16:48 +0000101 --enable-targets "$(TARGETS_TO_BUILD)" \
Daniel Dunbare29c3162011-11-03 22:46:21 +0000102 --write-library-table $(LLVMConfigLibraryDependenciesInc) \
103 --write-make-fragment $(LLVMBuildMakeFrag)
104
Daniel Dunbar28088532011-11-09 18:48:22 +0000105# For completeness, let Make know how the extra files are generated.
106$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrag)
107
Daniel Dunbare29c3162011-11-03 22:46:21 +0000108# Include the generated Makefile fragment.
109#
110# We currently only include the dependencies for the fragment itself if we are
111# at the top-level. Otherwise, recursive invocations would ends up doing
112# substantially more redundant stat'ing.
113#
114# This means that we won't properly regenerate things for developers used to
115# building from a subdirectory, but that is always somewhat unreliable.
116ifeq ($(LEVEL),.)
117LLVMBUILD_INCLUDE_DEPENDENCIES := 1
118endif
119-include $(LLVMBuildMakeFrag)
120
Reid Spencer9411c642004-10-26 22:26:33 +0000121################################################################################
122# PRECONDITIONS: that which must be built/checked first
123################################################################################
124
Reid Spencer44cb1b32004-12-03 20:08:48 +0000125SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencer11fde542005-01-16 02:20:54 +0000126 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
127ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
128ConfigureScript := $(PROJ_SRC_ROOT)/configure
129ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
130MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
131MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
132MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
133MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
134PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
135ifneq ($(MakefileCommonIn),)
136PreConditions += $(MakefileCommon)
137endif
Chris Lattner0a1db822006-09-04 05:23:20 +0000138
Reid Spencer11fde542005-01-16 02:20:54 +0000139ifneq ($(MakefileConfigIn),)
140PreConditions += $(MakefileConfig)
141endif
Reid Spencer9411c642004-10-26 22:26:33 +0000142
Reid Spencerca739c62005-08-25 04:59:49 +0000143preconditions: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000144
145#------------------------------------------------------------------------
146# Make sure the BUILT_SOURCES are built first
147#------------------------------------------------------------------------
Reid Spencer07a549a2004-12-16 07:15:16 +0000148$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +0000149
Reid Spencer9bb399c2007-02-07 19:13:19 +0000150clean-all-local::
Reid Spencer9411c642004-10-26 22:26:33 +0000151ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000152 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +0000153endif
154
Reid Spencer11fde542005-01-16 02:20:54 +0000155ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer31f95242004-12-16 08:00:46 +0000156spotless:
Reid Spencer31f95242004-12-16 08:00:46 +0000157 $(Verb) if test -x config.status ; then \
Reid Spencer11fde542005-01-16 02:20:54 +0000158 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000159 $(MKDIR) .spotless.save ; \
160 $(MV) config.status .spotless.save ; \
161 $(MV) mklib .spotless.save ; \
162 $(MV) projects .spotless.save ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000163 $(RM) -rf * ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000164 $(MV) .spotless.save/config.status . ; \
165 $(MV) .spotless.save/mklib . ; \
166 $(MV) .spotless.save/projects . ; \
167 $(RM) -rf .spotless.save ; \
Reid Spencer11fde542005-01-16 02:20:54 +0000168 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000169 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
170 $(ConfigStatusScript) ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000171 else \
Reid Spencer11fde542005-01-16 02:20:54 +0000172 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer31f95242004-12-16 08:00:46 +0000173 fi
Reid Spencer25e8a702005-12-21 23:17:06 +0000174else
175spotless:
176 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer31f95242004-12-16 08:00:46 +0000177endif
178
Reid Spencercc2d1e22004-10-30 09:19:36 +0000179$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +0000180
Reid Spencer9411c642004-10-26 22:26:33 +0000181#------------------------------------------------------------------------
182# Make sure we're not using a stale configuration
183#------------------------------------------------------------------------
Reid Spencerc3719842004-12-16 18:26:53 +0000184reconfigure:
Reid Spencer11fde542005-01-16 02:20:54 +0000185 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
186 $(Verb) cd $(PROJ_OBJ_ROOT) && \
Reid Spencerc3719842004-12-16 18:26:53 +0000187 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
188 $(ConfigStatusScript)
189
Reid Spencercc2d1e22004-10-30 09:19:36 +0000190.PRECIOUS: $(ConfigStatusScript)
Jim Grosbache5e2c412010-10-01 22:32:12 +0000191$(ConfigStatusScript): $(ConfigureScript)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000192 $(Echo) Reconfiguring with $<
Reid Spencer11fde542005-01-16 02:20:54 +0000193 $(Verb) cd $(PROJ_OBJ_ROOT) && \
Reid Spencer7d277002004-11-29 12:37:44 +0000194 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
195 $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +0000196
Reid Spencer6f5f8b32005-08-25 04:44:18 +0000197#------------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +0000198# Make sure the configuration makefile is up to date
199#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +0000200ifneq ($(MakefileConfigIn),)
201$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000202 $(Echo) Regenerating $@
Reid Spencer11fde542005-01-16 02:20:54 +0000203 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
204endif
205
206ifneq ($(MakefileCommonIn),)
207$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
208 $(Echo) Regenerating $@
209 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
210endif
Reid Spencer9411c642004-10-26 22:26:33 +0000211
212#------------------------------------------------------------------------
213# If the Makefile in the source tree has been updated, copy it over into the
214# build tree. But, only do this if the source and object makefiles differ
215#------------------------------------------------------------------------
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000216ifndef PROJ_MAKEFILE
217PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
218endif
219
Reid Spencer11fde542005-01-16 02:20:54 +0000220ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer9411c642004-10-26 22:26:33 +0000221
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000222Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000223 $(Echo) "Updating Makefile"
224 $(Verb) $(MKDIR) $(@D)
Reid Spencerc3719842004-12-16 18:26:53 +0000225 $(Verb) $(CP) -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000226
227# Copy the Makefile.* files unless we're in the root directory which avoids
228# the copying of Makefile.config.in or other things that should be explicitly
229# taken care of.
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000230$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
Reid Spencer86606782004-10-26 23:10:00 +0000231 @case '$?' in \
232 *Makefile.rules) ;; \
233 *.in) ;; \
Gordon Henriksen7252dc02008-03-10 15:58:40 +0000234 *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000235 $(MKDIR) $(@D) ; \
Reid Spencerc3719842004-12-16 18:26:53 +0000236 $(CP) -f $< $@ ;; \
Reid Spencer86606782004-10-26 23:10:00 +0000237 esac
Gabor Greif0a4c3782008-02-27 13:34:15 +0000238
Reid Spencer9411c642004-10-26 22:26:33 +0000239endif
240
241#------------------------------------------------------------------------
242# Set up the basic dependencies
243#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000244$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000245
246all:: all-local
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000247clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000248clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000249install:: install-local
250uninstall:: uninstall-local
Misha Brukmanef5dc702009-01-08 02:11:55 +0000251install-local:: all-local
Reid Spencer44cb1b32004-12-03 20:08:48 +0000252install-bytecode:: install-bytecode-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000253
254###############################################################################
255# VARIABLES: Set up various variables based on configuration data
256###############################################################################
257
Daniel Dunbar94e98af2008-10-03 19:11:19 +0000258# Variable for if this make is for a "cleaning" target
259ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
260 IS_CLEANING_TARGET=1
261endif
262
Reid Spencer3a561f52004-10-23 20:04:14 +0000263#--------------------------------------------------------------------
264# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000265#--------------------------------------------------------------------
266
Reid Spencer0a522b12007-07-10 07:19:53 +0000267CPP.Defines :=
David Greenedbefd0c2009-04-17 14:49:22 +0000268ifeq ($(ENABLE_OPTIMIZED),1)
269 BuildMode := Release
270 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
Anton Korobeynikove55db742009-08-18 00:40:33 +0000271 ifneq ($(HOST_OS),FreeBSD)
272 ifneq ($(HOST_OS),Darwin)
David Greenedbefd0c2009-04-17 14:49:22 +0000273 OmitFramePointer := -fomit-frame-pointer
Chris Lattner760da062003-03-14 20:25:22 +0000274 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000275 endif
276
277 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Chengea84e932009-04-20 22:49:59 +0000278 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
279 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Anton Korobeynikove55db742009-08-18 00:40:33 +0000280 #ifeq ($(HOST_OS),Darwin)
Evan Chengb306e382009-04-20 22:16:40 +0000281 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
282 #endif
David Greenedbefd0c2009-04-17 14:49:22 +0000283 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
284 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
285 LD.Flags += $(OPTIMIZE_OPTION)
Jeffrey Yasskin7fd82e52009-09-27 17:47:29 +0000286 ifdef DEBUG_SYMBOLS
Jeffrey Yasskind4482922009-09-25 16:46:09 +0000287 BuildMode := $(BuildMode)+Debug
288 CXX.Flags += -g
289 C.Flags += -g
290 LD.Flags += -g
291 KEEP_SYMBOLS := 1
292 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000293else
Daniel Dunbardee8dbe2009-11-16 22:37:52 +0000294 ifdef NO_DEBUG_SYMBOLS
295 BuildMode := Unoptimized
296 CXX.Flags +=
297 C.Flags +=
298 LD.Flags +=
299 KEEP_SYMBOLS := 1
300 else
301 BuildMode := Debug
302 CXX.Flags += -g
303 C.Flags += -g
304 LD.Flags += -g
305 KEEP_SYMBOLS := 1
306 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000307endif
308
Eric Christopherbee515f2011-11-11 22:51:42 +0000309ifeq ($(ENABLE_LIBCPP),1)
310 CXX.Flags += -stdlib=libc++
311 LD.Flags += -stdlib=libc++
312endif
Chris Lattner16969802011-11-10 21:12:28 +0000313
David Greenedbefd0c2009-04-17 14:49:22 +0000314ifeq ($(ENABLE_PROFILING),1)
315 BuildMode := $(BuildMode)+Profile
316 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
317 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
318 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
319 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000320endif
321
Benjamin Kramer01442cd2011-12-22 21:41:32 +0000322ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
Benjamin Kramer01442cd2011-12-22 21:41:32 +0000323 CXX.Flags += -fvisibility-inlines-hidden
324endif
Daniel Dunbarecfe67c2008-09-02 17:35:16 +0000325
Chris Lattnerc96d5082010-01-24 20:20:40 +0000326ifdef ENABLE_EXPENSIVE_CHECKS
327 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
328 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
329 REQUIRES_RTTI := 1
330endif
331
Reid Spencer99655e12006-08-25 19:54:53 +0000332# IF REQUIRES_EH=1 is specified then don't disable exceptions
Reid Spencerdcea1402006-08-25 20:56:59 +0000333ifndef REQUIRES_EH
334 CXX.Flags += -fno-exceptions
Chris Lattnerc6150382010-01-24 20:21:50 +0000335else
336 # If the library requires EH, it also requires RTTI.
337 REQUIRES_RTTI := 1
Reid Spencerdcea1402006-08-25 20:56:59 +0000338endif
Reid Spencer99655e12006-08-25 19:54:53 +0000339
Nicolas Geoffray8ed81412009-08-19 22:04:44 +0000340ifdef REQUIRES_FRAME_POINTER
341 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
342 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
343 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
344endif
345
Daniel Dunbarccb75c22009-09-11 15:47:24 +0000346# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
Chris Lattner43b5f932010-01-24 20:43:08 +0000347ifneq ($(REQUIRES_RTTI), 1)
348 CXX.Flags += -fno-rtti
Reid Spencer6548bf12007-05-02 21:29:39 +0000349endif
350
Peter Collingbourneed50d382010-10-22 12:54:34 +0000351ifeq ($(ENABLE_COVERAGE),1)
Daniel Dunbar55a07b22009-03-13 20:59:41 +0000352 BuildMode := $(BuildMode)+Coverage
Chris Lattner6be92662009-06-16 23:00:42 +0000353 CXX.Flags += -ftest-coverage -fprofile-arcs
354 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar55a07b22009-03-13 20:59:41 +0000355endif
356
Reid Spencer854071c2006-04-10 16:46:04 +0000357# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
358# then disable assertions by defining the appropriate preprocessor symbols.
Peter Collingbourneed50d382010-10-22 12:54:34 +0000359ifeq ($(DISABLE_ASSERTIONS),1)
360 CPP.Defines += -DNDEBUG
361else
Duncan Sands8246adc2010-07-07 07:48:00 +0000362 BuildMode := $(BuildMode)+Asserts
Reid Spencer0a522b12007-07-10 07:19:53 +0000363 CPP.Defines += -D_DEBUG
Chris Lattner71927862006-03-21 01:06:41 +0000364endif
365
Misha Brukmanef5dc702009-01-08 02:11:55 +0000366# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
367# configured), then enable expensive checks by defining the
David Greenecba29182007-06-29 03:36:21 +0000368# appropriate preprocessor symbols.
Peter Collingbourneed50d382010-10-22 12:54:34 +0000369ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
David Greenea696d242007-06-28 19:36:08 +0000370 BuildMode := $(BuildMode)+Checks
Duncan Sands47d9dcc2008-12-09 21:33:20 +0000371 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
David Greenea696d242007-06-28 19:36:08 +0000372endif
373
Nick Lewyckya15dc032009-02-26 07:44:16 +0000374# LOADABLE_MODULE implies several other things so we force them to be
375# defined/on.
376ifdef LOADABLE_MODULE
377 SHARED_LIBRARY := 1
Nick Lewyckya15dc032009-02-26 07:44:16 +0000378 LINK_LIBS_IN_SHARED := 1
379endif
380
381ifdef SHARED_LIBRARY
382 ENABLE_PIC := 1
383 PIC_FLAG = "(PIC)"
384endif
385
Reid Spencer89b0d992006-12-16 22:07:52 +0000386ifeq ($(ENABLE_PIC),1)
Anton Korobeynikove55db742009-08-18 00:40:33 +0000387 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Nick Lewycky8e87e652009-02-21 08:41:09 +0000388 # Nothing. Win32 defaults to PIC and warns when given -fPIC
389 else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000390 ifeq ($(HOST_OS),Darwin)
Nick Lewyckya15dc032009-02-26 07:44:16 +0000391 # Common symbols not allowed in dylib files
Nick Lewycky8e87e652009-02-21 08:41:09 +0000392 CXX.Flags += -fno-common
393 C.Flags += -fno-common
394 else
395 # Linux and others; pass -fPIC
396 CXX.Flags += -fPIC
397 C.Flags += -fPIC
398 endif
399 endif
Mike Stump3fbdbd92009-05-08 23:08:58 +0000400else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000401 ifeq ($(HOST_OS),Darwin)
Mike Stump3fbdbd92009-05-08 23:08:58 +0000402 CXX.Flags += -mdynamic-no-pic
403 C.Flags += -mdynamic-no-pic
404 endif
Reid Spencer89b0d992006-12-16 22:07:52 +0000405endif
406
Daniel Dunbardd464df2010-05-10 20:11:56 +0000407# Support makefile variable to disable any kind of timestamp/non-deterministic
408# info from being used in the build.
409ifeq ($(ENABLE_TIMESTAMPS),1)
410 DOTDIR_TIMESTAMP_COMMAND := $(DATE)
411else
412 DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
413endif
414
Anton Korobeynikov2b02b432010-01-16 14:06:58 +0000415ifeq ($(HOST_OS),MingW)
416 # Work around PR4957
417 CPP.Defines += -D__NO_CTYPE_INLINE
418 ifeq ($(LLVM_CROSS_COMPILING),1)
419 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
420 ifdef TOOLNAME
421 LD.Flags += -Wl,--allow-multiple-definition
422 endif
423 endif
424endif
425
Chris Lattner1bdedb92011-04-09 06:01:28 +0000426CXX.Flags += -Woverloaded-virtual
David Greenea696d242007-06-28 19:36:08 +0000427CPP.BaseFlags += $(CPP.Defines)
Reid Spencerf2722ca2006-03-22 15:59:55 +0000428AR.Flags := cru
Reid Spencer3a561f52004-10-23 20:04:14 +0000429
Chris Lattner16620fc2006-07-27 18:19:51 +0000430# Make Floating point IEEE compliant on Alpha.
Andrew Lenharth39bcf5b2005-02-13 03:41:10 +0000431ifeq ($(ARCH),Alpha)
Reid Spencer89b0d992006-12-16 22:07:52 +0000432 CXX.Flags += -mieee
433 CPP.BaseFlags += -mieee
434ifeq ($(ENABLE_PIC),0)
435 CXX.Flags += -fPIC
436 CPP.BaseFlags += -fPIC
437endif
Andrew Lenharth39bcf5b2005-02-13 03:41:10 +0000438
Andrew Lenharthc5e455d2007-01-26 13:34:50 +0000439 LD.Flags += -Wl,--no-relax
440endif
441
NAKAMURA Takumib9dec1f2010-11-26 09:32:02 +0000442# GNU ld/PECOFF accepts but ignores them below;
443# --version-script
444# --export-dynamic
445# --rpath
446# FIXME: autoconf should be aware of them.
447ifneq (,$(filter $(HOST_OS),Cygwin MingW))
448 HAVE_LINK_VERSION_SCRIPT := 0
449 RPATH :=
450 RDYNAMIC := -Wl,--export-all-symbols
451endif
452
Reid Spencer3a561f52004-10-23 20:04:14 +0000453#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000454# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000455#--------------------------------------------------------------------
Jim Grosbach673612e2008-10-02 22:56:44 +0000456TargetMode :=
457ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000458 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbach673612e2008-10-02 22:56:44 +0000459endif
460
461ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000462ObjDir := $(ObjRootDir)
463LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
464ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
465ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
466LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
467LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
468LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell7a73b802003-06-30 21:59:07 +0000469
Reid Spencer3a561f52004-10-23 20:04:14 +0000470#--------------------------------------------------------------------
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000471# Locations of shared libraries
472#--------------------------------------------------------------------
473
474SharedPrefix := lib
475SharedLibDir := $(LibDir)
476LLVMSharedLibDir := $(LLVMLibDir)
477
478# Win32.DLL prefers to be located on the "PATH" of binaries.
479ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
480 SharedLibDir := $(ToolDir)
481 LLVMSharedLibDir := $(LLVMToolDir)
482
483 ifeq ($(HOST_OS),Cygwin)
484 SharedPrefix := cyg
485 else
486 SharedPrefix :=
487 endif
488endif
489
490#--------------------------------------------------------------------
Daniel Dunbar797faed2010-02-23 10:00:53 +0000491# LLVM Capable Compiler
492#--------------------------------------------------------------------
493
Chris Lattner70d77002011-04-09 19:53:16 +0000494ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
Daniel Dunbar797faed2010-02-23 10:00:53 +0000495 LLVMCC := $(LLVMGCC)
496 LLVMCXX := $(LLVMGXX)
497else
Chris Lattner70d77002011-04-09 19:53:16 +0000498 ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
Daniel Dunbar797faed2010-02-23 10:00:53 +0000499 ifneq ($(CLANGPATH),)
500 LLVMCC := $(CLANGPATH)
501 LLVMCXX := $(CLANGXXPATH)
502 else
503 ifeq ($(ENABLE_BUILT_CLANG),1)
504 LLVMCC := $(LLVMToolDir)/clang
505 LLVMCXX := $(LLVMToolDir)/clang++
506 endif
507 endif
508 endif
509endif
510
511#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000512# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000513#--------------------------------------------------------------------
Daniel Dunbar01b825d2011-11-11 22:59:45 +0000514EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
515ifdef BUILD_DIRS_ONLY
516EchoCmd := $(EchoCmd) "(build tools)":
517endif
518
519Echo := @$(EchoCmd)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000520ifndef LLVMAS
521LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
522endif
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000523ifndef LLVM_TBLGEN
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000524 ifeq ($(LLVM_CROSS_COMPILING),1)
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000525 LLVM_TBLGEN := $(BuildLLVMToolDir)/llvm-tblgen$(BUILD_EXEEXT)
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000526 else
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000527 LLVM_TBLGEN := $(LLVMToolDir)/llvm-tblgen$(EXEEXT)
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000528 endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000529endif
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000530ifeq ($(LLVM_CROSS_COMPILING),1)
Daniel Dunbarcb497b82011-12-01 20:18:09 +0000531 LLVM_CONFIG := $(BuildLLVMToolDir)/llvm-config$(BUILD_EXEEXT)
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000532else
Daniel Dunbarcb497b82011-12-01 20:18:09 +0000533 LLVM_CONFIG := $(LLVMToolDir)/llvm-config$(EXEEXT)
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000534endif
Reid Spencer43eb96c2007-02-09 15:52:07 +0000535ifndef LLVMLD
Reid Spencer18464122007-02-09 17:09:14 +0000536LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000537endif
Chris Lattner0a1db822006-09-04 05:23:20 +0000538ifndef LLVMDIS
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000539LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
540endif
541ifndef LLI
542LLI := $(LLVMToolDir)/lli$(EXEEXT)
543endif
Alkis Evlogimenoseebaf332005-02-27 10:21:37 +0000544ifndef LLC
545LLC := $(LLVMToolDir)/llc$(EXEEXT)
546endif
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000547ifndef LOPT
Alkis Evlogimenos20d793a2004-12-13 18:08:29 +0000548LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000549endif
Alkis Evlogimenos270e8512005-02-02 00:40:15 +0000550ifndef LBUGPOINT
551LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
552endif
Reid Spencere46687c2006-12-03 21:01:45 +0000553
Reid Spencer3a561f52004-10-23 20:04:14 +0000554#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000555# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000556#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000557
Anton Korobeynikove55db742009-08-18 00:40:33 +0000558ifeq ($(HOST_OS),Darwin)
Scott Michel87af5f02009-03-12 21:03:53 +0000559 DARWIN_VERSION := `sw_vers -productVersion`
560 # Strip a number like 10.4.7 to 10.4
561 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
562 # Get "4" out of 10.4 for later pieces in the makefile.
563 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendlingaca56952009-03-22 08:28:45 +0000564
Daniel Dunbar7bc0f272010-12-08 01:48:05 +0000565 LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
566 SharedLinkOptions := -dynamiclib
Evan Chenga5e225e2009-09-08 18:52:20 +0000567 ifneq ($(ARCH),ARM)
568 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
569 endif
Scott Michel87af5f02009-03-12 21:03:53 +0000570else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000571 SharedLinkOptions=-shared
Scott Michel87af5f02009-03-12 21:03:53 +0000572endif
573
Anton Korobeynikove55db742009-08-18 00:40:33 +0000574ifeq ($(TARGET_OS),Darwin)
Evan Chenga5e225e2009-09-08 18:52:20 +0000575 ifneq ($(ARCH),ARM)
576 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
577 endif
Anton Korobeynikove55db742009-08-18 00:40:33 +0000578endif
579
Reid Spencer492c2932005-01-11 04:31:07 +0000580ifdef SHARED_LIBRARY
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000581ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Rafael Espindolaa89efd52010-05-16 03:05:14 +0000582ifneq ($(HOST_OS),Darwin)
583 LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
John Criswell82f4a5a2003-07-31 20:58:51 +0000584endif
Scott Michel87af5f02009-03-12 21:03:53 +0000585endif
Rafael Espindolaa89efd52010-05-16 03:05:14 +0000586endif
John Criswell82f4a5a2003-07-31 20:58:51 +0000587
Reid Spencercceed9f2004-11-08 17:32:12 +0000588ifdef TOOL_VERBOSE
589 C.Flags += -v
590 CXX.Flags += -v
591 LD.Flags += -v
Reid Spencercceed9f2004-11-08 17:32:12 +0000592 VERBOSE := 1
593endif
594
Reid Spencer3a561f52004-10-23 20:04:14 +0000595# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000596ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000597 Verb := @
Reid Spencer491a6cd2007-07-23 08:20:46 +0000598 AR.Flags += >/dev/null 2>/dev/null
Reid Spencer11fde542005-01-16 02:20:54 +0000599 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000600else
Misha Brukmanef5dc702009-01-08 02:11:55 +0000601 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000602endif
603
Vikram S. Advefeeae582002-09-18 11:55:13 +0000604# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000605ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000606 Strip := $(PLATFORMSTRIPOPTS)
607 StripWarnMsg := "(without symbols)"
Charles Davis13460c92011-10-26 02:28:32 +0000608 Install.StripFlag += -s
Vikram S. Advefeeae582002-09-18 11:55:13 +0000609endif
610
Rafael Espindola31552a92010-10-15 00:58:12 +0000611ifdef TOOL_NO_EXPORTS
612 DynamicFlags :=
613else
614 DynamicFlag := $(RDYNAMIC)
615endif
616
Reid Spencer3a561f52004-10-23 20:04:14 +0000617# Adjust linker flags for building an executable
Nick Lewyckye28015c2010-08-02 03:16:19 +0000618ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
619ifneq ($(HOST_OS), Darwin)
Reid Spencer4d71b662004-10-22 21:01:56 +0000620ifdef TOOLNAME
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000621 LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
622 ifdef EXAMPLE_TOOL
Rafael Espindola31552a92010-10-15 00:58:12 +0000623 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000624 else
Rafael Espindola31552a92010-10-15 00:58:12 +0000625 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000626 endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000627endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000628else
629ifneq ($(DARWIN_MAJVERS),4)
630 LD.Flags += $(RPATH) -Wl,@executable_path/../lib
Nick Lewyckya15dc032009-02-26 07:44:16 +0000631endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000632endif
Nick Lewyckye28015c2010-08-02 03:16:19 +0000633endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000634
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000635
Reid Spencer3a561f52004-10-23 20:04:14 +0000636#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000637# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000638#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000639
Daniel Dunbare2a91a72011-06-16 22:30:38 +0000640ifdef EXTRA_LD_OPTIONS
641LD.Flags += $(EXTRA_LD_OPTIONS)
642endif
643
Daniel Dunbare36b6d42009-05-12 07:26:49 +0000644ifndef NO_PEDANTIC
Duncan Sands9ff4c132009-06-19 12:40:30 +0000645CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbare36b6d42009-05-12 07:26:49 +0000646endif
Duncan Sands9ff4c132009-06-19 12:40:30 +0000647CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
648 $(EXTRA_OPTIONS)
Dan Gohman3072b8a2010-04-19 18:33:28 +0000649# Enable cast-qual for C++; the workaround is to use const_cast.
650CXX.Flags += -Wcast-qual
Reid Spencer4d71b662004-10-22 21:01:56 +0000651
Anton Korobeynikove55db742009-08-18 00:40:33 +0000652ifeq ($(HOST_OS),HP-UX)
Duraid Madinaeb713402006-02-15 03:20:16 +0000653 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
Duraid Madina0ad8fcf2005-05-16 06:38:09 +0000654endif
655
Chris Lattner73faa392006-05-30 16:38:06 +0000656# If we are building a universal binary on Mac OS/X, pass extra options. This
657# is useful to people that want to link the LLVM libraries into their universal
Chris Lattner7dabf392006-06-29 19:38:04 +0000658# apps.
659#
660# The following can be optionally specified:
661# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
662# For Mac OS/X 10.4 Intel machines, the traditional one is:
663# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
664# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
665# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
666# i386/ppc only.
Chris Lattnerba466652006-04-06 06:30:15 +0000667ifdef UNIVERSAL
Chris Lattner7dabf392006-06-29 19:38:04 +0000668 ifndef UNIVERSAL_ARCH
669 UNIVERSAL_ARCH := i386 ppc
670 endif
671 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
672 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattnerf988e532006-06-16 21:47:59 +0000673 ifdef UNIVERSAL_SDK_PATH
674 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattnerf988e532006-06-16 21:47:59 +0000675 endif
676
677 # Building universal cannot compute dependencies automatically.
Chris Lattnerba466652006-04-06 06:30:15 +0000678 DISABLE_AUTO_DEPENDENCIES=1
Evan Chengc785b4f2009-03-09 18:28:37 +0000679else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000680 ifeq ($(TARGET_OS),Darwin)
Bill Wendlinga0833352009-03-12 04:10:09 +0000681 ifeq ($(ARCH),x86_64)
Evan Chenga38ff642009-03-23 03:45:56 +0000682 TargetCommonOpts = -m64
Bill Wendlinga0833352009-03-12 04:10:09 +0000683 else
684 ifeq ($(ARCH),x86)
Evan Chenga38ff642009-03-23 03:45:56 +0000685 TargetCommonOpts = -m32
Bill Wendlinga0833352009-03-12 04:10:09 +0000686 endif
Evan Chengc785b4f2009-03-09 18:28:37 +0000687 endif
688 endif
Chris Lattnerba466652006-04-06 06:30:15 +0000689endif
690
Anton Korobeynikove55db742009-08-18 00:40:33 +0000691ifeq ($(HOST_OS),SunOS)
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000692CPP.BaseFlags += -include llvm/Support/Solaris.h
Chris Lattner58a4c5e2008-06-24 17:44:42 +0000693endif
694
Edward O'Callaghandf199f12009-10-14 05:55:03 +0000695ifeq ($(HOST_OS),AuroraUX)
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000696CPP.BaseFlags += -include llvm/Support/Solaris.h
Edward O'Callaghandf199f12009-10-14 05:55:03 +0000697endif # !HOST_OS - AuroraUX.
698
Misha Brukmanef5dc702009-01-08 02:11:55 +0000699LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
NAKAMURA Takumie2aa5d52011-10-11 12:51:44 +0000700CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Reid Spencerf2722ca2006-03-22 15:59:55 +0000701# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands095765e2008-01-28 17:38:30 +0000702CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
703 $(patsubst %,-I%/include,\
Chris Lattner2671fc32008-01-28 04:18:41 +0000704 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
705 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
706 $(CPP.BaseFlags)
Reid Spencer4d71b662004-10-22 21:01:56 +0000707
Daniel Dunbar8d694142011-11-03 21:01:32 +0000708ifeq ($(INCLUDE_BUILD_DIR),1)
709 CPP.Flags += -I$(ObjDir)
710endif
711
Daniel Dunbar58194302011-04-11 22:37:39 +0000712# SHOW_DIAGNOSTICS support.
713ifeq ($(SHOW_DIAGNOSTICS),1)
714 Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
715 CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
716else
717 Compile.Wrapper :=
718endif
719
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000720Compile.C = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000721 $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000722 $(TargetCommonOpts) $(CompileCommonOpts) -c
723Compile.CXX = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000724 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000725 $(TargetCommonOpts) $(CompileCommonOpts) -c
726Preprocess.CXX= $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000727 $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000728 $(CompileCommonOpts) $(CXX.Flags) -E
729Link = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000730 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000731 $(LDFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) $(Strip)
Jim Grosbach673612e2008-10-02 22:56:44 +0000732
Daniel Dunbar7cfbe252010-02-23 10:28:06 +0000733BCCompile.C = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000734 $(TargetCommonOpts) $(CompileCommonOpts)
Eric Christopher2bd4bb02009-08-18 03:23:40 +0000735Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000736 $(TargetCommonOpts) $(CompileCommonOpts) -E
Chris Lattner0cb09f12005-10-05 00:28:41 +0000737
Daniel Dunbar7cfbe252010-02-23 10:28:06 +0000738BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000739 $(TargetCommonOpts) $(CompileCommonOpts)
Chris Lattnerd95e3f22006-09-29 18:47:13 +0000740
Misha Brukmanef5dc702009-01-08 02:11:55 +0000741ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
742ScriptInstall = $(INSTALL) -m 0755
Reid Spencer860598a2005-02-24 07:12:43 +0000743DataInstall = $(INSTALL) -m 0644
Chris Lattner6e0a5292008-01-15 23:27:40 +0000744
745# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
746# paths. In this case, the SYSPATH function (defined in
747# Makefile.config) transforms Unix paths into Windows paths.
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000748TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkovafa22592009-01-09 16:31:01 +0000749 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner6e0a5292008-01-15 23:27:40 +0000750 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
751 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000752LLVMTableGen = $(LLVM_TBLGEN) $(TableGen.Flags)
Chris Lattner6e0a5292008-01-15 23:27:40 +0000753
Reid Spencercc2d1e22004-10-30 09:19:36 +0000754Archive = $(AR) $(AR.Flags)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000755LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000756ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000757Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000758else
Reid Spencer3a561f52004-10-23 20:04:14 +0000759Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000760endif
761
Daniel Dunbarfd96b132009-11-19 00:14:53 +0000762AliasTool = ln -s
763
Chris Lattner00950542001-06-06 20:29:01 +0000764#----------------------------------------------------------
Misha Brukmanef5dc702009-01-08 02:11:55 +0000765# Get the list of source files and compute object file
766# names from them.
Reid Spencer3a561f52004-10-23 20:04:14 +0000767#----------------------------------------------------------
Chris Lattner89681112006-01-27 22:13:12 +0000768
769ifndef SOURCES
770 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattnerc9480642009-01-02 07:16:45 +0000771 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000772else
Chris Lattner89681112006-01-27 22:13:12 +0000773 Sources := $(SOURCES)
Misha Brukmanef5dc702009-01-08 02:11:55 +0000774endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000775
Chris Lattner89681112006-01-27 22:13:12 +0000776ifdef BUILT_SOURCES
Chris Lattnerc9480642009-01-02 07:16:45 +0000777Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Reid Spencer345235ca2004-12-04 22:34:09 +0000778endif
Reid Spencer3a561f52004-10-23 20:04:14 +0000779
Chris Lattner89681112006-01-27 22:13:12 +0000780BaseNameSources := $(sort $(basename $(Sources)))
781
782ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Chris Lattner89681112006-01-27 22:13:12 +0000783ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
784
NAKAMURA Takumi02724852011-03-08 12:25:10 +0000785#----------------------------------------------------------
786# For Mingw MSYS bash and Python/w32:
787#
788# $(ECHOPATH) prints DOSish pathstring.
789# ex) $(ECHOPATH) /include/sys/types.h
790# --> C:/mingw/include/sys/types.h
791# built-in "echo" does not transform path to DOSish path.
792#
793# FIXME: It would not be needed when MSYS's python
794# were provided.
795#----------------------------------------------------------
796
797ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
798 ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
799else
800 ECHOPATH := $(Verb)$(ECHO)
801endif
802
Reid Spencer3a561f52004-10-23 20:04:14 +0000803###############################################################################
804# DIRECTORIES: Handle recursive descent of directory structure
805###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000806
Chris Lattner00950542001-06-06 20:29:01 +0000807#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000808# Provide rules to make install dirs. This must be early
809# in the file so they get built before dependencies
810#---------------------------------------------------------
811
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000812$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
Mike Stumpe50f34a2009-01-22 03:24:22 +0000813 $(Verb) $(MKDIR) $@
Reid Spencera69b1ea2004-10-28 09:15:28 +0000814
Reid Spencercc2d1e22004-10-30 09:19:36 +0000815# To create other directories, as needed, and timestamp their creation
816%/.dir:
817 $(Verb) $(MKDIR) $* > /dev/null
Daniel Dunbardd464df2010-05-10 20:11:56 +0000818 $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000819
Reid Spencer815cbcf2004-11-18 10:03:46 +0000820.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
821.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000822
823#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000824# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000825#---------------------------------------------------------
826
Misha Brukmanef5dc702009-01-08 02:11:55 +0000827SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000828ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000829SubDirs += $(DIRS)
Chris Lattner82033602006-07-26 20:22:26 +0000830
831ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000832$(RecursiveTargets)::
833 $(Verb) for dir in $(DIRS); do \
Daniel Dunbar546023f2010-06-08 20:10:13 +0000834 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000835 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000836 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000837 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000838 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000839 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000840 done
Chris Lattner82033602006-07-26 20:22:26 +0000841else
842$(RecursiveTargets)::
843 $(Verb) for dir in $(DIRS); do \
844 ($(MAKE) -C $$dir $@ ) || exit 1; \
845 done
846endif
847
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000848endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000849
Reid Spencer3a561f52004-10-23 20:04:14 +0000850#---------------------------------------------------------
851# Handle the EXPERIMENTAL_DIRS options ensuring success
852# after each directory is built.
853#---------------------------------------------------------
854ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000855$(RecursiveTargets)::
856 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Daniel Dunbar546023f2010-06-08 20:10:13 +0000857 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000858 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer3a561f52004-10-23 20:04:14 +0000859 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000860 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000861 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000862 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000863 done
864endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000865
Reid Spencer25e8a702005-12-21 23:17:06 +0000866#-----------------------------------------------------------
Mike Stump0a268912009-01-24 00:00:41 +0000867# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
868#-----------------------------------------------------------
869ifdef OPTIONAL_PARALLEL_DIRS
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000870 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) -o -f $(T)/Makefile && echo "$(T)"))
Mike Stump0a268912009-01-24 00:00:41 +0000871endif
872
873#-----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000874# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencer25e8a702005-12-21 23:17:06 +0000875#-----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000876ifdef PARALLEL_DIRS
877
Reid Spencercc2d1e22004-10-30 09:19:36 +0000878SubDirs += $(PARALLEL_DIRS)
879
Reid Spencer44cb1b32004-12-03 20:08:48 +0000880# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencercc2d1e22004-10-30 09:19:36 +0000881all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
882clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000883clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000884install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000885uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencer44cb1b32004-12-03 20:08:48 +0000886install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Daniel Dunbar7f068f42009-09-13 22:39:27 +0000887unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000888
Reid Spencer345235ca2004-12-04 22:34:09 +0000889ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000890
Reid Spencer345235ca2004-12-04 22:34:09 +0000891$(ParallelTargets) :
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000892 $(Verb) \
893 SD=$(PROJ_SRC_DIR)/$(@D); \
894 DD=$(@D); \
895 if [ ! -f $$SD/Makefile ]; then \
896 SD=$(@D); \
897 DD=$(notdir $(@D)); \
898 fi; \
899 if ([ ! -f $$DD/Makefile ] || \
900 command test $$DD/Makefile -ot \
901 $$SD/Makefile ); then \
902 $(MKDIR) $$DD; \
903 $(CP) $$SD/Makefile $$DD/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000904 fi; \
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000905 $(MAKE) -C $$DD $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000906endif
907
Reid Spencer3a561f52004-10-23 20:04:14 +0000908#---------------------------------------------------------
909# Handle the OPTIONAL_DIRS options for directores that may
910# or may not exist.
911#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000912ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000913
Reid Spencercc2d1e22004-10-30 09:19:36 +0000914SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000915
Chris Lattner82033602006-07-26 20:22:26 +0000916ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000917$(RecursiveTargets)::
918 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000919 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Daniel Dunbar546023f2010-06-08 20:10:13 +0000920 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000921 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000922 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000923 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000924 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000925 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000926 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000927 done
Chris Lattner82033602006-07-26 20:22:26 +0000928else
929$(RecursiveTargets)::
930 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Stephen Wilsonc1566322011-02-20 03:51:07 +0000931 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
932 ($(MAKE) -C$$dir $@ ) || exit 1; \
933 fi \
Chris Lattner82033602006-07-26 20:22:26 +0000934 done
935endif
John Criswell2a6530f2003-06-27 16:58:44 +0000936endif
937
Reid Spencerfc945082004-08-20 09:20:05 +0000938#---------------------------------------------------------
939# Handle the CONFIG_FILES options
940#---------------------------------------------------------
941ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000942
Reid Spencera2a31bf2007-02-06 18:53:14 +0000943ifdef NO_INSTALL
944install-local::
945 $(Echo) Install circumvented with NO_INSTALL
946uninstall-local::
947 $(Echo) UnInstall circumvented with NO_INSTALL
948else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000949install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
950 $(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000951 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000952 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000953 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencer11fde542005-01-16 02:20:54 +0000954 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000955 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencer1b426ab2004-11-23 05:59:53 +0000956 else \
957 $(ECHO) Error: cannot find config file $${file}. ; \
958 fi \
Reid Spencerfc945082004-08-20 09:20:05 +0000959 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000960
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000961uninstall-local::
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000962 $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000963 $(Verb)for file in $(CONFIG_FILES); do \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000964 $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000965 done
Reid Spencera2a31bf2007-02-06 18:53:14 +0000966endif
Reid Spencere5487ba2004-10-24 07:53:21 +0000967
Reid Spencerfc945082004-08-20 09:20:05 +0000968endif
969
Reid Spencer3a561f52004-10-23 20:04:14 +0000970###############################################################################
Eric Christopherdf7d4192010-06-21 23:49:08 +0000971# Set up variables for building libraries
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000972###############################################################################
973
974#---------------------------------------------------------
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000975# Define various command line options pertaining to the
Misha Brukmanef5dc702009-01-08 02:11:55 +0000976# libraries needed when linking. There are "Proj" libs
977# (defined by the user's project) and "LLVM" libs (defined
Chris Lattneref0d0f12006-09-04 04:47:21 +0000978# by the LLVM project).
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000979#---------------------------------------------------------
Andrew Lenharth7ac17522005-08-13 05:09:50 +0000980
Chris Lattneref0d0f12006-09-04 04:47:21 +0000981ifdef USEDLIBS
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000982ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
983ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
Chris Lattneref0d0f12006-09-04 04:47:21 +0000984ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
985ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
986endif
987
988ifdef LLVMLIBS
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000989LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
990LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000991LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000992LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattneref0d0f12006-09-04 04:47:21 +0000993endif
994
NAKAMURA Takumia64eb832010-09-10 06:27:02 +0000995# Loadable module for Win32 requires all symbols resolved for linking.
996# Then all symbols in LLVM.dll will be available.
997ifeq ($(ENABLE_SHARED),1)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000998 ifdef LOADABLE_MODULE
NAKAMURA Takumia64eb832010-09-10 06:27:02 +0000999 ifneq (,$(filter $(HOST_OS),Cygwin MingW))
1000 LINK_COMPONENTS += all
1001 endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001002 endif
1003endif
1004
Daniel Dunbar94e98af2008-10-03 19:11:19 +00001005ifndef IS_CLEANING_TARGET
Chris Lattneref0d0f12006-09-04 04:47:21 +00001006ifdef LINK_COMPONENTS
Chris Lattner0a1db822006-09-04 05:23:20 +00001007
1008# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
1009# clean in tools, then do a make in tools (instead of at the top level).
1010$(LLVM_CONFIG):
1011 @echo "*** llvm-config doesn't exist - rebuilding it."
1012 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greif0a4c3782008-02-27 13:34:15 +00001013
Chris Lattner0a1db822006-09-04 05:23:20 +00001014$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
1015
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001016ifeq ($(ENABLE_SHARED), 1)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001017# We can take the "auto-import" feature to get rid of using dllimport.
1018ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1019LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
1020 -L $(SharedLibDir)
1021endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001022LLVMLibsOptions += -lLLVM-$(LLVMVersion)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001023LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001024else
Chris Lattnerf636aa92010-09-01 16:11:17 +00001025
1026ifndef NO_LLVM_CONFIG
1027LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
1028ifeq ($(LLVMConfigLibs),Error)
1029$(error llvm-config --libs failed)
1030endif
1031LLVMLibsOptions += $(LLVMConfigLibs)
1032LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
1033ifeq ($(LLVMConfigLibfiles),Error)
1034$(error llvm-config --libfiles failed)
1035endif
1036LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
1037endif
1038
Chris Lattneref0d0f12006-09-04 04:47:21 +00001039endif
Chris Lattner55e6c4a2006-09-04 04:50:10 +00001040endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001041endif
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001042
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001043# Set up the library exports file.
1044ifdef EXPORTED_SYMBOL_FILE
1045
1046# First, set up the native export file, which may differ from the source
1047# export file.
1048
1049ifeq ($(HOST_OS),Darwin)
1050# Darwin convention prefixes symbols with underscores.
Dan Gohman7c52f2e2010-04-15 23:08:00 +00001051NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
Dan Gohman2d675f12010-04-15 22:46:27 +00001052$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
Dan Gohmanf4ef72e2010-06-01 17:08:56 +00001053 $(Verb) sed -e 's/^/_/' < $< > $@
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001054clean-local::
1055 -$(Verb) $(RM) -f $(NativeExportsFile)
1056else
Dan Gohmanda612d62010-06-01 14:56:56 +00001057ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1058# Gold and BFD ld require a version script rather than a plain list.
1059NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
1060$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1061 $(Verb) echo "{" > $@
1062 $(Verb) grep -q "\<" $< && echo " global:" >> $@ || :
Dan Gohmanf4ef72e2010-06-01 17:08:56 +00001063 $(Verb) sed -e 's/$$/;/' -e 's/^/ /' < $< >> $@
Chris Lattnerc625d312011-02-21 18:38:56 +00001064ifneq ($(HOST_OS),OpenBSD)
Dan Gohmanda612d62010-06-01 14:56:56 +00001065 $(Verb) echo " local: *;" >> $@
Chris Lattnerc625d312011-02-21 18:38:56 +00001066endif
Dan Gohmanda612d62010-06-01 14:56:56 +00001067 $(Verb) echo "};" >> $@
1068clean-local::
1069 -$(Verb) $(RM) -f $(NativeExportsFile)
1070else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001071ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Dan Gohman9a7570c2010-09-03 17:29:33 +00001072# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001073NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001074$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1075 $(Echo) Generating $(notdir $@)
1076 $(Verb) $(ECHO) "EXPORTS" > $@
1077 $(Verb) $(CAT) $< >> $@
1078clean-local::
1079 -$(Verb) $(RM) -f $(NativeExportsFile)
1080else
Dan Gohman9a7570c2010-09-03 17:29:33 +00001081# Default behavior: just use the exports file verbatim.
1082NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
1083endif
1084endif
1085endif
1086
1087# Now add the linker command-line options to use the native export file.
1088
1089# Darwin
1090ifeq ($(HOST_OS),Darwin)
1091LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
1092endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001093
Dan Gohmane05f6092010-04-16 22:58:15 +00001094# gold, bfd ld, etc.
Dan Gohmanda612d62010-06-01 14:56:56 +00001095ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1096LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001097endif
1098
Dan Gohman9a7570c2010-09-03 17:29:33 +00001099# Windows
1100ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1101# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1102SharedLinkOptions += $(NativeExportsFile)
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001103endif
1104
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001105endif
1106
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001107###############################################################################
Reid Spencer3a561f52004-10-23 20:04:14 +00001108# Library Build Rules: Four ways to build a library
1109###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +00001110
Reid Spencer7980ea42004-12-05 05:17:22 +00001111#---------------------------------------------------------
1112# Bytecode Module Targets:
1113# If the user set MODULE_NAME then they want to build a
1114# bytecode module from the sources. We compile all the
1115# sources and link it together into a single bytecode
1116# module.
1117#---------------------------------------------------------
1118
1119ifdef MODULE_NAME
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001120ifeq ($(strip $(LLVMCC)),)
1121$(warning Modules require LLVM capable compiler but none is available ****)
Reid Spencer9a8398e2005-02-14 21:54:08 +00001122else
Reid Spencer7980ea42004-12-05 05:17:22 +00001123
1124Module := $(LibDir)/$(MODULE_NAME).bc
Daniel Dunbar112257d2010-02-23 09:28:50 +00001125LinkModule := $(LLVMLD) -r
Reid Spencerbbd5e432006-04-12 18:21:35 +00001126
Reid Spencer7980ea42004-12-05 05:17:22 +00001127
1128ifdef EXPORTED_SYMBOL_FILE
Chris Lattner89681112006-01-27 22:13:12 +00001129LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer7980ea42004-12-05 05:17:22 +00001130endif
1131
Reid Spencer43eb96c2007-02-09 15:52:07 +00001132$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
Reid Spencer0d255bd2005-05-13 18:32:54 +00001133 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencer7980ea42004-12-05 05:17:22 +00001134 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1135
1136all-local:: $(Module)
1137
1138clean-local::
1139ifneq ($(strip $(Module)),)
1140 -$(Verb) $(RM) -f $(Module)
1141endif
1142
Reid Spencerab3690b2004-12-13 07:38:07 +00001143ifdef BYTECODE_DESTINATION
1144ModuleDestDir := $(BYTECODE_DESTINATION)
1145else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001146ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencerab3690b2004-12-13 07:38:07 +00001147endif
Reid Spencer7980ea42004-12-05 05:17:22 +00001148
Reid Spencera2a31bf2007-02-06 18:53:14 +00001149ifdef NO_INSTALL
1150install-local::
1151 $(Echo) Install circumvented with NO_INSTALL
1152uninstall-local::
1153 $(Echo) Uninstall circumvented with NO_INSTALL
1154else
Reid Spencerab3690b2004-12-13 07:38:07 +00001155DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1156
1157install-module:: $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +00001158install-local:: $(DestModule)
1159
Misha Brukmanef5dc702009-01-08 02:11:55 +00001160$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencer7980ea42004-12-05 05:17:22 +00001161 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencer151bbe42005-02-24 21:30:37 +00001162 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +00001163
1164uninstall-local::
1165 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1166 -$(Verb) $(RM) -f $(DestModule)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001167endif
Reid Spencer7980ea42004-12-05 05:17:22 +00001168
1169endif
Reid Spencer9a8398e2005-02-14 21:54:08 +00001170endif
Brian Gaeke8abff792004-01-22 22:53:48 +00001171
Reid Spencer3a561f52004-10-23 20:04:14 +00001172# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +00001173ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +00001174
Misha Brukmanf547a122009-08-17 15:31:24 +00001175# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +00001176LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer492c2932005-01-11 04:31:07 +00001177ifdef LOADABLE_MODULE
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001178BaseLibName.A := $(LIBRARYNAME).a
1179BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer492c2932005-01-11 04:31:07 +00001180else
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001181BaseLibName.A := lib$(LIBRARYNAME).a
1182BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001183endif
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001184LibName.A := $(LibDir)/$(BaseLibName.A)
1185LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001186LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer9a2f1372004-12-02 09:28:21 +00001187LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnerccb4ebd2002-09-16 22:34:56 +00001188
Reid Spencer3a561f52004-10-23 20:04:14 +00001189#---------------------------------------------------------
1190# Shared Library Targets:
1191# If the user asked for a shared library to be built
1192# with the SHARED_LIBRARY variable, then we provide
1193# targets for building them.
1194#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +00001195ifdef SHARED_LIBRARY
1196
Nick Lewyckya15dc032009-02-26 07:44:16 +00001197all-local:: $(LibName.SO)
Reid Spencer4d71b662004-10-22 21:01:56 +00001198
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001199ifdef EXPORTED_SYMBOL_FILE
1200$(LibName.SO): $(NativeExportsFile)
1201endif
1202
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001203ifdef LINK_LIBS_IN_SHARED
Reid Spencer42fe4552006-08-07 23:12:15 +00001204ifdef LOADABLE_MODULE
Chris Lattner166f45e2006-11-15 21:04:15 +00001205SharedLibKindMessage := "Loadable Module"
Daniel Dunbar7bc0f272010-12-08 01:48:05 +00001206SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
Reid Spencer42fe4552006-08-07 23:12:15 +00001207else
1208SharedLibKindMessage := "Shared Library"
1209endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001210$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
Reid Spencer42fe4552006-08-07 23:12:15 +00001211 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
Dan Gohman6b156a32010-07-26 20:15:47 +00001212 $(notdir $@)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001213 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Torok Edwin2efc73d2009-05-26 19:11:47 +00001214 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001215else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001216$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
Dan Gohman6b156a32010-07-26 20:15:47 +00001217 $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001218 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001219endif
Reid Spencer3a561f52004-10-23 20:04:14 +00001220
1221clean-local::
Nick Lewyckya15dc032009-02-26 07:44:16 +00001222ifneq ($(strip $(LibName.SO)),)
1223 -$(Verb) $(RM) -f $(LibName.SO)
Reid Spencere5487ba2004-10-24 07:53:21 +00001224endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001225
Reid Spencera2a31bf2007-02-06 18:53:14 +00001226ifdef NO_INSTALL
1227install-local::
1228 $(Echo) Install circumvented with NO_INSTALL
1229uninstall-local::
1230 $(Echo) Uninstall circumvented with NO_INSTALL
1231else
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001232
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001233# Win32.DLL prefers to be located on the "PATH" of binaries.
1234ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1235DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001236else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001237DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001238endif
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001239DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
Reid Spencer4d71b662004-10-22 21:01:56 +00001240
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001241install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001242
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001243$(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
Reid Spencer9af3b292004-11-01 07:50:27 +00001244 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001245 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001246
Misha Brukmanef5dc702009-01-08 02:11:55 +00001247uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001248 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001249 -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
Reid Spencera2a31bf2007-02-06 18:53:14 +00001250endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001251endif
1252
Reid Spencer3a561f52004-10-23 20:04:14 +00001253#---------------------------------------------------------
1254# Bytecode Library Targets:
1255# If the user asked for a bytecode library to be built
Misha Brukmanef5dc702009-01-08 02:11:55 +00001256# with the BYTECODE_LIBRARY variable, then we provide
Reid Spencer3a561f52004-10-23 20:04:14 +00001257# targets for building them.
1258#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +00001259ifdef BYTECODE_LIBRARY
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001260ifeq ($(strip $(LLVMCC)),)
1261$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
Reid Spencer9a8398e2005-02-14 21:54:08 +00001262else
Reid Spencer4d71b662004-10-22 21:01:56 +00001263
Reid Spencer9a2f1372004-12-02 09:28:21 +00001264all-local:: $(LibName.BCA)
1265
1266ifdef EXPORTED_SYMBOL_FILE
Daniel Dunbar112257d2010-02-23 09:28:50 +00001267BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer9a2f1372004-12-02 09:28:21 +00001268
Reid Spencer43eb96c2007-02-09 15:52:07 +00001269$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
Chris Lattner264ccbe2004-12-15 17:14:06 +00001270 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +00001271 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1272 "(internalize)"
Daniel Dunbare5f1b2f2009-08-28 16:14:46 +00001273 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
Reid Spencerefd6bb32004-12-13 03:59:35 +00001274 $(Verb) $(RM) -f $@
Daniel Dunbare5f1b2f2009-08-28 16:14:46 +00001275 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
Reid Spencer4d71b662004-10-22 21:01:56 +00001276else
Reid Spencerf2ac1892004-12-16 07:36:08 +00001277$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattner264ccbe2004-12-15 17:14:06 +00001278 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +00001279 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencerefd6bb32004-12-13 03:59:35 +00001280 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +00001281 $(Verb) $(LArchive) $@ $(ObjectsBC)
1282
Reid Spencer4d71b662004-10-22 21:01:56 +00001283endif
1284
Reid Spencer3a561f52004-10-23 20:04:14 +00001285clean-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +00001286ifneq ($(strip $(LibName.BCA)),)
1287 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencere5487ba2004-10-24 07:53:21 +00001288endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001289
Reid Spencer8f094f32004-12-13 07:28:21 +00001290ifdef BYTECODE_DESTINATION
1291BytecodeDestDir := $(BYTECODE_DESTINATION)
1292else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001293BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencer8f094f32004-12-13 07:28:21 +00001294endif
1295
Daniel Dunbard62031e2009-05-12 05:35:40 +00001296DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Reid Spencer9a2f1372004-12-02 09:28:21 +00001297
Reid Spencer44cb1b32004-12-03 20:08:48 +00001298install-bytecode-local:: $(DestBytecodeLib)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001299
Reid Spencera2a31bf2007-02-06 18:53:14 +00001300ifdef NO_INSTALL
1301install-local::
1302 $(Echo) Install circumvented with NO_INSTALL
1303uninstall-local::
1304 $(Echo) Uninstall circumvented with NO_INSTALL
1305else
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001306install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +00001307
Mike Stumpb445d742009-02-12 23:45:11 +00001308$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Reid Spencer9a2f1372004-12-02 09:28:21 +00001309 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerb80621f2005-02-24 21:36:32 +00001310 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001311
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001312uninstall-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +00001313 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001314 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001315endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001316endif
Reid Spencer9a8398e2005-02-14 21:54:08 +00001317endif
Vikram S. Adve60f56062002-08-02 18:34:12 +00001318
Reid Spencercc2d1e22004-10-30 09:19:36 +00001319#---------------------------------------------------------
Chris Lattner6be92662009-06-16 23:00:42 +00001320# Library Targets:
1321# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1322# building an archive.
Reid Spencercc2d1e22004-10-30 09:19:36 +00001323#---------------------------------------------------------
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001324ifndef NO_BUILD_ARCHIVE
Chris Lattner89938082005-10-24 02:21:45 +00001325ifndef BUILD_ARCHIVE
Chris Lattner6be92662009-06-16 23:00:42 +00001326ifndef LOADABLE_MODULE
1327BUILD_ARCHIVE = 1
Reid Spencera2a31bf2007-02-06 18:53:14 +00001328endif
Chris Lattnere62dbe92002-07-23 17:56:16 +00001329endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001330endif
Chris Lattner760da062003-03-14 20:25:22 +00001331
Reid Spencercc2d1e22004-10-30 09:19:36 +00001332#---------------------------------------------------------
1333# Archive Library Targets:
Misha Brukmanef5dc702009-01-08 02:11:55 +00001334# If the user wanted a regular archive library built,
Reid Spencercc2d1e22004-10-30 09:19:36 +00001335# then we provide targets for building them.
1336#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +00001337ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +00001338
Reid Spencercc2d1e22004-10-30 09:19:36 +00001339all-local:: $(LibName.A)
1340
Reid Spencerf2ac1892004-12-16 07:36:08 +00001341$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +00001342 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001343 -$(Verb) $(RM) -f $@
Bill Wendlingdfaf4f92009-01-03 22:46:50 +00001344 $(Verb) $(Archive) $@ $(ObjectsO)
1345 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +00001346
Reid Spencer3a561f52004-10-23 20:04:14 +00001347clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001348ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001349 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +00001350endif
1351
Reid Spencera2a31bf2007-02-06 18:53:14 +00001352ifdef NO_INSTALL
1353install-local::
1354 $(Echo) Install circumvented with NO_INSTALL
1355uninstall-local::
1356 $(Echo) Uninstall circumvented with NO_INSTALL
Daniel Dunbaree40a162010-04-30 22:00:17 +00001357else
1358ifdef NO_INSTALL_ARCHIVES
Daniel Dunbar24d9d972010-04-30 20:04:53 +00001359install-local::
1360 $(Echo) Install circumvented with NO_INSTALL
1361uninstall-local::
1362 $(Echo) Uninstall circumvented with NO_INSTALL
Reid Spencera2a31bf2007-02-06 18:53:14 +00001363else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001364DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencere5487ba2004-10-24 07:53:21 +00001365
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001366install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001367
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001368$(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
Reid Spencer9af3b292004-11-01 07:50:27 +00001369 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001370 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001371 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001372
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001373uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001374 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001375 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001376endif
Reid Spencere5487ba2004-10-24 07:53:21 +00001377endif
Daniel Dunbaree40a162010-04-30 22:00:17 +00001378endif
Reid Spencere5487ba2004-10-24 07:53:21 +00001379
1380# endif LIBRARYNAME
Misha Brukmanef5dc702009-01-08 02:11:55 +00001381endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001382
Reid Spencerb1dd3dd2004-10-24 08:21:04 +00001383###############################################################################
1384# Tool Build Rules: Build executable tool based on TOOLNAME option
1385###############################################################################
1386
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001387ifdef TOOLNAME
1388
Reid Spencercc2d1e22004-10-30 09:19:36 +00001389#---------------------------------------------------------
1390# Set up variables for building a tool.
1391#---------------------------------------------------------
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001392TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +00001393ifdef EXAMPLE_TOOL
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001394ToolBuildPath := $(ExmplDir)/$(TOOLEXENAME)
Reid Spencer815cbcf2004-11-18 10:03:46 +00001395else
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001396ToolBuildPath := $(ToolDir)/$(TOOLEXENAME)
1397endif
1398
1399# TOOLALIAS is a name to symlink (or copy) the tool to.
1400ifdef TOOLALIAS
1401ifdef EXAMPLE_TOOL
1402ToolAliasBuildPath := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1403else
1404ToolAliasBuildPath := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1405endif
Reid Spencer815cbcf2004-11-18 10:03:46 +00001406endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001407
Reid Spencercc2d1e22004-10-30 09:19:36 +00001408#---------------------------------------------------------
Chris Lattner61863a32009-02-26 17:47:49 +00001409# Prune Exports
1410#---------------------------------------------------------
1411
1412# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1413# not exporting all of the weak symbols from the binary. This reduces dyld
1414# startup time by 4x on darwin in some cases.
1415ifdef TOOL_NO_EXPORTS
Anton Korobeynikove55db742009-08-18 00:40:33 +00001416ifeq ($(HOST_OS),Darwin)
Chris Lattner1b030a12009-03-10 17:15:56 +00001417
1418# Tiger tools don't support this.
1419ifneq ($(DARWIN_MAJVERS),4)
Dan Gohmane05f6092010-04-16 22:58:15 +00001420LD.Flags += -Wl,-exported_symbol,_main
Chris Lattner61863a32009-02-26 17:47:49 +00001421endif
Chris Lattner1b030a12009-03-10 17:15:56 +00001422endif
Chris Lattner61863a32009-02-26 17:47:49 +00001423
Anton Korobeynikove55db742009-08-18 00:40:33 +00001424ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
Bruno Cardoso Lopes6651b3f2010-07-20 08:44:20 +00001425ifneq ($(ARCH), Mips)
Nick Lewycky0d203662009-10-25 03:22:00 +00001426 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner61863a32009-02-26 17:47:49 +00001427endif
1428endif
Bruno Cardoso Lopes6651b3f2010-07-20 08:44:20 +00001429endif
Chris Lattner61863a32009-02-26 17:47:49 +00001430
Devang Patel83be4512010-07-15 20:57:09 +00001431#---------------------------------------------------------
Daniel Dunbarccfaa4b2010-09-16 00:42:32 +00001432# Tool Order File Support
1433#---------------------------------------------------------
1434
1435ifeq ($(HOST_OS),Darwin)
Daniel Dunbarade490a2011-06-28 22:30:17 +00001436ifdef TOOL_ORDER_FILE
Daniel Dunbarccfaa4b2010-09-16 00:42:32 +00001437
1438LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1439
1440endif
1441endif
1442
1443#---------------------------------------------------------
Devang Patel83be4512010-07-15 20:57:09 +00001444# Tool Version Info Support
1445#---------------------------------------------------------
1446
1447ifeq ($(HOST_OS),Darwin)
1448ifdef TOOL_INFO_PLIST
1449
1450LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1451
1452$(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1453
Daniel Dunbar14ceb872010-07-15 21:51:52 +00001454$(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
Devang Patel83be4512010-07-15 20:57:09 +00001455 $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1456 $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1457 -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1458 -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1459 -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1460 $< > $@
1461
1462endif
1463endif
Chris Lattner61863a32009-02-26 17:47:49 +00001464
1465#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +00001466# Provide targets for building the tools
1467#---------------------------------------------------------
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001468all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +00001469
Reid Spencer3a561f52004-10-23 20:04:14 +00001470clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001471ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001472 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +00001473endif
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001474ifneq ($(strip $(ToolAliasBuildPath)),)
1475 -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1476endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001477
Reid Spencer815cbcf2004-11-18 10:03:46 +00001478ifdef EXAMPLE_TOOL
1479$(ToolBuildPath): $(ExmplDir)/.dir
1480else
1481$(ToolBuildPath): $(ToolDir)/.dir
1482endif
1483
Chris Lattnera7868af2006-09-04 06:39:52 +00001484$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +00001485 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001486 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencerab519972006-05-16 06:25:14 +00001487 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattnerd25ad612006-02-14 04:25:54 +00001488 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukmanef5dc702009-01-08 02:11:55 +00001489 $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +00001490
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001491ifneq ($(strip $(ToolAliasBuildPath)),)
1492$(ToolAliasBuildPath): $(ToolBuildPath)
1493 $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1494 $(Verb) $(RM) -f $(ToolAliasBuildPath)
1495 $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
Dan Gohmanf9d11632010-08-18 01:35:53 +00001496 $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001497 $(StripWarnMsg)
1498endif
1499
Reid Spencera2a31bf2007-02-06 18:53:14 +00001500ifdef NO_INSTALL
1501install-local::
1502 $(Echo) Install circumvented with NO_INSTALL
1503uninstall-local::
1504 $(Echo) Uninstall circumvented with NO_INSTALL
1505else
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001506
1507ifdef INTERNAL_TOOL
1508ToolBinDir = $(DESTDIR)$(PROJ_internal_prefix)/bin
1509else
1510ToolBinDir = $(DESTDIR)$(PROJ_bindir)
1511endif
1512DestTool = $(ToolBinDir)/$(TOOLEXENAME)
Reid Spencere5487ba2004-10-24 07:53:21 +00001513
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001514install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001515
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001516$(DestTool): $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +00001517 $(Echo) Installing $(BuildMode) $(DestTool)
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001518 $(Verb) $(MKDIR) $(ToolBinDir)
Reid Spencer4a0aaea2005-02-24 03:56:32 +00001519 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +00001520
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001521uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001522 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001523 -$(Verb) $(RM) -f $(DestTool)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001524
1525# TOOLALIAS install.
1526ifdef TOOLALIAS
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001527DestToolAlias = $(ToolBinDir)/$(TOOLALIAS)$(EXEEXT)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001528
1529install-local:: $(DestToolAlias)
1530
Daniel Dunbar8fcd4182010-04-30 20:47:09 +00001531$(DestToolAlias): $(DestTool)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001532 $(Echo) Installing $(BuildMode) $(DestToolAlias)
1533 $(Verb) $(RM) -f $(DestToolAlias)
1534 $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1535
1536uninstall-local::
1537 $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1538 -$(Verb) $(RM) -f $(DestToolAlias)
1539endif
1540
Reid Spencera2a31bf2007-02-06 18:53:14 +00001541endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001542endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001543
Reid Spencercc2d1e22004-10-30 09:19:36 +00001544###############################################################################
Misha Brukmanef5dc702009-01-08 02:11:55 +00001545# Object Build Rules: Build object files based on sources
Reid Spencercc2d1e22004-10-30 09:19:36 +00001546###############################################################################
1547
Duraid Madina197ab872006-02-15 03:23:26 +00001548# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
Anton Korobeynikove55db742009-08-18 00:40:33 +00001549ifeq ($(HOST_OS),HP-UX)
Duraid Madina197ab872006-02-15 03:23:26 +00001550 DISABLE_AUTO_DEPENDENCIES=1
1551endif
1552
Reid Spencercc2d1e22004-10-30 09:19:36 +00001553# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +00001554ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +00001555
Reid Spencercc2d1e22004-10-30 09:19:36 +00001556#---------------------------------------------------------
Nick Lewyckya15dc032009-02-26 07:44:16 +00001557# Create .o files in the ObjDir directory from the .cpp and .c files...
Reid Spencercc2d1e22004-10-30 09:19:36 +00001558#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001559
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001560DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewyckya15dc032009-02-26 07:44:16 +00001561 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greif0a4c3782008-02-27 13:34:15 +00001562
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001563# If the build succeeded, move the dependency file over, otherwise
1564# remove it.
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001565DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1566 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1567
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001568$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Jakob Stoklund Olesen52020782009-10-04 17:54:36 +00001569 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001570 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001571 $(DEPEND_MOVEFILE)
Reid Spencer3a561f52004-10-23 20:04:14 +00001572
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001573$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001574 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1575 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1576 $(DEPEND_MOVEFILE)
1577
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001578$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001579 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001580 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001581 $(DEPEND_MOVEFILE)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001582
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001583$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001584 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001585 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001586 $(DEPEND_MOVEFILE)
Reid Spencer3a561f52004-10-23 20:04:14 +00001587
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001588$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001589 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1590 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1591 $(DEPEND_MOVEFILE)
1592
Reid Spencercc2d1e22004-10-30 09:19:36 +00001593#---------------------------------------------------------
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001594# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencercc2d1e22004-10-30 09:19:36 +00001595#---------------------------------------------------------
Chris Lattner89681112006-01-27 22:13:12 +00001596
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001597BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1598 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1599
1600# If the build succeeded, move the dependency file over, otherwise
1601# remove it.
1602BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1603 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1604
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001605$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencer9af3b292004-11-01 07:50:27 +00001606 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001607 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001608 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001609 $(BC_DEPEND_MOVEFILE)
Reid Spencer4d71b662004-10-22 21:01:56 +00001610
Greg Clayton43bc79a2010-07-13 18:47:09 +00001611$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1612 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1613 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001614 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Greg Clayton43bc79a2010-07-13 18:47:09 +00001615 $(BC_DEPEND_MOVEFILE)
1616
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001617$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001618 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001619 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001620 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001621 $(BC_DEPEND_MOVEFILE)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001622
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001623$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencer9af3b292004-11-01 07:50:27 +00001624 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001625 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001626 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001627 $(BC_DEPEND_MOVEFILE)
Reid Spencer4d71b662004-10-22 21:01:56 +00001628
Greg Clayton43bc79a2010-07-13 18:47:09 +00001629$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1630 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1631 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001632 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Greg Clayton43bc79a2010-07-13 18:47:09 +00001633 $(BC_DEPEND_MOVEFILE)
1634
Reid Spencercc2d1e22004-10-30 09:19:36 +00001635# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +00001636else
1637
Nick Lewyckya15dc032009-02-26 07:44:16 +00001638$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001639 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001640 $(Compile.CXX) $< -o $@
Reid Spencer3a561f52004-10-23 20:04:14 +00001641
Greg Clayton43bc79a2010-07-13 18:47:09 +00001642$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1643 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1644 $(Compile.CXX) $< -o $@
1645
Nick Lewyckya15dc032009-02-26 07:44:16 +00001646$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001647 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001648 $(Compile.CXX) $< -o $@
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001649
Nick Lewyckya15dc032009-02-26 07:44:16 +00001650$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001651 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001652 $(Compile.C) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +00001653
Greg Clayton43bc79a2010-07-13 18:47:09 +00001654$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1655 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1656 $(Compile.C) $< -o $@
1657
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001658$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencer9af3b292004-11-01 07:50:27 +00001659 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001660 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Reid Spencer4d71b662004-10-22 21:01:56 +00001661
Greg Clayton43bc79a2010-07-13 18:47:09 +00001662$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1663 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001664 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001665
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001666$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001667 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001668 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001669
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001670$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencer9af3b292004-11-01 07:50:27 +00001671 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001672 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Brian Gaeke44909cf2003-12-10 00:26:28 +00001673
Greg Clayton43bc79a2010-07-13 18:47:09 +00001674$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1675 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001676 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001677
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001678endif
1679
Chris Lattner8eb12de2006-06-21 21:01:20 +00001680
1681## Rules for building preprocessed (.i/.ii) outputs.
1682$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1683 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1684 $(Verb) $(Preprocess.CXX) $< -o $@
1685
Greg Clayton43bc79a2010-07-13 18:47:09 +00001686$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1687 $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1688 $(Verb) $(Preprocess.CXX) $< -o $@
1689
Chris Lattner8eb12de2006-06-21 21:01:20 +00001690$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1691 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1692 $(Verb) $(Preprocess.CXX) $< -o $@
1693
Reid Spencer44136722006-12-10 04:56:38 +00001694$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner8eb12de2006-06-21 21:01:20 +00001695 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1696 $(Verb) $(Preprocess.C) $< -o $@
1697
Greg Clayton43bc79a2010-07-13 18:47:09 +00001698$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1699 $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1700 $(Verb) $(Preprocess.C) $< -o $@
1701
Chris Lattner8eb12de2006-06-21 21:01:20 +00001702
1703$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1704 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001705 $(Compile.CXX) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001706
Greg Clayton43bc79a2010-07-13 18:47:09 +00001707$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1708 $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1709 $(Compile.CXX) $< -o $@ -S
1710
Chris Lattner8eb12de2006-06-21 21:01:20 +00001711$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1712 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001713 $(Compile.CXX) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001714
1715$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1716 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001717 $(Compile.C) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001718
Greg Clayton43bc79a2010-07-13 18:47:09 +00001719$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1720 $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1721 $(Compile.C) $< -o $@ -S
1722
Reid Spencer8b2e1412006-11-17 03:32:33 +00001723
Chris Lattner89681112006-01-27 22:13:12 +00001724# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer8b2e1412006-11-17 03:32:33 +00001725ifdef DEBUG_RUNTIME
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001726$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Reid Spencer8b2e1412006-11-17 03:32:33 +00001727 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001728 $(Verb) $(LOPT) $< -std-compile-opts -o $@
Reid Spencer8b2e1412006-11-17 03:32:33 +00001729else
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001730$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Chris Lattner89681112006-01-27 22:13:12 +00001731 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001732 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
Reid Spencer8b2e1412006-11-17 03:32:33 +00001733endif
1734
Chris Lattner89681112006-01-27 22:13:12 +00001735
Reid Spencercc2d1e22004-10-30 09:19:36 +00001736#---------------------------------------------------------
1737# Provide rule to build .bc files from .ll sources,
1738# regardless of dependencies
1739#---------------------------------------------------------
1740$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +00001741 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +00001742 $(Verb) $(LLVMAS) $< -f -o $@
1743
1744###############################################################################
1745# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1746###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +00001747
Reid Spencer4d71b662004-10-22 21:01:56 +00001748ifdef TARGET
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001749TABLEGEN_INC_FILES_COMMON = 1
1750endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001751
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001752ifdef TABLEGEN_INC_FILES_COMMON
1753
Reid Spencercc2d1e22004-10-30 09:19:36 +00001754INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner3c473472004-12-16 17:28:50 +00001755INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1756.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001757
Misha Brukmanef5dc702009-01-08 02:11:55 +00001758# INCFiles rule: All of the tblgen generated files are emitted to
Chris Lattner23ee7952004-12-16 17:38:56 +00001759# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1760# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbareb909ca2008-11-03 17:33:36 +00001761# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Chris Lattner23ee7952004-12-16 17:38:56 +00001762# dependencies of the .inc files are, unless the contents of the .inc file
1763# changes.
1764$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerc3719842004-12-16 18:26:53 +00001765 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner3c473472004-12-16 17:28:50 +00001766
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001767endif # TABLEGEN_INC_FILES_COMMON
1768
1769ifdef TARGET
1770
1771TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1772 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1773 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1774 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1775 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1776 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1777 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1778
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001779# All .inc.tmp files depend on the .td files.
1780$(INCTMPFiles) : $(TDFiles)
Rafael Espindola075630a2009-03-10 17:58:54 +00001781
Chris Lattner3c473472004-12-16 17:28:50 +00001782$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001783$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001784 $(Echo) "Building $(<F) register info implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001785 $(Verb) $(LLVMTableGen) -gen-register-info -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001786
Chris Lattner3c473472004-12-16 17:28:50 +00001787$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001788$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001789 $(Echo) "Building $(<F) instruction information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001790 $(Verb) $(LLVMTableGen) -gen-instr-info -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001791
Chris Lattner3c473472004-12-16 17:28:50 +00001792$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001793$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001794 $(Echo) "Building $(<F) assembly writer with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001795 $(Verb) $(LLVMTableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001796
Chris Lattner02a4f902004-12-16 17:34:04 +00001797$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001798$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Chris Lattner02a4f902004-12-16 17:34:04 +00001799 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001800 $(Verb) $(LLVMTableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001801
Daniel Dunbarc464e512009-07-13 18:35:35 +00001802$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001803$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Daniel Dunbarc464e512009-07-13 18:35:35 +00001804 $(Echo) "Building $(<F) assembly matcher with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001805 $(Verb) $(LLVMTableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
Daniel Dunbarc464e512009-07-13 18:35:35 +00001806
Jim Grosbachbd29a362010-11-03 23:46:01 +00001807$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001808$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Grosbachbd29a362010-11-03 23:46:01 +00001809 $(Echo) "Building $(<F) MC code emitter with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001810 $(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
Jim Grosbachbd29a362010-11-03 23:46:01 +00001811
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001812$(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001813$(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001814 $(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001815 $(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001816
Chris Lattner3c473472004-12-16 17:28:50 +00001817$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001818$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001819 $(Echo) "Building $(<F) code emitter with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001820 $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001821
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001822$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001823$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001824 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001825 $(Verb) $(LLVMTableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001826
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001827$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001828$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001829 $(Echo) "Building $(<F) disassembly tables with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001830 $(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001831
Sean Callanan95fcebd2010-01-29 00:21:04 +00001832$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001833$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Sean Callanan95fcebd2010-01-29 00:21:04 +00001834 $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001835 $(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
Sean Callanan95fcebd2010-01-29 00:21:04 +00001836
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001837$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001838$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001839 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001840 $(Verb) $(LLVMTableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001841
Evan Cheng385e9302011-07-01 22:36:09 +00001842$(TARGET:%=$(ObjDir)/%GenSubtargetInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001843$(ObjDir)/%GenSubtargetInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +00001844 $(Echo) "Building $(<F) subtarget information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001845 $(Verb) $(LLVMTableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001846
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001847$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001848$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001849 $(Echo) "Building $(<F) calling convention information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001850 $(Verb) $(LLVMTableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001851
Dale Johannesen49de9822009-02-05 01:49:45 +00001852$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001853$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jakob Stoklund Olesen7b68ffc2009-10-15 18:48:47 +00001854 $(Echo) "Building $(<F) intrinsics information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001855 $(Verb) $(LLVMTableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
Dale Johannesen49de9822009-02-05 01:49:45 +00001856
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001857$(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001858 $(Echo) "Building $(<F) decoder tables with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001859 $(Verb) $(LLVMTableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001860
Anshuman Dasguptadc81e5d2011-12-01 21:10:21 +00001861$(ObjDir)/%GenDFAPacketizer.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1862 $(Echo) "Building $(<F) DFA packetizer tables with tblgen"
1863 $(Verb) $(LLVMTableGen) -gen-dfa-packetizer -o $(call SYSPATH, $@) $<
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001864
Reid Spencer3a561f52004-10-23 20:04:14 +00001865clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001866 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001867
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001868endif # TARGET
1869
Reid Spencercc2d1e22004-10-30 09:19:36 +00001870###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001871# OTHER RULES: Other rules needed
1872###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001873
Chris Lattner30440c62003-01-16 21:06:18 +00001874# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +00001875ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +00001876%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +00001877 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +00001878else
1879%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +00001880 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +00001881endif
Chris Lattner30440c62003-01-16 21:06:18 +00001882
John Criswell7f336952003-09-06 14:44:17 +00001883# This rules ensures that header files that are removed still have a rule for
1884# which they can be "generated." This allows make to ignore them and
1885# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +00001886%.h:: ;
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001887%.hpp:: ;
John Criswell7f336952003-09-06 14:44:17 +00001888
Reid Spencercc2d1e22004-10-30 09:19:36 +00001889# Define clean-local to clean the current directory. Note that this uses a
Misha Brukmanef5dc702009-01-08 02:11:55 +00001890# very conservative approach ensuring that empty variables do not cause
Reid Spencercc2d1e22004-10-30 09:19:36 +00001891# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +00001892clean-local::
Jim Grosbach673612e2008-10-02 22:56:44 +00001893ifneq ($(strip $(ObjRootDir)),)
1894 -$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencere5487ba2004-10-24 07:53:21 +00001895endif
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001896ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001897 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001898endif
John Criswell7a73b802003-06-30 21:59:07 +00001899
Reid Spencer3d659492004-11-02 16:36:03 +00001900clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001901 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +00001902
Reid Spencer12d79512004-11-12 02:27:36 +00001903
Reid Spencer3a561f52004-10-23 20:04:14 +00001904###############################################################################
1905# DEPENDENCIES: Include the dependency files if we should
1906###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +00001907ifndef DISABLE_AUTO_DEPENDENCIES
1908
Reid Spencer3a561f52004-10-23 20:04:14 +00001909# If its not one of the cleaning targets
Daniel Dunbar94e98af2008-10-03 19:11:19 +00001910ifndef IS_CLEANING_TARGET
Reid Spencer4d71b662004-10-22 21:01:56 +00001911
Reid Spencer3a561f52004-10-23 20:04:14 +00001912# Get the list of dependency files
Greg Clayton43bc79a2010-07-13 18:47:09 +00001913DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001914DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1915
1916# Include bitcode dependency files if using bitcode libraries
1917ifdef BYTECODE_LIBRARY
1918DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1919endif
Misha Brukman4f7a8cf2003-11-09 21:36:19 +00001920
Reid Spencer491a6cd2007-07-23 08:20:46 +00001921-include $(DependFiles) ""
Reid Spencer3a561f52004-10-23 20:04:14 +00001922
John Criswelld741bcf2003-08-12 18:51:51 +00001923endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +00001924
Misha Brukmanef5dc702009-01-08 02:11:55 +00001925endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001926
Reid Spencer151f8ba2004-10-25 08:27:37 +00001927###############################################################################
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001928# CHECK: Running the test suite
1929###############################################################################
1930
Bill Wendling29c0e3d2009-04-09 18:26:57 +00001931check::
Reid Spencer11fde542005-01-16 02:20:54 +00001932 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1933 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001934 $(EchoCmd) Running test suite ; \
Reid Spencer11fde542005-01-16 02:20:54 +00001935 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001936 TESTSUITE=$(TESTSUITE) ; \
1937 else \
1938 $(EchoCmd) No Makefile in test directory ; \
1939 fi ; \
1940 else \
1941 $(EchoCmd) No test directory ; \
1942 fi
1943
Daniel Dunbar666b4022010-08-02 00:05:18 +00001944check-lit:: check
1945
1946check-dg::
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001947 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1948 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1949 $(EchoCmd) Running test suite ; \
Daniel Dunbar666b4022010-08-02 00:05:18 +00001950 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001951 else \
1952 $(EchoCmd) No Makefile in test directory ; \
1953 fi ; \
1954 else \
1955 $(EchoCmd) No test directory ; \
1956 fi
1957
Daniel Dunbar34185792009-09-20 06:17:21 +00001958check-all::
1959 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1960 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1961 $(EchoCmd) Running test suite ; \
1962 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1963 else \
1964 $(EchoCmd) No Makefile in test directory ; \
1965 fi ; \
1966 else \
1967 $(EchoCmd) No test directory ; \
1968 fi
1969
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001970###############################################################################
Bill Wendling4113bd12009-01-04 23:12:21 +00001971# UNITTESTS: Running the unittests test suite
1972###############################################################################
1973
Bill Wendling29c0e3d2009-04-09 18:26:57 +00001974unittests::
Bill Wendling4113bd12009-01-04 23:12:21 +00001975 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1976 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1977 $(EchoCmd) Running unittests test suite ; \
Daniel Dunbar7f068f42009-09-13 22:39:27 +00001978 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
Bill Wendling4113bd12009-01-04 23:12:21 +00001979 else \
1980 $(EchoCmd) No Makefile in unittests directory ; \
1981 fi ; \
1982 else \
1983 $(EchoCmd) No unittests directory ; \
1984 fi
1985
1986###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001987# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +00001988###############################################################################
1989
Reid Spencere45ebfa2004-10-26 07:09:33 +00001990#------------------------------------------------------------------------
1991# Define distribution related variables
1992#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00001993DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1994DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1995TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1996DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1997DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1998DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer151f8ba2004-10-25 08:27:37 +00001999DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
2000 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002001 Makefile.config.in configure autoconf
2002DistOther := $(notdir $(wildcard \
Reid Spencer11fde542005-01-16 02:20:54 +00002003 $(PROJ_SRC_DIR)/*.h \
2004 $(PROJ_SRC_DIR)/*.td \
2005 $(PROJ_SRC_DIR)/*.def \
2006 $(PROJ_SRC_DIR)/*.ll \
2007 $(PROJ_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00002008DistSubDirs := $(SubDirs)
Reid Spencerfbbf3072004-11-29 05:00:33 +00002009DistSources = $(Sources) $(EXTRA_DIST)
2010DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00002011
Reid Spencere45ebfa2004-10-26 07:09:33 +00002012#------------------------------------------------------------------------
2013# We MUST build distribution with OBJ_DIR != SRC_DIR
2014#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00002015ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencere45ebfa2004-10-26 07:09:33 +00002016dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002017 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00002018
Reid Spencere45ebfa2004-10-26 07:09:33 +00002019else
2020
Reid Spencere45ebfa2004-10-26 07:09:33 +00002021#------------------------------------------------------------------------
Reid Spencere45ebfa2004-10-26 07:09:33 +00002022# Prevent attempt to run dist targets from anywhere but the top level
2023#------------------------------------------------------------------------
2024ifneq ($(LEVEL),.)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002025dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencer11fde542005-01-16 02:20:54 +00002026 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002027else
2028
2029#------------------------------------------------------------------------
2030# Provide the top level targets
2031#------------------------------------------------------------------------
2032
Reid Spencercc2d1e22004-10-30 09:19:36 +00002033dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002034
Reid Spencer345235ca2004-12-04 22:34:09 +00002035$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002036 $(Echo) Packing gzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00002037 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00002038 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00002039
Reid Spencercc2d1e22004-10-30 09:19:36 +00002040dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002041
Reid Spencer345235ca2004-12-04 22:34:09 +00002042$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002043 $(Echo) Packing bzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00002044 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00002045 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002046
Reid Spencercc2d1e22004-10-30 09:19:36 +00002047dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002048
Reid Spencer345235ca2004-12-04 22:34:09 +00002049$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002050 $(Echo) Packing zipped distribution file.
2051 $(Verb) rm -f $(DistZip)
Reid Spencer11fde542005-01-16 02:20:54 +00002052 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002053
Misha Brukmanef5dc702009-01-08 02:11:55 +00002054dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Chris Lattner7a2bdde2011-04-15 05:18:47 +00002055 $(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00002056
Reid Spencerf8f57402005-01-28 19:52:32 +00002057DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencere45ebfa2004-10-26 07:09:33 +00002058
Reid Spencer345235ca2004-12-04 22:34:09 +00002059dist-check:: $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00002060 $(Echo) Checking distribution tar file.
2061 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002062 $(RM) -rf $(DistCheckDir) ; \
2063 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00002064 $(Verb) $(MKDIR) $(DistCheckDir)
2065 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002066 $(MKDIR) $(DistCheckDir)/build && \
2067 $(MKDIR) $(DistCheckDir)/install && \
2068 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
2069 cd build && \
2070 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer45eeed92005-05-24 02:33:20 +00002071 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer345235ca2004-12-04 22:34:09 +00002072 $(MAKE) all && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002073 $(MAKE) check && \
Bill Wendling4113bd12009-01-04 23:12:21 +00002074 $(MAKE) unittests && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002075 $(MAKE) install && \
2076 $(MAKE) uninstall && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002077 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00002078 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00002079
2080dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002081 $(Echo) Cleaning distribution files
Reid Spencer345235ca2004-12-04 22:34:09 +00002082 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2083 $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002084
2085endif
2086
2087#------------------------------------------------------------------------
2088# Provide the recursive distdir target for building the distribution directory
2089#------------------------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +00002090distdir: $(DistDir)/.makedistdir
2091$(DistDir)/.makedistdir: $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00002092 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002093 if test -d "$(DistDir)" ; then \
2094 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
2095 exit 1 ; \
2096 fi ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002097 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002098 $(RM) -rf $(DistDir); \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00002099 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer854071c2006-04-10 16:46:04 +00002100 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002101 fi
Reid Spencerfbbf3072004-11-29 05:00:33 +00002102 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukmanef5dc702009-01-08 02:11:55 +00002103 $(Verb) $(MKDIR) $(DistDir)
Reid Spencer11fde542005-01-16 02:20:54 +00002104 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2105 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002106 for file in $(DistFiles) ; do \
2107 case "$$file" in \
Reid Spencer11fde542005-01-16 02:20:54 +00002108 $(PROJ_SRC_DIR)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00002109 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2110 ;; \
Reid Spencer11fde542005-01-16 02:20:54 +00002111 $(PROJ_SRC_ROOT)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00002112 file=`echo "$$file" | \
2113 sed "s#^$$srcrootstrip/##"` \
2114 ;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002115 esac; \
Reid Spencer11fde542005-01-16 02:20:54 +00002116 if test -f "$(PROJ_SRC_DIR)/$$file" || \
2117 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2118 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002119 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002120 from_dir=. ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002121 fi ; \
2122 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002123 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2124 to_dir="$(DistDir)/$$dir"; \
2125 $(MKDIR) "$$to_dir" ; \
2126 else \
2127 to_dir="$(DistDir)"; \
2128 fi; \
2129 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2130 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002131 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002132 fi ; \
2133 if test -d "$$from_dir/$$file"; then \
Reid Spencer11fde542005-01-16 02:20:54 +00002134 if test -d "$(PROJ_SRC_DIR)/$$file" && \
2135 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer45eeed92005-05-24 02:33:20 +00002136 cd $(PROJ_SRC_DIR) ; \
2137 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2138 ( cd $$to_dir ; $(TAR) xf - ) ; \
2139 cd $(PROJ_OBJ_DIR) ; \
2140 else \
2141 cd $$from_dir ; \
2142 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2143 ( cd $$to_dir ; $(TAR) xf - ) ; \
2144 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002145 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002146 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00002147 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002148 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00002149 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002150 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer345235ca2004-12-04 22:34:09 +00002151 $(EchoCmd) "===== WARNING: Distribution Source " \
2152 "$$from_dir/$$file Not Found!" ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00002153 elif test "$(Verb)" != '@' ; then \
2154 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002155 fi; \
2156 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00002157 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002158 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002159 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002160 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer854071c2006-04-10 16:46:04 +00002161 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencerbac3ca22006-04-07 16:06:18 +00002162 DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002163 fi; \
2164 done
Reid Spencer345235ca2004-12-04 22:34:09 +00002165 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer45eeed92005-05-24 02:33:20 +00002166 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
Chris Lattner77efe272006-02-14 04:27:15 +00002167 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2168 -name .svn \) -print` ;\
Reid Spencer345235ca2004-12-04 22:34:09 +00002169 $(MAKE) dist-hook ; \
2170 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2171 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2172 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2173 -o ! -type d ! -perm -444 -exec \
2174 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2175 || chmod -R a+r $(DistDir) ; \
2176 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +00002177
Reid Spencercc2d1e22004-10-30 09:19:36 +00002178# This is invoked by distdir target, define it as a no-op to avoid errors if not
2179# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00002180dist-hook::
2181
Reid Spencere53e3972004-10-22 23:06:30 +00002182endif
Reid Spencer4d71b662004-10-22 21:01:56 +00002183
2184###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00002185# TOP LEVEL - targets only to apply at the top level directory
2186###############################################################################
2187
2188ifeq ($(LEVEL),.)
2189
2190#------------------------------------------------------------------------
Reid Spencer9e8d54a2004-12-06 05:35:13 +00002191# Install support for the project's include files:
Reid Spencere5487ba2004-10-24 07:53:21 +00002192#------------------------------------------------------------------------
Reid Spencera2a31bf2007-02-06 18:53:14 +00002193ifdef NO_INSTALL
2194install-local::
2195 $(Echo) Install circumvented with NO_INSTALL
2196uninstall-local::
2197 $(Echo) Uninstall circumvented with NO_INSTALL
2198else
Reid Spencere5487ba2004-10-24 07:53:21 +00002199install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002200 $(Echo) Installing include files
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002201 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002202 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencer11fde542005-01-16 02:20:54 +00002203 cd $(PROJ_SRC_ROOT)/include && \
NAKAMURA Takumi6716b8e2011-03-09 09:11:27 +00002204 for hdr in `find . -type f \
2205 '(' -name LICENSE.TXT \
2206 -o -name '*.def' \
2207 -o -name '*.h' \
2208 -o -name '*.inc' \
2209 -o -name '*.td' \
2210 ')' -print | grep -v CVS | \
Reid Spencer0522d8b2007-04-09 19:08:58 +00002211 grep -v .svn` ; do \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002212 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002213 if test \! -d "$$instdir" ; then \
2214 $(EchoCmd) Making install directory $$instdir ; \
2215 $(MKDIR) $$instdir ;\
2216 fi ; \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002217 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer2edabc02005-02-16 15:54:03 +00002218 done ; \
Reid Spencere5487ba2004-10-24 07:53:21 +00002219 fi
Reid Spencer443045a2005-12-23 22:27:56 +00002220ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002221 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer2edabc02005-02-16 15:54:03 +00002222 cd $(PROJ_OBJ_ROOT)/include && \
NAKAMURA Takumi6716b8e2011-03-09 09:11:27 +00002223 for hdr in `find . -type f \
2224 '(' -name LICENSE.TXT \
2225 -o -name '*.def' \
2226 -o -name '*.h' \
2227 -o -name '*.inc' \
2228 -o -name '*.td' \
2229 ')' -print | grep -v CVS | \
2230 grep -v .svn` ; do \
2231 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2232 if test \! -d "$$instdir" ; then \
2233 $(EchoCmd) Making install directory $$instdir ; \
2234 $(MKDIR) $$instdir ;\
2235 fi ; \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002236 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer2edabc02005-02-16 15:54:03 +00002237 done ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002238 fi
Reid Spencer443045a2005-12-23 22:27:56 +00002239endif
Reid Spencere5487ba2004-10-24 07:53:21 +00002240
2241uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002242 $(Echo) Uninstalling include files
Reid Spencer11fde542005-01-16 02:20:54 +00002243 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2244 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencere5487ba2004-10-24 07:53:21 +00002245 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattnerc9480642009-01-02 07:16:45 +00002246 '!' '(' -name '*~' -o -name '.#*' \
Chris Lattnerd25ad612006-02-14 04:25:54 +00002247 -o -name '*.in' ')' -print ')' | \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002248 grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002249 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnerd25ad612006-02-14 04:25:54 +00002250 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002251 -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002252 fi
Reid Spencera2a31bf2007-02-06 18:53:14 +00002253endif
Reid Spencere5487ba2004-10-24 07:53:21 +00002254endif
2255
Chris Lattner03840ac2007-04-14 23:35:45 +00002256check-line-length:
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002257 @echo searching for overlength lines in files: $(Sources)
2258 @echo
2259 @echo
Gabor Greif5039a6f2008-08-28 22:32:39 +00002260 egrep -n '.{81}' $(Sources) /dev/null
Chris Lattner03840ac2007-04-14 23:35:45 +00002261
Anton Korobeynikovbed29462007-04-16 18:10:23 +00002262check-for-tabs:
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002263 @echo searching for tabs in files: $(Sources)
2264 @echo
2265 @echo
Gabor Greif5039a6f2008-08-28 22:32:39 +00002266 egrep -n ' ' $(Sources) /dev/null
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002267
Reid Spencer6548bf12007-05-02 21:29:39 +00002268check-footprint:
2269 @ls -l $(LibDir) | awk '\
2270 BEGIN { sum = 0; } \
2271 { sum += $$5; } \
2272 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2273 @ls -l $(ToolDir) | awk '\
2274 BEGIN { sum = 0; } \
2275 { sum += $$5; } \
2276 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
Reid Spencer4d71b662004-10-22 21:01:56 +00002277#------------------------------------------------------------------------
2278# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00002279#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00002280printvars::
Reid Spencer11fde542005-01-16 02:20:54 +00002281 $(Echo) "BuildMode : " '$(BuildMode)'
2282 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2283 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2284 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2285 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2286 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2287 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2288 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
Bob Wilsonae7e2a42011-11-28 07:59:52 +00002289 $(Echo) "PROJ_internal_prefix : " '$(PROJ_internal_prefix)'
Reid Spencer11fde542005-01-16 02:20:54 +00002290 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
2291 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
2292 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencer1a9a69c2005-02-16 16:13:02 +00002293 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencer11fde542005-01-16 02:20:54 +00002294 $(Echo) "UserTargets : " '$(UserTargets)'
2295 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2296 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2297 $(Echo) "ObjDir : " '$(ObjDir)'
2298 $(Echo) "LibDir : " '$(LibDir)'
2299 $(Echo) "ToolDir : " '$(ToolDir)'
2300 $(Echo) "ExmplDir : " '$(ExmplDir)'
2301 $(Echo) "Sources : " '$(Sources)'
2302 $(Echo) "TDFiles : " '$(TDFiles)'
2303 $(Echo) "INCFiles : " '$(INCFiles)'
2304 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencere0acb762005-03-01 16:27:06 +00002305 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencer11fde542005-01-16 02:20:54 +00002306 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
2307 $(Echo) "Compile.C : " '$(Compile.C)'
2308 $(Echo) "Archive : " '$(Archive)'
2309 $(Echo) "YaccFiles : " '$(YaccFiles)'
2310 $(Echo) "LexFiles : " '$(LexFiles)'
2311 $(Echo) "Module : " '$(Module)'
Reid Spencer755bcf02005-08-24 10:43:10 +00002312 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
Reid Spencerf9f431c2006-04-09 23:41:14 +00002313 $(Echo) "SubDirs : " '$(SubDirs)'
Reid Spencer8475ec02007-03-29 19:05:44 +00002314 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2315 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar92acef02009-02-21 20:42:39 +00002316
2317###
2318# Debugging
2319
Daniel Dunbar3c898122009-03-06 22:23:25 +00002320# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar92acef02009-02-21 20:42:39 +00002321# definition, value and origin of XXX.
Daniel Dunbar3c898122009-03-06 22:23:25 +00002322make-print-%:
Daniel Dunbar92acef02009-02-21 20:42:39 +00002323 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))