blob: 9f0e58c42841ff84c9705af41b60144758a0df01 [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))
201REQUIRES_EH := 1
202
203# Build a dynamic library if the user runs `make` directly from the plugin
204# directory.
205ifndef LLVMC_BUILTIN_PLUGIN
206LOADABLE_MODULE = 1
207endif
208
209# TableGen stuff...
210ifneq ($(BUILT_SOURCES),)
Mikhail Glushenkov72145e32009-03-02 09:42:59 +0000211LLVMC_BUILD_AUTOGENERATED_INC=1
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +0000212endif
213
214endif # LLVMC_PLUGIN
215
216###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217# VARIABLES: Set up various variables based on configuration data
218###############################################################################
219
Daniel Dunbara89194e2008-10-03 19:11:19 +0000220# Variable for if this make is for a "cleaning" target
221ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
222 IS_CLEANING_TARGET=1
223endif
224
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225#--------------------------------------------------------------------
226# Variables derived from configuration we are building
227#--------------------------------------------------------------------
228
229CPP.Defines :=
230# OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
231# this can be overridden on the make command line.
232ifneq ($(OS),MingW)
233 OPTIMIZE_OPTION := -O3
234else
235 OPTIMIZE_OPTION := -O2
236endif
237
238ifdef ENABLE_PROFILING
239 BuildMode := Profile
Gordon Henriksen09968862008-01-06 21:54:35 +0000240 CXX.Flags += $(OPTIMIZE_OPTION) -pg -g
241 C.Flags += $(OPTIMIZE_OPTION) -pg -g
242 LD.Flags += $(OPTIMIZE_OPTION) -pg -g
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243 KEEP_SYMBOLS := 1
244else
245 ifeq ($(ENABLE_OPTIMIZED),1)
246 BuildMode := Release
247 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
248 ifneq ($(OS),FreeBSD)
249 ifneq ($(OS),Darwin)
250 OmitFramePointer := -fomit-frame-pointer
251 endif
252 endif
253
254 # Darwin requires -fstrict-aliasing to be explicitly enabled.
255 ifeq ($(OS),Darwin)
Evan Cheng1bde8892008-06-05 23:00:08 +0000256 EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 endif
258
Gordon Henriksen09968862008-01-06 21:54:35 +0000259 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
260 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
261 LD.Flags += $(OPTIMIZE_OPTION)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 else
263 BuildMode := Debug
Gordon Henriksen09968862008-01-06 21:54:35 +0000264 CXX.Flags += -g
265 C.Flags += -g
266 LD.Flags += -g
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 KEEP_SYMBOLS := 1
268 endif
269endif
270
Daniel Dunbar886e1832008-09-02 17:35:16 +0000271#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
272# CXX.Flags += -fvisibility-inlines-hidden
273#endif
274
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275# IF REQUIRES_EH=1 is specified then don't disable exceptions
276ifndef REQUIRES_EH
277 CXX.Flags += -fno-exceptions
278endif
279
280# IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
281ifndef REQUIRES_RTTI
282# CXX.Flags += -fno-rtti
283endif
284
285# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
286# then disable assertions by defining the appropriate preprocessor symbols.
287ifdef DISABLE_ASSERTIONS
288 BuildMode := $(BuildMode)-Asserts
289 CPP.Defines += -DNDEBUG
290else
291 CPP.Defines += -D_DEBUG
292endif
293
Misha Brukman89fe5162009-01-08 02:11:55 +0000294# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
295# configured), then enable expensive checks by defining the
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296# appropriate preprocessor symbols.
297ifdef ENABLE_EXPENSIVE_CHECKS
298 BuildMode := $(BuildMode)+Checks
Duncan Sands871e55f2008-12-09 21:33:20 +0000299 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300endif
301
Nick Lewycky8d91e192009-02-26 07:44:16 +0000302# LOADABLE_MODULE implies several other things so we force them to be
303# defined/on.
304ifdef LOADABLE_MODULE
305 SHARED_LIBRARY := 1
306 DONT_BUILD_RELINKED := 1
307 LINK_LIBS_IN_SHARED := 1
308endif
309
310ifdef SHARED_LIBRARY
311 ENABLE_PIC := 1
312 PIC_FLAG = "(PIC)"
313endif
314
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315ifeq ($(ENABLE_PIC),1)
Nick Lewycky5b882f22009-02-21 08:41:09 +0000316 ifeq ($(LLVM_ON_WIN32),1)
317 # Nothing. Win32 defaults to PIC and warns when given -fPIC
318 else
319 ifeq ($(OS),Darwin)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000320 # Common symbols not allowed in dylib files
Nick Lewycky5b882f22009-02-21 08:41:09 +0000321 CXX.Flags += -fno-common
322 C.Flags += -fno-common
323 else
324 # Linux and others; pass -fPIC
325 CXX.Flags += -fPIC
326 C.Flags += -fPIC
327 endif
328 endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329endif
330
331CXX.Flags += $(CXXFLAGS) -Woverloaded-virtual
332C.Flags += $(CFLAGS)
333CPP.Defines += $(CPPFLAGS)
334CPP.BaseFlags += $(CPP.Defines)
335LD.Flags += $(LDFLAGS)
336AR.Flags := cru
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337
338# Make Floating point IEEE compliant on Alpha.
339ifeq ($(ARCH),Alpha)
340 CXX.Flags += -mieee
341 CPP.BaseFlags += -mieee
342ifeq ($(ENABLE_PIC),0)
343 CXX.Flags += -fPIC
344 CPP.BaseFlags += -fPIC
345endif
346endif
347
348ifeq ($(ARCH),Alpha)
349 LD.Flags += -Wl,--no-relax
350endif
351
352#--------------------------------------------------------------------
353# Directory locations
354#--------------------------------------------------------------------
Jim Grosbache4c032e2008-10-02 22:56:44 +0000355TargetMode :=
356ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000357 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
Jim Grosbache4c032e2008-10-02 22:56:44 +0000358endif
359
360ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000361ObjDir := $(ObjRootDir)
362LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
363ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
364ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
365LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
366LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
367LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368CFERuntimeLibDir := $(LLVMGCCDIR)/lib
369
370#--------------------------------------------------------------------
371# Full Paths To Compiled Tools and Utilities
372#--------------------------------------------------------------------
373EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
374Echo = @$(EchoCmd)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375ifndef LLVMAS
376LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
377endif
378ifndef TBLGEN
379 ifeq ($(LLVM_CROSS_COMPILING),1)
Anton Korobeynikov06565172008-11-10 07:33:13 +0000380 TBLGEN := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 else
382 TBLGEN := $(LLVMToolDir)/tblgen$(EXEEXT)
383 endif
384endif
Misha Brukman89fe5162009-01-08 02:11:55 +0000385LLVM_CONFIG := $(LLVMToolDir)/llvm-config
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386ifndef LLVMLD
387LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
388endif
389ifndef LLVMDIS
390LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
391endif
392ifndef LLI
393LLI := $(LLVMToolDir)/lli$(EXEEXT)
394endif
395ifndef LLC
396LLC := $(LLVMToolDir)/llc$(EXEEXT)
397endif
398ifndef LOPT
399LOPT := $(LLVMToolDir)/opt$(EXEEXT)
400endif
401ifndef LBUGPOINT
402LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
403endif
404ifndef LUPGRADE
405LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
406endif
407ifeq ($(LLVMGCC_MAJVERS),3)
408UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
409UPGRADE_LL = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
410LLVMGCCWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
411LLVMGXXWITHPATH := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
412else
413UPGRADE_MSG =
414UPGRADE_LL =
415LLVMGCCWITHPATH := $(LLVMGCC)
416LLVMGXXWITHPATH := $(LLVMGXX)
417endif
418
419#--------------------------------------------------------------------
420# Adjust to user's request
421#--------------------------------------------------------------------
422
Nick Lewycky8d91e192009-02-26 07:44:16 +0000423# Adjust LD.Flags depending on the kind of library that is to be built. Note
424# that if LOADABLE_MODULE is specified then the resulting shared library can
425# be opened with dlopen.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426ifdef LOADABLE_MODULE
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427 LD.Flags += -module
428endif
429
430ifdef SHARED_LIBRARY
Nick Lewycky8d91e192009-02-26 07:44:16 +0000431 LD.Flags += -Wl,-rpath -Wl,$(LibDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432endif
433
434ifdef TOOL_VERBOSE
435 C.Flags += -v
436 CXX.Flags += -v
437 LD.Flags += -v
438 VERBOSE := 1
439endif
440
441# Adjust settings for verbose mode
442ifndef VERBOSE
443 Verb := @
Reid Spencerdfb3d5b2007-07-23 08:20:46 +0000444 AR.Flags += >/dev/null 2>/dev/null
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
446else
Misha Brukman89fe5162009-01-08 02:11:55 +0000447 ConfigureScriptFLAGS :=
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448endif
449
450# By default, strip symbol information from executable
451ifndef KEEP_SYMBOLS
452 Strip := $(PLATFORMSTRIPOPTS)
453 StripWarnMsg := "(without symbols)"
454 Install.StripFlag += -s
455endif
456
457# Adjust linker flags for building an executable
Nick Lewycky324b1192009-02-26 08:03:36 +0000458ifneq ($(OS),Darwin)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459ifdef TOOLNAME
460ifdef EXAMPLE_TOOL
Nick Lewycky8d91e192009-02-26 07:44:16 +0000461 LD.Flags += -Wl,-rpath -Wl,$(ExmplDir) -export-dynamic
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462else
Nick Lewycky8d91e192009-02-26 07:44:16 +0000463 LD.Flags += -Wl,-rpath -Wl,$(ToolDir) -export-dynamic
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464endif
465endif
Nick Lewycky8d91e192009-02-26 07:44:16 +0000466endif
467
468ifeq ($(OS),Darwin)
Chris Lattner323808e2009-02-26 17:44:38 +0000469 DARWIN_VERSION := `sw_vers -productVersion`
470 SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress -bundle \
471 -mmacosx-version-min=$(DARWIN_VERSION)
472 CompileCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000473else
474 SharedLinkOptions=-shared
475endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476
477#----------------------------------------------------------
478# Options To Invoke Tools
479#----------------------------------------------------------
480
Chris Lattner323808e2009-02-26 17:44:38 +0000481CompileCommonOpts += -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482 -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
483
484ifeq ($(OS),HP-UX)
485 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
486endif
487
488# If we are building a universal binary on Mac OS/X, pass extra options. This
489# is useful to people that want to link the LLVM libraries into their universal
490# apps.
491#
492# The following can be optionally specified:
493# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
494# For Mac OS/X 10.4 Intel machines, the traditional one is:
495# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
496# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
497# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
498# i386/ppc only.
499ifdef UNIVERSAL
500 ifndef UNIVERSAL_ARCH
501 UNIVERSAL_ARCH := i386 ppc
502 endif
503 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
504 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
Chris Lattnerc372e1c2009-02-26 19:08:30 +0000505 Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 ifdef UNIVERSAL_SDK_PATH
507 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
Chris Lattnerc372e1c2009-02-26 19:08:30 +0000508 Relink.Flags += -isysroot $(UNIVERSAL_SDK_PATH)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509 endif
510
511 # Building universal cannot compute dependencies automatically.
512 DISABLE_AUTO_DEPENDENCIES=1
513endif
514
Chris Lattner35c997c2008-06-24 17:44:42 +0000515ifeq ($(OS),SunOS)
516CPP.BaseFlags += -include llvm/System/Solaris.h
517endif
518
Misha Brukman89fe5162009-01-08 02:11:55 +0000519LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
Dan Gohman5a5e6e92008-10-17 01:33:43 +0000520CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521# All -I flags should go here, so that they don't confuse llvm-config.
Duncan Sands3b960292008-01-28 17:38:30 +0000522CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
523 $(patsubst %,-I%/include,\
Chris Lattner6ee48752008-01-28 04:18:41 +0000524 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
525 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
526 $(CPP.BaseFlags)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527
Jim Grosbache4c032e2008-10-02 22:56:44 +0000528 ifeq ($(BUILD_COMPONENT), 1)
529 Compile.C = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
530 Compile.CXX = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
531 Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
532 Link = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
533 $(LD.Flags) $(Strip)
534 Relink = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
535 $(Relink.Flags)
536else
537 Compile.C = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
538 Compile.CXX = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
539 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
540 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
541 $(LD.Flags) $(Strip)
542 Relink = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
543 $(Relink.Flags)
544endif
545
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546BCCompile.C = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
547Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
548
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
550 $(CompileCommonOpts)
551
Misha Brukman89fe5162009-01-08 02:11:55 +0000552ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
553ScriptInstall = $(INSTALL) -m 0755
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554DataInstall = $(INSTALL) -m 0644
Chris Lattner1b0a3a12008-01-15 23:27:40 +0000555
556# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
557# paths. In this case, the SYSPATH function (defined in
558# Makefile.config) transforms Unix paths into Windows paths.
559TableGen = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
Mikhail Glushenkov3e6bf9a2009-01-09 16:31:01 +0000560 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
Chris Lattner1b0a3a12008-01-15 23:27:40 +0000561 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
562 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
563
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564Archive = $(AR) $(AR.Flags)
565LArchive = $(LLVMToolDir)/llvm-ar rcsf
566ifdef RANLIB
567Ranlib = $(RANLIB)
568else
569Ranlib = ranlib
570endif
571
572#----------------------------------------------------------
Misha Brukman89fe5162009-01-08 02:11:55 +0000573# Get the list of source files and compute object file
574# names from them.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575#----------------------------------------------------------
576
577ifndef SOURCES
578 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +0000579 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580else
581 Sources := $(SOURCES)
Misha Brukman89fe5162009-01-08 02:11:55 +0000582endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583
584ifdef BUILT_SOURCES
Chris Lattnerbfaed4c2009-01-02 07:16:45 +0000585Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586endif
587
588BaseNameSources := $(sort $(basename $(Sources)))
589
590ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
592
593###############################################################################
594# DIRECTORIES: Handle recursive descent of directory structure
595###############################################################################
596
597#---------------------------------------------------------
598# Provide rules to make install dirs. This must be early
599# in the file so they get built before dependencies
600#---------------------------------------------------------
601
Mike Stump98f72e02009-02-12 23:45:11 +0000602$(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
Mike Stumpf0feefd2009-01-22 03:24:22 +0000603 $(Verb) $(MKDIR) $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604
605# To create other directories, as needed, and timestamp their creation
606%/.dir:
607 $(Verb) $(MKDIR) $* > /dev/null
608 $(Verb) $(DATE) > $@
609
610.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
611.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
612
613#---------------------------------------------------------
614# Handle the DIRS options for sequential construction
615#---------------------------------------------------------
616
Misha Brukman89fe5162009-01-08 02:11:55 +0000617SubDirs :=
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618ifdef DIRS
619SubDirs += $(DIRS)
620
621ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
622$(RecursiveTargets)::
623 $(Verb) for dir in $(DIRS); do \
624 if [ ! -f $$dir/Makefile ]; then \
625 $(MKDIR) $$dir; \
626 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
627 fi; \
628 ($(MAKE) -C $$dir $@ ) || exit 1; \
629 done
630else
631$(RecursiveTargets)::
632 $(Verb) for dir in $(DIRS); do \
633 ($(MAKE) -C $$dir $@ ) || exit 1; \
634 done
635endif
636
637endif
638
639#---------------------------------------------------------
640# Handle the EXPERIMENTAL_DIRS options ensuring success
641# after each directory is built.
642#---------------------------------------------------------
643ifdef EXPERIMENTAL_DIRS
644$(RecursiveTargets)::
645 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
646 if [ ! -f $$dir/Makefile ]; then \
647 $(MKDIR) $$dir; \
648 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
649 fi; \
650 ($(MAKE) -C $$dir $@ ) || exit 0; \
651 done
652endif
653
654#-----------------------------------------------------------
Mike Stump0fec3192009-01-24 00:00:41 +0000655# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
656#-----------------------------------------------------------
657ifdef OPTIONAL_PARALLEL_DIRS
658 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
659endif
660
661#-----------------------------------------------------------
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662# Handle the PARALLEL_DIRS options for parallel construction
663#-----------------------------------------------------------
664ifdef PARALLEL_DIRS
665
666SubDirs += $(PARALLEL_DIRS)
667
668# Unfortunately, this list must be maintained if new recursive targets are added
669all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
670clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
671clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
672install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
673uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
674install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
675
676ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
677
678$(ParallelTargets) :
679 $(Verb) if [ ! -f $(@D)/Makefile ]; then \
680 $(MKDIR) $(@D); \
681 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
682 fi; \
683 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
684endif
685
686#---------------------------------------------------------
687# Handle the OPTIONAL_DIRS options for directores that may
688# or may not exist.
689#---------------------------------------------------------
690ifdef OPTIONAL_DIRS
691
692SubDirs += $(OPTIONAL_DIRS)
693
694ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
695$(RecursiveTargets)::
696 $(Verb) for dir in $(OPTIONAL_DIRS); do \
697 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
698 if [ ! -f $$dir/Makefile ]; then \
699 $(MKDIR) $$dir; \
700 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
701 fi; \
702 ($(MAKE) -C$$dir $@ ) || exit 1; \
703 fi \
704 done
705else
706$(RecursiveTargets)::
707 $(Verb) for dir in $(OPTIONAL_DIRS); do \
708 ($(MAKE) -C$$dir $@ ) || exit 1; \
709 done
710endif
711endif
712
713#---------------------------------------------------------
714# Handle the CONFIG_FILES options
715#---------------------------------------------------------
716ifdef CONFIG_FILES
717
718ifdef NO_INSTALL
719install-local::
720 $(Echo) Install circumvented with NO_INSTALL
721uninstall-local::
722 $(Echo) UnInstall circumvented with NO_INSTALL
723else
724install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
725 $(Echo) Installing Configuration Files To $(PROJ_etcdir)
726 $(Verb)for file in $(CONFIG_FILES); do \
727 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
728 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
729 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
730 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
731 else \
732 $(ECHO) Error: cannot find config file $${file}. ; \
733 fi \
734 done
735
736uninstall-local::
737 $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
738 $(Verb)for file in $(CONFIG_FILES); do \
739 $(RM) -f $(PROJ_etcdir)/$${file} ; \
740 done
741endif
742
743endif
744
745###############################################################################
746# Set up variables for building libararies
747###############################################################################
748
749#---------------------------------------------------------
750# Define various command line options pertaining to the
Misha Brukman89fe5162009-01-08 02:11:55 +0000751# libraries needed when linking. There are "Proj" libs
752# (defined by the user's project) and "LLVM" libs (defined
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753# by the LLVM project).
754#---------------------------------------------------------
755
756ifdef USEDLIBS
757ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
758ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
759ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
760ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
761endif
762
763ifdef LLVMLIBS
764LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
765LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
766LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
767LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
768endif
769
Daniel Dunbara89194e2008-10-03 19:11:19 +0000770ifndef IS_CLEANING_TARGET
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771ifdef LINK_COMPONENTS
772
773# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
774# clean in tools, then do a make in tools (instead of at the top level).
775$(LLVM_CONFIG):
776 @echo "*** llvm-config doesn't exist - rebuilding it."
777 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
Gabor Greif14c4c8e2008-02-27 13:34:15 +0000778
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
780
781ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
782ProjLibsPaths += $(LLVM_CONFIG) \
783 $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
784endif
785endif
786
787###############################################################################
788# Library Build Rules: Four ways to build a library
789###############################################################################
790
791#---------------------------------------------------------
792# Bytecode Module Targets:
793# If the user set MODULE_NAME then they want to build a
794# bytecode module from the sources. We compile all the
795# sources and link it together into a single bytecode
796# module.
797#---------------------------------------------------------
798
799ifdef MODULE_NAME
800ifeq ($(strip $(LLVMGCC)),)
801$(warning Modules require llvm-gcc but no llvm-gcc is available ****)
802else
803
804Module := $(LibDir)/$(MODULE_NAME).bc
Andrew Lenharthd0020772008-02-25 22:41:55 +0000805LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806
807
808ifdef EXPORTED_SYMBOL_FILE
809LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
810endif
811
812$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
813 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
814 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
815
816all-local:: $(Module)
817
818clean-local::
819ifneq ($(strip $(Module)),)
820 -$(Verb) $(RM) -f $(Module)
821endif
822
823ifdef BYTECODE_DESTINATION
824ModuleDestDir := $(BYTECODE_DESTINATION)
825else
826ModuleDestDir := $(PROJ_libdir)
827endif
828
829ifdef NO_INSTALL
830install-local::
831 $(Echo) Install circumvented with NO_INSTALL
832uninstall-local::
833 $(Echo) Uninstall circumvented with NO_INSTALL
834else
835DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
836
837install-module:: $(DestModule)
838install-local:: $(DestModule)
839
Misha Brukman89fe5162009-01-08 02:11:55 +0000840$(DestModule): $(ModuleDestDir) $(Module)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
842 $(Verb) $(DataInstall) $(Module) $(DestModule)
843
844uninstall-local::
845 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
846 -$(Verb) $(RM) -f $(DestModule)
847endif
848
849endif
850endif
851
852# if we're building a library ...
853ifdef LIBRARYNAME
854
855# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
856LIBRARYNAME := $(strip $(LIBRARYNAME))
857ifdef LOADABLE_MODULE
Nick Lewycky8d91e192009-02-26 07:44:16 +0000858LibName.A := $(LibDir)/$(LIBRARYNAME).a
859LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861LibName.A := $(LibDir)/lib$(LIBRARYNAME).a
Nick Lewycky8d91e192009-02-26 07:44:16 +0000862LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
863endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864LibName.O := $(LibDir)/$(LIBRARYNAME).o
865LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
866
867#---------------------------------------------------------
868# Shared Library Targets:
869# If the user asked for a shared library to be built
870# with the SHARED_LIBRARY variable, then we provide
871# targets for building them.
872#---------------------------------------------------------
873ifdef SHARED_LIBRARY
874
Nick Lewycky8d91e192009-02-26 07:44:16 +0000875all-local:: $(LibName.SO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000876
877ifdef LINK_LIBS_IN_SHARED
878ifdef LOADABLE_MODULE
879SharedLibKindMessage := "Loadable Module"
880else
881SharedLibKindMessage := "Shared Library"
882endif
Nick Lewycky8d91e192009-02-26 07:44:16 +0000883$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
885 $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000886 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
887 $(ProjLibsOptions) $(LLVMLibsOptions)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888else
Nick Lewycky8d91e192009-02-26 07:44:16 +0000889$(LibName.SO): $(ObjectsO) $(LibDir)/.dir
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000890 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000891 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000892endif
893
894clean-local::
Nick Lewycky8d91e192009-02-26 07:44:16 +0000895ifneq ($(strip $(LibName.SO)),)
896 -$(Verb) $(RM) -f $(LibName.SO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897endif
898
899ifdef NO_INSTALL
900install-local::
901 $(Echo) Install circumvented with NO_INSTALL
902uninstall-local::
903 $(Echo) Uninstall circumvented with NO_INSTALL
904else
905DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
906
907install-local:: $(DestSharedLib)
908
Nick Lewycky8d91e192009-02-26 07:44:16 +0000909$(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000910 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
Nick Lewycky8d91e192009-02-26 07:44:16 +0000911 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912
Misha Brukman89fe5162009-01-08 02:11:55 +0000913uninstall-local::
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
915 -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
916endif
917endif
918
919#---------------------------------------------------------
920# Bytecode Library Targets:
921# If the user asked for a bytecode library to be built
Misha Brukman89fe5162009-01-08 02:11:55 +0000922# with the BYTECODE_LIBRARY variable, then we provide
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923# targets for building them.
924#---------------------------------------------------------
925ifdef BYTECODE_LIBRARY
926ifeq ($(strip $(LLVMGCC)),)
927$(warning Bytecode libraries require llvm-gcc which could not be found ****)
928else
929
930all-local:: $(LibName.BCA)
931
932ifdef EXPORTED_SYMBOL_FILE
933BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
934 -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
935
936$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
937 $(LLVMToolDir)/llvm-ar
938 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
939 "(internalize)"
940 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
941 $(Verb) $(RM) -f $@
942 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
943else
944$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
945 $(LLVMToolDir)/llvm-ar
946 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
947 $(Verb) $(RM) -f $@
948 $(Verb) $(LArchive) $@ $(ObjectsBC)
949
950endif
951
952clean-local::
953ifneq ($(strip $(LibName.BCA)),)
954 -$(Verb) $(RM) -f $(LibName.BCA)
955endif
956
957ifdef BYTECODE_DESTINATION
958BytecodeDestDir := $(BYTECODE_DESTINATION)
959else
960BytecodeDestDir := $(PROJ_libdir)
961endif
962
963DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
964
965install-bytecode-local:: $(DestBytecodeLib)
966
967ifdef NO_INSTALL
968install-local::
969 $(Echo) Install circumvented with NO_INSTALL
970uninstall-local::
971 $(Echo) Uninstall circumvented with NO_INSTALL
972else
973install-local:: $(DestBytecodeLib)
974
Mike Stump98f72e02009-02-12 23:45:11 +0000975$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
977 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
978
979uninstall-local::
980 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
981 -$(Verb) $(RM) -f $(DestBytecodeLib)
982endif
983endif
984endif
985
986#---------------------------------------------------------
987# ReLinked Library Targets:
988# If the user explicitly requests a relinked library with
989# BUILD_RELINKED, provide it. Otherwise, if they specify
990# neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
991# them one.
992#---------------------------------------------------------
993ifndef BUILD_ARCHIVE
994ifndef DONT_BUILD_RELINKED
995BUILD_RELINKED = 1
996endif
997endif
998
999ifdef BUILD_RELINKED
1000
1001all-local:: $(LibName.O)
1002
1003$(LibName.O): $(ObjectsO) $(LibDir)/.dir
1004 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
Nick Lewycky14c68542009-02-26 08:48:14 +00001005 $(Verb) $(Relink) -Wl,-r -nodefaultlibs -nostdlib -nostartfiles -o $@ $(ObjectsO)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006
1007clean-local::
1008ifneq ($(strip $(LibName.O)),)
1009 -$(Verb) $(RM) -f $(LibName.O)
1010endif
1011
1012ifdef NO_INSTALL
1013install-local::
1014 $(Echo) Install circumvented with NO_INSTALL
1015uninstall-local::
1016 $(Echo) Uninstall circumvented with NO_INSTALL
1017else
1018DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
1019
1020install-local:: $(DestRelinkedLib)
1021
Mike Stump98f72e02009-02-12 23:45:11 +00001022$(DestRelinkedLib): $(LibName.O) $(PROJ_libdir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001024 $(Verb) $(INSTALL) $(LibName.O) $(DestRelinkedLib)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001025
1026uninstall-local::
1027 $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
1028 -$(Verb) $(RM) -f $(DestRelinkedLib)
1029endif
1030endif
1031
1032#---------------------------------------------------------
1033# Archive Library Targets:
Misha Brukman89fe5162009-01-08 02:11:55 +00001034# If the user wanted a regular archive library built,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035# then we provide targets for building them.
1036#---------------------------------------------------------
1037ifdef BUILD_ARCHIVE
1038
1039all-local:: $(LibName.A)
1040
1041$(LibName.A): $(ObjectsO) $(LibDir)/.dir
1042 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1043 -$(Verb) $(RM) -f $@
Bill Wendling3d6df102009-01-03 22:46:50 +00001044 $(Verb) $(Archive) $@ $(ObjectsO)
1045 $(Verb) $(Ranlib) $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046
1047clean-local::
1048ifneq ($(strip $(LibName.A)),)
1049 -$(Verb) $(RM) -f $(LibName.A)
1050endif
1051
1052ifdef NO_INSTALL
1053install-local::
1054 $(Echo) Install circumvented with NO_INSTALL
1055uninstall-local::
1056 $(Echo) Uninstall circumvented with NO_INSTALL
1057else
1058DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
1059
1060install-local:: $(DestArchiveLib)
1061
Mike Stump98f72e02009-02-12 23:45:11 +00001062$(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1064 $(Verb) $(MKDIR) $(PROJ_libdir)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001065 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066
1067uninstall-local::
1068 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1069 -$(Verb) $(RM) -f $(DestArchiveLib)
1070endif
1071endif
1072
1073# endif LIBRARYNAME
Misha Brukman89fe5162009-01-08 02:11:55 +00001074endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075
1076###############################################################################
1077# Tool Build Rules: Build executable tool based on TOOLNAME option
1078###############################################################################
1079
1080ifdef TOOLNAME
1081
1082#---------------------------------------------------------
1083# Set up variables for building a tool.
1084#---------------------------------------------------------
1085ifdef EXAMPLE_TOOL
1086ToolBuildPath := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1087else
1088ToolBuildPath := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1089endif
1090
1091#---------------------------------------------------------
Chris Lattner8b04ea72009-02-26 17:47:49 +00001092# Prune Exports
1093#---------------------------------------------------------
1094
1095# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1096# not exporting all of the weak symbols from the binary. This reduces dyld
1097# startup time by 4x on darwin in some cases.
1098ifdef TOOL_NO_EXPORTS
1099ifeq ($(OS),Darwin)
1100LD.Flags += -Wl,-exported_symbol -Wl,_main
1101endif
1102
1103ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
Chris Lattner7c024612009-02-26 18:38:40 +00001104LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
Chris Lattner8b04ea72009-02-26 17:47:49 +00001105endif
1106endif
1107
1108
1109#---------------------------------------------------------
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110# Provide targets for building the tools
1111#---------------------------------------------------------
1112all-local:: $(ToolBuildPath)
1113
1114clean-local::
1115ifneq ($(strip $(ToolBuildPath)),)
1116 -$(Verb) $(RM) -f $(ToolBuildPath)
1117endif
1118
1119ifdef EXAMPLE_TOOL
1120$(ToolBuildPath): $(ExmplDir)/.dir
1121else
1122$(ToolBuildPath): $(ToolDir)/.dir
1123endif
1124
1125$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1126 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001127 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1129 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
Misha Brukman89fe5162009-01-08 02:11:55 +00001130 $(StripWarnMsg)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131
1132ifdef NO_INSTALL
1133install-local::
1134 $(Echo) Install circumvented with NO_INSTALL
1135uninstall-local::
1136 $(Echo) Uninstall circumvented with NO_INSTALL
1137else
1138DestTool = $(PROJ_bindir)/$(TOOLNAME)
1139
1140install-local:: $(DestTool)
1141
Mike Stump98f72e02009-02-12 23:45:11 +00001142$(DestTool): $(ToolBuildPath) $(PROJ_bindir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143 $(Echo) Installing $(BuildMode) $(DestTool)
1144 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1145
1146uninstall-local::
1147 $(Echo) Uninstalling $(BuildMode) $(DestTool)
1148 -$(Verb) $(RM) -f $(DestTool)
1149endif
1150endif
1151
1152###############################################################################
Misha Brukman89fe5162009-01-08 02:11:55 +00001153# Object Build Rules: Build object files based on sources
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154###############################################################################
1155
1156# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1157ifeq ($(OS),HP-UX)
1158 DISABLE_AUTO_DEPENDENCIES=1
1159endif
1160
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161# Provide rule sets for when dependency generation is enabled
1162ifndef DISABLE_AUTO_DEPENDENCIES
1163
1164#---------------------------------------------------------
Nick Lewycky8d91e192009-02-26 07:44:16 +00001165# Create .o files in the ObjDir directory from the .cpp and .c files...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166#---------------------------------------------------------
1167
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001168DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
Nick Lewycky8d91e192009-02-26 07:44:16 +00001169 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
Gabor Greif14c4c8e2008-02-27 13:34:15 +00001170
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001171# If the build succeeded, move the dependency file over. If it failed, put an
1172# empty file there.
1173DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1174 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1175
Nick Lewycky8d91e192009-02-26 07:44:16 +00001176$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001178 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001179 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001180
Nick Lewycky8d91e192009-02-26 07:44:16 +00001181$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001183 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001184 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185
Nick Lewycky8d91e192009-02-26 07:44:16 +00001186$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001188 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
Chris Lattner87fd1ec2007-12-31 23:58:31 +00001189 $(DEPEND_MOVEFILE)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190
1191#---------------------------------------------------------
1192# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1193#---------------------------------------------------------
1194
1195$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1196 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1197 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1198 $< -o $@ -S -emit-llvm ; \
1199 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1200 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Misha Brukman89fe5162009-01-08 02:11:55 +00001201 $(call UPGRADE_MSG,$@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001202 $(call UPGRADE_LL,$@)
1203
1204$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1205 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1206 $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1207 $< -o $@ -S -emit-llvm ; \
1208 then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1209 else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
Misha Brukman89fe5162009-01-08 02:11:55 +00001210 $(call UPGRADE_MSG,$@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001211 $(call UPGRADE_LL,$@)
1212
1213$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1214 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1215 $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1216 $< -o $@ -S -emit-llvm ; \
1217 then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1218 else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
Misha Brukman89fe5162009-01-08 02:11:55 +00001219 $(call UPGRADE_MSG,$@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 $(call UPGRADE_LL,$@)
1221
1222# Provide alternate rule sets if dependencies are disabled
1223else
1224
Nick Lewycky8d91e192009-02-26 07:44:16 +00001225$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001226 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001227 $(Compile.CXX) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001228
Nick Lewycky8d91e192009-02-26 07:44:16 +00001229$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001231 $(Compile.CXX) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001232
Nick Lewycky8d91e192009-02-26 07:44:16 +00001233$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001235 $(Compile.C) $< -o $@
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001236
1237$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1238 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1239 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Misha Brukman89fe5162009-01-08 02:11:55 +00001240 $(call UPGRADE_MSG,$@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001241 $(call UPGRADE_LL,$@)
1242
1243$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1244 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1245 $(BCCompile.CXX) $< -o $@ -S -emit-llvm
Misha Brukman89fe5162009-01-08 02:11:55 +00001246 $(call UPGRADE_MSG,$@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001247 $(call UPGRADE_LL,$@)
1248
1249$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1250 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1251 $(BCCompile.C) $< -o $@ -S -emit-llvm
Misha Brukman89fe5162009-01-08 02:11:55 +00001252 $(call UPGRADE_MSG,@)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253 $(call UPGRADE_LL,@)
1254
1255endif
1256
1257
1258## Rules for building preprocessed (.i/.ii) outputs.
1259$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1260 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1261 $(Verb) $(Preprocess.CXX) $< -o $@
1262
1263$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1264 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1265 $(Verb) $(Preprocess.CXX) $< -o $@
1266
1267$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1268 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1269 $(Verb) $(Preprocess.C) $< -o $@
1270
1271
1272$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1273 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001274 $(Compile.CXX) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001275
1276$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1277 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001278 $(Compile.CXX) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279
1280$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1281 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
Nick Lewycky8d91e192009-02-26 07:44:16 +00001282 $(Compile.C) $< -o $@ -S
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283
1284
1285# make the C and C++ compilers strip debug info out of bytecode libraries.
1286ifdef DEBUG_RUNTIME
1287$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1288 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1289 $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1290else
1291$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1292 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1293 $(Verb) $(LLVMAS) $< -o - | \
1294 $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1295endif
1296
1297
1298#---------------------------------------------------------
1299# Provide rule to build .bc files from .ll sources,
1300# regardless of dependencies
1301#---------------------------------------------------------
1302$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1303 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1304 $(Verb) $(LLVMAS) $< -f -o $@
1305
1306###############################################################################
1307# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1308###############################################################################
1309
1310ifdef TARGET
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001311TABLEGEN_INC_FILES_COMMON = 1
1312endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001314ifdef LLVMC_BUILD_AUTOGENERATED_INC
1315TABLEGEN_INC_FILES_COMMON = 1
1316endif
1317
1318ifdef TABLEGEN_INC_FILES_COMMON
1319
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1321INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1322.PRECIOUS: $(INCTMPFiles) $(INCFiles)
1323
1324# All of these files depend on tblgen and the .td files.
1325$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1326
Misha Brukman89fe5162009-01-08 02:11:55 +00001327# INCFiles rule: All of the tblgen generated files are emitted to
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001328# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1329# us to only "touch" the real file if the contents of it change. IOW, if
Daniel Dunbar90f3e7f2008-11-03 17:33:36 +00001330# tblgen is modified, all of the .inc.tmp files are regenerated, but no
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001331# dependencies of the .inc files are, unless the contents of the .inc file
1332# changes.
1333$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1334 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1335
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001336endif # TABLEGEN_INC_FILES_COMMON
1337
1338ifdef TARGET
1339
1340TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1341 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1342 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1343 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1344 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1345 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1346 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1347
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001348$(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1349$(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1350 $(Echo) "Building $(<F) register names with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001351 $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001352
1353$(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1354$(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1355 $(Echo) "Building $(<F) register information header with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001356 $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001357
1358$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1359$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1360 $(Echo) "Building $(<F) register info implementation with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001361 $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001362
1363$(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1364$(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1365 $(Echo) "Building $(<F) instruction names with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001366 $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367
1368$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1369$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1370 $(Echo) "Building $(<F) instruction information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001371 $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001372
1373$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1374$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1375 $(Echo) "Building $(<F) assembly writer with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001376 $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001377
1378$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1379$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1380 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
Misha Brukman89fe5162009-01-08 02:11:55 +00001381 $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001382
1383$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1384$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1385 $(Echo) "Building $(<F) code emitter with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001386 $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001387
1388$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1389$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
Dan Gohmanb75dead2008-08-13 20:19:35 +00001390 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001391 $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001392
Dan Gohmanb75dead2008-08-13 20:19:35 +00001393$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1394$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1395 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1396 $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1397
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001398$(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1399$(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1400 $(Echo) "Building $(<F) subtarget information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001401 $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001402
1403$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1404$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1405 $(Echo) "Building $(<F) calling convention information with tblgen"
Chris Lattner1b0a3a12008-01-15 23:27:40 +00001406 $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001407
Dale Johannesenfe5921a2009-02-05 01:49:45 +00001408$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1409$(ObjDir)/%GenIntrinsics.inc.tmp : Intrinsics%.td $(ObjDir)/.dir
1410 $(Echo) "Building $(<F) calling convention information with tblgen"
1411 $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1412
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001413clean-local::
1414 -$(Verb) $(RM) -f $(INCFiles)
1415
Mikhail Glushenkov72145e32009-03-02 09:42:59 +00001416endif # TARGET
1417
1418ifdef LLVMC_BUILD_AUTOGENERATED_INC
1419
1420LLVMCPluginSrc := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td))
1421
1422TDFiles := $(LLVMCPluginSrc) \
1423 $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1424
1425$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1426 $(TBLGEN) $(TD_COMMON)
1427 $(Echo) "Building LLVMC configuration library with tblgen"
1428 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1429
1430endif # LLVMC_BUILD_AUTOGENERATED_INC
1431
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001432
1433###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001434# OTHER RULES: Other rules needed
1435###############################################################################
1436
1437# To create postscript files from dot files...
1438ifneq ($(DOT),false)
1439%.ps: %.dot
1440 $(DOT) -Tps < $< > $@
1441else
1442%.ps: %.dot
1443 $(Echo) "Cannot build $@: The program dot is not installed"
1444endif
1445
1446# This rules ensures that header files that are removed still have a rule for
1447# which they can be "generated." This allows make to ignore them and
1448# reproduce the dependency lists.
1449%.h:: ;
1450%.hpp:: ;
1451
1452# Define clean-local to clean the current directory. Note that this uses a
Misha Brukman89fe5162009-01-08 02:11:55 +00001453# very conservative approach ensuring that empty variables do not cause
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454# errors or disastrous removal.
1455clean-local::
Jim Grosbache4c032e2008-10-02 22:56:44 +00001456ifneq ($(strip $(ObjRootDir)),)
1457 -$(Verb) $(RM) -rf $(ObjRootDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001458endif
1459 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1460ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1461 -$(Verb) $(RM) -f *$(SHLIBEXT)
1462endif
1463
1464clean-all-local::
1465 -$(Verb) $(RM) -rf Debug Release Profile
1466
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001467
1468###############################################################################
1469# DEPENDENCIES: Include the dependency files if we should
1470###############################################################################
1471ifndef DISABLE_AUTO_DEPENDENCIES
1472
1473# If its not one of the cleaning targets
Daniel Dunbara89194e2008-10-03 19:11:19 +00001474ifndef IS_CLEANING_TARGET
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001475
1476# Get the list of dependency files
1477DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1478DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1479
Reid Spencerdfb3d5b2007-07-23 08:20:46 +00001480-include $(DependFiles) ""
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001481
1482endif
1483
Misha Brukman89fe5162009-01-08 02:11:55 +00001484endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001485
1486###############################################################################
1487# CHECK: Running the test suite
1488###############################################################################
1489
1490check::
1491 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1492 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1493 $(EchoCmd) Running test suite ; \
1494 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1495 TESTSUITE=$(TESTSUITE) ; \
1496 else \
1497 $(EchoCmd) No Makefile in test directory ; \
1498 fi ; \
1499 else \
1500 $(EchoCmd) No test directory ; \
1501 fi
1502
1503###############################################################################
Bill Wendling2e3646a2009-01-04 23:12:21 +00001504# UNITTESTS: Running the unittests test suite
1505###############################################################################
1506
1507unittests::
1508 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1509 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1510 $(EchoCmd) Running unittests test suite ; \
1511 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests ; \
1512 else \
1513 $(EchoCmd) No Makefile in unittests directory ; \
1514 fi ; \
1515 else \
1516 $(EchoCmd) No unittests directory ; \
1517 fi
1518
1519###############################################################################
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520# DISTRIBUTION: Handle construction of a distribution tarball
1521###############################################################################
1522
1523#------------------------------------------------------------------------
1524# Define distribution related variables
1525#------------------------------------------------------------------------
1526DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1527DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1528TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1529DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1530DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1531DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1532DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1533 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1534 Makefile.config.in configure autoconf
1535DistOther := $(notdir $(wildcard \
1536 $(PROJ_SRC_DIR)/*.h \
1537 $(PROJ_SRC_DIR)/*.td \
1538 $(PROJ_SRC_DIR)/*.def \
1539 $(PROJ_SRC_DIR)/*.ll \
1540 $(PROJ_SRC_DIR)/*.in))
1541DistSubDirs := $(SubDirs)
1542DistSources = $(Sources) $(EXTRA_DIST)
1543DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1544
1545#------------------------------------------------------------------------
1546# We MUST build distribution with OBJ_DIR != SRC_DIR
1547#------------------------------------------------------------------------
1548ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1549dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1550 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1551
1552else
1553
1554#------------------------------------------------------------------------
1555# Prevent attempt to run dist targets from anywhere but the top level
1556#------------------------------------------------------------------------
1557ifneq ($(LEVEL),.)
1558dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1559 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1560else
1561
1562#------------------------------------------------------------------------
1563# Provide the top level targets
1564#------------------------------------------------------------------------
1565
1566dist-gzip:: $(DistTarGZip)
1567
1568$(DistTarGZip) : $(TopDistDir)/.makedistdir
1569 $(Echo) Packing gzipped distribution tar file.
1570 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1571 $(GZIP) -c > "$(DistTarGZip)"
1572
1573dist-bzip2:: $(DistTarBZ2)
1574
1575$(DistTarBZ2) : $(TopDistDir)/.makedistdir
1576 $(Echo) Packing bzipped distribution tar file.
1577 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1578 $(BZIP2) -c >$(DistTarBZ2)
1579
1580dist-zip:: $(DistZip)
1581
1582$(DistZip) : $(TopDistDir)/.makedistdir
1583 $(Echo) Packing zipped distribution file.
1584 $(Verb) rm -f $(DistZip)
1585 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1586
Misha Brukman89fe5162009-01-08 02:11:55 +00001587dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001588 $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1589
1590DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1591
1592dist-check:: $(DistTarGZip)
1593 $(Echo) Checking distribution tar file.
1594 $(Verb) if test -d $(DistCheckDir) ; then \
1595 $(RM) -rf $(DistCheckDir) ; \
1596 fi
1597 $(Verb) $(MKDIR) $(DistCheckDir)
1598 $(Verb) cd $(DistCheckDir) && \
1599 $(MKDIR) $(DistCheckDir)/build && \
1600 $(MKDIR) $(DistCheckDir)/install && \
1601 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1602 cd build && \
1603 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1604 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1605 $(MAKE) all && \
1606 $(MAKE) check && \
Bill Wendling2e3646a2009-01-04 23:12:21 +00001607 $(MAKE) unittests && \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001608 $(MAKE) install && \
1609 $(MAKE) uninstall && \
1610 $(MAKE) dist-clean && \
1611 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1612
1613dist-clean::
1614 $(Echo) Cleaning distribution files
1615 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1616 $(DistCheckDir)
1617
1618endif
1619
1620#------------------------------------------------------------------------
1621# Provide the recursive distdir target for building the distribution directory
1622#------------------------------------------------------------------------
1623distdir: $(DistDir)/.makedistdir
1624$(DistDir)/.makedistdir: $(DistSources)
1625 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1626 if test -d "$(DistDir)" ; then \
1627 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
1628 exit 1 ; \
1629 fi ; \
1630 $(EchoCmd) Removing old $(DistDir) ; \
1631 $(RM) -rf $(DistDir); \
1632 $(EchoCmd) Making 'all' to verify build ; \
1633 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1634 fi
1635 $(Echo) Building Distribution Directory $(DistDir)
Misha Brukman89fe5162009-01-08 02:11:55 +00001636 $(Verb) $(MKDIR) $(DistDir)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001637 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1638 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1639 for file in $(DistFiles) ; do \
1640 case "$$file" in \
1641 $(PROJ_SRC_DIR)/*) \
1642 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1643 ;; \
1644 $(PROJ_SRC_ROOT)/*) \
1645 file=`echo "$$file" | \
1646 sed "s#^$$srcrootstrip/##"` \
1647 ;; \
1648 esac; \
1649 if test -f "$(PROJ_SRC_DIR)/$$file" || \
1650 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1651 from_dir="$(PROJ_SRC_DIR)" ; \
1652 elif test -f "$$file" || test -d "$$file" ; then \
1653 from_dir=. ; \
1654 fi ; \
1655 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1656 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1657 to_dir="$(DistDir)/$$dir"; \
1658 $(MKDIR) "$$to_dir" ; \
1659 else \
1660 to_dir="$(DistDir)"; \
1661 fi; \
1662 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1663 if test -n "$$mid_dir" ; then \
1664 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1665 fi ; \
1666 if test -d "$$from_dir/$$file"; then \
1667 if test -d "$(PROJ_SRC_DIR)/$$file" && \
1668 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1669 cd $(PROJ_SRC_DIR) ; \
1670 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1671 ( cd $$to_dir ; $(TAR) xf - ) ; \
1672 cd $(PROJ_OBJ_DIR) ; \
1673 else \
1674 cd $$from_dir ; \
1675 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1676 ( cd $$to_dir ; $(TAR) xf - ) ; \
1677 cd $(PROJ_OBJ_DIR) ; \
1678 fi; \
1679 elif test -f "$$from_dir/$$file" ; then \
1680 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1681 elif test -L "$$from_dir/$$file" ; then \
1682 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1683 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1684 $(EchoCmd) "===== WARNING: Distribution Source " \
1685 "$$from_dir/$$file Not Found!" ; \
1686 elif test "$(Verb)" != '@' ; then \
1687 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1688 fi; \
1689 done
1690 $(Verb) for subdir in $(DistSubDirs) ; do \
1691 if test "$$subdir" \!= "." ; then \
1692 new_distdir="$(DistDir)/$$subdir" ; \
1693 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1694 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1695 DistDir="$$new_distdir" distdir ) || exit 1; \
1696 fi; \
1697 done
1698 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1699 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1700 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1701 -name .svn \) -print` ;\
1702 $(MAKE) dist-hook ; \
1703 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1704 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1705 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1706 -o ! -type d ! -perm -444 -exec \
1707 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1708 || chmod -R a+r $(DistDir) ; \
1709 fi
1710
1711# This is invoked by distdir target, define it as a no-op to avoid errors if not
1712# defined by user.
1713dist-hook::
1714
1715endif
1716
1717###############################################################################
1718# TOP LEVEL - targets only to apply at the top level directory
1719###############################################################################
1720
1721ifeq ($(LEVEL),.)
1722
1723#------------------------------------------------------------------------
1724# Install support for the project's include files:
1725#------------------------------------------------------------------------
1726ifdef NO_INSTALL
1727install-local::
1728 $(Echo) Install circumvented with NO_INSTALL
1729uninstall-local::
1730 $(Echo) Uninstall circumvented with NO_INSTALL
1731else
1732install-local::
1733 $(Echo) Installing include files
1734 $(Verb) $(MKDIR) $(PROJ_includedir)
1735 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1736 cd $(PROJ_SRC_ROOT)/include && \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +00001737 for hdr in `find . -type f '!' '(' -name '*~' \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001738 -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1739 grep -v .svn` ; do \
1740 instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1741 if test \! -d "$$instdir" ; then \
1742 $(EchoCmd) Making install directory $$instdir ; \
1743 $(MKDIR) $$instdir ;\
1744 fi ; \
1745 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1746 done ; \
1747 fi
1748ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1749 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1750 cd $(PROJ_OBJ_ROOT)/include && \
1751 for hdr in `find . -type f -print | grep -v CVS` ; do \
1752 $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1753 done ; \
1754 fi
1755endif
1756
1757uninstall-local::
1758 $(Echo) Uninstalling include files
1759 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1760 cd $(PROJ_SRC_ROOT)/include && \
1761 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
Chris Lattnerbfaed4c2009-01-02 07:16:45 +00001762 '!' '(' -name '*~' -o -name '.#*' \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001763 -o -name '*.in' ')' -print ')' | \
1764 grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1765 cd $(PROJ_SRC_ROOT)/include && \
1766 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1767 -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1768 fi
1769endif
1770endif
1771
1772check-line-length:
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001773 @echo searching for overlength lines in files: $(Sources)
1774 @echo
1775 @echo
Gabor Greif3033d032008-08-28 22:32:39 +00001776 egrep -n '.{81}' $(Sources) /dev/null
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001777
1778check-for-tabs:
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001779 @echo searching for tabs in files: $(Sources)
1780 @echo
1781 @echo
Gabor Greif3033d032008-08-28 22:32:39 +00001782 egrep -n ' ' $(Sources) /dev/null
Gabor Greifb91ea9d2008-05-15 10:04:30 +00001783
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001784check-footprint:
1785 @ls -l $(LibDir) | awk '\
1786 BEGIN { sum = 0; } \
1787 { sum += $$5; } \
1788 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1789 @ls -l $(ToolDir) | awk '\
1790 BEGIN { sum = 0; } \
1791 { sum += $$5; } \
1792 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1793#------------------------------------------------------------------------
1794# Print out the directories used for building
1795#------------------------------------------------------------------------
1796printvars::
1797 $(Echo) "BuildMode : " '$(BuildMode)'
1798 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1799 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1800 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1801 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1802 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1803 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1804 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
1805 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
1806 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
1807 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
1808 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
1809 $(Echo) "UserTargets : " '$(UserTargets)'
1810 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1811 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1812 $(Echo) "ObjDir : " '$(ObjDir)'
1813 $(Echo) "LibDir : " '$(LibDir)'
1814 $(Echo) "ToolDir : " '$(ToolDir)'
1815 $(Echo) "ExmplDir : " '$(ExmplDir)'
1816 $(Echo) "Sources : " '$(Sources)'
1817 $(Echo) "TDFiles : " '$(TDFiles)'
1818 $(Echo) "INCFiles : " '$(INCFiles)'
1819 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
1820 $(Echo) "PreConditions: " '$(PreConditions)'
1821 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
1822 $(Echo) "Compile.C : " '$(Compile.C)'
1823 $(Echo) "Archive : " '$(Archive)'
1824 $(Echo) "YaccFiles : " '$(YaccFiles)'
1825 $(Echo) "LexFiles : " '$(LexFiles)'
1826 $(Echo) "Module : " '$(Module)'
1827 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1828 $(Echo) "SubDirs : " '$(SubDirs)'
1829 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1830 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
Daniel Dunbar190b3d52009-02-21 20:42:39 +00001831
1832###
1833# Debugging
1834
1835# General debugging rule, use 'make print-XXX' to print the
1836# definition, value and origin of XXX.
Mikhail Glushenkov5f7ba0f2009-03-02 09:04:13 +00001837print-%:
Daniel Dunbar190b3d52009-02-21 20:42:39 +00001838 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))