blob: 32a97c646c717dbbc3b350cf690f7baeb1c8415e [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.
Daniel Dunbar8979f4e2012-02-02 23:27:32 +000097$(LLVMBuildMakeFrag): $(PROJ_SRC_ROOT)/Makefile.rules \
98 $(PROJ_OBJ_ROOT)/Makefile.config
Daniel Dunbard5574f62011-11-03 23:01:50 +000099 $(Echo) Constructing LLVMBuild project information.
100 $(Verb) $(LLVMBuildTool) \
Daniel Dunbara7de1d62011-11-12 00:18:02 +0000101 --native-target "$(TARGET_NATIVE_ARCH)" \
Daniel Dunbar83337302011-11-10 01:16:48 +0000102 --enable-targets "$(TARGETS_TO_BUILD)" \
Daniel Dunbare29c3162011-11-03 22:46:21 +0000103 --write-library-table $(LLVMConfigLibraryDependenciesInc) \
104 --write-make-fragment $(LLVMBuildMakeFrag)
105
Daniel Dunbar28088532011-11-09 18:48:22 +0000106# For completeness, let Make know how the extra files are generated.
107$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrag)
108
Daniel Dunbare29c3162011-11-03 22:46:21 +0000109# Include the generated Makefile fragment.
110#
111# We currently only include the dependencies for the fragment itself if we are
112# at the top-level. Otherwise, recursive invocations would ends up doing
113# substantially more redundant stat'ing.
114#
115# This means that we won't properly regenerate things for developers used to
116# building from a subdirectory, but that is always somewhat unreliable.
117ifeq ($(LEVEL),.)
118LLVMBUILD_INCLUDE_DEPENDENCIES := 1
Daniel Dunbar2e5b88e2012-02-02 23:27:34 +0000119
120# Clean the generated makefile fragment at the top-level.
121clean-local::
122 -$(Verb) $(RM) -f $(LLVMBuildMakeFrag)
Daniel Dunbare29c3162011-11-03 22:46:21 +0000123endif
124-include $(LLVMBuildMakeFrag)
125
Reid Spencer9411c642004-10-26 22:26:33 +0000126################################################################################
127# PRECONDITIONS: that which must be built/checked first
128################################################################################
129
Reid Spencer44cb1b32004-12-03 20:08:48 +0000130SrcMakefiles := $(filter %Makefile %Makefile.tests,\
Reid Spencer11fde542005-01-16 02:20:54 +0000131 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
132ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
133ConfigureScript := $(PROJ_SRC_ROOT)/configure
134ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
135MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
136MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
137MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
138MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
139PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
140ifneq ($(MakefileCommonIn),)
141PreConditions += $(MakefileCommon)
142endif
Chris Lattner0a1db822006-09-04 05:23:20 +0000143
Reid Spencer11fde542005-01-16 02:20:54 +0000144ifneq ($(MakefileConfigIn),)
145PreConditions += $(MakefileConfig)
146endif
Reid Spencer9411c642004-10-26 22:26:33 +0000147
Reid Spencerca739c62005-08-25 04:59:49 +0000148preconditions: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000149
150#------------------------------------------------------------------------
151# Make sure the BUILT_SOURCES are built first
152#------------------------------------------------------------------------
Reid Spencer07a549a2004-12-16 07:15:16 +0000153$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +0000154
Reid Spencer9bb399c2007-02-07 19:13:19 +0000155clean-all-local::
Reid Spencer9411c642004-10-26 22:26:33 +0000156ifneq ($(strip $(BUILT_SOURCES)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000157 -$(Verb) $(RM) -f $(BUILT_SOURCES)
Reid Spencer9411c642004-10-26 22:26:33 +0000158endif
159
Reid Spencer11fde542005-01-16 02:20:54 +0000160ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
Reid Spencer31f95242004-12-16 08:00:46 +0000161spotless:
Reid Spencer31f95242004-12-16 08:00:46 +0000162 $(Verb) if test -x config.status ; then \
Reid Spencer11fde542005-01-16 02:20:54 +0000163 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000164 $(MKDIR) .spotless.save ; \
165 $(MV) config.status .spotless.save ; \
166 $(MV) mklib .spotless.save ; \
167 $(MV) projects .spotless.save ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000168 $(RM) -rf * ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000169 $(MV) .spotless.save/config.status . ; \
170 $(MV) .spotless.save/mklib . ; \
171 $(MV) .spotless.save/projects . ; \
172 $(RM) -rf .spotless.save ; \
Reid Spencer11fde542005-01-16 02:20:54 +0000173 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
Reid Spencer39b73632004-12-17 07:45:03 +0000174 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
175 $(ConfigStatusScript) ; \
Reid Spencer31f95242004-12-16 08:00:46 +0000176 else \
Reid Spencer11fde542005-01-16 02:20:54 +0000177 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
Reid Spencer31f95242004-12-16 08:00:46 +0000178 fi
Reid Spencer25e8a702005-12-21 23:17:06 +0000179else
180spotless:
181 $(EchoCmd) "spotless target not supported for objdir == srcdir"
Reid Spencer31f95242004-12-16 08:00:46 +0000182endif
183
Reid Spencercc2d1e22004-10-30 09:19:36 +0000184$(BUILT_SOURCES) : $(ObjMakefiles)
Reid Spencer80f0ef72004-10-28 00:41:43 +0000185
Reid Spencer9411c642004-10-26 22:26:33 +0000186#------------------------------------------------------------------------
187# Make sure we're not using a stale configuration
188#------------------------------------------------------------------------
Reid Spencerc3719842004-12-16 18:26:53 +0000189reconfigure:
Reid Spencer11fde542005-01-16 02:20:54 +0000190 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
191 $(Verb) cd $(PROJ_OBJ_ROOT) && \
Reid Spencerc3719842004-12-16 18:26:53 +0000192 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
193 $(ConfigStatusScript)
194
Reid Spencercc2d1e22004-10-30 09:19:36 +0000195.PRECIOUS: $(ConfigStatusScript)
Jim Grosbache5e2c412010-10-01 22:32:12 +0000196$(ConfigStatusScript): $(ConfigureScript)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000197 $(Echo) Reconfiguring with $<
Reid Spencer11fde542005-01-16 02:20:54 +0000198 $(Verb) cd $(PROJ_OBJ_ROOT) && \
Reid Spencer7d277002004-11-29 12:37:44 +0000199 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
200 $(ConfigStatusScript)
Reid Spencer9411c642004-10-26 22:26:33 +0000201
Reid Spencer6f5f8b32005-08-25 04:44:18 +0000202#------------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +0000203# Make sure the configuration makefile is up to date
204#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +0000205ifneq ($(MakefileConfigIn),)
206$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000207 $(Echo) Regenerating $@
Reid Spencer11fde542005-01-16 02:20:54 +0000208 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
209endif
210
211ifneq ($(MakefileCommonIn),)
212$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
213 $(Echo) Regenerating $@
214 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
215endif
Reid Spencer9411c642004-10-26 22:26:33 +0000216
217#------------------------------------------------------------------------
218# If the Makefile in the source tree has been updated, copy it over into the
219# build tree. But, only do this if the source and object makefiles differ
220#------------------------------------------------------------------------
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000221ifndef PROJ_MAKEFILE
222PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
223endif
224
Reid Spencer11fde542005-01-16 02:20:54 +0000225ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
Reid Spencer9411c642004-10-26 22:26:33 +0000226
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000227Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000228 $(Echo) "Updating Makefile"
229 $(Verb) $(MKDIR) $(@D)
Reid Spencerc3719842004-12-16 18:26:53 +0000230 $(Verb) $(CP) -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000231
232# Copy the Makefile.* files unless we're in the root directory which avoids
233# the copying of Makefile.config.in or other things that should be explicitly
234# taken care of.
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +0000235$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
Reid Spencer86606782004-10-26 23:10:00 +0000236 @case '$?' in \
237 *Makefile.rules) ;; \
238 *.in) ;; \
Gordon Henriksen7252dc02008-03-10 15:58:40 +0000239 *) $(EchoCmd) "Updating $(@F)" ; \
Reid Spencer86606782004-10-26 23:10:00 +0000240 $(MKDIR) $(@D) ; \
Reid Spencerc3719842004-12-16 18:26:53 +0000241 $(CP) -f $< $@ ;; \
Reid Spencer86606782004-10-26 23:10:00 +0000242 esac
Gabor Greif0a4c3782008-02-27 13:34:15 +0000243
Reid Spencer9411c642004-10-26 22:26:33 +0000244endif
245
246#------------------------------------------------------------------------
247# Set up the basic dependencies
248#------------------------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +0000249$(UserTargets):: $(PreConditions)
Reid Spencer9411c642004-10-26 22:26:33 +0000250
251all:: all-local
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000252clean:: clean-local
Reid Spencer3d659492004-11-02 16:36:03 +0000253clean-all:: clean-local clean-all-local
Reid Spencer9411c642004-10-26 22:26:33 +0000254install:: install-local
255uninstall:: uninstall-local
Misha Brukmanef5dc702009-01-08 02:11:55 +0000256install-local:: all-local
Reid Spencer44cb1b32004-12-03 20:08:48 +0000257install-bytecode:: install-bytecode-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000258
259###############################################################################
260# VARIABLES: Set up various variables based on configuration data
261###############################################################################
262
Daniel Dunbar94e98af2008-10-03 19:11:19 +0000263# Variable for if this make is for a "cleaning" target
264ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
265 IS_CLEANING_TARGET=1
266endif
267
Reid Spencer3a561f52004-10-23 20:04:14 +0000268#--------------------------------------------------------------------
269# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000270#--------------------------------------------------------------------
271
Reid Spencer0a522b12007-07-10 07:19:53 +0000272CPP.Defines :=
David Greenedbefd0c2009-04-17 14:49:22 +0000273ifeq ($(ENABLE_OPTIMIZED),1)
274 BuildMode := Release
275 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
Anton Korobeynikove55db742009-08-18 00:40:33 +0000276 ifneq ($(HOST_OS),FreeBSD)
277 ifneq ($(HOST_OS),Darwin)
David Greenedbefd0c2009-04-17 14:49:22 +0000278 OmitFramePointer := -fomit-frame-pointer
Chris Lattner760da062003-03-14 20:25:22 +0000279 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000280 endif
281
282 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Chengea84e932009-04-20 22:49:59 +0000283 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
284 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Anton Korobeynikove55db742009-08-18 00:40:33 +0000285 #ifeq ($(HOST_OS),Darwin)
Evan Chengb306e382009-04-20 22:16:40 +0000286 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
287 #endif
David Greenedbefd0c2009-04-17 14:49:22 +0000288 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
289 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
290 LD.Flags += $(OPTIMIZE_OPTION)
Jeffrey Yasskin7fd82e52009-09-27 17:47:29 +0000291 ifdef DEBUG_SYMBOLS
Jeffrey Yasskind4482922009-09-25 16:46:09 +0000292 BuildMode := $(BuildMode)+Debug
293 CXX.Flags += -g
294 C.Flags += -g
295 LD.Flags += -g
296 KEEP_SYMBOLS := 1
297 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000298else
Daniel Dunbardee8dbe2009-11-16 22:37:52 +0000299 ifdef NO_DEBUG_SYMBOLS
300 BuildMode := Unoptimized
301 CXX.Flags +=
302 C.Flags +=
303 LD.Flags +=
304 KEEP_SYMBOLS := 1
305 else
306 BuildMode := Debug
307 CXX.Flags += -g
308 C.Flags += -g
309 LD.Flags += -g
310 KEEP_SYMBOLS := 1
311 endif
David Greenedbefd0c2009-04-17 14:49:22 +0000312endif
313
Eric Christopherbee515f2011-11-11 22:51:42 +0000314ifeq ($(ENABLE_LIBCPP),1)
315 CXX.Flags += -stdlib=libc++
316 LD.Flags += -stdlib=libc++
317endif
Chris Lattner16969802011-11-10 21:12:28 +0000318
David Greenedbefd0c2009-04-17 14:49:22 +0000319ifeq ($(ENABLE_PROFILING),1)
320 BuildMode := $(BuildMode)+Profile
321 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
322 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
323 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
324 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000325endif
326
Benjamin Kramer01442cd2011-12-22 21:41:32 +0000327ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
Benjamin Kramer01442cd2011-12-22 21:41:32 +0000328 CXX.Flags += -fvisibility-inlines-hidden
329endif
Daniel Dunbarecfe67c2008-09-02 17:35:16 +0000330
Chris Lattnerc96d5082010-01-24 20:20:40 +0000331ifdef ENABLE_EXPENSIVE_CHECKS
332 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
333 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
334 REQUIRES_RTTI := 1
335endif
336
Reid Spencer99655e12006-08-25 19:54:53 +0000337# IF REQUIRES_EH=1 is specified then don't disable exceptions
Reid Spencerdcea1402006-08-25 20:56:59 +0000338ifndef REQUIRES_EH
339 CXX.Flags += -fno-exceptions
Chris Lattnerc6150382010-01-24 20:21:50 +0000340else
341 # If the library requires EH, it also requires RTTI.
342 REQUIRES_RTTI := 1
Reid Spencerdcea1402006-08-25 20:56:59 +0000343endif
Reid Spencer99655e12006-08-25 19:54:53 +0000344
Nicolas Geoffray8ed81412009-08-19 22:04:44 +0000345ifdef REQUIRES_FRAME_POINTER
346 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
347 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
348 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
349endif
350
Daniel Dunbarccb75c22009-09-11 15:47:24 +0000351# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
Chris Lattner43b5f932010-01-24 20:43:08 +0000352ifneq ($(REQUIRES_RTTI), 1)
353 CXX.Flags += -fno-rtti
Reid Spencer6548bf12007-05-02 21:29:39 +0000354endif
355
Peter Collingbourneed50d382010-10-22 12:54:34 +0000356ifeq ($(ENABLE_COVERAGE),1)
Daniel Dunbar55a07b22009-03-13 20:59:41 +0000357 BuildMode := $(BuildMode)+Coverage
Chris Lattner6be92662009-06-16 23:00:42 +0000358 CXX.Flags += -ftest-coverage -fprofile-arcs
359 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar55a07b22009-03-13 20:59:41 +0000360endif
361
Reid Spencer854071c2006-04-10 16:46:04 +0000362# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
363# then disable assertions by defining the appropriate preprocessor symbols.
Peter Collingbourneed50d382010-10-22 12:54:34 +0000364ifeq ($(DISABLE_ASSERTIONS),1)
365 CPP.Defines += -DNDEBUG
366else
Duncan Sands8246adc2010-07-07 07:48:00 +0000367 BuildMode := $(BuildMode)+Asserts
Reid Spencer0a522b12007-07-10 07:19:53 +0000368 CPP.Defines += -D_DEBUG
Chris Lattner71927862006-03-21 01:06:41 +0000369endif
370
Misha Brukmanef5dc702009-01-08 02:11:55 +0000371# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
372# configured), then enable expensive checks by defining the
David Greenecba29182007-06-29 03:36:21 +0000373# appropriate preprocessor symbols.
Peter Collingbourneed50d382010-10-22 12:54:34 +0000374ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
David Greenea696d242007-06-28 19:36:08 +0000375 BuildMode := $(BuildMode)+Checks
Duncan Sands47d9dcc2008-12-09 21:33:20 +0000376 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
David Greenea696d242007-06-28 19:36:08 +0000377endif
378
Nick Lewyckya15dc032009-02-26 07:44:16 +0000379# LOADABLE_MODULE implies several other things so we force them to be
380# defined/on.
381ifdef LOADABLE_MODULE
382 SHARED_LIBRARY := 1
Nick Lewyckya15dc032009-02-26 07:44:16 +0000383 LINK_LIBS_IN_SHARED := 1
384endif
385
386ifdef SHARED_LIBRARY
387 ENABLE_PIC := 1
388 PIC_FLAG = "(PIC)"
389endif
390
Reid Spencer89b0d992006-12-16 22:07:52 +0000391ifeq ($(ENABLE_PIC),1)
Anton Korobeynikove55db742009-08-18 00:40:33 +0000392 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Nick Lewycky8e87e652009-02-21 08:41:09 +0000393 # Nothing. Win32 defaults to PIC and warns when given -fPIC
394 else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000395 ifeq ($(HOST_OS),Darwin)
Nick Lewyckya15dc032009-02-26 07:44:16 +0000396 # Common symbols not allowed in dylib files
Nick Lewycky8e87e652009-02-21 08:41:09 +0000397 CXX.Flags += -fno-common
398 C.Flags += -fno-common
399 else
400 # Linux and others; pass -fPIC
401 CXX.Flags += -fPIC
402 C.Flags += -fPIC
403 endif
404 endif
Mike Stump3fbdbd92009-05-08 23:08:58 +0000405else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000406 ifeq ($(HOST_OS),Darwin)
Mike Stump3fbdbd92009-05-08 23:08:58 +0000407 CXX.Flags += -mdynamic-no-pic
408 C.Flags += -mdynamic-no-pic
409 endif
Reid Spencer89b0d992006-12-16 22:07:52 +0000410endif
411
Daniel Dunbardd464df2010-05-10 20:11:56 +0000412# Support makefile variable to disable any kind of timestamp/non-deterministic
413# info from being used in the build.
414ifeq ($(ENABLE_TIMESTAMPS),1)
415 DOTDIR_TIMESTAMP_COMMAND := $(DATE)
416else
417 DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
418endif
419
Anton Korobeynikov2b02b432010-01-16 14:06:58 +0000420ifeq ($(HOST_OS),MingW)
421 # Work around PR4957
422 CPP.Defines += -D__NO_CTYPE_INLINE
423 ifeq ($(LLVM_CROSS_COMPILING),1)
424 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
425 ifdef TOOLNAME
426 LD.Flags += -Wl,--allow-multiple-definition
427 endif
428 endif
429endif
430
Chris Lattner1bdedb92011-04-09 06:01:28 +0000431CXX.Flags += -Woverloaded-virtual
David Greenea696d242007-06-28 19:36:08 +0000432CPP.BaseFlags += $(CPP.Defines)
Reid Spencerf2722ca2006-03-22 15:59:55 +0000433AR.Flags := cru
Reid Spencer3a561f52004-10-23 20:04:14 +0000434
Chris Lattner16620fc2006-07-27 18:19:51 +0000435# Make Floating point IEEE compliant on Alpha.
Andrew Lenharth39bcf5b2005-02-13 03:41:10 +0000436ifeq ($(ARCH),Alpha)
Reid Spencer89b0d992006-12-16 22:07:52 +0000437 CXX.Flags += -mieee
438 CPP.BaseFlags += -mieee
439ifeq ($(ENABLE_PIC),0)
440 CXX.Flags += -fPIC
441 CPP.BaseFlags += -fPIC
442endif
Andrew Lenharth39bcf5b2005-02-13 03:41:10 +0000443
Andrew Lenharthc5e455d2007-01-26 13:34:50 +0000444 LD.Flags += -Wl,--no-relax
445endif
446
NAKAMURA Takumib9dec1f2010-11-26 09:32:02 +0000447# GNU ld/PECOFF accepts but ignores them below;
448# --version-script
449# --export-dynamic
450# --rpath
451# FIXME: autoconf should be aware of them.
452ifneq (,$(filter $(HOST_OS),Cygwin MingW))
453 HAVE_LINK_VERSION_SCRIPT := 0
454 RPATH :=
455 RDYNAMIC := -Wl,--export-all-symbols
456endif
457
Reid Spencer3a561f52004-10-23 20:04:14 +0000458#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000459# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000460#--------------------------------------------------------------------
Jim Grosbach673612e2008-10-02 22:56:44 +0000461TargetMode :=
462ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000463 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbach673612e2008-10-02 22:56:44 +0000464endif
465
466ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov569c45c2008-11-10 07:33:13 +0000467ObjDir := $(ObjRootDir)
468LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
469ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
470ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
471LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
472LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
473LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
John Criswell7a73b802003-06-30 21:59:07 +0000474
Reid Spencer3a561f52004-10-23 20:04:14 +0000475#--------------------------------------------------------------------
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000476# Locations of shared libraries
477#--------------------------------------------------------------------
478
479SharedPrefix := lib
480SharedLibDir := $(LibDir)
481LLVMSharedLibDir := $(LLVMLibDir)
482
483# Win32.DLL prefers to be located on the "PATH" of binaries.
484ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
485 SharedLibDir := $(ToolDir)
486 LLVMSharedLibDir := $(LLVMToolDir)
487
488 ifeq ($(HOST_OS),Cygwin)
489 SharedPrefix := cyg
490 else
491 SharedPrefix :=
492 endif
493endif
494
495#--------------------------------------------------------------------
Daniel Dunbar797faed2010-02-23 10:00:53 +0000496# LLVM Capable Compiler
497#--------------------------------------------------------------------
498
Chris Lattner70d77002011-04-09 19:53:16 +0000499ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
Daniel Dunbar797faed2010-02-23 10:00:53 +0000500 LLVMCC := $(LLVMGCC)
501 LLVMCXX := $(LLVMGXX)
502else
Chris Lattner70d77002011-04-09 19:53:16 +0000503 ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
Daniel Dunbar797faed2010-02-23 10:00:53 +0000504 ifneq ($(CLANGPATH),)
505 LLVMCC := $(CLANGPATH)
506 LLVMCXX := $(CLANGXXPATH)
507 else
508 ifeq ($(ENABLE_BUILT_CLANG),1)
509 LLVMCC := $(LLVMToolDir)/clang
510 LLVMCXX := $(LLVMToolDir)/clang++
511 endif
512 endif
513 endif
514endif
515
516#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000517# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000518#--------------------------------------------------------------------
Daniel Dunbar01b825d2011-11-11 22:59:45 +0000519EchoCmd := $(ECHO) llvm[$(MAKELEVEL)]:
520ifdef BUILD_DIRS_ONLY
521EchoCmd := $(EchoCmd) "(build tools)":
522endif
523
524Echo := @$(EchoCmd)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000525ifndef LLVMAS
526LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
527endif
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000528ifndef LLVM_TBLGEN
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000529 ifeq ($(LLVM_CROSS_COMPILING),1)
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000530 LLVM_TBLGEN := $(BuildLLVMToolDir)/llvm-tblgen$(BUILD_EXEEXT)
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000531 else
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000532 LLVM_TBLGEN := $(LLVMToolDir)/llvm-tblgen$(EXEEXT)
Reid Spencere2cfe5d2006-07-26 21:14:56 +0000533 endif
Reid Spencercc2d1e22004-10-30 09:19:36 +0000534endif
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000535ifeq ($(LLVM_CROSS_COMPILING),1)
Daniel Dunbarcb497b82011-12-01 20:18:09 +0000536 LLVM_CONFIG := $(BuildLLVMToolDir)/llvm-config$(BUILD_EXEEXT)
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000537else
Daniel Dunbarcb497b82011-12-01 20:18:09 +0000538 LLVM_CONFIG := $(LLVMToolDir)/llvm-config$(EXEEXT)
Daniel Dunbar7c67d322011-11-14 17:17:45 +0000539endif
Reid Spencer43eb96c2007-02-09 15:52:07 +0000540ifndef LLVMLD
Reid Spencer18464122007-02-09 17:09:14 +0000541LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000542endif
Chris Lattner0a1db822006-09-04 05:23:20 +0000543ifndef LLVMDIS
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000544LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
545endif
546ifndef LLI
547LLI := $(LLVMToolDir)/lli$(EXEEXT)
548endif
Alkis Evlogimenoseebaf332005-02-27 10:21:37 +0000549ifndef LLC
550LLC := $(LLVMToolDir)/llc$(EXEEXT)
551endif
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000552ifndef LOPT
Alkis Evlogimenos20d793a2004-12-13 18:08:29 +0000553LOPT := $(LLVMToolDir)/opt$(EXEEXT)
Alkis Evlogimenos7e80cd92004-12-13 17:44:14 +0000554endif
Alkis Evlogimenos270e8512005-02-02 00:40:15 +0000555ifndef LBUGPOINT
556LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
557endif
Reid Spencere46687c2006-12-03 21:01:45 +0000558
Reid Spencer3a561f52004-10-23 20:04:14 +0000559#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000560# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000561#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000562
Anton Korobeynikove55db742009-08-18 00:40:33 +0000563ifeq ($(HOST_OS),Darwin)
Scott Michel87af5f02009-03-12 21:03:53 +0000564 DARWIN_VERSION := `sw_vers -productVersion`
565 # Strip a number like 10.4.7 to 10.4
566 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
567 # Get "4" out of 10.4 for later pieces in the makefile.
568 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendlingaca56952009-03-22 08:28:45 +0000569
Daniel Dunbar7bc0f272010-12-08 01:48:05 +0000570 LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
571 SharedLinkOptions := -dynamiclib
Evan Chenga5e225e2009-09-08 18:52:20 +0000572 ifneq ($(ARCH),ARM)
573 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
574 endif
Scott Michel87af5f02009-03-12 21:03:53 +0000575else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000576 SharedLinkOptions=-shared
Scott Michel87af5f02009-03-12 21:03:53 +0000577endif
578
Anton Korobeynikove55db742009-08-18 00:40:33 +0000579ifeq ($(TARGET_OS),Darwin)
Evan Chenga5e225e2009-09-08 18:52:20 +0000580 ifneq ($(ARCH),ARM)
581 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
582 endif
Anton Korobeynikove55db742009-08-18 00:40:33 +0000583endif
584
Reid Spencer492c2932005-01-11 04:31:07 +0000585ifdef SHARED_LIBRARY
Anton Korobeynikov59a430f2010-08-17 19:03:03 +0000586ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Rafael Espindolaa89efd52010-05-16 03:05:14 +0000587ifneq ($(HOST_OS),Darwin)
588 LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
John Criswell82f4a5a2003-07-31 20:58:51 +0000589endif
Scott Michel87af5f02009-03-12 21:03:53 +0000590endif
Rafael Espindolaa89efd52010-05-16 03:05:14 +0000591endif
John Criswell82f4a5a2003-07-31 20:58:51 +0000592
Reid Spencercceed9f2004-11-08 17:32:12 +0000593ifdef TOOL_VERBOSE
594 C.Flags += -v
595 CXX.Flags += -v
596 LD.Flags += -v
Reid Spencercceed9f2004-11-08 17:32:12 +0000597 VERBOSE := 1
598endif
599
Reid Spencer3a561f52004-10-23 20:04:14 +0000600# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000601ifndef VERBOSE
Reid Spencercc2d1e22004-10-30 09:19:36 +0000602 Verb := @
Reid Spencer491a6cd2007-07-23 08:20:46 +0000603 AR.Flags += >/dev/null 2>/dev/null
Reid Spencer11fde542005-01-16 02:20:54 +0000604 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
Reid Spencer151f8ba2004-10-25 08:27:37 +0000605else
Misha Brukmanef5dc702009-01-08 02:11:55 +0000606 ConfigureScriptFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000607endif
608
Vikram S. Advefeeae582002-09-18 11:55:13 +0000609# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000610ifndef KEEP_SYMBOLS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000611 Strip := $(PLATFORMSTRIPOPTS)
612 StripWarnMsg := "(without symbols)"
Charles Davis13460c92011-10-26 02:28:32 +0000613 Install.StripFlag += -s
Vikram S. Advefeeae582002-09-18 11:55:13 +0000614endif
615
Rafael Espindola31552a92010-10-15 00:58:12 +0000616ifdef TOOL_NO_EXPORTS
617 DynamicFlags :=
618else
619 DynamicFlag := $(RDYNAMIC)
620endif
621
Reid Spencer3a561f52004-10-23 20:04:14 +0000622# Adjust linker flags for building an executable
Nick Lewyckye28015c2010-08-02 03:16:19 +0000623ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
624ifneq ($(HOST_OS), Darwin)
Reid Spencer4d71b662004-10-22 21:01:56 +0000625ifdef TOOLNAME
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000626 LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
627 ifdef EXAMPLE_TOOL
Rafael Espindola31552a92010-10-15 00:58:12 +0000628 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000629 else
Rafael Espindola31552a92010-10-15 00:58:12 +0000630 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +0000631 endif
Reid Spencer815cbcf2004-11-18 10:03:46 +0000632endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000633else
634ifneq ($(DARWIN_MAJVERS),4)
635 LD.Flags += $(RPATH) -Wl,@executable_path/../lib
Nick Lewyckya15dc032009-02-26 07:44:16 +0000636endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000637endif
Nick Lewyckye28015c2010-08-02 03:16:19 +0000638endif
Ted Kremenekd634bcb2010-07-15 06:36:57 +0000639
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000640
Reid Spencer3a561f52004-10-23 20:04:14 +0000641#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000642# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000643#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000644
Daniel Dunbare2a91a72011-06-16 22:30:38 +0000645ifdef EXTRA_LD_OPTIONS
646LD.Flags += $(EXTRA_LD_OPTIONS)
647endif
648
Daniel Dunbare36b6d42009-05-12 07:26:49 +0000649ifndef NO_PEDANTIC
Duncan Sands9ff4c132009-06-19 12:40:30 +0000650CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbare36b6d42009-05-12 07:26:49 +0000651endif
Duncan Sands9ff4c132009-06-19 12:40:30 +0000652CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
653 $(EXTRA_OPTIONS)
Dan Gohman3072b8a2010-04-19 18:33:28 +0000654# Enable cast-qual for C++; the workaround is to use const_cast.
655CXX.Flags += -Wcast-qual
Reid Spencer4d71b662004-10-22 21:01:56 +0000656
Anton Korobeynikove55db742009-08-18 00:40:33 +0000657ifeq ($(HOST_OS),HP-UX)
Duraid Madinaeb713402006-02-15 03:20:16 +0000658 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
Duraid Madina0ad8fcf2005-05-16 06:38:09 +0000659endif
660
Chris Lattner73faa392006-05-30 16:38:06 +0000661# If we are building a universal binary on Mac OS/X, pass extra options. This
662# is useful to people that want to link the LLVM libraries into their universal
Chris Lattner7dabf392006-06-29 19:38:04 +0000663# apps.
664#
665# The following can be optionally specified:
666# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
667# For Mac OS/X 10.4 Intel machines, the traditional one is:
668# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
669# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
670# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
671# i386/ppc only.
Chris Lattnerba466652006-04-06 06:30:15 +0000672ifdef UNIVERSAL
Chris Lattner7dabf392006-06-29 19:38:04 +0000673 ifndef UNIVERSAL_ARCH
674 UNIVERSAL_ARCH := i386 ppc
675 endif
676 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
677 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattnerf988e532006-06-16 21:47:59 +0000678 ifdef UNIVERSAL_SDK_PATH
679 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattnerf988e532006-06-16 21:47:59 +0000680 endif
681
682 # Building universal cannot compute dependencies automatically.
Chris Lattnerba466652006-04-06 06:30:15 +0000683 DISABLE_AUTO_DEPENDENCIES=1
Evan Chengc785b4f2009-03-09 18:28:37 +0000684else
Anton Korobeynikove55db742009-08-18 00:40:33 +0000685 ifeq ($(TARGET_OS),Darwin)
Bill Wendlinga0833352009-03-12 04:10:09 +0000686 ifeq ($(ARCH),x86_64)
Evan Chenga38ff642009-03-23 03:45:56 +0000687 TargetCommonOpts = -m64
Bill Wendlinga0833352009-03-12 04:10:09 +0000688 else
689 ifeq ($(ARCH),x86)
Evan Chenga38ff642009-03-23 03:45:56 +0000690 TargetCommonOpts = -m32
Bill Wendlinga0833352009-03-12 04:10:09 +0000691 endif
Evan Chengc785b4f2009-03-09 18:28:37 +0000692 endif
693 endif
Chris Lattnerba466652006-04-06 06:30:15 +0000694endif
695
Anton Korobeynikove55db742009-08-18 00:40:33 +0000696ifeq ($(HOST_OS),SunOS)
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000697CPP.BaseFlags += -include llvm/Support/Solaris.h
Chris Lattner58a4c5e2008-06-24 17:44:42 +0000698endif
699
Edward O'Callaghandf199f12009-10-14 05:55:03 +0000700ifeq ($(HOST_OS),AuroraUX)
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000701CPP.BaseFlags += -include llvm/Support/Solaris.h
Edward O'Callaghandf199f12009-10-14 05:55:03 +0000702endif # !HOST_OS - AuroraUX.
703
Misha Brukmanef5dc702009-01-08 02:11:55 +0000704LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
NAKAMURA Takumie2aa5d52011-10-11 12:51:44 +0000705CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Reid Spencerf2722ca2006-03-22 15:59:55 +0000706# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands095765e2008-01-28 17:38:30 +0000707CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
708 $(patsubst %,-I%/include,\
Chris Lattner2671fc32008-01-28 04:18:41 +0000709 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
710 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
711 $(CPP.BaseFlags)
Reid Spencer4d71b662004-10-22 21:01:56 +0000712
Daniel Dunbar8d694142011-11-03 21:01:32 +0000713ifeq ($(INCLUDE_BUILD_DIR),1)
714 CPP.Flags += -I$(ObjDir)
715endif
716
Daniel Dunbar58194302011-04-11 22:37:39 +0000717# SHOW_DIAGNOSTICS support.
718ifeq ($(SHOW_DIAGNOSTICS),1)
719 Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
720 CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
721else
722 Compile.Wrapper :=
723endif
724
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000725Compile.C = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000726 $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000727 $(TargetCommonOpts) $(CompileCommonOpts) -c
728Compile.CXX = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000729 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000730 $(TargetCommonOpts) $(CompileCommonOpts) -c
731Preprocess.CXX= $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000732 $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000733 $(CompileCommonOpts) $(CXX.Flags) -E
734Link = $(Compile.Wrapper) \
Daniel Dunbar58194302011-04-11 22:37:39 +0000735 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
Daniel Dunbar9969bc92011-11-11 22:59:42 +0000736 $(LDFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) $(Strip)
Jim Grosbach673612e2008-10-02 22:56:44 +0000737
Daniel Dunbar7cfbe252010-02-23 10:28:06 +0000738BCCompile.C = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000739 $(TargetCommonOpts) $(CompileCommonOpts)
Eric Christopher2bd4bb02009-08-18 03:23:40 +0000740Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000741 $(TargetCommonOpts) $(CompileCommonOpts) -E
Chris Lattner0cb09f12005-10-05 00:28:41 +0000742
Daniel Dunbar7cfbe252010-02-23 10:28:06 +0000743BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
Evan Chenga38ff642009-03-23 03:45:56 +0000744 $(TargetCommonOpts) $(CompileCommonOpts)
Chris Lattnerd95e3f22006-09-29 18:47:13 +0000745
Misha Brukmanef5dc702009-01-08 02:11:55 +0000746ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
747ScriptInstall = $(INSTALL) -m 0755
Reid Spencer860598a2005-02-24 07:12:43 +0000748DataInstall = $(INSTALL) -m 0644
Chris Lattner6e0a5292008-01-15 23:27:40 +0000749
750# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
751# paths. In this case, the SYSPATH function (defined in
752# Makefile.config) transforms Unix paths into Windows paths.
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000753TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkovafa22592009-01-09 16:31:01 +0000754 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner6e0a5292008-01-15 23:27:40 +0000755 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
756 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
Peter Collingbournede8f33c2011-10-06 01:51:51 +0000757LLVMTableGen = $(LLVM_TBLGEN) $(TableGen.Flags)
Chris Lattner6e0a5292008-01-15 23:27:40 +0000758
Reid Spencercc2d1e22004-10-30 09:19:36 +0000759Archive = $(AR) $(AR.Flags)
Reid Spencer9a2f1372004-12-02 09:28:21 +0000760LArchive = $(LLVMToolDir)/llvm-ar rcsf
Reid Spencer4d71b662004-10-22 21:01:56 +0000761ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000762Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000763else
Reid Spencer3a561f52004-10-23 20:04:14 +0000764Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000765endif
766
Daniel Dunbarfd96b132009-11-19 00:14:53 +0000767AliasTool = ln -s
768
Chris Lattner00950542001-06-06 20:29:01 +0000769#----------------------------------------------------------
Misha Brukmanef5dc702009-01-08 02:11:55 +0000770# Get the list of source files and compute object file
771# names from them.
Reid Spencer3a561f52004-10-23 20:04:14 +0000772#----------------------------------------------------------
Chris Lattner89681112006-01-27 22:13:12 +0000773
774ifndef SOURCES
775 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattnerc9480642009-01-02 07:16:45 +0000776 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000777else
Chris Lattner89681112006-01-27 22:13:12 +0000778 Sources := $(SOURCES)
Misha Brukmanef5dc702009-01-08 02:11:55 +0000779endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000780
Chris Lattner89681112006-01-27 22:13:12 +0000781ifdef BUILT_SOURCES
Chris Lattnerc9480642009-01-02 07:16:45 +0000782Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Reid Spencer345235ca2004-12-04 22:34:09 +0000783endif
Reid Spencer3a561f52004-10-23 20:04:14 +0000784
Chris Lattner89681112006-01-27 22:13:12 +0000785BaseNameSources := $(sort $(basename $(Sources)))
786
787ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Chris Lattner89681112006-01-27 22:13:12 +0000788ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
789
NAKAMURA Takumi02724852011-03-08 12:25:10 +0000790#----------------------------------------------------------
791# For Mingw MSYS bash and Python/w32:
792#
793# $(ECHOPATH) prints DOSish pathstring.
794# ex) $(ECHOPATH) /include/sys/types.h
795# --> C:/mingw/include/sys/types.h
796# built-in "echo" does not transform path to DOSish path.
797#
798# FIXME: It would not be needed when MSYS's python
799# were provided.
800#----------------------------------------------------------
801
802ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
803 ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
804else
805 ECHOPATH := $(Verb)$(ECHO)
806endif
807
Reid Spencer3a561f52004-10-23 20:04:14 +0000808###############################################################################
809# DIRECTORIES: Handle recursive descent of directory structure
810###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000811
Chris Lattner00950542001-06-06 20:29:01 +0000812#---------------------------------------------------------
Reid Spencera69b1ea2004-10-28 09:15:28 +0000813# Provide rules to make install dirs. This must be early
814# in the file so they get built before dependencies
815#---------------------------------------------------------
816
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000817$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
Mike Stumpe50f34a2009-01-22 03:24:22 +0000818 $(Verb) $(MKDIR) $@
Reid Spencera69b1ea2004-10-28 09:15:28 +0000819
Reid Spencercc2d1e22004-10-30 09:19:36 +0000820# To create other directories, as needed, and timestamp their creation
821%/.dir:
822 $(Verb) $(MKDIR) $* > /dev/null
Daniel Dunbardd464df2010-05-10 20:11:56 +0000823 $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
Reid Spencercc2d1e22004-10-30 09:19:36 +0000824
Reid Spencer815cbcf2004-11-18 10:03:46 +0000825.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
826.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
Reid Spencera69b1ea2004-10-28 09:15:28 +0000827
828#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000829# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000830#---------------------------------------------------------
831
Misha Brukmanef5dc702009-01-08 02:11:55 +0000832SubDirs :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000833ifdef DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000834SubDirs += $(DIRS)
Chris Lattner82033602006-07-26 20:22:26 +0000835
836ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000837$(RecursiveTargets)::
838 $(Verb) for dir in $(DIRS); do \
Daniel Dunbar546023f2010-06-08 20:10:13 +0000839 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000840 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000841 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000842 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000843 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000844 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000845 done
Chris Lattner82033602006-07-26 20:22:26 +0000846else
847$(RecursiveTargets)::
848 $(Verb) for dir in $(DIRS); do \
849 ($(MAKE) -C $$dir $@ ) || exit 1; \
850 done
851endif
852
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000853endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000854
Reid Spencer3a561f52004-10-23 20:04:14 +0000855#---------------------------------------------------------
856# Handle the EXPERIMENTAL_DIRS options ensuring success
857# after each directory is built.
858#---------------------------------------------------------
859ifdef EXPERIMENTAL_DIRS
Reid Spencercc2d1e22004-10-30 09:19:36 +0000860$(RecursiveTargets)::
861 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
Daniel Dunbar546023f2010-06-08 20:10:13 +0000862 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000863 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer3a561f52004-10-23 20:04:14 +0000864 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000865 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000866 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000867 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000868 done
869endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000870
Reid Spencer25e8a702005-12-21 23:17:06 +0000871#-----------------------------------------------------------
Mike Stump0a268912009-01-24 00:00:41 +0000872# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
873#-----------------------------------------------------------
874ifdef OPTIONAL_PARALLEL_DIRS
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000875 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 +0000876endif
877
878#-----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000879# Handle the PARALLEL_DIRS options for parallel construction
Reid Spencer25e8a702005-12-21 23:17:06 +0000880#-----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000881ifdef PARALLEL_DIRS
882
Reid Spencercc2d1e22004-10-30 09:19:36 +0000883SubDirs += $(PARALLEL_DIRS)
884
Reid Spencer44cb1b32004-12-03 20:08:48 +0000885# Unfortunately, this list must be maintained if new recursive targets are added
Reid Spencercc2d1e22004-10-30 09:19:36 +0000886all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
887clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
Reid Spencerca5fe8f2004-11-02 16:56:15 +0000888clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000889install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000890uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
Reid Spencer44cb1b32004-12-03 20:08:48 +0000891install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
Daniel Dunbar7f068f42009-09-13 22:39:27 +0000892unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
Reid Spencer3a561f52004-10-23 20:04:14 +0000893
Reid Spencer345235ca2004-12-04 22:34:09 +0000894ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
Reid Spencer3a561f52004-10-23 20:04:14 +0000895
Reid Spencer345235ca2004-12-04 22:34:09 +0000896$(ParallelTargets) :
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000897 $(Verb) \
898 SD=$(PROJ_SRC_DIR)/$(@D); \
899 DD=$(@D); \
900 if [ ! -f $$SD/Makefile ]; then \
901 SD=$(@D); \
902 DD=$(notdir $(@D)); \
903 fi; \
904 if ([ ! -f $$DD/Makefile ] || \
905 command test $$DD/Makefile -ot \
906 $$SD/Makefile ); then \
907 $(MKDIR) $$DD; \
908 $(CP) $$SD/Makefile $$DD/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000909 fi; \
NAKAMURA Takumia87a7db2011-10-16 02:54:19 +0000910 $(MAKE) -C $$DD $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000911endif
912
Reid Spencer3a561f52004-10-23 20:04:14 +0000913#---------------------------------------------------------
914# Handle the OPTIONAL_DIRS options for directores that may
915# or may not exist.
916#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000917ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000918
Reid Spencercc2d1e22004-10-30 09:19:36 +0000919SubDirs += $(OPTIONAL_DIRS)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000920
Chris Lattner82033602006-07-26 20:22:26 +0000921ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencercc2d1e22004-10-30 09:19:36 +0000922$(RecursiveTargets)::
923 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000924 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
Daniel Dunbar546023f2010-06-08 20:10:13 +0000925 if ([ ! -f $$dir/Makefile ] || \
Chris Lattnerf2a12242010-06-18 00:35:32 +0000926 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
Reid Spencer4d71b662004-10-22 21:01:56 +0000927 $(MKDIR) $$dir; \
Reid Spencer11fde542005-01-16 02:20:54 +0000928 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000929 fi; \
Reid Spencerdd1aac32006-05-17 22:55:35 +0000930 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000931 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000932 done
Chris Lattner82033602006-07-26 20:22:26 +0000933else
934$(RecursiveTargets)::
935 $(Verb) for dir in $(OPTIONAL_DIRS); do \
Stephen Wilsonc1566322011-02-20 03:51:07 +0000936 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
937 ($(MAKE) -C$$dir $@ ) || exit 1; \
938 fi \
Chris Lattner82033602006-07-26 20:22:26 +0000939 done
940endif
John Criswell2a6530f2003-06-27 16:58:44 +0000941endif
942
Reid Spencerfc945082004-08-20 09:20:05 +0000943#---------------------------------------------------------
944# Handle the CONFIG_FILES options
945#---------------------------------------------------------
946ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000947
Reid Spencera2a31bf2007-02-06 18:53:14 +0000948ifdef NO_INSTALL
949install-local::
950 $(Echo) Install circumvented with NO_INSTALL
951uninstall-local::
952 $(Echo) UnInstall circumvented with NO_INSTALL
953else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000954install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
955 $(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000956 $(Verb)for file in $(CONFIG_FILES); do \
Reid Spencer11fde542005-01-16 02:20:54 +0000957 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000958 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencer11fde542005-01-16 02:20:54 +0000959 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000960 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
Reid Spencer1b426ab2004-11-23 05:59:53 +0000961 else \
962 $(ECHO) Error: cannot find config file $${file}. ; \
963 fi \
Reid Spencerfc945082004-08-20 09:20:05 +0000964 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000965
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000966uninstall-local::
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000967 $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
Reid Spencercc2d1e22004-10-30 09:19:36 +0000968 $(Verb)for file in $(CONFIG_FILES); do \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +0000969 $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000970 done
Reid Spencera2a31bf2007-02-06 18:53:14 +0000971endif
Reid Spencere5487ba2004-10-24 07:53:21 +0000972
Reid Spencerfc945082004-08-20 09:20:05 +0000973endif
974
Reid Spencer3a561f52004-10-23 20:04:14 +0000975###############################################################################
Eric Christopherdf7d4192010-06-21 23:49:08 +0000976# Set up variables for building libraries
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000977###############################################################################
978
979#---------------------------------------------------------
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000980# Define various command line options pertaining to the
Misha Brukmanef5dc702009-01-08 02:11:55 +0000981# libraries needed when linking. There are "Proj" libs
982# (defined by the user's project) and "LLVM" libs (defined
Chris Lattneref0d0f12006-09-04 04:47:21 +0000983# by the LLVM project).
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000984#---------------------------------------------------------
Andrew Lenharth7ac17522005-08-13 05:09:50 +0000985
Chris Lattneref0d0f12006-09-04 04:47:21 +0000986ifdef USEDLIBS
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000987ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
988ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
Chris Lattneref0d0f12006-09-04 04:47:21 +0000989ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
990ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
991endif
992
993ifdef LLVMLIBS
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000994LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
995LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000996LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
Reid Spencer8f9e21e2005-05-19 00:37:31 +0000997LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
Chris Lattneref0d0f12006-09-04 04:47:21 +0000998endif
999
NAKAMURA Takumia64eb832010-09-10 06:27:02 +00001000# Loadable module for Win32 requires all symbols resolved for linking.
1001# Then all symbols in LLVM.dll will be available.
1002ifeq ($(ENABLE_SHARED),1)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001003 ifdef LOADABLE_MODULE
NAKAMURA Takumia64eb832010-09-10 06:27:02 +00001004 ifneq (,$(filter $(HOST_OS),Cygwin MingW))
1005 LINK_COMPONENTS += all
1006 endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001007 endif
1008endif
1009
Daniel Dunbar94e98af2008-10-03 19:11:19 +00001010ifndef IS_CLEANING_TARGET
Chris Lattneref0d0f12006-09-04 04:47:21 +00001011ifdef LINK_COMPONENTS
Chris Lattner0a1db822006-09-04 05:23:20 +00001012
1013# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
1014# clean in tools, then do a make in tools (instead of at the top level).
1015$(LLVM_CONFIG):
1016 @echo "*** llvm-config doesn't exist - rebuilding it."
1017 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greif0a4c3782008-02-27 13:34:15 +00001018
Chris Lattner0a1db822006-09-04 05:23:20 +00001019$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
1020
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001021ifeq ($(ENABLE_SHARED), 1)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001022# We can take the "auto-import" feature to get rid of using dllimport.
1023ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1024LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
1025 -L $(SharedLibDir)
1026endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001027LLVMLibsOptions += -lLLVM-$(LLVMVersion)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001028LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001029else
Chris Lattnerf636aa92010-09-01 16:11:17 +00001030
1031ifndef NO_LLVM_CONFIG
1032LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
1033ifeq ($(LLVMConfigLibs),Error)
1034$(error llvm-config --libs failed)
1035endif
1036LLVMLibsOptions += $(LLVMConfigLibs)
1037LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
1038ifeq ($(LLVMConfigLibfiles),Error)
1039$(error llvm-config --libfiles failed)
1040endif
1041LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
1042endif
1043
Chris Lattneref0d0f12006-09-04 04:47:21 +00001044endif
Chris Lattner55e6c4a2006-09-04 04:50:10 +00001045endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001046endif
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001047
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001048# Set up the library exports file.
1049ifdef EXPORTED_SYMBOL_FILE
1050
1051# First, set up the native export file, which may differ from the source
1052# export file.
1053
1054ifeq ($(HOST_OS),Darwin)
1055# Darwin convention prefixes symbols with underscores.
Dan Gohman7c52f2e2010-04-15 23:08:00 +00001056NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
Dan Gohman2d675f12010-04-15 22:46:27 +00001057$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
Dan Gohmanf4ef72e2010-06-01 17:08:56 +00001058 $(Verb) sed -e 's/^/_/' < $< > $@
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001059clean-local::
1060 -$(Verb) $(RM) -f $(NativeExportsFile)
1061else
Dan Gohmanda612d62010-06-01 14:56:56 +00001062ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1063# Gold and BFD ld require a version script rather than a plain list.
1064NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
1065$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1066 $(Verb) echo "{" > $@
1067 $(Verb) grep -q "\<" $< && echo " global:" >> $@ || :
Dan Gohmanf4ef72e2010-06-01 17:08:56 +00001068 $(Verb) sed -e 's/$$/;/' -e 's/^/ /' < $< >> $@
Chris Lattnerc625d312011-02-21 18:38:56 +00001069ifneq ($(HOST_OS),OpenBSD)
Dan Gohmanda612d62010-06-01 14:56:56 +00001070 $(Verb) echo " local: *;" >> $@
Chris Lattnerc625d312011-02-21 18:38:56 +00001071endif
Dan Gohmanda612d62010-06-01 14:56:56 +00001072 $(Verb) echo "};" >> $@
1073clean-local::
1074 -$(Verb) $(RM) -f $(NativeExportsFile)
1075else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001076ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
Dan Gohman9a7570c2010-09-03 17:29:33 +00001077# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001078NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001079$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1080 $(Echo) Generating $(notdir $@)
1081 $(Verb) $(ECHO) "EXPORTS" > $@
1082 $(Verb) $(CAT) $< >> $@
1083clean-local::
1084 -$(Verb) $(RM) -f $(NativeExportsFile)
1085else
Dan Gohman9a7570c2010-09-03 17:29:33 +00001086# Default behavior: just use the exports file verbatim.
1087NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
1088endif
1089endif
1090endif
1091
1092# Now add the linker command-line options to use the native export file.
1093
1094# Darwin
1095ifeq ($(HOST_OS),Darwin)
1096LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
1097endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001098
Dan Gohmane05f6092010-04-16 22:58:15 +00001099# gold, bfd ld, etc.
Dan Gohmanda612d62010-06-01 14:56:56 +00001100ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1101LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001102endif
1103
Dan Gohman9a7570c2010-09-03 17:29:33 +00001104# Windows
1105ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1106# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1107SharedLinkOptions += $(NativeExportsFile)
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001108endif
1109
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001110endif
1111
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001112###############################################################################
Reid Spencer3a561f52004-10-23 20:04:14 +00001113# Library Build Rules: Four ways to build a library
1114###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +00001115
Reid Spencer7980ea42004-12-05 05:17:22 +00001116#---------------------------------------------------------
1117# Bytecode Module Targets:
1118# If the user set MODULE_NAME then they want to build a
1119# bytecode module from the sources. We compile all the
1120# sources and link it together into a single bytecode
1121# module.
1122#---------------------------------------------------------
1123
1124ifdef MODULE_NAME
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001125ifeq ($(strip $(LLVMCC)),)
1126$(warning Modules require LLVM capable compiler but none is available ****)
Reid Spencer9a8398e2005-02-14 21:54:08 +00001127else
Reid Spencer7980ea42004-12-05 05:17:22 +00001128
1129Module := $(LibDir)/$(MODULE_NAME).bc
Daniel Dunbar112257d2010-02-23 09:28:50 +00001130LinkModule := $(LLVMLD) -r
Reid Spencerbbd5e432006-04-12 18:21:35 +00001131
Reid Spencer7980ea42004-12-05 05:17:22 +00001132
1133ifdef EXPORTED_SYMBOL_FILE
Chris Lattner89681112006-01-27 22:13:12 +00001134LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer7980ea42004-12-05 05:17:22 +00001135endif
1136
Reid Spencer43eb96c2007-02-09 15:52:07 +00001137$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
Reid Spencer0d255bd2005-05-13 18:32:54 +00001138 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
Reid Spencer7980ea42004-12-05 05:17:22 +00001139 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1140
1141all-local:: $(Module)
1142
1143clean-local::
1144ifneq ($(strip $(Module)),)
1145 -$(Verb) $(RM) -f $(Module)
1146endif
1147
Reid Spencerab3690b2004-12-13 07:38:07 +00001148ifdef BYTECODE_DESTINATION
1149ModuleDestDir := $(BYTECODE_DESTINATION)
1150else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001151ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencerab3690b2004-12-13 07:38:07 +00001152endif
Reid Spencer7980ea42004-12-05 05:17:22 +00001153
Reid Spencera2a31bf2007-02-06 18:53:14 +00001154ifdef NO_INSTALL
1155install-local::
1156 $(Echo) Install circumvented with NO_INSTALL
1157uninstall-local::
1158 $(Echo) Uninstall circumvented with NO_INSTALL
1159else
Reid Spencerab3690b2004-12-13 07:38:07 +00001160DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1161
1162install-module:: $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +00001163install-local:: $(DestModule)
1164
Misha Brukmanef5dc702009-01-08 02:11:55 +00001165$(DestModule): $(ModuleDestDir) $(Module)
Reid Spencer7980ea42004-12-05 05:17:22 +00001166 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
Reid Spencer151bbe42005-02-24 21:30:37 +00001167 $(Verb) $(DataInstall) $(Module) $(DestModule)
Reid Spencer7980ea42004-12-05 05:17:22 +00001168
1169uninstall-local::
1170 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1171 -$(Verb) $(RM) -f $(DestModule)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001172endif
Reid Spencer7980ea42004-12-05 05:17:22 +00001173
1174endif
Reid Spencer9a8398e2005-02-14 21:54:08 +00001175endif
Brian Gaeke8abff792004-01-22 22:53:48 +00001176
Reid Spencer3a561f52004-10-23 20:04:14 +00001177# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +00001178ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +00001179
Misha Brukmanf547a122009-08-17 15:31:24 +00001180# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +00001181LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer492c2932005-01-11 04:31:07 +00001182ifdef LOADABLE_MODULE
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001183BaseLibName.A := $(LIBRARYNAME).a
1184BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer492c2932005-01-11 04:31:07 +00001185else
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001186BaseLibName.A := lib$(LIBRARYNAME).a
1187BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001188endif
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001189LibName.A := $(LibDir)/$(BaseLibName.A)
1190LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001191LibName.O := $(LibDir)/$(LIBRARYNAME).o
Reid Spencer9a2f1372004-12-02 09:28:21 +00001192LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
Chris Lattnerccb4ebd2002-09-16 22:34:56 +00001193
Reid Spencer3a561f52004-10-23 20:04:14 +00001194#---------------------------------------------------------
1195# Shared Library Targets:
1196# If the user asked for a shared library to be built
1197# with the SHARED_LIBRARY variable, then we provide
1198# targets for building them.
1199#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +00001200ifdef SHARED_LIBRARY
1201
Nick Lewyckya15dc032009-02-26 07:44:16 +00001202all-local:: $(LibName.SO)
Reid Spencer4d71b662004-10-22 21:01:56 +00001203
Dan Gohmanb16b53b2010-04-15 20:54:25 +00001204ifdef EXPORTED_SYMBOL_FILE
1205$(LibName.SO): $(NativeExportsFile)
1206endif
1207
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001208ifdef LINK_LIBS_IN_SHARED
Reid Spencer42fe4552006-08-07 23:12:15 +00001209ifdef LOADABLE_MODULE
Chris Lattner166f45e2006-11-15 21:04:15 +00001210SharedLibKindMessage := "Loadable Module"
Daniel Dunbar7bc0f272010-12-08 01:48:05 +00001211SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
Reid Spencer42fe4552006-08-07 23:12:15 +00001212else
1213SharedLibKindMessage := "Shared Library"
1214endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001215$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
Reid Spencer42fe4552006-08-07 23:12:15 +00001216 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
Dan Gohman6b156a32010-07-26 20:15:47 +00001217 $(notdir $@)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001218 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Torok Edwin2efc73d2009-05-26 19:11:47 +00001219 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001220else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001221$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
Dan Gohman6b156a32010-07-26 20:15:47 +00001222 $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001223 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Reid Spencer8f9e21e2005-05-19 00:37:31 +00001224endif
Reid Spencer3a561f52004-10-23 20:04:14 +00001225
1226clean-local::
Nick Lewyckya15dc032009-02-26 07:44:16 +00001227ifneq ($(strip $(LibName.SO)),)
1228 -$(Verb) $(RM) -f $(LibName.SO)
Reid Spencere5487ba2004-10-24 07:53:21 +00001229endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001230
Reid Spencera2a31bf2007-02-06 18:53:14 +00001231ifdef NO_INSTALL
1232install-local::
1233 $(Echo) Install circumvented with NO_INSTALL
1234uninstall-local::
1235 $(Echo) Uninstall circumvented with NO_INSTALL
1236else
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001237
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001238# Win32.DLL prefers to be located on the "PATH" of binaries.
1239ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1240DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001241else
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001242DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
Rafael Espindolabbe03f82010-05-16 03:13:23 +00001243endif
Rafael Espindola0ecd2962011-02-03 22:01:15 +00001244DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
Reid Spencer4d71b662004-10-22 21:01:56 +00001245
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001246install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001247
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001248$(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
Reid Spencer9af3b292004-11-01 07:50:27 +00001249 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001250 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001251
Misha Brukmanef5dc702009-01-08 02:11:55 +00001252uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001253 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
Anton Korobeynikov59a430f2010-08-17 19:03:03 +00001254 -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
Reid Spencera2a31bf2007-02-06 18:53:14 +00001255endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001256endif
1257
Reid Spencer3a561f52004-10-23 20:04:14 +00001258#---------------------------------------------------------
1259# Bytecode Library Targets:
1260# If the user asked for a bytecode library to be built
Misha Brukmanef5dc702009-01-08 02:11:55 +00001261# with the BYTECODE_LIBRARY variable, then we provide
Reid Spencer3a561f52004-10-23 20:04:14 +00001262# targets for building them.
1263#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +00001264ifdef BYTECODE_LIBRARY
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001265ifeq ($(strip $(LLVMCC)),)
1266$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
Reid Spencer9a8398e2005-02-14 21:54:08 +00001267else
Reid Spencer4d71b662004-10-22 21:01:56 +00001268
Reid Spencer9a2f1372004-12-02 09:28:21 +00001269all-local:: $(LibName.BCA)
1270
1271ifdef EXPORTED_SYMBOL_FILE
Daniel Dunbar112257d2010-02-23 09:28:50 +00001272BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
Reid Spencer9a2f1372004-12-02 09:28:21 +00001273
Reid Spencer43eb96c2007-02-09 15:52:07 +00001274$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
Chris Lattner264ccbe2004-12-15 17:14:06 +00001275 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +00001276 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1277 "(internalize)"
Daniel Dunbare5f1b2f2009-08-28 16:14:46 +00001278 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
Reid Spencerefd6bb32004-12-13 03:59:35 +00001279 $(Verb) $(RM) -f $@
Daniel Dunbare5f1b2f2009-08-28 16:14:46 +00001280 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
Reid Spencer4d71b662004-10-22 21:01:56 +00001281else
Reid Spencerf2ac1892004-12-16 07:36:08 +00001282$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
Chris Lattner264ccbe2004-12-15 17:14:06 +00001283 $(LLVMToolDir)/llvm-ar
Reid Spencer9a2f1372004-12-02 09:28:21 +00001284 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
Reid Spencerefd6bb32004-12-13 03:59:35 +00001285 $(Verb) $(RM) -f $@
Reid Spencer9a2f1372004-12-02 09:28:21 +00001286 $(Verb) $(LArchive) $@ $(ObjectsBC)
1287
Reid Spencer4d71b662004-10-22 21:01:56 +00001288endif
1289
Reid Spencer3a561f52004-10-23 20:04:14 +00001290clean-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +00001291ifneq ($(strip $(LibName.BCA)),)
1292 -$(Verb) $(RM) -f $(LibName.BCA)
Reid Spencere5487ba2004-10-24 07:53:21 +00001293endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001294
Reid Spencer8f094f32004-12-13 07:28:21 +00001295ifdef BYTECODE_DESTINATION
1296BytecodeDestDir := $(BYTECODE_DESTINATION)
1297else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001298BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
Reid Spencer8f094f32004-12-13 07:28:21 +00001299endif
1300
Daniel Dunbard62031e2009-05-12 05:35:40 +00001301DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Reid Spencer9a2f1372004-12-02 09:28:21 +00001302
Reid Spencer44cb1b32004-12-03 20:08:48 +00001303install-bytecode-local:: $(DestBytecodeLib)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001304
Reid Spencera2a31bf2007-02-06 18:53:14 +00001305ifdef NO_INSTALL
1306install-local::
1307 $(Echo) Install circumvented with NO_INSTALL
1308uninstall-local::
1309 $(Echo) Uninstall circumvented with NO_INSTALL
1310else
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001311install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +00001312
Mike Stumpb445d742009-02-12 23:45:11 +00001313$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Reid Spencer9a2f1372004-12-02 09:28:21 +00001314 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerb80621f2005-02-24 21:36:32 +00001315 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001316
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001317uninstall-local::
Reid Spencer9a2f1372004-12-02 09:28:21 +00001318 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001319 -$(Verb) $(RM) -f $(DestBytecodeLib)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001320endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001321endif
Reid Spencer9a8398e2005-02-14 21:54:08 +00001322endif
Vikram S. Adve60f56062002-08-02 18:34:12 +00001323
Reid Spencercc2d1e22004-10-30 09:19:36 +00001324#---------------------------------------------------------
Chris Lattner6be92662009-06-16 23:00:42 +00001325# Library Targets:
1326# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1327# building an archive.
Reid Spencercc2d1e22004-10-30 09:19:36 +00001328#---------------------------------------------------------
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001329ifndef NO_BUILD_ARCHIVE
Chris Lattner89938082005-10-24 02:21:45 +00001330ifndef BUILD_ARCHIVE
Chris Lattner6be92662009-06-16 23:00:42 +00001331ifndef LOADABLE_MODULE
1332BUILD_ARCHIVE = 1
Reid Spencera2a31bf2007-02-06 18:53:14 +00001333endif
Chris Lattnere62dbe92002-07-23 17:56:16 +00001334endif
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001335endif
Chris Lattner760da062003-03-14 20:25:22 +00001336
Reid Spencercc2d1e22004-10-30 09:19:36 +00001337#---------------------------------------------------------
1338# Archive Library Targets:
Misha Brukmanef5dc702009-01-08 02:11:55 +00001339# If the user wanted a regular archive library built,
Reid Spencercc2d1e22004-10-30 09:19:36 +00001340# then we provide targets for building them.
1341#---------------------------------------------------------
Chris Lattnere62dbe92002-07-23 17:56:16 +00001342ifdef BUILD_ARCHIVE
Chris Lattnere62dbe92002-07-23 17:56:16 +00001343
Reid Spencercc2d1e22004-10-30 09:19:36 +00001344all-local:: $(LibName.A)
1345
Reid Spencerf2ac1892004-12-16 07:36:08 +00001346$(LibName.A): $(ObjectsO) $(LibDir)/.dir
Reid Spencer9af3b292004-11-01 07:50:27 +00001347 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001348 -$(Verb) $(RM) -f $@
Bill Wendlingdfaf4f92009-01-03 22:46:50 +00001349 $(Verb) $(Archive) $@ $(ObjectsO)
1350 $(Verb) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +00001351
Reid Spencer3a561f52004-10-23 20:04:14 +00001352clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001353ifneq ($(strip $(LibName.A)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001354 -$(Verb) $(RM) -f $(LibName.A)
Chris Lattner00950542001-06-06 20:29:01 +00001355endif
1356
Reid Spencera2a31bf2007-02-06 18:53:14 +00001357ifdef NO_INSTALL
1358install-local::
1359 $(Echo) Install circumvented with NO_INSTALL
1360uninstall-local::
1361 $(Echo) Uninstall circumvented with NO_INSTALL
Daniel Dunbaree40a162010-04-30 22:00:17 +00001362else
1363ifdef NO_INSTALL_ARCHIVES
Daniel Dunbar24d9d972010-04-30 20:04:53 +00001364install-local::
1365 $(Echo) Install circumvented with NO_INSTALL
1366uninstall-local::
1367 $(Echo) Uninstall circumvented with NO_INSTALL
Reid Spencera2a31bf2007-02-06 18:53:14 +00001368else
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001369DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
Reid Spencere5487ba2004-10-24 07:53:21 +00001370
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001371install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001372
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001373$(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
Reid Spencer9af3b292004-11-01 07:50:27 +00001374 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00001375 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001376 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +00001377
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001378uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001379 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001380 -$(Verb) $(RM) -f $(DestArchiveLib)
Reid Spencera2a31bf2007-02-06 18:53:14 +00001381endif
Reid Spencere5487ba2004-10-24 07:53:21 +00001382endif
Daniel Dunbaree40a162010-04-30 22:00:17 +00001383endif
Reid Spencere5487ba2004-10-24 07:53:21 +00001384
1385# endif LIBRARYNAME
Misha Brukmanef5dc702009-01-08 02:11:55 +00001386endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001387
Reid Spencerb1dd3dd2004-10-24 08:21:04 +00001388###############################################################################
1389# Tool Build Rules: Build executable tool based on TOOLNAME option
1390###############################################################################
1391
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001392ifdef TOOLNAME
1393
Reid Spencercc2d1e22004-10-30 09:19:36 +00001394#---------------------------------------------------------
1395# Set up variables for building a tool.
1396#---------------------------------------------------------
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001397TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
Reid Spencer815cbcf2004-11-18 10:03:46 +00001398ifdef EXAMPLE_TOOL
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001399ToolBuildPath := $(ExmplDir)/$(TOOLEXENAME)
Reid Spencer815cbcf2004-11-18 10:03:46 +00001400else
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001401ToolBuildPath := $(ToolDir)/$(TOOLEXENAME)
1402endif
1403
1404# TOOLALIAS is a name to symlink (or copy) the tool to.
1405ifdef TOOLALIAS
1406ifdef EXAMPLE_TOOL
1407ToolAliasBuildPath := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1408else
1409ToolAliasBuildPath := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1410endif
Reid Spencer815cbcf2004-11-18 10:03:46 +00001411endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001412
Reid Spencercc2d1e22004-10-30 09:19:36 +00001413#---------------------------------------------------------
Chris Lattner61863a32009-02-26 17:47:49 +00001414# Prune Exports
1415#---------------------------------------------------------
1416
1417# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1418# not exporting all of the weak symbols from the binary. This reduces dyld
1419# startup time by 4x on darwin in some cases.
1420ifdef TOOL_NO_EXPORTS
Anton Korobeynikove55db742009-08-18 00:40:33 +00001421ifeq ($(HOST_OS),Darwin)
Chris Lattner1b030a12009-03-10 17:15:56 +00001422
1423# Tiger tools don't support this.
1424ifneq ($(DARWIN_MAJVERS),4)
Dan Gohmane05f6092010-04-16 22:58:15 +00001425LD.Flags += -Wl,-exported_symbol,_main
Chris Lattner61863a32009-02-26 17:47:49 +00001426endif
Chris Lattner1b030a12009-03-10 17:15:56 +00001427endif
Chris Lattner61863a32009-02-26 17:47:49 +00001428
Anton Korobeynikove55db742009-08-18 00:40:33 +00001429ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
Bruno Cardoso Lopes6651b3f2010-07-20 08:44:20 +00001430ifneq ($(ARCH), Mips)
Nick Lewycky0d203662009-10-25 03:22:00 +00001431 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner61863a32009-02-26 17:47:49 +00001432endif
1433endif
Bruno Cardoso Lopes6651b3f2010-07-20 08:44:20 +00001434endif
Chris Lattner61863a32009-02-26 17:47:49 +00001435
Devang Patel83be4512010-07-15 20:57:09 +00001436#---------------------------------------------------------
Daniel Dunbarccfaa4b2010-09-16 00:42:32 +00001437# Tool Order File Support
1438#---------------------------------------------------------
1439
1440ifeq ($(HOST_OS),Darwin)
Daniel Dunbarade490a2011-06-28 22:30:17 +00001441ifdef TOOL_ORDER_FILE
Daniel Dunbarccfaa4b2010-09-16 00:42:32 +00001442
1443LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1444
1445endif
1446endif
1447
1448#---------------------------------------------------------
Devang Patel83be4512010-07-15 20:57:09 +00001449# Tool Version Info Support
1450#---------------------------------------------------------
1451
1452ifeq ($(HOST_OS),Darwin)
1453ifdef TOOL_INFO_PLIST
1454
1455LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1456
1457$(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1458
Daniel Dunbar14ceb872010-07-15 21:51:52 +00001459$(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
Devang Patel83be4512010-07-15 20:57:09 +00001460 $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1461 $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1462 -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1463 -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1464 -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1465 $< > $@
1466
1467endif
1468endif
Chris Lattner61863a32009-02-26 17:47:49 +00001469
1470#---------------------------------------------------------
Reid Spencercc2d1e22004-10-30 09:19:36 +00001471# Provide targets for building the tools
1472#---------------------------------------------------------
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001473all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
John Criswell2a6530f2003-06-27 16:58:44 +00001474
Reid Spencer3a561f52004-10-23 20:04:14 +00001475clean-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00001476ifneq ($(strip $(ToolBuildPath)),)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001477 -$(Verb) $(RM) -f $(ToolBuildPath)
Reid Spencere5487ba2004-10-24 07:53:21 +00001478endif
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001479ifneq ($(strip $(ToolAliasBuildPath)),)
1480 -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1481endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001482
Reid Spencer815cbcf2004-11-18 10:03:46 +00001483ifdef EXAMPLE_TOOL
1484$(ToolBuildPath): $(ExmplDir)/.dir
1485else
1486$(ToolBuildPath): $(ToolDir)/.dir
1487endif
1488
Chris Lattnera7868af2006-09-04 06:39:52 +00001489$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
Reid Spencer9af3b292004-11-01 07:50:27 +00001490 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001491 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Reid Spencerab519972006-05-16 06:25:14 +00001492 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
Chris Lattnerd25ad612006-02-14 04:25:54 +00001493 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukmanef5dc702009-01-08 02:11:55 +00001494 $(StripWarnMsg)
Reid Spencere5487ba2004-10-24 07:53:21 +00001495
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001496ifneq ($(strip $(ToolAliasBuildPath)),)
1497$(ToolAliasBuildPath): $(ToolBuildPath)
1498 $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1499 $(Verb) $(RM) -f $(ToolAliasBuildPath)
1500 $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
Dan Gohmanf9d11632010-08-18 01:35:53 +00001501 $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001502 $(StripWarnMsg)
1503endif
1504
Reid Spencera2a31bf2007-02-06 18:53:14 +00001505ifdef NO_INSTALL
1506install-local::
1507 $(Echo) Install circumvented with NO_INSTALL
1508uninstall-local::
1509 $(Echo) Uninstall circumvented with NO_INSTALL
1510else
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001511
1512ifdef INTERNAL_TOOL
1513ToolBinDir = $(DESTDIR)$(PROJ_internal_prefix)/bin
1514else
1515ToolBinDir = $(DESTDIR)$(PROJ_bindir)
1516endif
1517DestTool = $(ToolBinDir)/$(TOOLEXENAME)
Reid Spencere5487ba2004-10-24 07:53:21 +00001518
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001519install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +00001520
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001521$(DestTool): $(ToolBuildPath)
Reid Spencer9af3b292004-11-01 07:50:27 +00001522 $(Echo) Installing $(BuildMode) $(DestTool)
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001523 $(Verb) $(MKDIR) $(ToolBinDir)
Reid Spencer4a0aaea2005-02-24 03:56:32 +00001524 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +00001525
Reid Spencerc6dcc6a2004-10-28 07:57:28 +00001526uninstall-local::
Reid Spencer9af3b292004-11-01 07:50:27 +00001527 $(Echo) Uninstalling $(BuildMode) $(DestTool)
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001528 -$(Verb) $(RM) -f $(DestTool)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001529
1530# TOOLALIAS install.
1531ifdef TOOLALIAS
Bob Wilsonae7e2a42011-11-28 07:59:52 +00001532DestToolAlias = $(ToolBinDir)/$(TOOLALIAS)$(EXEEXT)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001533
1534install-local:: $(DestToolAlias)
1535
Daniel Dunbar8fcd4182010-04-30 20:47:09 +00001536$(DestToolAlias): $(DestTool)
Daniel Dunbarfd96b132009-11-19 00:14:53 +00001537 $(Echo) Installing $(BuildMode) $(DestToolAlias)
1538 $(Verb) $(RM) -f $(DestToolAlias)
1539 $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1540
1541uninstall-local::
1542 $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1543 -$(Verb) $(RM) -f $(DestToolAlias)
1544endif
1545
Reid Spencera2a31bf2007-02-06 18:53:14 +00001546endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001547endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001548
Reid Spencercc2d1e22004-10-30 09:19:36 +00001549###############################################################################
Misha Brukmanef5dc702009-01-08 02:11:55 +00001550# Object Build Rules: Build object files based on sources
Reid Spencercc2d1e22004-10-30 09:19:36 +00001551###############################################################################
1552
Duraid Madina197ab872006-02-15 03:23:26 +00001553# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
Anton Korobeynikove55db742009-08-18 00:40:33 +00001554ifeq ($(HOST_OS),HP-UX)
Duraid Madina197ab872006-02-15 03:23:26 +00001555 DISABLE_AUTO_DEPENDENCIES=1
1556endif
1557
Reid Spencercc2d1e22004-10-30 09:19:36 +00001558# Provide rule sets for when dependency generation is enabled
Reid Spencer4d71b662004-10-22 21:01:56 +00001559ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +00001560
Reid Spencercc2d1e22004-10-30 09:19:36 +00001561#---------------------------------------------------------
Nick Lewyckya15dc032009-02-26 07:44:16 +00001562# Create .o files in the ObjDir directory from the .cpp and .c files...
Reid Spencercc2d1e22004-10-30 09:19:36 +00001563#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00001564
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001565DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewyckya15dc032009-02-26 07:44:16 +00001566 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greif0a4c3782008-02-27 13:34:15 +00001567
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001568# If the build succeeded, move the dependency file over, otherwise
1569# remove it.
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001570DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1571 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1572
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001573$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Jakob Stoklund Olesen52020782009-10-04 17:54:36 +00001574 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001575 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001576 $(DEPEND_MOVEFILE)
Reid Spencer3a561f52004-10-23 20:04:14 +00001577
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001578$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001579 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1580 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1581 $(DEPEND_MOVEFILE)
1582
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001583$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001584 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001585 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001586 $(DEPEND_MOVEFILE)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001587
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001588$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001589 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001590 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattnere43ba3d2007-12-31 23:58:31 +00001591 $(DEPEND_MOVEFILE)
Reid Spencer3a561f52004-10-23 20:04:14 +00001592
Daniel Dunbar9ae4ca62010-09-09 17:38:11 +00001593$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001594 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1595 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1596 $(DEPEND_MOVEFILE)
1597
Reid Spencercc2d1e22004-10-30 09:19:36 +00001598#---------------------------------------------------------
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001599# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
Reid Spencercc2d1e22004-10-30 09:19:36 +00001600#---------------------------------------------------------
Chris Lattner89681112006-01-27 22:13:12 +00001601
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001602BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1603 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1604
1605# If the build succeeded, move the dependency file over, otherwise
1606# remove it.
1607BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1608 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1609
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001610$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencer9af3b292004-11-01 07:50:27 +00001611 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001612 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001613 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001614 $(BC_DEPEND_MOVEFILE)
Reid Spencer4d71b662004-10-22 21:01:56 +00001615
Greg Clayton43bc79a2010-07-13 18:47:09 +00001616$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1617 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1618 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001619 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Greg Clayton43bc79a2010-07-13 18:47:09 +00001620 $(BC_DEPEND_MOVEFILE)
1621
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001622$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001623 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001624 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001625 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001626 $(BC_DEPEND_MOVEFILE)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001627
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001628$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencer9af3b292004-11-01 07:50:27 +00001629 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001630 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001631 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001632 $(BC_DEPEND_MOVEFILE)
Reid Spencer4d71b662004-10-22 21:01:56 +00001633
Greg Clayton43bc79a2010-07-13 18:47:09 +00001634$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1635 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1636 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
Chris Lattner6c299ea2011-04-09 19:56:28 +00001637 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
Greg Clayton43bc79a2010-07-13 18:47:09 +00001638 $(BC_DEPEND_MOVEFILE)
1639
Reid Spencercc2d1e22004-10-30 09:19:36 +00001640# Provide alternate rule sets if dependencies are disabled
Reid Spencer4d71b662004-10-22 21:01:56 +00001641else
1642
Nick Lewyckya15dc032009-02-26 07:44:16 +00001643$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001644 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001645 $(Compile.CXX) $< -o $@
Reid Spencer3a561f52004-10-23 20:04:14 +00001646
Greg Clayton43bc79a2010-07-13 18:47:09 +00001647$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1648 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1649 $(Compile.CXX) $< -o $@
1650
Nick Lewyckya15dc032009-02-26 07:44:16 +00001651$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001652 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001653 $(Compile.CXX) $< -o $@
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001654
Nick Lewyckya15dc032009-02-26 07:44:16 +00001655$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattnerd92490f2006-06-21 20:58:03 +00001656 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001657 $(Compile.C) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +00001658
Greg Clayton43bc79a2010-07-13 18:47:09 +00001659$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1660 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1661 $(Compile.C) $< -o $@
1662
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001663$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Reid Spencer9af3b292004-11-01 07:50:27 +00001664 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001665 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Reid Spencer4d71b662004-10-22 21:01:56 +00001666
Greg Clayton43bc79a2010-07-13 18:47:09 +00001667$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1668 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001669 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001670
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001671$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001672 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001673 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001674
Daniel Dunbar7cfbe252010-02-23 10:28:06 +00001675$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
Reid Spencer9af3b292004-11-01 07:50:27 +00001676 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001677 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Brian Gaeke44909cf2003-12-10 00:26:28 +00001678
Greg Clayton43bc79a2010-07-13 18:47:09 +00001679$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1680 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
Chris Lattner6c299ea2011-04-09 19:56:28 +00001681 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
Greg Clayton43bc79a2010-07-13 18:47:09 +00001682
Chris Lattner1cbc29f2001-09-07 22:57:58 +00001683endif
1684
Chris Lattner8eb12de2006-06-21 21:01:20 +00001685
1686## Rules for building preprocessed (.i/.ii) outputs.
1687$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1688 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1689 $(Verb) $(Preprocess.CXX) $< -o $@
1690
Greg Clayton43bc79a2010-07-13 18:47:09 +00001691$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1692 $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1693 $(Verb) $(Preprocess.CXX) $< -o $@
1694
Chris Lattner8eb12de2006-06-21 21:01:20 +00001695$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1696 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1697 $(Verb) $(Preprocess.CXX) $< -o $@
1698
Reid Spencer44136722006-12-10 04:56:38 +00001699$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Chris Lattner8eb12de2006-06-21 21:01:20 +00001700 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1701 $(Verb) $(Preprocess.C) $< -o $@
1702
Greg Clayton43bc79a2010-07-13 18:47:09 +00001703$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1704 $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1705 $(Verb) $(Preprocess.C) $< -o $@
1706
Chris Lattner8eb12de2006-06-21 21:01:20 +00001707
1708$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1709 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001710 $(Compile.CXX) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001711
Greg Clayton43bc79a2010-07-13 18:47:09 +00001712$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1713 $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1714 $(Compile.CXX) $< -o $@ -S
1715
Chris Lattner8eb12de2006-06-21 21:01:20 +00001716$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1717 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001718 $(Compile.CXX) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001719
1720$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1721 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewyckya15dc032009-02-26 07:44:16 +00001722 $(Compile.C) $< -o $@ -S
Chris Lattner8eb12de2006-06-21 21:01:20 +00001723
Greg Clayton43bc79a2010-07-13 18:47:09 +00001724$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1725 $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1726 $(Compile.C) $< -o $@ -S
1727
Reid Spencer8b2e1412006-11-17 03:32:33 +00001728
Chris Lattner89681112006-01-27 22:13:12 +00001729# make the C and C++ compilers strip debug info out of bytecode libraries.
Reid Spencer8b2e1412006-11-17 03:32:33 +00001730ifdef DEBUG_RUNTIME
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001731$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Reid Spencer8b2e1412006-11-17 03:32:33 +00001732 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001733 $(Verb) $(LOPT) $< -std-compile-opts -o $@
Reid Spencer8b2e1412006-11-17 03:32:33 +00001734else
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001735$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
Chris Lattner89681112006-01-27 22:13:12 +00001736 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
Dan Gohman0e6a4da2009-09-08 15:52:56 +00001737 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
Reid Spencer8b2e1412006-11-17 03:32:33 +00001738endif
1739
Chris Lattner89681112006-01-27 22:13:12 +00001740
Reid Spencercc2d1e22004-10-30 09:19:36 +00001741#---------------------------------------------------------
1742# Provide rule to build .bc files from .ll sources,
1743# regardless of dependencies
1744#---------------------------------------------------------
1745$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
Reid Spencer9af3b292004-11-01 07:50:27 +00001746 $(Echo) "Compiling $*.ll for $(BuildMode) build"
Reid Spencercc2d1e22004-10-30 09:19:36 +00001747 $(Verb) $(LLVMAS) $< -f -o $@
1748
1749###############################################################################
1750# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1751###############################################################################
Chris Lattner481cc7c2003-08-15 02:18:35 +00001752
Reid Spencer4d71b662004-10-22 21:01:56 +00001753ifdef TARGET
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001754TABLEGEN_INC_FILES_COMMON = 1
1755endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001756
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001757ifdef TABLEGEN_INC_FILES_COMMON
1758
Reid Spencercc2d1e22004-10-30 09:19:36 +00001759INCFiles := $(filter %.inc,$(BUILT_SOURCES))
Chris Lattner3c473472004-12-16 17:28:50 +00001760INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1761.PRECIOUS: $(INCTMPFiles) $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001762
Misha Brukmanef5dc702009-01-08 02:11:55 +00001763# INCFiles rule: All of the tblgen generated files are emitted to
Chris Lattner23ee7952004-12-16 17:38:56 +00001764# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1765# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbareb909ca2008-11-03 17:33:36 +00001766# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Chris Lattner23ee7952004-12-16 17:38:56 +00001767# dependencies of the .inc files are, unless the contents of the .inc file
1768# changes.
1769$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
Reid Spencerc3719842004-12-16 18:26:53 +00001770 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
Chris Lattner3c473472004-12-16 17:28:50 +00001771
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001772endif # TABLEGEN_INC_FILES_COMMON
1773
1774ifdef TARGET
1775
1776TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1777 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1778 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1779 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1780 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1781 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1782 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1783
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001784# All .inc.tmp files depend on the .td files.
1785$(INCTMPFiles) : $(TDFiles)
Rafael Espindola075630a2009-03-10 17:58:54 +00001786
Chris Lattner3c473472004-12-16 17:28:50 +00001787$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001788$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001789 $(Echo) "Building $(<F) register info implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001790 $(Verb) $(LLVMTableGen) -gen-register-info -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001791
Chris Lattner3c473472004-12-16 17:28:50 +00001792$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001793$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001794 $(Echo) "Building $(<F) instruction information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001795 $(Verb) $(LLVMTableGen) -gen-instr-info -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001796
Chris Lattner3c473472004-12-16 17:28:50 +00001797$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001798$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001799 $(Echo) "Building $(<F) assembly writer with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001800 $(Verb) $(LLVMTableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001801
Chris Lattner02a4f902004-12-16 17:34:04 +00001802$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001803$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Chris Lattner02a4f902004-12-16 17:34:04 +00001804 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001805 $(Verb) $(LLVMTableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001806
Daniel Dunbarc464e512009-07-13 18:35:35 +00001807$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001808$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Daniel Dunbarc464e512009-07-13 18:35:35 +00001809 $(Echo) "Building $(<F) assembly matcher with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001810 $(Verb) $(LLVMTableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
Daniel Dunbarc464e512009-07-13 18:35:35 +00001811
Jim Grosbachbd29a362010-11-03 23:46:01 +00001812$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001813$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Grosbachbd29a362010-11-03 23:46:01 +00001814 $(Echo) "Building $(<F) MC code emitter with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001815 $(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
Jim Grosbachbd29a362010-11-03 23:46:01 +00001816
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001817$(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001818$(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001819 $(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001820 $(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
Jim Grosbach86f9adb2011-07-08 17:36:35 +00001821
Chris Lattner3c473472004-12-16 17:28:50 +00001822$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001823$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Reid Spencercc2d1e22004-10-30 09:19:36 +00001824 $(Echo) "Building $(<F) code emitter with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001825 $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Reid Spencer4d71b662004-10-22 21:01:56 +00001826
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001827$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001828$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001829 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001830 $(Verb) $(LLVMTableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001831
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001832$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001833$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001834 $(Echo) "Building $(<F) disassembly tables with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001835 $(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
Daniel Dunbarf87ea4d2009-11-25 04:46:58 +00001836
Sean Callanan95fcebd2010-01-29 00:21:04 +00001837$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001838$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Sean Callanan95fcebd2010-01-29 00:21:04 +00001839 $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001840 $(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
Sean Callanan95fcebd2010-01-29 00:21:04 +00001841
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001842$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001843$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001844 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001845 $(Verb) $(LLVMTableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001846
Evan Cheng385e9302011-07-01 22:36:09 +00001847$(TARGET:%=$(ObjDir)/%GenSubtargetInfo.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001848$(ObjDir)/%GenSubtargetInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +00001849 $(Echo) "Building $(<F) subtarget information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001850 $(Verb) $(LLVMTableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Chris Lattnerf31f09e2005-09-03 01:15:25 +00001851
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001852$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001853$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001854 $(Echo) "Building $(<F) calling convention information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001855 $(Verb) $(LLVMTableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Chris Lattnerbcc3c192007-02-27 20:44:12 +00001856
Dale Johannesen49de9822009-02-05 01:49:45 +00001857$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001858$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Jakob Stoklund Olesen7b68ffc2009-10-15 18:48:47 +00001859 $(Echo) "Building $(<F) intrinsics information with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001860 $(Verb) $(LLVMTableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
Dale Johannesen49de9822009-02-05 01:49:45 +00001861
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001862$(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir $(LLVM_TBLGEN)
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001863 $(Echo) "Building $(<F) decoder tables with tblgen"
Peter Collingbournede8f33c2011-10-06 01:51:51 +00001864 $(Verb) $(LLVMTableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001865
Anshuman Dasguptadc81e5d2011-12-01 21:10:21 +00001866$(ObjDir)/%GenDFAPacketizer.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1867 $(Echo) "Building $(<F) DFA packetizer tables with tblgen"
1868 $(Verb) $(LLVMTableGen) -gen-dfa-packetizer -o $(call SYSPATH, $@) $<
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001869
Reid Spencer3a561f52004-10-23 20:04:14 +00001870clean-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001871 -$(Verb) $(RM) -f $(INCFiles)
Reid Spencer4d71b662004-10-22 21:01:56 +00001872
Mikhail Glushenkov1386ae42009-03-02 09:42:59 +00001873endif # TARGET
1874
Reid Spencercc2d1e22004-10-30 09:19:36 +00001875###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001876# OTHER RULES: Other rules needed
1877###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001878
Chris Lattner30440c62003-01-16 21:06:18 +00001879# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +00001880ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +00001881%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +00001882 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +00001883else
1884%.ps: %.dot
Reid Spencercc2d1e22004-10-30 09:19:36 +00001885 $(Echo) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +00001886endif
Chris Lattner30440c62003-01-16 21:06:18 +00001887
John Criswell7f336952003-09-06 14:44:17 +00001888# This rules ensures that header files that are removed still have a rule for
1889# which they can be "generated." This allows make to ignore them and
1890# reproduce the dependency lists.
John Criswell4b6e5d12003-09-18 18:37:08 +00001891%.h:: ;
Chris Lattnerb05a76c2005-02-04 21:28:50 +00001892%.hpp:: ;
John Criswell7f336952003-09-06 14:44:17 +00001893
Reid Spencercc2d1e22004-10-30 09:19:36 +00001894# Define clean-local to clean the current directory. Note that this uses a
Misha Brukmanef5dc702009-01-08 02:11:55 +00001895# very conservative approach ensuring that empty variables do not cause
Reid Spencercc2d1e22004-10-30 09:19:36 +00001896# errors or disastrous removal.
Reid Spencer3a561f52004-10-23 20:04:14 +00001897clean-local::
Jim Grosbach673612e2008-10-02 22:56:44 +00001898ifneq ($(strip $(ObjRootDir)),)
1899 -$(Verb) $(RM) -rf $(ObjRootDir)
Reid Spencere5487ba2004-10-24 07:53:21 +00001900endif
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001901ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001902 -$(Verb) $(RM) -f *$(SHLIBEXT)
Brian Gaeke9d3cd402004-01-21 19:53:11 +00001903endif
John Criswell7a73b802003-06-30 21:59:07 +00001904
Reid Spencer3d659492004-11-02 16:36:03 +00001905clean-all-local::
Reid Spencerca5fe8f2004-11-02 16:56:15 +00001906 -$(Verb) $(RM) -rf Debug Release Profile
Reid Spencer3d659492004-11-02 16:36:03 +00001907
Reid Spencer12d79512004-11-12 02:27:36 +00001908
Reid Spencer3a561f52004-10-23 20:04:14 +00001909###############################################################################
1910# DEPENDENCIES: Include the dependency files if we should
1911###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +00001912ifndef DISABLE_AUTO_DEPENDENCIES
1913
Reid Spencer3a561f52004-10-23 20:04:14 +00001914# If its not one of the cleaning targets
Daniel Dunbar94e98af2008-10-03 19:11:19 +00001915ifndef IS_CLEANING_TARGET
Reid Spencer4d71b662004-10-22 21:01:56 +00001916
Reid Spencer3a561f52004-10-23 20:04:14 +00001917# Get the list of dependency files
Greg Clayton43bc79a2010-07-13 18:47:09 +00001918DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
Daniel Dunbarfab3d682009-05-12 06:35:50 +00001919DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1920
1921# Include bitcode dependency files if using bitcode libraries
1922ifdef BYTECODE_LIBRARY
1923DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1924endif
Misha Brukman4f7a8cf2003-11-09 21:36:19 +00001925
Reid Spencer491a6cd2007-07-23 08:20:46 +00001926-include $(DependFiles) ""
Reid Spencer3a561f52004-10-23 20:04:14 +00001927
John Criswelld741bcf2003-08-12 18:51:51 +00001928endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +00001929
Misha Brukmanef5dc702009-01-08 02:11:55 +00001930endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001931
Reid Spencer151f8ba2004-10-25 08:27:37 +00001932###############################################################################
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001933# CHECK: Running the test suite
1934###############################################################################
1935
Bill Wendling29c0e3d2009-04-09 18:26:57 +00001936check::
Reid Spencer11fde542005-01-16 02:20:54 +00001937 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1938 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001939 $(EchoCmd) Running test suite ; \
Reid Spencer11fde542005-01-16 02:20:54 +00001940 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001941 TESTSUITE=$(TESTSUITE) ; \
1942 else \
1943 $(EchoCmd) No Makefile in test directory ; \
1944 fi ; \
1945 else \
1946 $(EchoCmd) No test directory ; \
1947 fi
1948
Daniel Dunbar666b4022010-08-02 00:05:18 +00001949check-lit:: check
1950
1951check-dg::
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001952 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1953 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1954 $(EchoCmd) Running test suite ; \
Daniel Dunbar666b4022010-08-02 00:05:18 +00001955 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001956 else \
1957 $(EchoCmd) No Makefile in test directory ; \
1958 fi ; \
1959 else \
1960 $(EchoCmd) No test directory ; \
1961 fi
1962
Daniel Dunbar34185792009-09-20 06:17:21 +00001963check-all::
1964 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1965 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1966 $(EchoCmd) Running test suite ; \
1967 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1968 else \
1969 $(EchoCmd) No Makefile in test directory ; \
1970 fi ; \
1971 else \
1972 $(EchoCmd) No test directory ; \
1973 fi
1974
Reid Spencer9e8d54a2004-12-06 05:35:13 +00001975###############################################################################
Bill Wendling4113bd12009-01-04 23:12:21 +00001976# UNITTESTS: Running the unittests test suite
1977###############################################################################
1978
Bill Wendling29c0e3d2009-04-09 18:26:57 +00001979unittests::
Bill Wendling4113bd12009-01-04 23:12:21 +00001980 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1981 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1982 $(EchoCmd) Running unittests test suite ; \
Daniel Dunbar7f068f42009-09-13 22:39:27 +00001983 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
Bill Wendling4113bd12009-01-04 23:12:21 +00001984 else \
1985 $(EchoCmd) No Makefile in unittests directory ; \
1986 fi ; \
1987 else \
1988 $(EchoCmd) No unittests directory ; \
1989 fi
1990
1991###############################################################################
Reid Spencercc2d1e22004-10-30 09:19:36 +00001992# DISTRIBUTION: Handle construction of a distribution tarball
Reid Spencer151f8ba2004-10-25 08:27:37 +00001993###############################################################################
1994
Reid Spencere45ebfa2004-10-26 07:09:33 +00001995#------------------------------------------------------------------------
1996# Define distribution related variables
1997#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00001998DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1999DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
2000TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
2001DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
2002DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
2003DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
Reid Spencer151f8ba2004-10-25 08:27:37 +00002004DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
2005 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002006 Makefile.config.in configure autoconf
2007DistOther := $(notdir $(wildcard \
Reid Spencer11fde542005-01-16 02:20:54 +00002008 $(PROJ_SRC_DIR)/*.h \
2009 $(PROJ_SRC_DIR)/*.td \
2010 $(PROJ_SRC_DIR)/*.def \
2011 $(PROJ_SRC_DIR)/*.ll \
2012 $(PROJ_SRC_DIR)/*.in))
Reid Spencercc2d1e22004-10-30 09:19:36 +00002013DistSubDirs := $(SubDirs)
Reid Spencerfbbf3072004-11-29 05:00:33 +00002014DistSources = $(Sources) $(EXTRA_DIST)
2015DistFiles = $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +00002016
Reid Spencere45ebfa2004-10-26 07:09:33 +00002017#------------------------------------------------------------------------
2018# We MUST build distribution with OBJ_DIR != SRC_DIR
2019#------------------------------------------------------------------------
Reid Spencer11fde542005-01-16 02:20:54 +00002020ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
Reid Spencere45ebfa2004-10-26 07:09:33 +00002021dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002022 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
Reid Spencere45ebfa2004-10-26 07:09:33 +00002023
Reid Spencere45ebfa2004-10-26 07:09:33 +00002024else
2025
Reid Spencere45ebfa2004-10-26 07:09:33 +00002026#------------------------------------------------------------------------
Reid Spencere45ebfa2004-10-26 07:09:33 +00002027# Prevent attempt to run dist targets from anywhere but the top level
2028#------------------------------------------------------------------------
2029ifneq ($(LEVEL),.)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002030dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
Reid Spencer11fde542005-01-16 02:20:54 +00002031 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002032else
2033
2034#------------------------------------------------------------------------
2035# Provide the top level targets
2036#------------------------------------------------------------------------
2037
Reid Spencercc2d1e22004-10-30 09:19:36 +00002038dist-gzip:: $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002039
Reid Spencer345235ca2004-12-04 22:34:09 +00002040$(DistTarGZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002041 $(Echo) Packing gzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00002042 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00002043 $(GZIP) -c > "$(DistTarGZip)"
Reid Spencere45ebfa2004-10-26 07:09:33 +00002044
Reid Spencercc2d1e22004-10-30 09:19:36 +00002045dist-bzip2:: $(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002046
Reid Spencer345235ca2004-12-04 22:34:09 +00002047$(DistTarBZ2) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002048 $(Echo) Packing bzipped distribution tar file.
Reid Spencer11fde542005-01-16 02:20:54 +00002049 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
Reid Spencerfbbf3072004-11-29 05:00:33 +00002050 $(BZIP2) -c >$(DistTarBZ2)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002051
Reid Spencercc2d1e22004-10-30 09:19:36 +00002052dist-zip:: $(DistZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002053
Reid Spencer345235ca2004-12-04 22:34:09 +00002054$(DistZip) : $(TopDistDir)/.makedistdir
Reid Spencercc2d1e22004-10-30 09:19:36 +00002055 $(Echo) Packing zipped distribution file.
2056 $(Verb) rm -f $(DistZip)
Reid Spencer11fde542005-01-16 02:20:54 +00002057 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002058
Misha Brukmanef5dc702009-01-08 02:11:55 +00002059dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Chris Lattner7a2bdde2011-04-15 05:18:47 +00002060 $(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00002061
Reid Spencerf8f57402005-01-28 19:52:32 +00002062DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
Reid Spencere45ebfa2004-10-26 07:09:33 +00002063
Reid Spencer345235ca2004-12-04 22:34:09 +00002064dist-check:: $(DistTarGZip)
Reid Spencercc2d1e22004-10-30 09:19:36 +00002065 $(Echo) Checking distribution tar file.
2066 $(Verb) if test -d $(DistCheckDir) ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002067 $(RM) -rf $(DistCheckDir) ; \
2068 fi
Reid Spencercc2d1e22004-10-30 09:19:36 +00002069 $(Verb) $(MKDIR) $(DistCheckDir)
2070 $(Verb) cd $(DistCheckDir) && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002071 $(MKDIR) $(DistCheckDir)/build && \
2072 $(MKDIR) $(DistCheckDir)/install && \
2073 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
2074 cd build && \
2075 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
Reid Spencer45eeed92005-05-24 02:33:20 +00002076 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
Reid Spencer345235ca2004-12-04 22:34:09 +00002077 $(MAKE) all && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002078 $(MAKE) check && \
Bill Wendling4113bd12009-01-04 23:12:21 +00002079 $(MAKE) unittests && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002080 $(MAKE) install && \
2081 $(MAKE) uninstall && \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002082 $(MAKE) dist-clean && \
Reid Spencercc2d1e22004-10-30 09:19:36 +00002083 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
Reid Spencere45ebfa2004-10-26 07:09:33 +00002084
2085dist-clean::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002086 $(Echo) Cleaning distribution files
Reid Spencer345235ca2004-12-04 22:34:09 +00002087 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2088 $(DistCheckDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +00002089
2090endif
2091
2092#------------------------------------------------------------------------
2093# Provide the recursive distdir target for building the distribution directory
2094#------------------------------------------------------------------------
Reid Spencer345235ca2004-12-04 22:34:09 +00002095distdir: $(DistDir)/.makedistdir
2096$(DistDir)/.makedistdir: $(DistSources)
Reid Spencercc2d1e22004-10-30 09:19:36 +00002097 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002098 if test -d "$(DistDir)" ; then \
2099 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
2100 exit 1 ; \
2101 fi ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002102 $(EchoCmd) Removing old $(DistDir) ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002103 $(RM) -rf $(DistDir); \
Reid Spencer9e8d54a2004-12-06 05:35:13 +00002104 $(EchoCmd) Making 'all' to verify build ; \
Reid Spencer854071c2006-04-10 16:46:04 +00002105 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002106 fi
Reid Spencerfbbf3072004-11-29 05:00:33 +00002107 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukmanef5dc702009-01-08 02:11:55 +00002108 $(Verb) $(MKDIR) $(DistDir)
Reid Spencer11fde542005-01-16 02:20:54 +00002109 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2110 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002111 for file in $(DistFiles) ; do \
2112 case "$$file" in \
Reid Spencer11fde542005-01-16 02:20:54 +00002113 $(PROJ_SRC_DIR)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00002114 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2115 ;; \
Reid Spencer11fde542005-01-16 02:20:54 +00002116 $(PROJ_SRC_ROOT)/*) \
Reid Spencer345235ca2004-12-04 22:34:09 +00002117 file=`echo "$$file" | \
2118 sed "s#^$$srcrootstrip/##"` \
2119 ;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002120 esac; \
Reid Spencer11fde542005-01-16 02:20:54 +00002121 if test -f "$(PROJ_SRC_DIR)/$$file" || \
2122 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2123 from_dir="$(PROJ_SRC_DIR)" ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002124 elif test -f "$$file" || test -d "$$file" ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002125 from_dir=. ; \
Reid Spencer345235ca2004-12-04 22:34:09 +00002126 fi ; \
2127 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002128 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2129 to_dir="$(DistDir)/$$dir"; \
2130 $(MKDIR) "$$to_dir" ; \
2131 else \
2132 to_dir="$(DistDir)"; \
2133 fi; \
2134 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2135 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002136 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002137 fi ; \
2138 if test -d "$$from_dir/$$file"; then \
Reid Spencer11fde542005-01-16 02:20:54 +00002139 if test -d "$(PROJ_SRC_DIR)/$$file" && \
2140 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
Reid Spencer45eeed92005-05-24 02:33:20 +00002141 cd $(PROJ_SRC_DIR) ; \
2142 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2143 ( cd $$to_dir ; $(TAR) xf - ) ; \
2144 cd $(PROJ_OBJ_DIR) ; \
2145 else \
2146 cd $$from_dir ; \
2147 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2148 ( cd $$to_dir ; $(TAR) xf - ) ; \
2149 cd $(PROJ_OBJ_DIR) ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002150 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002151 elif test -f "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00002152 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002153 elif test -L "$$from_dir/$$file" ; then \
Reid Spencerc3719842004-12-16 18:26:53 +00002154 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002155 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
Reid Spencer345235ca2004-12-04 22:34:09 +00002156 $(EchoCmd) "===== WARNING: Distribution Source " \
2157 "$$from_dir/$$file Not Found!" ; \
Reid Spencercc2d1e22004-10-30 09:19:36 +00002158 elif test "$(Verb)" != '@' ; then \
2159 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002160 fi; \
2161 done
Reid Spencercc2d1e22004-10-30 09:19:36 +00002162 $(Verb) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002163 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002164 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00002165 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
Reid Spencer854071c2006-04-10 16:46:04 +00002166 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
Reid Spencerbac3ca22006-04-07 16:06:18 +00002167 DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00002168 fi; \
2169 done
Reid Spencer345235ca2004-12-04 22:34:09 +00002170 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
Reid Spencer45eeed92005-05-24 02:33:20 +00002171 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
Chris Lattner77efe272006-02-14 04:27:15 +00002172 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2173 -name .svn \) -print` ;\
Reid Spencer345235ca2004-12-04 22:34:09 +00002174 $(MAKE) dist-hook ; \
2175 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2176 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2177 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2178 -o ! -type d ! -perm -444 -exec \
2179 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2180 || chmod -R a+r $(DistDir) ; \
2181 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +00002182
Reid Spencercc2d1e22004-10-30 09:19:36 +00002183# This is invoked by distdir target, define it as a no-op to avoid errors if not
2184# defined by user.
Reid Spencer151f8ba2004-10-25 08:27:37 +00002185dist-hook::
2186
Reid Spencere53e3972004-10-22 23:06:30 +00002187endif
Reid Spencer4d71b662004-10-22 21:01:56 +00002188
2189###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00002190# TOP LEVEL - targets only to apply at the top level directory
2191###############################################################################
2192
2193ifeq ($(LEVEL),.)
2194
2195#------------------------------------------------------------------------
Reid Spencer9e8d54a2004-12-06 05:35:13 +00002196# Install support for the project's include files:
Reid Spencere5487ba2004-10-24 07:53:21 +00002197#------------------------------------------------------------------------
Reid Spencera2a31bf2007-02-06 18:53:14 +00002198ifdef NO_INSTALL
2199install-local::
2200 $(Echo) Install circumvented with NO_INSTALL
2201uninstall-local::
2202 $(Echo) Uninstall circumvented with NO_INSTALL
2203else
Reid Spencere5487ba2004-10-24 07:53:21 +00002204install-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002205 $(Echo) Installing include files
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002206 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002207 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
Reid Spencer11fde542005-01-16 02:20:54 +00002208 cd $(PROJ_SRC_ROOT)/include && \
NAKAMURA Takumi6716b8e2011-03-09 09:11:27 +00002209 for hdr in `find . -type f \
2210 '(' -name LICENSE.TXT \
2211 -o -name '*.def' \
2212 -o -name '*.h' \
2213 -o -name '*.inc' \
2214 -o -name '*.td' \
2215 ')' -print | grep -v CVS | \
Reid Spencer0522d8b2007-04-09 19:08:58 +00002216 grep -v .svn` ; do \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002217 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002218 if test \! -d "$$instdir" ; then \
2219 $(EchoCmd) Making install directory $$instdir ; \
2220 $(MKDIR) $$instdir ;\
2221 fi ; \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002222 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer2edabc02005-02-16 15:54:03 +00002223 done ; \
Reid Spencere5487ba2004-10-24 07:53:21 +00002224 fi
Reid Spencer443045a2005-12-23 22:27:56 +00002225ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
Reid Spencer4a0aaea2005-02-24 03:56:32 +00002226 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
Reid Spencer2edabc02005-02-16 15:54:03 +00002227 cd $(PROJ_OBJ_ROOT)/include && \
NAKAMURA Takumi6716b8e2011-03-09 09:11:27 +00002228 for hdr in `find . -type f \
2229 '(' -name LICENSE.TXT \
2230 -o -name '*.def' \
2231 -o -name '*.h' \
2232 -o -name '*.inc' \
2233 -o -name '*.td' \
2234 ')' -print | grep -v CVS | \
2235 grep -v .svn` ; do \
2236 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2237 if test \! -d "$$instdir" ; then \
2238 $(EchoCmd) Making install directory $$instdir ; \
2239 $(MKDIR) $$instdir ;\
2240 fi ; \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002241 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
Reid Spencer2edabc02005-02-16 15:54:03 +00002242 done ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002243 fi
Reid Spencer443045a2005-12-23 22:27:56 +00002244endif
Reid Spencere5487ba2004-10-24 07:53:21 +00002245
2246uninstall-local::
Reid Spencercc2d1e22004-10-30 09:19:36 +00002247 $(Echo) Uninstalling include files
Reid Spencer11fde542005-01-16 02:20:54 +00002248 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2249 cd $(PROJ_SRC_ROOT)/include && \
Reid Spencere5487ba2004-10-24 07:53:21 +00002250 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattnerc9480642009-01-02 07:16:45 +00002251 '!' '(' -name '*~' -o -name '.#*' \
Chris Lattnerd25ad612006-02-14 04:25:54 +00002252 -o -name '*.in' ')' -print ')' | \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002253 grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002254 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnerd25ad612006-02-14 04:25:54 +00002255 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
Erick Tryzelaard4076cf2010-03-04 20:56:19 +00002256 -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
Chris Lattnerca94fa22005-02-09 02:24:00 +00002257 fi
Reid Spencera2a31bf2007-02-06 18:53:14 +00002258endif
Reid Spencere5487ba2004-10-24 07:53:21 +00002259endif
2260
Chris Lattner03840ac2007-04-14 23:35:45 +00002261check-line-length:
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002262 @echo searching for overlength lines in files: $(Sources)
2263 @echo
2264 @echo
Gabor Greif5039a6f2008-08-28 22:32:39 +00002265 egrep -n '.{81}' $(Sources) /dev/null
Chris Lattner03840ac2007-04-14 23:35:45 +00002266
Anton Korobeynikovbed29462007-04-16 18:10:23 +00002267check-for-tabs:
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002268 @echo searching for tabs in files: $(Sources)
2269 @echo
2270 @echo
Gabor Greif5039a6f2008-08-28 22:32:39 +00002271 egrep -n ' ' $(Sources) /dev/null
Gabor Greifb1dbcd82008-05-15 10:04:30 +00002272
Reid Spencer6548bf12007-05-02 21:29:39 +00002273check-footprint:
2274 @ls -l $(LibDir) | awk '\
2275 BEGIN { sum = 0; } \
2276 { sum += $$5; } \
2277 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2278 @ls -l $(ToolDir) | awk '\
2279 BEGIN { sum = 0; } \
2280 { sum += $$5; } \
2281 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
Reid Spencer4d71b662004-10-22 21:01:56 +00002282#------------------------------------------------------------------------
2283# Print out the directories used for building
Reid Spencercc2d1e22004-10-30 09:19:36 +00002284#------------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +00002285printvars::
Reid Spencer11fde542005-01-16 02:20:54 +00002286 $(Echo) "BuildMode : " '$(BuildMode)'
2287 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2288 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2289 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2290 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2291 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2292 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2293 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
Bob Wilsonae7e2a42011-11-28 07:59:52 +00002294 $(Echo) "PROJ_internal_prefix : " '$(PROJ_internal_prefix)'
Reid Spencer11fde542005-01-16 02:20:54 +00002295 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
2296 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
2297 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
Reid Spencer1a9a69c2005-02-16 16:13:02 +00002298 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
Reid Spencer11fde542005-01-16 02:20:54 +00002299 $(Echo) "UserTargets : " '$(UserTargets)'
2300 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2301 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2302 $(Echo) "ObjDir : " '$(ObjDir)'
2303 $(Echo) "LibDir : " '$(LibDir)'
2304 $(Echo) "ToolDir : " '$(ToolDir)'
2305 $(Echo) "ExmplDir : " '$(ExmplDir)'
2306 $(Echo) "Sources : " '$(Sources)'
2307 $(Echo) "TDFiles : " '$(TDFiles)'
2308 $(Echo) "INCFiles : " '$(INCFiles)'
2309 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
Reid Spencere0acb762005-03-01 16:27:06 +00002310 $(Echo) "PreConditions: " '$(PreConditions)'
Reid Spencer11fde542005-01-16 02:20:54 +00002311 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
2312 $(Echo) "Compile.C : " '$(Compile.C)'
2313 $(Echo) "Archive : " '$(Archive)'
2314 $(Echo) "YaccFiles : " '$(YaccFiles)'
2315 $(Echo) "LexFiles : " '$(LexFiles)'
2316 $(Echo) "Module : " '$(Module)'
Reid Spencer755bcf02005-08-24 10:43:10 +00002317 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
Reid Spencerf9f431c2006-04-09 23:41:14 +00002318 $(Echo) "SubDirs : " '$(SubDirs)'
Reid Spencer8475ec02007-03-29 19:05:44 +00002319 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2320 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar92acef02009-02-21 20:42:39 +00002321
2322###
2323# Debugging
2324
Daniel Dunbar3c898122009-03-06 22:23:25 +00002325# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar92acef02009-02-21 20:42:39 +00002326# definition, value and origin of XXX.
Daniel Dunbar3c898122009-03-06 22:23:25 +00002327make-print-%:
Daniel Dunbar92acef02009-02-21 20:42:39 +00002328 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))