blob: 6fe68681b1e8d4c1aee840965842a60c29065252 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
3# The LLVM Compiler Infrastructure
4#
Chris Lattner3876aa72007-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 Brukman89fe5162009-01-08 02:11:55 +00007#
Dan Gohmanf17a25c2007-07-18 16:29:46 +00008#===------------------------------------------------------------------------===#
9#
10# 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.
12#
13#===-----------------------------------------------------------------------====#
14
15################################################################################
16# TARGETS: Define standard targets that can be invoked
17################################################################################
18
19#--------------------------------------------------------------------
20# Define the various target sets
21#--------------------------------------------------------------------
22RecursiveTargets := all clean clean-all install uninstall install-bytecode
23LocalTargets := all-local clean-local clean-all-local check-local \
24 install-local printvars uninstall-local \
Bill Wendling2e3646a2009-01-04 23:12:21 +000025 install-bytecode-local unittests
Chris Lattner42596062007-09-26 06:10:47 +000026TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
Bill Wendling2e3646a2009-01-04 23:12:21 +000027 dist-zip unittests
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29InternalTargets := preconditions distdir dist-hook
30
31################################################################################
32# INITIALIZATION: Basic things the makefile needs
33################################################################################
34
35#--------------------------------------------------------------------
36# Set the VPATH so that we can find source files.
37#--------------------------------------------------------------------
38VPATH=$(PROJ_SRC_DIR)
39
40#--------------------------------------------------------------------
41# Reset the list of suffixes we know how to build.
42#--------------------------------------------------------------------
43.SUFFIXES:
Nick Lewycky8d91e192009-02-26 07:44:16 +000044.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46
47#--------------------------------------------------------------------
48# Mark all of these targets as phony to avoid implicit rule search
49#--------------------------------------------------------------------
50.PHONY: $(UserTargets) $(InternalTargets)
51
52#--------------------------------------------------------------------
Misha Brukman89fe5162009-01-08 02:11:55 +000053# Make sure all the user-target rules are double colon rules and
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054# they are defined first.
55#--------------------------------------------------------------------
56
57$(UserTargets)::
58
59################################################################################
60# PRECONDITIONS: that which must be built/checked first
61################################################################################
62
63SrcMakefiles := $(filter %Makefile %Makefile.tests,\
64 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66ConfigureScript := $(PROJ_SRC_ROOT)/configure
67ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
71MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
72PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
73ifneq ($(MakefileCommonIn),)
74PreConditions += $(MakefileCommon)
75endif
76
77ifneq ($(MakefileConfigIn),)
78PreConditions += $(MakefileConfig)
79endif
80
81preconditions: $(PreConditions)
82
83#------------------------------------------------------------------------
84# Make sure the BUILT_SOURCES are built first
85#------------------------------------------------------------------------
86$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
87
88clean-all-local::
89ifneq ($(strip $(BUILT_SOURCES)),)
90 -$(Verb) $(RM) -f $(BUILT_SOURCES)
91endif
92
93ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94spotless:
95 $(Verb) if test -x config.status ; then \
96 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
97 $(MKDIR) .spotless.save ; \
98 $(MV) config.status .spotless.save ; \
99 $(MV) mklib .spotless.save ; \
100 $(MV) projects .spotless.save ; \
101 $(RM) -rf * ; \
102 $(MV) .spotless.save/config.status . ; \
103 $(MV) .spotless.save/mklib . ; \
104 $(MV) .spotless.save/projects . ; \
105 $(RM) -rf .spotless.save ; \
106 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
107 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108 $(ConfigStatusScript) ; \
109 else \
110 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
111 fi
112else
113spotless:
114 $(EchoCmd) "spotless target not supported for objdir == srcdir"
115endif
116
117$(BUILT_SOURCES) : $(ObjMakefiles)
118
119#------------------------------------------------------------------------
120# Make sure we're not using a stale configuration
121#------------------------------------------------------------------------
122reconfigure:
123 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124 $(Verb) cd $(PROJ_OBJ_ROOT) && \
125 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127 fi ; \
128 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129 $(ConfigStatusScript)
130
131.PRECIOUS: $(ConfigStatusScript)
132$(ConfigStatusScript): $(ConfigureScript)
133 $(Echo) Reconfiguring with $<
134 $(Verb) cd $(PROJ_OBJ_ROOT) && \
135 if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
136 $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137 fi ; \
138 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
139 $(ConfigStatusScript)
140
141#------------------------------------------------------------------------
142# Make sure the configuration makefile is up to date
143#------------------------------------------------------------------------
144ifneq ($(MakefileConfigIn),)
145$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
146 $(Echo) Regenerating $@
147 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
148endif
149
150ifneq ($(MakefileCommonIn),)
151$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
152 $(Echo) Regenerating $@
153 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
154endif
155
156#------------------------------------------------------------------------
157# If the Makefile in the source tree has been updated, copy it over into the
158# build tree. But, only do this if the source and object makefiles differ
159#------------------------------------------------------------------------
160ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161
Gordon Henriksen4290f662008-03-10 15:58:40 +0000162Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 $(Echo) "Updating Makefile"
164 $(Verb) $(MKDIR) $(@D)
165 $(Verb) $(CP) -f $< $@
166
167# Copy the Makefile.* files unless we're in the root directory which avoids
168# the copying of Makefile.config.in or other things that should be explicitly
169# taken care of.
170$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171 @case '$?' in \
172 *Makefile.rules) ;; \
173 *.in) ;; \
Gordon Henriksen4290f662008-03-10 15:58:40 +0000174 *) $(EchoCmd) "Updating $(@F)" ; \
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175 $(MKDIR) $(@D) ; \
176 $(CP) -f $< $@ ;; \
177 esac
Gabor Greif14c4c8e2008-02-27 13:34:15 +0000178
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179endif
180
181#------------------------------------------------------------------------
182# Set up the basic dependencies
183#------------------------------------------------------------------------
184$(UserTargets):: $(PreConditions)
185
186all:: all-local
Anton Korobeynikov06565172008-11-10 07:33:13 +0000187clean:: clean-local
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188clean-all:: clean-local clean-all-local
189install:: install-local
190uninstall:: uninstall-local
Misha Brukman89fe5162009-01-08 02:11:55 +0000191install-local:: all-local
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192install-bytecode:: install-bytecode-local
193
194###############################################################################
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000195# LLVMC: Provide rules for compiling llvmc plugins
196###############################################################################
197
198ifdef LLVMC_PLUGIN
199
200LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
Mikhail Glushenkovd500a272009-06-23 20:46:48 +0000201CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000202REQUIRES_EH := 1
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000203
204ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
205 LD.Flags += -lCompilerDriver
206endif
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000207
208# Build a dynamic library if the user runs `make` directly from the plugin
209# directory.
210ifndef LLVMC_BUILTIN_PLUGIN
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000211 LOADABLE_MODULE = 1
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000212endif
213
214# TableGen stuff...
215ifneq ($(BUILT_SOURCES),)
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000216 LLVMC_BUILD_AUTOGENERATED_INC=1
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000217endif
218
219endif # LLVMC_PLUGIN
220
Mikhail Glushenkovbe76ef22009-06-25 01:07:00 +0000221ifdef LLVMC_BASED_DRIVER
222
223TOOLNAME = $(LLVMC_BASED_DRIVER)
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000224
Mikhail Glushenkovbe76ef22009-06-25 01:07:00 +0000225REQUIRES_EH := 1
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000226
227ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
228 LD.Flags += -lCompilerDriver
229else
230 LLVMLIBS = CompilerDriver.a
231 LINK_COMPONENTS = support system
232endif
Mikhail Glushenkovbe76ef22009-06-25 01:07:00 +0000233
234# Preprocessor magic that generates references to static variables in built-in
235# plugins.
236ifneq ($(LLVMC_BUILTIN_PLUGINS),)
237
238USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
239
240LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
241LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
242LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
243LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
244LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
245
246ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
247CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
248endif
249
250ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
251CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
252endif
253
254ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
255CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
256endif
257
258ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
259CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
260endif
261
262ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
263CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
264endif
265
266endif
267
268endif # LLVMC_BASED_DRIVER
269
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000270###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271# VARIABLES: Set up various variables based on configuration data
272###############################################################################
273
Daniel Dunbara89194e2008-10-03 19:11:19 +0000274# Variable for if this make is for a "cleaning" target
275ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
276 IS_CLEANING_TARGET=1
277endif
278
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279#--------------------------------------------------------------------
280# Variables derived from configuration we are building
281#--------------------------------------------------------------------
282
283CPP.Defines :=
284# OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
285# this can be overridden on the make command line.
Evan Cheng107dae12009-04-20 22:16:40 +0000286ifndef OPTIMIZE_OPTION
287 ifneq ($(OS),MingW)
288 OPTIMIZE_OPTION := -O3
289 else
290 OPTIMIZE_OPTION := -O2
291 endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292endif
293
David Greene8cd590c2009-04-17 14:49:22 +0000294ifeq ($(ENABLE_OPTIMIZED),1)
295 BuildMode := Release
296 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
297 ifneq ($(OS),FreeBSD)
298 ifneq ($(OS),Darwin)
299 OmitFramePointer := -fomit-frame-pointer
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 endif
David Greene8cd590c2009-04-17 14:49:22 +0000301 endif
302
303 # Darwin requires -fstrict-aliasing to be explicitly enabled.
Evan Cheng95e92ae2009-04-20 22:49:59 +0000304 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
305 # with -fstrict-aliasing and ipa-type-escape radr://6756684
Evan Cheng107dae12009-04-20 22:16:40 +0000306 #ifeq ($(OS),Darwin)
307 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
308 #endif
David Greene8cd590c2009-04-17 14:49:22 +0000309 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
310 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
311 LD.Flags += $(OPTIMIZE_OPTION)
312else
313 BuildMode := Debug
314 CXX.Flags += -g
315 C.Flags += -g
316 LD.Flags += -g
317 KEEP_SYMBOLS := 1
318endif
319
320ifeq ($(ENABLE_PROFILING),1)
321 BuildMode := $(BuildMode)+Profile
322 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
323 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
324 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
325 KEEP_SYMBOLS := 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326endif
327
Daniel Dunbar886e1832008-09-02 17:35:16 +0000328#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
329# CXX.Flags += -fvisibility-inlines-hidden
330#endif
331
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332# IF REQUIRES_EH=1 is specified then don't disable exceptions
333ifndef REQUIRES_EH
334 CXX.Flags += -fno-exceptions
335endif
336
337# IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
338ifndef REQUIRES_RTTI
339# CXX.Flags += -fno-rtti
340endif
341
Daniel Dunbar3fd1aa72009-03-13 20:59:41 +0000342ifdef ENABLE_COVERAGE
343 BuildMode := $(BuildMode)+Coverage
Chris Lattner20cba1c2009-06-16 23:00:42 +0000344 CXX.Flags += -ftest-coverage -fprofile-arcs
345 C.Flags += -ftest-coverage -fprofile-arcs
Daniel Dunbar3fd1aa72009-03-13 20:59:41 +0000346endif
347
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
349# then disable assertions by defining the appropriate preprocessor symbols.
350ifdef DISABLE_ASSERTIONS
Duncan Sands86a7a222009-03-27 11:35:00 +0000351 # Indicate that assertions are turned off using a minus sign
352 BuildMode := $(BuildMode)-Asserts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353 CPP.Defines += -DNDEBUG
354else
355 CPP.Defines += -D_DEBUG
356endif
357
Misha Brukman89fe5162009-01-08 02:11:55 +0000358# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
359# configured), then enable expensive checks by defining the
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360# appropriate preprocessor symbols.
361ifdef ENABLE_EXPENSIVE_CHECKS
362 BuildMode := $(BuildMode)+Checks
Duncan Sands871e55f2008-12-09 21:33:20 +0000363 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364endif
365
Nick Lewycky8d91e192009-02-26 07:44:16 +0000366# LOADABLE_MODULE implies several other things so we force them to be
367# defined/on.
368ifdef LOADABLE_MODULE
369 SHARED_LIBRARY := 1
Nick Lewycky8d91e192009-02-26 07:44:16 +0000370 LINK_LIBS_IN_SHARED := 1
371endif
372
373ifdef SHARED_LIBRARY
374 ENABLE_PIC := 1
375 PIC_FLAG = "(PIC)"
376endif
377
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378ifeq ($(ENABLE_PIC),1)
Nick Lewyckyce6daa452009-03-03 03:36:50 +0000379 ifeq ($(OS), $(filter $(OS), Cygwin MingW))
Nick Lewycky5b882f22009-02-21 08:41:09 +0000380 # Nothing. Win32 defaults to PIC and warns when given -fPIC
381 else
382 ifeq ($(OS),Darwin)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000383 # Common symbols not allowed in dylib files
Nick Lewycky5b882f22009-02-21 08:41:09 +0000384 CXX.Flags += -fno-common
385 C.Flags += -fno-common
386 else
387 # Linux and others; pass -fPIC
388 CXX.Flags += -fPIC
389 C.Flags += -fPIC
390 endif
391 endif
Mike Stump8efa3542009-05-08 23:08:58 +0000392else
393 ifeq ($(OS),Darwin)
394 CXX.Flags += -mdynamic-no-pic
395 C.Flags += -mdynamic-no-pic
396 endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397endif
398
399CXX.Flags += $(CXXFLAGS) -Woverloaded-virtual
400C.Flags += $(CFLAGS)
401CPP.Defines += $(CPPFLAGS)
402CPP.BaseFlags += $(CPP.Defines)
403LD.Flags += $(LDFLAGS)
404AR.Flags := cru
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405
406# Make Floating point IEEE compliant on Alpha.
407ifeq ($(ARCH),Alpha)
408 CXX.Flags += -mieee
409 CPP.BaseFlags += -mieee
410ifeq ($(ENABLE_PIC),0)
411 CXX.Flags += -fPIC
412 CPP.BaseFlags += -fPIC
413endif
414endif
415
416ifeq ($(ARCH),Alpha)
417 LD.Flags += -Wl,--no-relax
418endif
419
Anton Korobeynikov025ddd42009-05-04 10:25:30 +0000420ifeq ($(OS),MingW)
421 ifeq ($(LLVM_CROSS_COMPILING),1)
422 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
423 ifdef TOOLNAME
424 LD.Flags += -Wl,--allow-multiple-definition
425 endif
426 endif
427endif
428
Jay Foad188e6472009-05-15 18:13:31 +0000429ifdef ENABLE_EXPENSIVE_CHECKS
430 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
431 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
432 CXX.Flags := $(filter-out -fno-rtti,$(CXX.Flags))
433endif
434
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435#--------------------------------------------------------------------
436# Directory locations
437#--------------------------------------------------------------------
Jim Grosbache4c032e2008-10-02 22:56:44 +0000438TargetMode :=
439ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000440 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbache4c032e2008-10-02 22:56:44 +0000441endif
442
443ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000444ObjDir := $(ObjRootDir)
445LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
446ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
447ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
448LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
449LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
450LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451CFERuntimeLibDir := $(LLVMGCCDIR)/lib
452
453#--------------------------------------------------------------------
454# Full Paths To Compiled Tools and Utilities
455#--------------------------------------------------------------------
456EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
457Echo = @$(EchoCmd)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458ifndef LLVMAS
459LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
460endif
461ifndef TBLGEN
462 ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000463 TBLGEN := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464 else
465 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
466 endif
467endif
Misha Brukman89fe5162009-01-08 02:11:55 +0000468LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469ifndef LLVMLD
470LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
471endif
472ifndef LLVMDIS
473LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
474endif
475ifndef LLI
476LLI := $(LLVMToolDir)/lli$(EXEEXT)
477endif
478ifndef LLC
479LLC := $(LLVMToolDir)/llc$(EXEEXT)
480endif
481ifndef LOPT
482LOPT := $(LLVMToolDir)/opt$(EXEEXT)
483endif
484ifndef LBUGPOINT
485LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
486endif
487ifndef LUPGRADE
488LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
489endif
490ifeq ($(LLVMGCC_MAJVERS),3)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
492LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
493else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494LLVMGCCWITHPATH := $(LLVMGCC)
495LLVMGXXWITHPATH := $(LLVMGXX)
496endif
497
498#--------------------------------------------------------------------
499# Adjust to user's request
500#--------------------------------------------------------------------
501
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000502ifeq ($(OS),Darwin)
503 DARWIN_VERSION := `sw_vers -productVersion`
504 # Strip a number like 10.4.7 to 10.4
505 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
506 # Get "4" out of 10.4 for later pieces in the makefile.
507 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
Bill Wendling3c0d23b2009-03-22 08:28:45 +0000508
Julien Lerouge64e1db82009-03-27 18:18:00 +0000509 SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
510 -dynamiclib -mmacosx-version-min=$(DARWIN_VERSION)
Evan Chengd1f1fc12009-03-23 03:45:56 +0000511 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000512else
513 ifeq ($(OS),Cygwin)
514 SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
Mikhail Glushenkov928de572009-07-03 03:52:47 +0000515 -Wl,--enable-auto-import -Wl,--enable-auto-image-base
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000516 else
517 SharedLinkOptions=-shared
518 endif
519endif
520
Nick Lewycky8d91e192009-02-26 07:44:16 +0000521# Adjust LD.Flags depending on the kind of library that is to be built. Note
522# that if LOADABLE_MODULE is specified then the resulting shared library can
523# be opened with dlopen.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524ifdef LOADABLE_MODULE
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525 LD.Flags += -module
526endif
527
528ifdef SHARED_LIBRARY
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000529ifneq ($(DARWIN_MAJVERS),4)
Nick Lewycky12015c12009-03-03 04:55:15 +0000530 LD.Flags += $(RPATH) -Wl,$(LibDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531endif
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000532endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533
534ifdef TOOL_VERBOSE
535 C.Flags += -v
536 CXX.Flags += -v
537 LD.Flags += -v
538 VERBOSE := 1
539endif
540
541# Adjust settings for verbose mode
542ifndef VERBOSE
543 Verb := @
Reid Spencerdfb3d5b2007-07-23 08:20:46 +0000544 AR.Flags += >/dev/null 2>/dev/null
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
546else
Misha Brukman89fe5162009-01-08 02:11:55 +0000547 ConfigureScriptFLAGS :=
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548endif
549
550# By default, strip symbol information from executable
551ifndef KEEP_SYMBOLS
552 Strip := $(PLATFORMSTRIPOPTS)
553 StripWarnMsg := "(without symbols)"
554 Install.StripFlag += -s
555endif
556
557# Adjust linker flags for building an executable
Nick Lewycky324b1192009-02-26 08:03:36 +0000558ifneq ($(OS),Darwin)
Scott Michelf9c9d7e2009-03-12 21:03:53 +0000559ifneq ($(DARWIN_MAJVERS),4)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000560ifdef TOOLNAME
561ifdef EXAMPLE_TOOL
Nick Lewyckyaca7e1c2009-03-07 22:17:05 +0000562 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563else
Nick Lewyckyaca7e1c2009-03-07 22:17:05 +0000564 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565endif
566endif
Nick Lewycky8d91e192009-02-26 07:44:16 +0000567endif
Nick Lewycky8d91e192009-02-26 07:44:16 +0000568endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569
570#----------------------------------------------------------
571# Options To Invoke Tools
572#----------------------------------------------------------
573
Daniel Dunbarb47afd52009-05-12 07:26:49 +0000574ifndef NO_PEDANTIC
Duncan Sands7d9ea942009-06-19 12:40:30 +0000575CompileCommonOpts += -pedantic -Wno-long-long
Daniel Dunbarb47afd52009-05-12 07:26:49 +0000576endif
Duncan Sands7d9ea942009-06-19 12:40:30 +0000577CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
578 $(EXTRA_OPTIONS)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579
580ifeq ($(OS),HP-UX)
581 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
582endif
583
584# If we are building a universal binary on Mac OS/X, pass extra options. This
585# is useful to people that want to link the LLVM libraries into their universal
586# apps.
587#
588# The following can be optionally specified:
589# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
590# For Mac OS/X 10.4 Intel machines, the traditional one is:
591# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
592# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
593# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
594# i386/ppc only.
595ifdef UNIVERSAL
596 ifndef UNIVERSAL_ARCH
597 UNIVERSAL_ARCH := i386 ppc
598 endif
599 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
600 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 ifdef UNIVERSAL_SDK_PATH
602 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000603 endif
604
605 # Building universal cannot compute dependencies automatically.
606 DISABLE_AUTO_DEPENDENCIES=1
Evan Chengd6ad5ff2009-03-09 18:28:37 +0000607else
Bill Wendling025cce52009-03-12 04:10:09 +0000608 ifeq ($(OS),Darwin)
609 ifeq ($(ARCH),x86_64)
Evan Chengd1f1fc12009-03-23 03:45:56 +0000610 TargetCommonOpts = -m64
Bill Wendling025cce52009-03-12 04:10:09 +0000611 else
612 ifeq ($(ARCH),x86)
Evan Chengd1f1fc12009-03-23 03:45:56 +0000613 TargetCommonOpts = -m32
Bill Wendling025cce52009-03-12 04:10:09 +0000614 endif
Evan Chengd6ad5ff2009-03-09 18:28:37 +0000615 endif
616 endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617endif
618
Chris Lattner35c997c2008-06-24 17:44:42 +0000619ifeq ($(OS),SunOS)
620CPP.BaseFlags += -include llvm/System/Solaris.h
621endif
622
Misha Brukman89fe5162009-01-08 02:11:55 +0000623LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Dan Gohman5a5e6e92008-10-17 01:33:43 +0000624CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands3b960292008-01-28 17:38:30 +0000626CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
627 $(patsubst %,-I%/include,\
Chris Lattner6ee48752008-01-28 04:18:41 +0000628 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
629 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
630 $(CPP.BaseFlags)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631
Daniel Dunbar3fd1aa72009-03-13 20:59:41 +0000632ifeq ($(BUILD_COMPONENT), 1)
Chris Lattner20cba1c2009-06-16 23:00:42 +0000633 Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000634 $(TargetCommonOpts) $(CompileCommonOpts) -c
Chris Lattner20cba1c2009-06-16 23:00:42 +0000635 Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000636 $(TargetCommonOpts) $(CompileCommonOpts) -c
637 Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(TargetCommonOpts) \
Chris Lattner20cba1c2009-06-16 23:00:42 +0000638 $(CompileCommonOpts) $(CXX.Flags) -E
639 Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000640 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbache4c032e2008-10-02 22:56:44 +0000641else
Chris Lattner20cba1c2009-06-16 23:00:42 +0000642 Compile.C = $(CC) $(CPP.Flags) $(C.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000643 $(TargetCommonOpts) $(CompileCommonOpts) -c
Chris Lattner20cba1c2009-06-16 23:00:42 +0000644 Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000645 $(TargetCommonOpts) $(CompileCommonOpts) -c
646 Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) \
Chris Lattner20cba1c2009-06-16 23:00:42 +0000647 $(CompileCommonOpts) $(CXX.Flags) -E
648 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000649 $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
Jim Grosbache4c032e2008-10-02 22:56:44 +0000650endif
651
Evan Chengd1f1fc12009-03-23 03:45:56 +0000652BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) \
653 $(TargetCommonOpts) $(CompileCommonOpts)
654Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) \
655 $(TargetCommonOpts) $(CompileCommonOpts) -E
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000657BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
Evan Chengd1f1fc12009-03-23 03:45:56 +0000658 $(TargetCommonOpts) $(CompileCommonOpts)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659
Misha Brukman89fe5162009-01-08 02:11:55 +0000660ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
661ScriptInstall = $(INSTALL) -m 0755
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662DataInstall = $(INSTALL) -m 0644
Chris Lattner1b0a3a12008-01-15 23:27:40 +0000663
664# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
665# paths. In this case, the SYSPATH function (defined in
666# Makefile.config) transforms Unix paths into Windows paths.
667TableGen = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkov3e6bf9a2009-01-09 16:31:01 +0000668 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner1b0a3a12008-01-15 23:27:40 +0000669 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
670 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
671
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672Archive = $(AR) $(AR.Flags)
673LArchive = $(LLVMToolDir)/llvm-ar rcsf
674ifdef RANLIB
675Ranlib = $(RANLIB)
676else
677Ranlib = ranlib
678endif
679
680#----------------------------------------------------------
Misha Brukman89fe5162009-01-08 02:11:55 +0000681# Get the list of source files and compute object file
682# names from them.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000683#----------------------------------------------------------
684
685ifndef SOURCES
686 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +0000687 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688else
689 Sources := $(SOURCES)
Misha Brukman89fe5162009-01-08 02:11:55 +0000690endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691
692ifdef BUILT_SOURCES
Chris Lattnerbfaed4c2009-01-02 07:16:45 +0000693Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694endif
695
696BaseNameSources := $(sort $(basename $(Sources)))
697
698ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
700
701###############################################################################
702# DIRECTORIES: Handle recursive descent of directory structure
703###############################################################################
704
705#---------------------------------------------------------
706# Provide rules to make install dirs. This must be early
707# in the file so they get built before dependencies
708#---------------------------------------------------------
709
Mike Stump98f72e02009-02-12 23:45:11 +0000710$(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
Mike Stumpf0feefd2009-01-22 03:24:22 +0000711 $(Verb) $(MKDIR) $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712
713# To create other directories, as needed, and timestamp their creation
714%/.dir:
715 $(Verb) $(MKDIR) $* > /dev/null
716 $(Verb) $(DATE) > $@
717
718.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
719.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
720
721#---------------------------------------------------------
722# Handle the DIRS options for sequential construction
723#---------------------------------------------------------
724
Misha Brukman89fe5162009-01-08 02:11:55 +0000725SubDirs :=
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726ifdef DIRS
727SubDirs += $(DIRS)
728
729ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
730$(RecursiveTargets)::
731 $(Verb) for dir in $(DIRS); do \
732 if [ ! -f $$dir/Makefile ]; then \
733 $(MKDIR) $$dir; \
734 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
735 fi; \
736 ($(MAKE) -C $$dir $@ ) || exit 1; \
737 done
738else
739$(RecursiveTargets)::
740 $(Verb) for dir in $(DIRS); do \
741 ($(MAKE) -C $$dir $@ ) || exit 1; \
742 done
743endif
744
745endif
746
747#---------------------------------------------------------
748# Handle the EXPERIMENTAL_DIRS options ensuring success
749# after each directory is built.
750#---------------------------------------------------------
751ifdef EXPERIMENTAL_DIRS
752$(RecursiveTargets)::
753 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
754 if [ ! -f $$dir/Makefile ]; then \
755 $(MKDIR) $$dir; \
756 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
757 fi; \
758 ($(MAKE) -C $$dir $@ ) || exit 0; \
759 done
760endif
761
762#-----------------------------------------------------------
Mike Stump0fec3192009-01-24 00:00:41 +0000763# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
764#-----------------------------------------------------------
765ifdef OPTIONAL_PARALLEL_DIRS
766 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
767endif
768
769#-----------------------------------------------------------
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000770# Handle the PARALLEL_DIRS options for parallel construction
771#-----------------------------------------------------------
772ifdef PARALLEL_DIRS
773
774SubDirs += $(PARALLEL_DIRS)
775
776# Unfortunately, this list must be maintained if new recursive targets are added
777all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
778clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
779clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
780install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
781uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
782install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
783
784ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
785
786$(ParallelTargets) :
787 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
788 $(MKDIR) $(@D); \
789 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
790 fi; \
791 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
792endif
793
794#---------------------------------------------------------
795# Handle the OPTIONAL_DIRS options for directores that may
796# or may not exist.
797#---------------------------------------------------------
798ifdef OPTIONAL_DIRS
799
800SubDirs += $(OPTIONAL_DIRS)
801
802ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
803$(RecursiveTargets)::
804 $(Verb) for dir in $(OPTIONAL_DIRS); do \
805 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
806 if [ ! -f $$dir/Makefile ]; then \
807 $(MKDIR) $$dir; \
808 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
809 fi; \
810 ($(MAKE) -C$$dir $@ ) || exit 1; \
811 fi \
812 done
813else
814$(RecursiveTargets)::
815 $(Verb) for dir in $(OPTIONAL_DIRS); do \
816 ($(MAKE) -C$$dir $@ ) || exit 1; \
817 done
818endif
819endif
820
821#---------------------------------------------------------
822# Handle the CONFIG_FILES options
823#---------------------------------------------------------
824ifdef CONFIG_FILES
825
826ifdef NO_INSTALL
827install-local::
828 $(Echo) Install circumvented with NO_INSTALL
829uninstall-local::
830 $(Echo) UnInstall circumvented with NO_INSTALL
831else
832install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
833 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
834 $(Verb)for file in $(CONFIG_FILES); do \
835 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
836 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
837 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
838 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
839 else \
840 $(ECHO) Error: cannot find config file $${file}. ; \
841 fi \
842 done
843
844uninstall-local::
845 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
846 $(Verb)for file in $(CONFIG_FILES); do \
847 $(RM) -f $(PROJ_etcdir)/$${file} ; \
848 done
849endif
850
851endif
852
853###############################################################################
854# Set up variables for building libararies
855###############################################################################
856
857#---------------------------------------------------------
858# Define various command line options pertaining to the
Misha Brukman89fe5162009-01-08 02:11:55 +0000859# libraries needed when linking. There are "Proj" libs
860# (defined by the user's project) and "LLVM" libs (defined
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861# by the LLVM project).
862#---------------------------------------------------------
863
864ifdef USEDLIBS
865ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
866ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
867ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
868ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
869endif
870
871ifdef LLVMLIBS
872LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
873LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
874LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
875LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
876endif
877
Daniel Dunbara89194e2008-10-03 19:11:19 +0000878ifndef IS_CLEANING_TARGET
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879ifdef LINK_COMPONENTS
880
881# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
882# clean in tools, then do a make in tools (instead of at the top level).
883$(LLVM_CONFIG):
884 @echo "*** llvm-config doesn't exist - rebuilding it."
885 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greif14c4c8e2008-02-27 13:34:15 +0000886
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000887$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
888
Mikhail Glushenkovfc320822009-03-03 10:03:27 +0000889LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
890LLVMLibsPaths += $(LLVM_CONFIG) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891 $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
892endif
893endif
894
895###############################################################################
896# Library Build Rules: Four ways to build a library
897###############################################################################
898
899#---------------------------------------------------------
900# Bytecode Module Targets:
901# If the user set MODULE_NAME then they want to build a
902# bytecode module from the sources. We compile all the
903# sources and link it together into a single bytecode
904# module.
905#---------------------------------------------------------
906
907ifdef MODULE_NAME
908ifeq ($(strip $(LLVMGCC)),)
909$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
910else
911
912Module := $(LibDir)/$(MODULE_NAME).bc
Andrew Lenharthd0020772008-02-25 22:41:55 +0000913LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914
915
916ifdef EXPORTED_SYMBOL_FILE
917LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
918endif
919
920$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
921 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
922 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
923
924all-local:: $(Module)
925
926clean-local::
927ifneq ($(strip $(Module)),)
928 -$(Verb) $(RM) -f $(Module)
929endif
930
931ifdef BYTECODE_DESTINATION
932ModuleDestDir := $(BYTECODE_DESTINATION)
933else
934ModuleDestDir := $(PROJ_libdir)
935endif
936
937ifdef NO_INSTALL
938install-local::
939 $(Echo) Install circumvented with NO_INSTALL
940uninstall-local::
941 $(Echo) Uninstall circumvented with NO_INSTALL
942else
943DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
944
945install-module:: $(DestModule)
946install-local:: $(DestModule)
947
Misha Brukman89fe5162009-01-08 02:11:55 +0000948$(DestModule): $(ModuleDestDir) $(Module)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
950 $(Verb) $(DataInstall) $(Module) $(DestModule)
951
952uninstall-local::
953 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
954 -$(Verb) $(RM) -f $(DestModule)
955endif
956
957endif
958endif
959
960# if we're building a library ...
961ifdef LIBRARYNAME
962
963# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
964LIBRARYNAME := $(strip $(LIBRARYNAME))
965ifdef LOADABLE_MODULE
Nick Lewycky8d91e192009-02-26 07:44:16 +0000966LibName.A := $(LibDir)/$(LIBRARYNAME).a
967LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000969LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
Nick Lewycky8d91e192009-02-26 07:44:16 +0000970LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
971endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972LibName.O := $(LibDir)/$(LIBRARYNAME).o
973LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
974
975#---------------------------------------------------------
976# Shared Library Targets:
977# If the user asked for a shared library to be built
978# with the SHARED_LIBRARY variable, then we provide
979# targets for building them.
980#---------------------------------------------------------
981ifdef SHARED_LIBRARY
982
Nick Lewycky8d91e192009-02-26 07:44:16 +0000983all-local:: $(LibName.SO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000984
985ifdef LINK_LIBS_IN_SHARED
986ifdef LOADABLE_MODULE
987SharedLibKindMessage := "Loadable Module"
988else
989SharedLibKindMessage := "Shared Library"
990endif
Nick Lewycky8d91e192009-02-26 07:44:16 +0000991$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000992 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
993 $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000994 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
Edwin Töröke59edce2009-05-26 19:11:47 +0000995 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000996else
Nick Lewycky8d91e192009-02-26 07:44:16 +0000997$(LibName.SO): $(ObjectsO) $(LibDir)/.dir
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000998 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000999 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000endif
1001
1002clean-local::
Nick Lewycky8d91e192009-02-26 07:44:16 +00001003ifneq ($(strip $(LibName.SO)),)
1004 -$(Verb) $(RM) -f $(LibName.SO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001005endif
1006
1007ifdef NO_INSTALL
1008install-local::
1009 $(Echo) Install circumvented with NO_INSTALL
1010uninstall-local::
1011 $(Echo) Uninstall circumvented with NO_INSTALL
1012else
1013DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
1014
1015install-local:: $(DestSharedLib)
1016
Nick Lewycky8d91e192009-02-26 07:44:16 +00001017$(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001019 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020
Misha Brukman89fe5162009-01-08 02:11:55 +00001021uninstall-local::
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001022 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
1023 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
1024endif
1025endif
1026
1027#---------------------------------------------------------
1028# Bytecode Library Targets:
1029# If the user asked for a bytecode library to be built
Misha Brukman89fe5162009-01-08 02:11:55 +00001030# with the BYTECODE_LIBRARY variable, then we provide
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031# targets for building them.
1032#---------------------------------------------------------
1033ifdef BYTECODE_LIBRARY
1034ifeq ($(strip $(LLVMGCC)),)
1035$(warning Bytecode libraries require llvm-gcc which could not be found ****)
1036else
1037
1038all-local:: $(LibName.BCA)
1039
1040ifdef EXPORTED_SYMBOL_FILE
1041BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
1042 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1043
1044$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
1045 $(LLVMToolDir)/llvm-ar
1046 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1047 "(internalize)"
1048 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
1049 $(Verb) $(RM) -f $@
1050 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
1051else
1052$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
1053 $(LLVMToolDir)/llvm-ar
1054 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
1055 $(Verb) $(RM) -f $@
1056 $(Verb) $(LArchive) $@ $(ObjectsBC)
1057
1058endif
1059
1060clean-local::
1061ifneq ($(strip $(LibName.BCA)),)
1062 -$(Verb) $(RM) -f $(LibName.BCA)
1063endif
1064
1065ifdef BYTECODE_DESTINATION
1066BytecodeDestDir := $(BYTECODE_DESTINATION)
1067else
1068BytecodeDestDir := $(PROJ_libdir)
1069endif
1070
Daniel Dunbar659cef82009-05-12 05:35:40 +00001071DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072
1073install-bytecode-local:: $(DestBytecodeLib)
1074
1075ifdef NO_INSTALL
1076install-local::
1077 $(Echo) Install circumvented with NO_INSTALL
1078uninstall-local::
1079 $(Echo) Uninstall circumvented with NO_INSTALL
1080else
1081install-local:: $(DestBytecodeLib)
1082
Mike Stump98f72e02009-02-12 23:45:11 +00001083$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1085 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1086
1087uninstall-local::
1088 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1089 -$(Verb) $(RM) -f $(DestBytecodeLib)
1090endif
1091endif
1092endif
1093
1094#---------------------------------------------------------
Chris Lattner20cba1c2009-06-16 23:00:42 +00001095# Library Targets:
1096# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1097# building an archive.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098#---------------------------------------------------------
1099ifndef BUILD_ARCHIVE
Chris Lattner20cba1c2009-06-16 23:00:42 +00001100ifndef LOADABLE_MODULE
1101BUILD_ARCHIVE = 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102endif
1103endif
1104
1105#---------------------------------------------------------
1106# Archive Library Targets:
Misha Brukman89fe5162009-01-08 02:11:55 +00001107# If the user wanted a regular archive library built,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001108# then we provide targets for building them.
1109#---------------------------------------------------------
1110ifdef BUILD_ARCHIVE
1111
1112all-local:: $(LibName.A)
1113
1114$(LibName.A): $(ObjectsO) $(LibDir)/.dir
1115 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1116 -$(Verb) $(RM) -f $@
Bill Wendling3d6df102009-01-03 22:46:50 +00001117 $(Verb) $(Archive) $@ $(ObjectsO)
1118 $(Verb) $(Ranlib) $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119
1120clean-local::
1121ifneq ($(strip $(LibName.A)),)
1122 -$(Verb) $(RM) -f $(LibName.A)
1123endif
1124
1125ifdef NO_INSTALL
1126install-local::
1127 $(Echo) Install circumvented with NO_INSTALL
1128uninstall-local::
1129 $(Echo) Uninstall circumvented with NO_INSTALL
1130else
1131DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
1132
1133install-local:: $(DestArchiveLib)
1134
Mike Stump98f72e02009-02-12 23:45:11 +00001135$(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1137 $(Verb) $(MKDIR) $(PROJ_libdir)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001138 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139
1140uninstall-local::
1141 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1142 -$(Verb) $(RM) -f $(DestArchiveLib)
1143endif
1144endif
1145
1146# endif LIBRARYNAME
Misha Brukman89fe5162009-01-08 02:11:55 +00001147endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001148
1149###############################################################################
1150# Tool Build Rules: Build executable tool based on TOOLNAME option
1151###############################################################################
1152
1153ifdef TOOLNAME
1154
1155#---------------------------------------------------------
1156# Set up variables for building a tool.
1157#---------------------------------------------------------
1158ifdef EXAMPLE_TOOL
1159ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1160else
1161ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1162endif
1163
1164#---------------------------------------------------------
Chris Lattner8b04ea72009-02-26 17:47:49 +00001165# Prune Exports
1166#---------------------------------------------------------
1167
1168# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1169# not exporting all of the weak symbols from the binary. This reduces dyld
1170# startup time by 4x on darwin in some cases.
1171ifdef TOOL_NO_EXPORTS
1172ifeq ($(OS),Darwin)
Chris Lattnerc6c51352009-03-10 17:15:56 +00001173
1174# Tiger tools don't support this.
1175ifneq ($(DARWIN_MAJVERS),4)
Chris Lattner8b04ea72009-02-26 17:47:49 +00001176LD.Flags += -Wl,-exported_symbol -Wl,_main
1177endif
Chris Lattnerc6c51352009-03-10 17:15:56 +00001178endif
Chris Lattner8b04ea72009-02-26 17:47:49 +00001179
1180ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
Chris Lattner7c024612009-02-26 18:38:40 +00001181LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner8b04ea72009-02-26 17:47:49 +00001182endif
1183endif
1184
1185
1186#---------------------------------------------------------
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187# Provide targets for building the tools
1188#---------------------------------------------------------
1189all-local:: $(ToolBuildPath)
1190
1191clean-local::
1192ifneq ($(strip $(ToolBuildPath)),)
1193 -$(Verb) $(RM) -f $(ToolBuildPath)
1194endif
1195
1196ifdef EXAMPLE_TOOL
1197$(ToolBuildPath): $(ExmplDir)/.dir
1198else
1199$(ToolBuildPath): $(ToolDir)/.dir
1200endif
1201
1202$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1203 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001204 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1206 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukman89fe5162009-01-08 02:11:55 +00001207 $(StripWarnMsg)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001208
1209ifdef NO_INSTALL
1210install-local::
1211 $(Echo) Install circumvented with NO_INSTALL
1212uninstall-local::
1213 $(Echo) Uninstall circumvented with NO_INSTALL
1214else
1215DestTool = $(PROJ_bindir)/$(TOOLNAME)
1216
1217install-local:: $(DestTool)
1218
Mike Stump98f72e02009-02-12 23:45:11 +00001219$(DestTool): $(ToolBuildPath) $(PROJ_bindir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 $(Echo) Installing $(BuildMode) $(DestTool)
1221 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1222
1223uninstall-local::
1224 $(Echo) Uninstalling $(BuildMode) $(DestTool)
1225 -$(Verb) $(RM) -f $(DestTool)
1226endif
1227endif
1228
1229###############################################################################
Misha Brukman89fe5162009-01-08 02:11:55 +00001230# Object Build Rules: Build object files based on sources
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231###############################################################################
1232
1233# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1234ifeq ($(OS),HP-UX)
1235 DISABLE_AUTO_DEPENDENCIES=1
1236endif
1237
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238# Provide rule sets for when dependency generation is enabled
1239ifndef DISABLE_AUTO_DEPENDENCIES
1240
1241#---------------------------------------------------------
Nick Lewycky8d91e192009-02-26 07:44:16 +00001242# Create .o files in the ObjDir directory from the .cpp and .c files...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243#---------------------------------------------------------
1244
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001245DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewycky8d91e192009-02-26 07:44:16 +00001246 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greif14c4c8e2008-02-27 13:34:15 +00001247
Daniel Dunbar285108f2009-05-12 06:35:50 +00001248# If the build succeeded, move the dependency file over, otherwise
1249# remove it.
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001250DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1251 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1252
Nick Lewycky8d91e192009-02-26 07:44:16 +00001253$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001254 $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001255 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001256 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001257
Nick Lewycky8d91e192009-02-26 07:44:16 +00001258$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001259 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001260 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001261 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001262
Nick Lewycky8d91e192009-02-26 07:44:16 +00001263$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001264 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001265 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001266 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001267
1268#---------------------------------------------------------
1269# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1270#---------------------------------------------------------
1271
Daniel Dunbar285108f2009-05-12 06:35:50 +00001272BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1273 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1274
1275# If the build succeeded, move the dependency file over, otherwise
1276# remove it.
1277BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1278 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1279
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001280$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1281 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
Daniel Dunbar285108f2009-05-12 06:35:50 +00001282 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1283 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1284 $(BC_DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001285
1286$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1287 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
Daniel Dunbar285108f2009-05-12 06:35:50 +00001288 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1289 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1290 $(BC_DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001291
1292$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1293 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
Daniel Dunbar285108f2009-05-12 06:35:50 +00001294 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1295 $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1296 $(BC_DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001297
1298# Provide alternate rule sets if dependencies are disabled
1299else
1300
Nick Lewycky8d91e192009-02-26 07:44:16 +00001301$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001302 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001303 $(Compile.CXX) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001304
Nick Lewycky8d91e192009-02-26 07:44:16 +00001305$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001306 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001307 $(Compile.CXX) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001308
Nick Lewycky8d91e192009-02-26 07:44:16 +00001309$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001311 $(Compile.C) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312
1313$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1314 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1315 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001316
1317$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1318 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1319 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320
1321$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1322 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1323 $(BCCompile.C) $< -o $@ -S -emit-llvm
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001324
1325endif
1326
1327
1328## Rules for building preprocessed (.i/.ii) outputs.
1329$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1330 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1331 $(Verb) $(Preprocess.CXX) $< -o $@
1332
1333$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1334 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1335 $(Verb) $(Preprocess.CXX) $< -o $@
1336
1337$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1338 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1339 $(Verb) $(Preprocess.C) $< -o $@
1340
1341
1342$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1343 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001344 $(Compile.CXX) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001345
1346$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1347 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001348 $(Compile.CXX) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349
1350$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1351 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001352 $(Compile.C) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001353
1354
1355# make the C and C++ compilers strip debug info out of bytecode libraries.
1356ifdef DEBUG_RUNTIME
1357$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1358 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1359 $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1360else
1361$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1362 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1363 $(Verb) $(LLVMAS) $< -o - | \
1364 $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1365endif
1366
1367
1368#---------------------------------------------------------
1369# Provide rule to build .bc files from .ll sources,
1370# regardless of dependencies
1371#---------------------------------------------------------
1372$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1373 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1374 $(Verb) $(LLVMAS) $< -f -o $@
1375
1376###############################################################################
1377# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1378###############################################################################
1379
1380ifdef TARGET
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001381TABLEGEN_INC_FILES_COMMON = 1
1382endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001383
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001384ifdef LLVMC_BUILD_AUTOGENERATED_INC
1385TABLEGEN_INC_FILES_COMMON = 1
1386endif
1387
1388ifdef TABLEGEN_INC_FILES_COMMON
1389
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001390INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1391INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1392.PRECIOUS: $(INCTMPFiles) $(INCFiles)
1393
Misha Brukman89fe5162009-01-08 02:11:55 +00001394# INCFiles rule: All of the tblgen generated files are emitted to
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001395# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1396# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbar90f3e7f2008-11-03 17:33:36 +00001397# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001398# dependencies of the .inc files are, unless the contents of the .inc file
1399# changes.
1400$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1401 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1402
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001403endif # TABLEGEN_INC_FILES_COMMON
1404
1405ifdef TARGET
1406
1407TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1408 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1409 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1410 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1411 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1412 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1413 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1414
Rafael Espindola4d8cd532009-03-10 17:58:54 +00001415# All of these files depend on tblgen and the .td files.
1416$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1417
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001418$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1419$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1420 $(Echo) "Building $(<F) register names with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001421 $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001422
1423$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1424$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1425 $(Echo) "Building $(<F) register information header with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001426 $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001427
1428$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1429$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1430 $(Echo) "Building $(<F) register info implementation with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001431 $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001432
1433$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1434$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1435 $(Echo) "Building $(<F) instruction names with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001436 $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001437
1438$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1439$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1440 $(Echo) "Building $(<F) instruction information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001441 $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442
1443$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1444$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1445 $(Echo) "Building $(<F) assembly writer with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001446 $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001447
1448$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1449$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1450 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Misha Brukman89fe5162009-01-08 02:11:55 +00001451 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001452
Daniel Dunbara9b43082009-07-13 18:35:35 +00001453$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1454$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
1455 $(Echo) "Building $(<F) assembly matcher with tblgen"
1456 $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1457
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001458$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1459$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1460 $(Echo) "Building $(<F) code emitter with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001461 $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001462
1463$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1464$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
Dan Gohmanb75dead2008-08-13 20:19:35 +00001465 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001466 $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001467
Dan Gohmanb75dead2008-08-13 20:19:35 +00001468$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1469$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1470 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1471 $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1472
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001473$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1474$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1475 $(Echo) "Building $(<F) subtarget information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001476 $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001477
1478$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1479$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1480 $(Echo) "Building $(<F) calling convention information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001481 $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482
Dale Johannesenfe5921a2009-02-05 01:49:45 +00001483$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1484$(ObjDir)/%GenIntrinsics.inc.tmp : Intrinsics%.td $(ObjDir)/.dir
1485 $(Echo) "Building $(<F) calling convention information with tblgen"
1486 $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1487
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001488clean-local::
1489 -$(Verb) $(RM) -f $(INCFiles)
1490
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001491endif # TARGET
1492
1493ifdef LLVMC_BUILD_AUTOGENERATED_INC
1494
Mikhail Glushenkov3b335a42009-04-21 19:46:10 +00001495LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1496 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001497
1498TDFiles := $(LLVMCPluginSrc) \
1499 $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1500
1501$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1502 $(TBLGEN) $(TD_COMMON)
1503 $(Echo) "Building LLVMC configuration library with tblgen"
1504 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1505
1506endif # LLVMC_BUILD_AUTOGENERATED_INC
1507
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001508###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001509# OTHER RULES: Other rules needed
1510###############################################################################
1511
1512# To create postscript files from dot files...
1513ifneq ($(DOT),false)
1514%.ps: %.dot
1515 $(DOT) -Tps < $< > $@
1516else
1517%.ps: %.dot
1518 $(Echo) "Cannot build $@: The program dot is not installed"
1519endif
1520
1521# This rules ensures that header files that are removed still have a rule for
1522# which they can be "generated." This allows make to ignore them and
1523# reproduce the dependency lists.
1524%.h:: ;
1525%.hpp:: ;
1526
1527# Define clean-local to clean the current directory. Note that this uses a
Misha Brukman89fe5162009-01-08 02:11:55 +00001528# very conservative approach ensuring that empty variables do not cause
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529# errors or disastrous removal.
1530clean-local::
Jim Grosbache4c032e2008-10-02 22:56:44 +00001531ifneq ($(strip $(ObjRootDir)),)
1532 -$(Verb) $(RM) -rf $(ObjRootDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533endif
1534 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1535ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1536 -$(Verb) $(RM) -f *$(SHLIBEXT)
1537endif
1538
1539clean-all-local::
1540 -$(Verb) $(RM) -rf Debug Release Profile
1541
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001542
1543###############################################################################
1544# DEPENDENCIES: Include the dependency files if we should
1545###############################################################################
1546ifndef DISABLE_AUTO_DEPENDENCIES
1547
1548# If its not one of the cleaning targets
Daniel Dunbara89194e2008-10-03 19:11:19 +00001549ifndef IS_CLEANING_TARGET
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001550
1551# Get the list of dependency files
Daniel Dunbar285108f2009-05-12 06:35:50 +00001552DependSourceFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1553DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1554
1555# Include bitcode dependency files if using bitcode libraries
1556ifdef BYTECODE_LIBRARY
1557DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1558endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001559
Reid Spencerdfb3d5b2007-07-23 08:20:46 +00001560-include $(DependFiles) ""
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001561
1562endif
1563
Misha Brukman89fe5162009-01-08 02:11:55 +00001564endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001565
1566###############################################################################
1567# CHECK: Running the test suite
1568###############################################################################
1569
Bill Wendlingea4af672009-04-09 18:26:57 +00001570check::
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001571 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1572 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1573 $(EchoCmd) Running test suite ; \
1574 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1575 TESTSUITE=$(TESTSUITE) ; \
1576 else \
1577 $(EchoCmd) No Makefile in test directory ; \
1578 fi ; \
1579 else \
1580 $(EchoCmd) No test directory ; \
1581 fi
1582
1583###############################################################################
Bill Wendling2e3646a2009-01-04 23:12:21 +00001584# UNITTESTS: Running the unittests test suite
1585###############################################################################
1586
Bill Wendlingea4af672009-04-09 18:26:57 +00001587unittests::
Bill Wendling2e3646a2009-01-04 23:12:21 +00001588 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1589 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1590 $(EchoCmd) Running unittests test suite ; \
1591 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests ; \
1592 else \
1593 $(EchoCmd) No Makefile in unittests directory ; \
1594 fi ; \
1595 else \
1596 $(EchoCmd) No unittests directory ; \
1597 fi
1598
1599###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001600# DISTRIBUTION: Handle construction of a distribution tarball
1601###############################################################################
1602
1603#------------------------------------------------------------------------
1604# Define distribution related variables
1605#------------------------------------------------------------------------
1606DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1607DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1608TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1609DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1610DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1611DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1612DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1613 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1614 Makefile.config.in configure autoconf
1615DistOther := $(notdir $(wildcard \
1616 $(PROJ_SRC_DIR)/*.h \
1617 $(PROJ_SRC_DIR)/*.td \
1618 $(PROJ_SRC_DIR)/*.def \
1619 $(PROJ_SRC_DIR)/*.ll \
1620 $(PROJ_SRC_DIR)/*.in))
1621DistSubDirs := $(SubDirs)
1622DistSources = $(Sources) $(EXTRA_DIST)
1623DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1624
1625#------------------------------------------------------------------------
1626# We MUST build distribution with OBJ_DIR != SRC_DIR
1627#------------------------------------------------------------------------
1628ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1629dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1630 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1631
1632else
1633
1634#------------------------------------------------------------------------
1635# Prevent attempt to run dist targets from anywhere but the top level
1636#------------------------------------------------------------------------
1637ifneq ($(LEVEL),.)
1638dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1639 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1640else
1641
1642#------------------------------------------------------------------------
1643# Provide the top level targets
1644#------------------------------------------------------------------------
1645
1646dist-gzip:: $(DistTarGZip)
1647
1648$(DistTarGZip) : $(TopDistDir)/.makedistdir
1649 $(Echo) Packing gzipped distribution tar file.
1650 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1651 $(GZIP) -c > "$(DistTarGZip)"
1652
1653dist-bzip2:: $(DistTarBZ2)
1654
1655$(DistTarBZ2) : $(TopDistDir)/.makedistdir
1656 $(Echo) Packing bzipped distribution tar file.
1657 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1658 $(BZIP2) -c >$(DistTarBZ2)
1659
1660dist-zip:: $(DistZip)
1661
1662$(DistZip) : $(TopDistDir)/.makedistdir
1663 $(Echo) Packing zipped distribution file.
1664 $(Verb) rm -f $(DistZip)
1665 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1666
Misha Brukman89fe5162009-01-08 02:11:55 +00001667dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001668 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1669
1670DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1671
1672dist-check:: $(DistTarGZip)
1673 $(Echo) Checking distribution tar file.
1674 $(Verb) if test -d $(DistCheckDir) ; then \
1675 $(RM) -rf $(DistCheckDir) ; \
1676 fi
1677 $(Verb) $(MKDIR) $(DistCheckDir)
1678 $(Verb) cd $(DistCheckDir) && \
1679 $(MKDIR) $(DistCheckDir)/build && \
1680 $(MKDIR) $(DistCheckDir)/install && \
1681 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1682 cd build && \
1683 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1684 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1685 $(MAKE) all && \
1686 $(MAKE) check && \
Bill Wendling2e3646a2009-01-04 23:12:21 +00001687 $(MAKE) unittests && \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001688 $(MAKE) install && \
1689 $(MAKE) uninstall && \
1690 $(MAKE) dist-clean && \
1691 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1692
1693dist-clean::
1694 $(Echo) Cleaning distribution files
1695 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1696 $(DistCheckDir)
1697
1698endif
1699
1700#------------------------------------------------------------------------
1701# Provide the recursive distdir target for building the distribution directory
1702#------------------------------------------------------------------------
1703distdir: $(DistDir)/.makedistdir
1704$(DistDir)/.makedistdir: $(DistSources)
1705 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1706 if test -d "$(DistDir)" ; then \
1707 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1708 exit 1 ; \
1709 fi ; \
1710 $(EchoCmd) Removing old $(DistDir) ; \
1711 $(RM) -rf $(DistDir); \
1712 $(EchoCmd) Making 'all' to verify build ; \
1713 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1714 fi
1715 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukman89fe5162009-01-08 02:11:55 +00001716 $(Verb) $(MKDIR) $(DistDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001717 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1718 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1719 for file in $(DistFiles) ; do \
1720 case "$$file" in \
1721 $(PROJ_SRC_DIR)/*) \
1722 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1723 ;; \
1724 $(PROJ_SRC_ROOT)/*) \
1725 file=`echo "$$file" | \
1726 sed "s#^$$srcrootstrip/##"` \
1727 ;; \
1728 esac; \
1729 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1730 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1731 from_dir="$(PROJ_SRC_DIR)" ; \
1732 elif test -f "$$file" || test -d "$$file" ; then \
1733 from_dir=. ; \
1734 fi ; \
1735 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1736 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1737 to_dir="$(DistDir)/$$dir"; \
1738 $(MKDIR) "$$to_dir" ; \
1739 else \
1740 to_dir="$(DistDir)"; \
1741 fi; \
1742 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1743 if test -n "$$mid_dir" ; then \
1744 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1745 fi ; \
1746 if test -d "$$from_dir/$$file"; then \
1747 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1748 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1749 cd $(PROJ_SRC_DIR) ; \
1750 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1751 ( cd $$to_dir ; $(TAR) xf - ) ; \
1752 cd $(PROJ_OBJ_DIR) ; \
1753 else \
1754 cd $$from_dir ; \
1755 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1756 ( cd $$to_dir ; $(TAR) xf - ) ; \
1757 cd $(PROJ_OBJ_DIR) ; \
1758 fi; \
1759 elif test -f "$$from_dir/$$file" ; then \
1760 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1761 elif test -L "$$from_dir/$$file" ; then \
1762 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1763 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1764 $(EchoCmd) "===== WARNING: Distribution Source " \
1765 "$$from_dir/$$file Not Found!" ; \
1766 elif test "$(Verb)" != '@' ; then \
1767 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1768 fi; \
1769 done
1770 $(Verb) for subdir in $(DistSubDirs) ; do \
1771 if test "$$subdir" \!= "." ; then \
1772 new_distdir="$(DistDir)/$$subdir" ; \
1773 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1774 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1775 DistDir="$$new_distdir" distdir ) || exit 1; \
1776 fi; \
1777 done
1778 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1779 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1780 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1781 -name .svn \) -print` ;\
1782 $(MAKE) dist-hook ; \
1783 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1784 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1785 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1786 -o ! -type d ! -perm -444 -exec \
1787 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1788 || chmod -R a+r $(DistDir) ; \
1789 fi
1790
1791# This is invoked by distdir target, define it as a no-op to avoid errors if not
1792# defined by user.
1793dist-hook::
1794
1795endif
1796
1797###############################################################################
1798# TOP LEVEL - targets only to apply at the top level directory
1799###############################################################################
1800
1801ifeq ($(LEVEL),.)
1802
1803#------------------------------------------------------------------------
1804# Install support for the project's include files:
1805#------------------------------------------------------------------------
1806ifdef NO_INSTALL
1807install-local::
1808 $(Echo) Install circumvented with NO_INSTALL
1809uninstall-local::
1810 $(Echo) Uninstall circumvented with NO_INSTALL
1811else
1812install-local::
1813 $(Echo) Installing include files
1814 $(Verb) $(MKDIR) $(PROJ_includedir)
1815 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1816 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +00001817 for hdr in `find . -type f '!' '(' -name '*~' \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001818 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1819 grep -v .svn` ; do \
1820 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1821 if test \! -d "$$instdir" ; then \
1822 $(EchoCmd) Making install directory $$instdir ; \
1823 $(MKDIR) $$instdir ;\
1824 fi ; \
1825 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1826 done ; \
1827 fi
1828ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1829 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1830 cd $(PROJ_OBJ_ROOT)/include && \
1831 for hdr in `find . -type f -print | grep -v CVS` ; do \
1832 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1833 done ; \
1834 fi
1835endif
1836
1837uninstall-local::
1838 $(Echo) Uninstalling include files
1839 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1840 cd $(PROJ_SRC_ROOT)/include && \
1841 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +00001842 '!' '(' -name '*~' -o -name '.#*' \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001843 -o -name '*.in' ')' -print ')' | \
1844 grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1845 cd $(PROJ_SRC_ROOT)/include && \
1846 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1847 -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1848 fi
1849endif
1850endif
1851
1852check-line-length:
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001853 @echo searching for overlength lines in files: $(Sources)
1854 @echo
1855 @echo
Gabor Greif3033d032008-08-28 22:32:39 +00001856 egrep -n '.{81}' $(Sources) /dev/null
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001857
1858check-for-tabs:
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001859 @echo searching for tabs in files: $(Sources)
1860 @echo
1861 @echo
Gabor Greif3033d032008-08-28 22:32:39 +00001862 egrep -n ' ' $(Sources) /dev/null
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001863
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864check-footprint:
1865 @ls -l $(LibDir) | awk '\
1866 BEGIN { sum = 0; } \
1867 { sum += $$5; } \
1868 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1869 @ls -l $(ToolDir) | awk '\
1870 BEGIN { sum = 0; } \
1871 { sum += $$5; } \
1872 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1873#------------------------------------------------------------------------
1874# Print out the directories used for building
1875#------------------------------------------------------------------------
1876printvars::
1877 $(Echo) "BuildMode : " '$(BuildMode)'
1878 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1879 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1880 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1881 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1882 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1883 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1884 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1885 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1886 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1887 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1888 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1889 $(Echo) "UserTargets : " '$(UserTargets)'
1890 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1891 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1892 $(Echo) "ObjDir : " '$(ObjDir)'
1893 $(Echo) "LibDir : " '$(LibDir)'
1894 $(Echo) "ToolDir : " '$(ToolDir)'
1895 $(Echo) "ExmplDir : " '$(ExmplDir)'
1896 $(Echo) "Sources : " '$(Sources)'
1897 $(Echo) "TDFiles : " '$(TDFiles)'
1898 $(Echo) "INCFiles : " '$(INCFiles)'
1899 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1900 $(Echo) "PreConditions: " '$(PreConditions)'
1901 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1902 $(Echo) "Compile.C : " '$(Compile.C)'
1903 $(Echo) "Archive : " '$(Archive)'
1904 $(Echo) "YaccFiles : " '$(YaccFiles)'
1905 $(Echo) "LexFiles : " '$(LexFiles)'
1906 $(Echo) "Module : " '$(Module)'
1907 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1908 $(Echo) "SubDirs : " '$(SubDirs)'
1909 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1910 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar190b3d52009-02-21 20:42:39 +00001911
1912###
1913# Debugging
1914
Daniel Dunbara6b02752009-03-06 22:23:25 +00001915# General debugging rule, use 'make dbg-print-XXX' to print the
Daniel Dunbar190b3d52009-02-21 20:42:39 +00001916# definition, value and origin of XXX.
Daniel Dunbara6b02752009-03-06 22:23:25 +00001917make-print-%:
Daniel Dunbar190b3d52009-02-21 20:42:39 +00001918 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))