blob: 6e047247c616b11158cf11a1b7fd0a828601680f [file] [log] [blame]
Daniel Dunbar2532fa22011-10-18 23:10:47 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
3# The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8#===------------------------------------------------------------------------===#
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 \
23 unitcheck
24LocalTargets := all-local clean-local clean-all-local check-local \
25 install-local printvars uninstall-local \
26 install-bytecode-local
27TopLevelTargets := check dist dist-check dist-clean dist-gzip dist-bzip2 \
28 dist-zip unittests
29UserTargets := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30InternalTargets := preconditions distdir dist-hook
31
32################################################################################
33# INITIALIZATION: Basic things the makefile needs
34################################################################################
35
36#--------------------------------------------------------------------
37# Set the VPATH so that we can find source files.
38#--------------------------------------------------------------------
39VPATH=$(PROJ_SRC_DIR)
40
41#--------------------------------------------------------------------
42# Reset the list of suffixes we know how to build.
43#--------------------------------------------------------------------
44.SUFFIXES:
45.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
46.SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
47
48#--------------------------------------------------------------------
49# Mark all of these targets as phony to avoid implicit rule search
50#--------------------------------------------------------------------
51.PHONY: $(UserTargets) $(InternalTargets)
52
53#--------------------------------------------------------------------
54# Make sure all the user-target rules are double colon rules and
55# they are defined first.
56#--------------------------------------------------------------------
57
58$(UserTargets)::
59
60################################################################################
61# PRECONDITIONS: that which must be built/checked first
62################################################################################
63
64SrcMakefiles := $(filter %Makefile %Makefile.tests,\
65 $(wildcard $(PROJ_SRC_DIR)/Makefile*))
66ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
67ConfigureScript := $(PROJ_SRC_ROOT)/configure
68ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
69MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
70MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
71MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
72MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
73PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
74ifneq ($(MakefileCommonIn),)
75PreConditions += $(MakefileCommon)
76endif
77
78ifneq ($(MakefileConfigIn),)
79PreConditions += $(MakefileConfig)
80endif
81
82preconditions: $(PreConditions)
83
84#------------------------------------------------------------------------
85# Make sure the BUILT_SOURCES are built first
86#------------------------------------------------------------------------
87$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
88
89clean-all-local::
90ifneq ($(strip $(BUILT_SOURCES)),)
91 -$(Verb) $(RM) -f $(BUILT_SOURCES)
92endif
93
94ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
95spotless:
96 $(Verb) if test -x config.status ; then \
97 $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
98 $(MKDIR) .spotless.save ; \
99 $(MV) config.status .spotless.save ; \
100 $(MV) mklib .spotless.save ; \
101 $(MV) projects .spotless.save ; \
102 $(RM) -rf * ; \
103 $(MV) .spotless.save/config.status . ; \
104 $(MV) .spotless.save/mklib . ; \
105 $(MV) .spotless.save/projects . ; \
106 $(RM) -rf .spotless.save ; \
107 $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
108 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
109 $(ConfigStatusScript) ; \
110 else \
111 $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
112 fi
113else
114spotless:
115 $(EchoCmd) "spotless target not supported for objdir == srcdir"
116endif
117
118$(BUILT_SOURCES) : $(ObjMakefiles)
119
120#------------------------------------------------------------------------
121# Make sure we're not using a stale configuration
122#------------------------------------------------------------------------
123reconfigure:
124 $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
125 $(Verb) cd $(PROJ_OBJ_ROOT) && \
126 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
127 $(ConfigStatusScript)
128
129.PRECIOUS: $(ConfigStatusScript)
130$(ConfigStatusScript): $(ConfigureScript)
131 $(Echo) Reconfiguring with $<
132 $(Verb) cd $(PROJ_OBJ_ROOT) && \
133 $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
134 $(ConfigStatusScript)
135
136#------------------------------------------------------------------------
137# Make sure the configuration makefile is up to date
138#------------------------------------------------------------------------
139ifneq ($(MakefileConfigIn),)
140$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
141 $(Echo) Regenerating $@
142 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
143endif
144
145ifneq ($(MakefileCommonIn),)
146$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
147 $(Echo) Regenerating $@
148 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
149endif
150
151#------------------------------------------------------------------------
152# If the Makefile in the source tree has been updated, copy it over into the
153# build tree. But, only do this if the source and object makefiles differ
154#------------------------------------------------------------------------
155ifndef PROJ_MAKEFILE
156PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
157endif
158
159ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
160
161Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
162 $(Echo) "Updating Makefile"
163 $(Verb) $(MKDIR) $(@D)
164 $(Verb) $(CP) -f $< $@
165
166# Copy the Makefile.* files unless we're in the root directory which avoids
167# the copying of Makefile.config.in or other things that should be explicitly
168# taken care of.
169$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
170 @case '$?' in \
171 *Makefile.rules) ;; \
172 *.in) ;; \
173 *) $(EchoCmd) "Updating $(@F)" ; \
174 $(MKDIR) $(@D) ; \
175 $(CP) -f $< $@ ;; \
176 esac
177
178endif
179
180#------------------------------------------------------------------------
181# Set up the basic dependencies
182#------------------------------------------------------------------------
183$(UserTargets):: $(PreConditions)
184
185all:: all-local
186clean:: clean-local
187clean-all:: clean-local clean-all-local
188install:: install-local
189uninstall:: uninstall-local
190install-local:: all-local
191install-bytecode:: install-bytecode-local
192
193###############################################################################
194# VARIABLES: Set up various variables based on configuration data
195###############################################################################
196
197# Variable for if this make is for a "cleaning" target
198ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
199 IS_CLEANING_TARGET=1
200endif
201
202#--------------------------------------------------------------------
203# Variables derived from configuration we are building
204#--------------------------------------------------------------------
205
206CPP.Defines :=
207ifeq ($(ENABLE_OPTIMIZED),1)
208 BuildMode := Release
209 # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
210 ifneq ($(HOST_OS),FreeBSD)
211 ifneq ($(HOST_OS),Darwin)
212 OmitFramePointer := -fomit-frame-pointer
213 endif
214 endif
215
216 # Darwin requires -fstrict-aliasing to be explicitly enabled.
217 # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
218 # with -fstrict-aliasing and ipa-type-escape radr://6756684
219 #ifeq ($(HOST_OS),Darwin)
220 # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
221 #endif
222 CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
223 C.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
224 LD.Flags += $(OPTIMIZE_OPTION)
225 ifdef DEBUG_SYMBOLS
226 BuildMode := $(BuildMode)+Debug
227 CXX.Flags += -g
228 C.Flags += -g
229 LD.Flags += -g
230 KEEP_SYMBOLS := 1
231 endif
232else
233 ifdef NO_DEBUG_SYMBOLS
234 BuildMode := Unoptimized
235 CXX.Flags +=
236 C.Flags +=
237 LD.Flags +=
238 KEEP_SYMBOLS := 1
239 else
240 BuildMode := Debug
241 CXX.Flags += -g
242 C.Flags += -g
243 LD.Flags += -g
244 KEEP_SYMBOLS := 1
245 endif
246endif
247
Eric Christopherb2bc6e42012-03-26 02:09:01 +0000248ifeq ($(ENABLE_LIBCPP),1)
249 CXX.Flags += -stdlib=libc++
250 LD.Flags += -stdlib=libc++
251endif
252
Daniel Dunbar2532fa22011-10-18 23:10:47 +0000253ifeq ($(ENABLE_PROFILING),1)
254 BuildMode := $(BuildMode)+Profile
255 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
256 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
257 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
258 KEEP_SYMBOLS := 1
259endif
260
261#ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
262# CXX.Flags += -fvisibility-inlines-hidden
263#endif
264
265ifdef ENABLE_EXPENSIVE_CHECKS
266 # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
267 # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
268 REQUIRES_RTTI := 1
269endif
270
271# IF REQUIRES_EH=1 is specified then don't disable exceptions
272ifndef REQUIRES_EH
273 CXX.Flags += -fno-exceptions
274else
275 # If the library requires EH, it also requires RTTI.
276 REQUIRES_RTTI := 1
277endif
278
279ifdef REQUIRES_FRAME_POINTER
280 CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
281 C.Flags := $(filter-out -fomit-frame-pointer,$(C.Flags))
282 LD.Flags := $(filter-out -fomit-frame-pointer,$(LD.Flags))
283endif
284
285# If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
286ifneq ($(REQUIRES_RTTI), 1)
287 CXX.Flags += -fno-rtti
288endif
289
290ifeq ($(ENABLE_COVERAGE),1)
291 BuildMode := $(BuildMode)+Coverage
292 CXX.Flags += -ftest-coverage -fprofile-arcs
293 C.Flags += -ftest-coverage -fprofile-arcs
294endif
295
296# If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
297# then disable assertions by defining the appropriate preprocessor symbols.
298ifeq ($(DISABLE_ASSERTIONS),1)
299 CPP.Defines += -DNDEBUG
300else
301 BuildMode := $(BuildMode)+Asserts
302 CPP.Defines += -D_DEBUG
303endif
304
305# If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
306# configured), then enable expensive checks by defining the
307# appropriate preprocessor symbols.
308ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
309 BuildMode := $(BuildMode)+Checks
310 CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
311endif
312
313# LOADABLE_MODULE implies several other things so we force them to be
314# defined/on.
315ifdef LOADABLE_MODULE
316 SHARED_LIBRARY := 1
317 LINK_LIBS_IN_SHARED := 1
318endif
319
320ifdef SHARED_LIBRARY
321 ENABLE_PIC := 1
322 PIC_FLAG = "(PIC)"
323endif
324
325ifeq ($(ENABLE_PIC),1)
326 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
327 # Nothing. Win32 defaults to PIC and warns when given -fPIC
328 else
329 ifeq ($(HOST_OS),Darwin)
330 # Common symbols not allowed in dylib files
331 CXX.Flags += -fno-common
332 C.Flags += -fno-common
333 else
334 # Linux and others; pass -fPIC
335 CXX.Flags += -fPIC
336 C.Flags += -fPIC
337 endif
338 endif
339else
340 ifeq ($(HOST_OS),Darwin)
341 CXX.Flags += -mdynamic-no-pic
342 C.Flags += -mdynamic-no-pic
343 endif
344endif
345
346# Support makefile variable to disable any kind of timestamp/non-deterministic
347# info from being used in the build.
348ifeq ($(ENABLE_TIMESTAMPS),1)
349 DOTDIR_TIMESTAMP_COMMAND := $(DATE)
350else
351 DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
352endif
353
354ifeq ($(HOST_OS),MingW)
355 # Work around PR4957
356 CPP.Defines += -D__NO_CTYPE_INLINE
357 ifeq ($(LLVM_CROSS_COMPILING),1)
358 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
359 ifdef TOOLNAME
360 LD.Flags += -Wl,--allow-multiple-definition
361 endif
362 endif
363endif
364
365CXX.Flags += -Woverloaded-virtual
366CPP.BaseFlags += $(CPP.Defines)
367AR.Flags := cru
368
369# Make Floating point IEEE compliant on Alpha.
370ifeq ($(ARCH),Alpha)
371 CXX.Flags += -mieee
372 CPP.BaseFlags += -mieee
373ifeq ($(ENABLE_PIC),0)
374 CXX.Flags += -fPIC
375 CPP.BaseFlags += -fPIC
376endif
377
378 LD.Flags += -Wl,--no-relax
379endif
380
381# GNU ld/PECOFF accepts but ignores them below;
382# --version-script
383# --export-dynamic
384# --rpath
385# FIXME: autoconf should be aware of them.
386ifneq (,$(filter $(HOST_OS),Cygwin MingW))
387 HAVE_LINK_VERSION_SCRIPT := 0
388 RPATH :=
389 RDYNAMIC := -Wl,--export-all-symbols
390endif
391
392#--------------------------------------------------------------------
393# Directory locations
394#--------------------------------------------------------------------
395TargetMode :=
396ifeq ($(LLVM_CROSS_COMPILING),1)
397 BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
398endif
399
400ObjRootDir := $(PROJ_OBJ_DIR)/$(BuildMode)
401ObjDir := $(ObjRootDir)
402LibDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
403ToolDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
404ExmplDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
405LLVMLibDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
406LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
407LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
408
409#--------------------------------------------------------------------
410# Locations of shared libraries
411#--------------------------------------------------------------------
412
413SharedPrefix := lib
414SharedLibDir := $(LibDir)
415LLVMSharedLibDir := $(LLVMLibDir)
416
417# Win32.DLL prefers to be located on the "PATH" of binaries.
418ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
419 SharedLibDir := $(ToolDir)
420 LLVMSharedLibDir := $(LLVMToolDir)
421
422 ifeq ($(HOST_OS),Cygwin)
423 SharedPrefix := cyg
424 else
425 SharedPrefix :=
426 endif
427endif
428
429#--------------------------------------------------------------------
430# LLVM Capable Compiler
431#--------------------------------------------------------------------
432
433ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
434 LLVMCC := $(LLVMGCC)
435 LLVMCXX := $(LLVMGXX)
436else
437 ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
438 ifneq ($(CLANGPATH),)
439 LLVMCC := $(CLANGPATH)
440 LLVMCXX := $(CLANGXXPATH)
441 else
442 ifeq ($(ENABLE_BUILT_CLANG),1)
443 LLVMCC := $(LLVMToolDir)/clang
444 LLVMCXX := $(LLVMToolDir)/clang++
445 endif
446 endif
447 endif
448endif
449
450#--------------------------------------------------------------------
451# Full Paths To Compiled Tools and Utilities
452#--------------------------------------------------------------------
453EchoCmd = $(ECHO) llvm[$(MAKELEVEL)]:
454Echo = @$(EchoCmd)
455ifndef LLVMAS
456LLVMAS := $(LLVMToolDir)/llvm-as$(EXEEXT)
457endif
458ifndef LLVM_TBLGEN
459 ifeq ($(LLVM_CROSS_COMPILING),1)
460 LLVM_TBLGEN := $(BuildLLVMToolDir)/llvm-tblgen$(BUILD_EXEEXT)
461 else
462 LLVM_TBLGEN := $(LLVMToolDir)/llvm-tblgen$(EXEEXT)
463 endif
464endif
465LLVM_CONFIG := $(LLVMToolDir)/llvm-config
466ifndef LLVMLD
467LLVMLD := $(LLVMToolDir)/llvm-ld$(EXEEXT)
468endif
469ifndef LLVMDIS
470LLVMDIS := $(LLVMToolDir)/llvm-dis$(EXEEXT)
471endif
472ifndef LLI
473LLI := $(LLVMToolDir)/lli$(EXEEXT)
474endif
475ifndef LLC
476LLC := $(LLVMToolDir)/llc$(EXEEXT)
477endif
478ifndef LOPT
479LOPT := $(LLVMToolDir)/opt$(EXEEXT)
480endif
481ifndef LBUGPOINT
482LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
483endif
484
485#--------------------------------------------------------------------
486# Adjust to user's request
487#--------------------------------------------------------------------
488
489ifeq ($(HOST_OS),Darwin)
490 DARWIN_VERSION := `sw_vers -productVersion`
491 # Strip a number like 10.4.7 to 10.4
492 DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
493 # Get "4" out of 10.4 for later pieces in the makefile.
494 DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
495
496 LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
497 SharedLinkOptions := -dynamiclib
498 ifneq ($(ARCH),ARM)
499 SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
500 endif
501else
502 SharedLinkOptions=-shared
503endif
504
505ifeq ($(TARGET_OS),Darwin)
506 ifneq ($(ARCH),ARM)
507 TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
508 endif
509endif
510
511ifdef SHARED_LIBRARY
512ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
513ifneq ($(HOST_OS),Darwin)
514 LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
515endif
516endif
517endif
518
519ifdef TOOL_VERBOSE
520 C.Flags += -v
521 CXX.Flags += -v
522 LD.Flags += -v
523 VERBOSE := 1
524endif
525
526# Adjust settings for verbose mode
527ifndef VERBOSE
528 Verb := @
529 AR.Flags += >/dev/null 2>/dev/null
530 ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
531else
532 ConfigureScriptFLAGS :=
533endif
534
535# By default, strip symbol information from executable
536ifndef KEEP_SYMBOLS
537 Strip := $(PLATFORMSTRIPOPTS)
538 StripWarnMsg := "(without symbols)"
539 Install.StripFlag += -s
540endif
541
542ifdef TOOL_NO_EXPORTS
543 DynamicFlags :=
544else
545 DynamicFlag := $(RDYNAMIC)
546endif
547
548# Adjust linker flags for building an executable
549ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
550ifneq ($(HOST_OS), Darwin)
551ifdef TOOLNAME
552 LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
553 ifdef EXAMPLE_TOOL
554 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
555 else
556 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
557 endif
558endif
559else
560ifneq ($(DARWIN_MAJVERS),4)
561 LD.Flags += $(RPATH) -Wl,@executable_path/../lib
562endif
563endif
564endif
565
566
567#----------------------------------------------------------
568# Options To Invoke Tools
569#----------------------------------------------------------
570
571ifdef EXTRA_LD_OPTIONS
572LD.Flags += $(EXTRA_LD_OPTIONS)
573endif
574
575ifndef NO_PEDANTIC
576CompileCommonOpts += -pedantic -Wno-long-long
577endif
578CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
Rafael Espindola9993a3a2012-02-28 23:32:06 +0000579 $(EXTRA_OPTIONS) $(COVERED_SWITCH_DEFAULT)
Daniel Dunbar2532fa22011-10-18 23:10:47 +0000580# Enable cast-qual for C++; the workaround is to use const_cast.
581CXX.Flags += -Wcast-qual
582
583ifeq ($(HOST_OS),HP-UX)
584 CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
585endif
586
587# If we are building a universal binary on Mac OS/X, pass extra options. This
588# is useful to people that want to link the LLVM libraries into their universal
589# apps.
590#
591# The following can be optionally specified:
592# UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
593# For Mac OS/X 10.4 Intel machines, the traditional one is:
594# UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
595# UNIVERSAL_ARCH can be optionally specified to be a list of architectures
596# to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64". This defaults to
597# i386/ppc only.
598ifdef UNIVERSAL
599 ifndef UNIVERSAL_ARCH
600 UNIVERSAL_ARCH := i386 ppc
601 endif
602 UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
603 CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
604 ifdef UNIVERSAL_SDK_PATH
605 CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
606 endif
607
608 # Building universal cannot compute dependencies automatically.
609 DISABLE_AUTO_DEPENDENCIES=1
610else
611 ifeq ($(TARGET_OS),Darwin)
612 ifeq ($(ARCH),x86_64)
613 TargetCommonOpts = -m64
614 else
615 ifeq ($(ARCH),x86)
616 TargetCommonOpts = -m32
617 endif
618 endif
619 endif
620endif
621
622ifeq ($(HOST_OS),SunOS)
623CPP.BaseFlags += -include llvm/Support/Solaris.h
624endif
625
626ifeq ($(HOST_OS),AuroraUX)
627CPP.BaseFlags += -include llvm/Support/Solaris.h
628endif # !HOST_OS - AuroraUX.
629
630LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
631CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
632# All -I flags should go here, so that they don't confuse llvm-config.
633CPP.Flags += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
634 $(patsubst %,-I%/include,\
635 $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
636 $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
637 $(CPP.BaseFlags)
638
639# SHOW_DIAGNOSTICS support.
640ifeq ($(SHOW_DIAGNOSTICS),1)
641 Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
642 CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
643else
644 Compile.Wrapper :=
645endif
646
647ifeq ($(BUILD_COMPONENT), 1)
648 Compile.C = $(Compile.Wrapper) \
649 $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
650 $(TargetCommonOpts) $(CompileCommonOpts) -c
651 Compile.CXX = $(Compile.Wrapper) \
652 $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
653 $(CPPFLAGS) \
654 $(TargetCommonOpts) $(CompileCommonOpts) -c
655 Preprocess.CXX= $(Compile.Wrapper) \
656 $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
657 $(CompileCommonOpts) $(CXX.Flags) -E
658 Link = $(Compile.Wrapper) \
659 $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
660 $(LD.Flags) $(LDFLAGS) \
661 $(TargetCommonOpts) $(CompileCommonOpts) $(Strip)
662else
663 Compile.C = $(Compile.Wrapper) \
664 $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
665 $(TargetCommonOpts) $(CompileCommonOpts) -c
666 Compile.CXX = $(Compile.Wrapper) \
667 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
668 $(TargetCommonOpts) $(CompileCommonOpts) -c
669 Preprocess.CXX= $(Compile.Wrapper) \
670 $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
671 $(CompileCommonOpts) $(CXX.Flags) -E
672 Link = $(Compile.Wrapper) \
673 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
674 $(LDFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) $(Strip)
675endif
676
677BCCompile.C = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
678 $(TargetCommonOpts) $(CompileCommonOpts)
679Preprocess.C = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
680 $(TargetCommonOpts) $(CompileCommonOpts) -E
681
682BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
683 $(TargetCommonOpts) $(CompileCommonOpts)
684
685ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
686ScriptInstall = $(INSTALL) -m 0755
687DataInstall = $(INSTALL) -m 0644
688
689# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
690# paths. In this case, the SYSPATH function (defined in
691# Makefile.config) transforms Unix paths into Windows paths.
692TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
693 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
694 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
695 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
696LLVMTableGen = $(LLVM_TBLGEN) $(TableGen.Flags)
697
698Archive = $(AR) $(AR.Flags)
699LArchive = $(LLVMToolDir)/llvm-ar rcsf
700ifdef RANLIB
701Ranlib = $(RANLIB)
702else
703Ranlib = ranlib
704endif
705
706AliasTool = ln -s
707
708#----------------------------------------------------------
709# Get the list of source files and compute object file
710# names from them.
711#----------------------------------------------------------
712
713ifndef SOURCES
714 Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
715 $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
716else
717 Sources := $(SOURCES)
718endif
719
720ifdef BUILT_SOURCES
721Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
722endif
723
724BaseNameSources := $(sort $(basename $(Sources)))
725
726ObjectsO := $(BaseNameSources:%=$(ObjDir)/%.o)
727ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
728
729#----------------------------------------------------------
730# For Mingw MSYS bash and Python/w32:
731#
732# $(ECHOPATH) prints DOSish pathstring.
733# ex) $(ECHOPATH) /include/sys/types.h
734# --> C:/mingw/include/sys/types.h
735# built-in "echo" does not transform path to DOSish path.
736#
737# FIXME: It would not be needed when MSYS's python
738# were provided.
739#----------------------------------------------------------
740
741ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
742 ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
743else
744 ECHOPATH := $(Verb)$(ECHO)
745endif
746
747###############################################################################
748# DIRECTORIES: Handle recursive descent of directory structure
749###############################################################################
750
751#---------------------------------------------------------
752# Provide rules to make install dirs. This must be early
753# in the file so they get built before dependencies
754#---------------------------------------------------------
755
756$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
757 $(Verb) $(MKDIR) $@
758
759# To create other directories, as needed, and timestamp their creation
760%/.dir:
761 $(Verb) $(MKDIR) $* > /dev/null
762 $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
763
764.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
765.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
766
767#---------------------------------------------------------
768# Handle the DIRS options for sequential construction
769#---------------------------------------------------------
770
771SubDirs :=
772ifdef DIRS
773SubDirs += $(DIRS)
774
775ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
776$(RecursiveTargets)::
777 $(Verb) for dir in $(DIRS); do \
778 if ([ ! -f $$dir/Makefile ] || \
779 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
780 $(MKDIR) $$dir; \
781 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
782 fi; \
783 ($(MAKE) -C $$dir $@ ) || exit 1; \
784 done
785else
786$(RecursiveTargets)::
787 $(Verb) for dir in $(DIRS); do \
788 ($(MAKE) -C $$dir $@ ) || exit 1; \
789 done
790endif
791
792endif
793
794#---------------------------------------------------------
795# Handle the EXPERIMENTAL_DIRS options ensuring success
796# after each directory is built.
797#---------------------------------------------------------
798ifdef EXPERIMENTAL_DIRS
799$(RecursiveTargets)::
800 $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
801 if ([ ! -f $$dir/Makefile ] || \
802 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
803 $(MKDIR) $$dir; \
804 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
805 fi; \
806 ($(MAKE) -C $$dir $@ ) || exit 0; \
807 done
808endif
809
810#-----------------------------------------------------------
811# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
812#-----------------------------------------------------------
813ifdef OPTIONAL_PARALLEL_DIRS
814 PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
815endif
816
817#-----------------------------------------------------------
818# Handle the PARALLEL_DIRS options for parallel construction
819#-----------------------------------------------------------
820ifdef PARALLEL_DIRS
821
822SubDirs += $(PARALLEL_DIRS)
823
824# Unfortunately, this list must be maintained if new recursive targets are added
825all :: $(addsuffix /.makeall ,$(PARALLEL_DIRS))
826clean :: $(addsuffix /.makeclean ,$(PARALLEL_DIRS))
827clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
828install :: $(addsuffix /.makeinstall ,$(PARALLEL_DIRS))
829uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
830install-bytecode :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
831unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
832
833ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
834
835$(ParallelTargets) :
836 $(Verb) if ([ ! -f $(@D)/Makefile ] || \
837 command test $(@D)/Makefile -ot \
838 $(PROJ_SRC_DIR)/$(@D)/Makefile ); then \
839 $(MKDIR) $(@D); \
840 $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
841 fi; \
842 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
843endif
844
845#---------------------------------------------------------
846# Handle the OPTIONAL_DIRS options for directores that may
847# or may not exist.
848#---------------------------------------------------------
849ifdef OPTIONAL_DIRS
850
851SubDirs += $(OPTIONAL_DIRS)
852
853ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
854$(RecursiveTargets)::
855 $(Verb) for dir in $(OPTIONAL_DIRS); do \
856 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
857 if ([ ! -f $$dir/Makefile ] || \
858 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
859 $(MKDIR) $$dir; \
860 $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
861 fi; \
862 ($(MAKE) -C$$dir $@ ) || exit 1; \
863 fi \
864 done
865else
866$(RecursiveTargets)::
867 $(Verb) for dir in $(OPTIONAL_DIRS); do \
868 if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
869 ($(MAKE) -C$$dir $@ ) || exit 1; \
870 fi \
871 done
872endif
873endif
874
875#---------------------------------------------------------
876# Handle the CONFIG_FILES options
877#---------------------------------------------------------
878ifdef CONFIG_FILES
879
880ifdef NO_INSTALL
881install-local::
882 $(Echo) Install circumvented with NO_INSTALL
883uninstall-local::
884 $(Echo) UnInstall circumvented with NO_INSTALL
885else
886install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
887 $(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
888 $(Verb)for file in $(CONFIG_FILES); do \
889 if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
890 $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
891 elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
892 $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
893 else \
894 $(ECHO) Error: cannot find config file $${file}. ; \
895 fi \
896 done
897
898uninstall-local::
899 $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
900 $(Verb)for file in $(CONFIG_FILES); do \
901 $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
902 done
903endif
904
905endif
906
907###############################################################################
908# Set up variables for building libraries
909###############################################################################
910
911#---------------------------------------------------------
912# Define various command line options pertaining to the
913# libraries needed when linking. There are "Proj" libs
914# (defined by the user's project) and "LLVM" libs (defined
915# by the LLVM project).
916#---------------------------------------------------------
917
918ifdef USEDLIBS
919ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
920ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o, $(ProjLibsOptions))
921ProjUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
922ProjLibsPaths := $(addprefix $(LibDir)/,$(ProjUsedLibs))
923endif
924
925ifdef LLVMLIBS
926LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
927LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
928LLVMUsedLibs := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
929LLVMLibsPaths := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
930endif
931
932# Loadable module for Win32 requires all symbols resolved for linking.
933# Then all symbols in LLVM.dll will be available.
934ifeq ($(ENABLE_SHARED),1)
935 ifdef LOADABLE_MODULE
936 ifneq (,$(filter $(HOST_OS),Cygwin MingW))
937 LINK_COMPONENTS += all
938 endif
939 endif
940endif
941
942ifndef IS_CLEANING_TARGET
943ifdef LINK_COMPONENTS
944
945# If LLVM_CONFIG doesn't exist, build it. This can happen if you do a make
946# clean in tools, then do a make in tools (instead of at the top level).
947$(LLVM_CONFIG):
948 @echo "*** llvm-config doesn't exist - rebuilding it."
949 @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
950
951$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
952
953ifeq ($(ENABLE_SHARED), 1)
954# We can take the "auto-import" feature to get rid of using dllimport.
955ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
956LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
957 -L $(SharedLibDir)
958endif
959LLVMLibsOptions += -lLLVM-$(LLVMVersion)
960LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
961else
962
963ifndef NO_LLVM_CONFIG
964LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
965ifeq ($(LLVMConfigLibs),Error)
966$(error llvm-config --libs failed)
967endif
968LLVMLibsOptions += $(LLVMConfigLibs)
969LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
970ifeq ($(LLVMConfigLibfiles),Error)
971$(error llvm-config --libfiles failed)
972endif
973LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
974endif
975
976endif
977endif
978endif
979
980# Set up the library exports file.
981ifdef EXPORTED_SYMBOL_FILE
982
983# First, set up the native export file, which may differ from the source
984# export file.
985
986ifeq ($(HOST_OS),Darwin)
987# Darwin convention prefixes symbols with underscores.
988NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
989$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
990 $(Verb) sed -e 's/^/_/' < $< > $@
991clean-local::
992 -$(Verb) $(RM) -f $(NativeExportsFile)
993else
994ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
995# Gold and BFD ld require a version script rather than a plain list.
996NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
997$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
998 $(Verb) echo "{" > $@
999 $(Verb) grep -q "\<" $< && echo " global:" >> $@ || :
1000 $(Verb) sed -e 's/$$/;/' -e 's/^/ /' < $< >> $@
1001ifneq ($(HOST_OS),OpenBSD)
1002 $(Verb) echo " local: *;" >> $@
1003endif
1004 $(Verb) echo "};" >> $@
1005clean-local::
1006 -$(Verb) $(RM) -f $(NativeExportsFile)
1007else
1008ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1009# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
1010NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
1011$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1012 $(Echo) Generating $(notdir $@)
1013 $(Verb) $(ECHO) "EXPORTS" > $@
1014 $(Verb) $(CAT) $< >> $@
1015clean-local::
1016 -$(Verb) $(RM) -f $(NativeExportsFile)
1017else
1018# Default behavior: just use the exports file verbatim.
1019NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
1020endif
1021endif
1022endif
1023
1024# Now add the linker command-line options to use the native export file.
1025
1026# Darwin
1027ifeq ($(HOST_OS),Darwin)
1028LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
1029endif
1030
1031# gold, bfd ld, etc.
1032ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1033LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
1034endif
1035
1036# Windows
1037ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1038# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1039SharedLinkOptions += $(NativeExportsFile)
1040endif
1041
1042endif
1043
1044###############################################################################
1045# Library Build Rules: Four ways to build a library
1046###############################################################################
1047
1048#---------------------------------------------------------
1049# Bytecode Module Targets:
1050# If the user set MODULE_NAME then they want to build a
1051# bytecode module from the sources. We compile all the
1052# sources and link it together into a single bytecode
1053# module.
1054#---------------------------------------------------------
1055
1056ifdef MODULE_NAME
1057ifeq ($(strip $(LLVMCC)),)
1058$(warning Modules require LLVM capable compiler but none is available ****)
1059else
1060
1061Module := $(LibDir)/$(MODULE_NAME).bc
1062LinkModule := $(LLVMLD) -r
1063
1064
1065ifdef EXPORTED_SYMBOL_FILE
1066LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1067endif
1068
1069$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
1070 $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
1071 $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1072
1073all-local:: $(Module)
1074
1075clean-local::
1076ifneq ($(strip $(Module)),)
1077 -$(Verb) $(RM) -f $(Module)
1078endif
1079
1080ifdef BYTECODE_DESTINATION
1081ModuleDestDir := $(BYTECODE_DESTINATION)
1082else
1083ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
1084endif
1085
1086ifdef NO_INSTALL
1087install-local::
1088 $(Echo) Install circumvented with NO_INSTALL
1089uninstall-local::
1090 $(Echo) Uninstall circumvented with NO_INSTALL
1091else
1092DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1093
1094install-module:: $(DestModule)
1095install-local:: $(DestModule)
1096
1097$(DestModule): $(ModuleDestDir) $(Module)
1098 $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
1099 $(Verb) $(DataInstall) $(Module) $(DestModule)
1100
1101uninstall-local::
1102 $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1103 -$(Verb) $(RM) -f $(DestModule)
1104endif
1105
1106endif
1107endif
1108
1109# if we're building a library ...
1110ifdef LIBRARYNAME
1111
1112# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
1113LIBRARYNAME := $(strip $(LIBRARYNAME))
1114ifdef LOADABLE_MODULE
1115BaseLibName.A := $(LIBRARYNAME).a
1116BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
1117else
1118BaseLibName.A := lib$(LIBRARYNAME).a
1119BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
1120endif
1121LibName.A := $(LibDir)/$(BaseLibName.A)
1122LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
1123LibName.O := $(LibDir)/$(LIBRARYNAME).o
1124LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
1125
1126#---------------------------------------------------------
1127# Shared Library Targets:
1128# If the user asked for a shared library to be built
1129# with the SHARED_LIBRARY variable, then we provide
1130# targets for building them.
1131#---------------------------------------------------------
1132ifdef SHARED_LIBRARY
1133
1134all-local:: $(LibName.SO)
1135
1136ifdef EXPORTED_SYMBOL_FILE
1137$(LibName.SO): $(NativeExportsFile)
1138endif
1139
1140ifdef LINK_LIBS_IN_SHARED
1141ifdef LOADABLE_MODULE
1142SharedLibKindMessage := "Loadable Module"
1143SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
1144else
1145SharedLibKindMessage := "Shared Library"
1146endif
1147$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
1148 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1149 $(notdir $@)
1150 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
1151 $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
1152else
1153$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
1154 $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
1155 $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
1156endif
1157
1158clean-local::
1159ifneq ($(strip $(LibName.SO)),)
1160 -$(Verb) $(RM) -f $(LibName.SO)
1161endif
1162
1163ifdef NO_INSTALL
1164install-local::
1165 $(Echo) Install circumvented with NO_INSTALL
1166uninstall-local::
1167 $(Echo) Uninstall circumvented with NO_INSTALL
1168else
1169
1170# Win32.DLL prefers to be located on the "PATH" of binaries.
1171ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1172DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
1173else
1174DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
1175endif
1176DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
1177
1178install-local:: $(DestSharedLib)
1179
1180$(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
1181 $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
1182 $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
1183
1184uninstall-local::
1185 $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
1186 -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
1187endif
1188endif
1189
1190#---------------------------------------------------------
1191# Bytecode Library Targets:
1192# If the user asked for a bytecode library to be built
1193# with the BYTECODE_LIBRARY variable, then we provide
1194# targets for building them.
1195#---------------------------------------------------------
1196ifdef BYTECODE_LIBRARY
1197ifeq ($(strip $(LLVMCC)),)
1198$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
1199else
1200
1201all-local:: $(LibName.BCA)
1202
1203ifdef EXPORTED_SYMBOL_FILE
1204BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1205
1206$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
1207 $(LLVMToolDir)/llvm-ar
1208 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1209 "(internalize)"
1210 $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
1211 $(Verb) $(RM) -f $@
1212 $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
1213else
1214$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
1215 $(LLVMToolDir)/llvm-ar
1216 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
1217 $(Verb) $(RM) -f $@
1218 $(Verb) $(LArchive) $@ $(ObjectsBC)
1219
1220endif
1221
1222clean-local::
1223ifneq ($(strip $(LibName.BCA)),)
1224 -$(Verb) $(RM) -f $(LibName.BCA)
1225endif
1226
1227ifdef BYTECODE_DESTINATION
1228BytecodeDestDir := $(BYTECODE_DESTINATION)
1229else
1230BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
1231endif
1232
1233DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
1234
1235install-bytecode-local:: $(DestBytecodeLib)
1236
1237ifdef NO_INSTALL
1238install-local::
1239 $(Echo) Install circumvented with NO_INSTALL
1240uninstall-local::
1241 $(Echo) Uninstall circumvented with NO_INSTALL
1242else
1243install-local:: $(DestBytecodeLib)
1244
1245$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
1246 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1247 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1248
1249uninstall-local::
1250 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1251 -$(Verb) $(RM) -f $(DestBytecodeLib)
1252endif
1253endif
1254endif
1255
1256#---------------------------------------------------------
1257# Library Targets:
1258# If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1259# building an archive.
1260#---------------------------------------------------------
1261ifndef NO_BUILD_ARCHIVE
1262ifndef BUILD_ARCHIVE
1263ifndef LOADABLE_MODULE
1264BUILD_ARCHIVE = 1
1265endif
1266endif
1267endif
1268
1269#---------------------------------------------------------
1270# Archive Library Targets:
1271# If the user wanted a regular archive library built,
1272# then we provide targets for building them.
1273#---------------------------------------------------------
1274ifdef BUILD_ARCHIVE
1275
1276all-local:: $(LibName.A)
1277
1278$(LibName.A): $(ObjectsO) $(LibDir)/.dir
1279 $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1280 -$(Verb) $(RM) -f $@
1281 $(Verb) $(Archive) $@ $(ObjectsO)
1282 $(Verb) $(Ranlib) $@
1283
1284clean-local::
1285ifneq ($(strip $(LibName.A)),)
1286 -$(Verb) $(RM) -f $(LibName.A)
1287endif
1288
1289ifdef NO_INSTALL
1290install-local::
1291 $(Echo) Install circumvented with NO_INSTALL
1292uninstall-local::
1293 $(Echo) Uninstall circumvented with NO_INSTALL
1294else
1295ifdef NO_INSTALL_ARCHIVES
1296install-local::
1297 $(Echo) Install circumvented with NO_INSTALL
1298uninstall-local::
1299 $(Echo) Uninstall circumvented with NO_INSTALL
1300else
1301DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
1302
1303install-local:: $(DestArchiveLib)
1304
1305$(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
1306 $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1307 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
1308 $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1309
1310uninstall-local::
1311 $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1312 -$(Verb) $(RM) -f $(DestArchiveLib)
1313endif
1314endif
1315endif
1316
1317# endif LIBRARYNAME
1318endif
1319
1320###############################################################################
1321# Tool Build Rules: Build executable tool based on TOOLNAME option
1322###############################################################################
1323
1324ifdef TOOLNAME
1325
1326#---------------------------------------------------------
1327# Set up variables for building a tool.
1328#---------------------------------------------------------
1329TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
1330ifdef EXAMPLE_TOOL
1331ToolBuildPath := $(ExmplDir)/$(TOOLEXENAME)
1332else
1333ToolBuildPath := $(ToolDir)/$(TOOLEXENAME)
1334endif
1335
1336# TOOLALIAS is a name to symlink (or copy) the tool to.
1337ifdef TOOLALIAS
1338ifdef EXAMPLE_TOOL
1339ToolAliasBuildPath := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1340else
1341ToolAliasBuildPath := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1342endif
1343endif
1344
1345#---------------------------------------------------------
1346# Prune Exports
1347#---------------------------------------------------------
1348
1349# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1350# not exporting all of the weak symbols from the binary. This reduces dyld
1351# startup time by 4x on darwin in some cases.
1352ifdef TOOL_NO_EXPORTS
1353ifeq ($(HOST_OS),Darwin)
1354
1355# Tiger tools don't support this.
1356ifneq ($(DARWIN_MAJVERS),4)
1357LD.Flags += -Wl,-exported_symbol,_main
1358endif
1359endif
1360
1361ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
1362ifneq ($(ARCH), Mips)
1363 LD.Flags += -Wl,--version-script=$(PROJ_SRC_ROOT)/autoconf/ExportMap.map
1364endif
1365endif
1366endif
1367
1368#---------------------------------------------------------
1369# Tool Order File Support
1370#---------------------------------------------------------
1371
1372ifeq ($(HOST_OS),Darwin)
1373ifdef TOOL_ORDER_FILE
1374
1375LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1376
1377endif
1378endif
1379
1380#---------------------------------------------------------
1381# Tool Version Info Support
1382#---------------------------------------------------------
1383
1384ifeq ($(HOST_OS),Darwin)
1385ifdef TOOL_INFO_PLIST
1386
1387LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1388
1389$(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1390
1391$(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
1392 $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1393 $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1394 -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1395 -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1396 -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1397 $< > $@
1398
1399endif
1400endif
1401
1402#---------------------------------------------------------
1403# Provide targets for building the tools
1404#---------------------------------------------------------
1405all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
1406
1407clean-local::
1408ifneq ($(strip $(ToolBuildPath)),)
1409 -$(Verb) $(RM) -f $(ToolBuildPath)
1410endif
1411ifneq ($(strip $(ToolAliasBuildPath)),)
1412 -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1413endif
1414
1415ifdef EXAMPLE_TOOL
1416$(ToolBuildPath): $(ExmplDir)/.dir
1417else
1418$(ToolBuildPath): $(ToolDir)/.dir
1419endif
1420
1421$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1422 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1423 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1424 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1425 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1426 $(StripWarnMsg)
1427
1428ifneq ($(strip $(ToolAliasBuildPath)),)
1429$(ToolAliasBuildPath): $(ToolBuildPath)
1430 $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1431 $(Verb) $(RM) -f $(ToolAliasBuildPath)
1432 $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
1433 $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
1434 $(StripWarnMsg)
1435endif
1436
1437ifdef NO_INSTALL
1438install-local::
1439 $(Echo) Install circumvented with NO_INSTALL
1440uninstall-local::
1441 $(Echo) Uninstall circumvented with NO_INSTALL
1442else
1443DestTool = $(DESTDIR)$(PROJ_bindir)/$(TOOLEXENAME)
1444
1445install-local:: $(DestTool)
1446
1447$(DestTool): $(ToolBuildPath) $(DESTDIR)$(PROJ_bindir)
1448 $(Echo) Installing $(BuildMode) $(DestTool)
1449 $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1450
1451uninstall-local::
1452 $(Echo) Uninstalling $(BuildMode) $(DestTool)
1453 -$(Verb) $(RM) -f $(DestTool)
1454
1455# TOOLALIAS install.
1456ifdef TOOLALIAS
1457DestToolAlias = $(DESTDIR)$(PROJ_bindir)/$(TOOLALIAS)$(EXEEXT)
1458
1459install-local:: $(DestToolAlias)
1460
1461$(DestToolAlias): $(DestTool)
1462 $(Echo) Installing $(BuildMode) $(DestToolAlias)
1463 $(Verb) $(RM) -f $(DestToolAlias)
1464 $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1465
1466uninstall-local::
1467 $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1468 -$(Verb) $(RM) -f $(DestToolAlias)
1469endif
1470
1471endif
1472endif
1473
1474###############################################################################
1475# Object Build Rules: Build object files based on sources
1476###############################################################################
1477
1478# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1479ifeq ($(HOST_OS),HP-UX)
1480 DISABLE_AUTO_DEPENDENCIES=1
1481endif
1482
1483# Provide rule sets for when dependency generation is enabled
1484ifndef DISABLE_AUTO_DEPENDENCIES
1485
1486#---------------------------------------------------------
1487# Create .o files in the ObjDir directory from the .cpp and .c files...
1488#---------------------------------------------------------
1489
1490DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1491 -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1492
1493# If the build succeeded, move the dependency file over, otherwise
1494# remove it.
1495DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1496 else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1497
1498$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1499 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1500 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1501 $(DEPEND_MOVEFILE)
1502
1503$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1504 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1505 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1506 $(DEPEND_MOVEFILE)
1507
1508$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1509 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1510 $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1511 $(DEPEND_MOVEFILE)
1512
1513$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1514 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1515 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1516 $(DEPEND_MOVEFILE)
1517
1518$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1519 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1520 $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1521 $(DEPEND_MOVEFILE)
1522
1523#---------------------------------------------------------
1524# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1525#---------------------------------------------------------
1526
1527BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1528 -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1529
1530# If the build succeeded, move the dependency file over, otherwise
1531# remove it.
1532BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1533 else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1534
1535$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1536 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1537 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1538 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1539 $(BC_DEPEND_MOVEFILE)
1540
1541$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1542 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1543 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1544 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1545 $(BC_DEPEND_MOVEFILE)
1546
1547$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1548 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1549 $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1550 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1551 $(BC_DEPEND_MOVEFILE)
1552
1553$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1554 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1555 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1556 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1557 $(BC_DEPEND_MOVEFILE)
1558
1559$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1560 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1561 $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1562 $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1563 $(BC_DEPEND_MOVEFILE)
1564
1565# Provide alternate rule sets if dependencies are disabled
1566else
1567
1568$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1569 $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1570 $(Compile.CXX) $< -o $@
1571
1572$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1573 $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1574 $(Compile.CXX) $< -o $@
1575
1576$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1577 $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1578 $(Compile.CXX) $< -o $@
1579
1580$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1581 $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1582 $(Compile.C) $< -o $@
1583
1584$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1585 $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1586 $(Compile.C) $< -o $@
1587
1588$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1589 $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1590 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1591
1592$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1593 $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1594 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1595
1596$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1597 $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1598 $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1599
1600$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1601 $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1602 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1603
1604$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1605 $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1606 $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1607
1608endif
1609
1610
1611## Rules for building preprocessed (.i/.ii) outputs.
1612$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1613 $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1614 $(Verb) $(Preprocess.CXX) $< -o $@
1615
1616$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1617 $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1618 $(Verb) $(Preprocess.CXX) $< -o $@
1619
1620$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1621 $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1622 $(Verb) $(Preprocess.CXX) $< -o $@
1623
1624$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1625 $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1626 $(Verb) $(Preprocess.C) $< -o $@
1627
1628$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1629 $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1630 $(Verb) $(Preprocess.C) $< -o $@
1631
1632
1633$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1634 $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1635 $(Compile.CXX) $< -o $@ -S
1636
1637$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1638 $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1639 $(Compile.CXX) $< -o $@ -S
1640
1641$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1642 $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1643 $(Compile.CXX) $< -o $@ -S
1644
1645$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1646 $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1647 $(Compile.C) $< -o $@ -S
1648
1649$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1650 $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1651 $(Compile.C) $< -o $@ -S
1652
1653
1654# make the C and C++ compilers strip debug info out of bytecode libraries.
1655ifdef DEBUG_RUNTIME
1656$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1657 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1658 $(Verb) $(LOPT) $< -std-compile-opts -o $@
1659else
1660$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1661 $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1662 $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
1663endif
1664
1665
1666#---------------------------------------------------------
1667# Provide rule to build .bc files from .ll sources,
1668# regardless of dependencies
1669#---------------------------------------------------------
1670$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1671 $(Echo) "Compiling $*.ll for $(BuildMode) build"
1672 $(Verb) $(LLVMAS) $< -f -o $@
1673
1674###############################################################################
1675# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1676###############################################################################
1677
1678ifdef TARGET
1679TABLEGEN_INC_FILES_COMMON = 1
1680endif
1681
1682ifdef TABLEGEN_INC_FILES_COMMON
1683
1684INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1685INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1686.PRECIOUS: $(INCTMPFiles) $(INCFiles)
1687
1688# INCFiles rule: All of the tblgen generated files are emitted to
1689# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc. This allows
1690# us to only "touch" the real file if the contents of it change. IOW, if
1691# tblgen is modified, all of the .inc.tmp files are regenerated, but no
1692# dependencies of the .inc files are, unless the contents of the .inc file
1693# changes.
1694$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1695 $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1696
1697endif # TABLEGEN_INC_FILES_COMMON
1698
1699ifdef TARGET
1700
1701TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1702 $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1703 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1704 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1705 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1706 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1707 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1708
1709# All .inc.tmp files depend on the .td files.
1710$(INCTMPFiles) : $(TDFiles)
1711
1712$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1713$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1714 $(Echo) "Building $(<F) register info implementation with tblgen"
1715 $(Verb) $(LLVMTableGen) -gen-register-info -o $(call SYSPATH, $@) $<
1716
1717$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1718$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1719 $(Echo) "Building $(<F) instruction information with tblgen"
1720 $(Verb) $(LLVMTableGen) -gen-instr-info -o $(call SYSPATH, $@) $<
1721
1722$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1723$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1724 $(Echo) "Building $(<F) assembly writer with tblgen"
1725 $(Verb) $(LLVMTableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1726
1727$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1728$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1729 $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1730 $(Verb) $(LLVMTableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1731
1732$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1733$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1734 $(Echo) "Building $(<F) assembly matcher with tblgen"
1735 $(Verb) $(LLVMTableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1736
1737$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
1738$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1739 $(Echo) "Building $(<F) MC code emitter with tblgen"
1740 $(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
1741
1742$(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
1743$(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1744 $(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
1745 $(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
1746
1747$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1748$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1749 $(Echo) "Building $(<F) code emitter with tblgen"
1750 $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1751
1752$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1753$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1754 $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1755 $(Verb) $(LLVMTableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1756
1757$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1758$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1759 $(Echo) "Building $(<F) disassembly tables with tblgen"
1760 $(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1761
1762$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1763$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1764 $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1765 $(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1766
1767$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1768$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1769 $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1770 $(Verb) $(LLVMTableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1771
1772$(TARGET:%=$(ObjDir)/%GenSubtargetInfo.inc.tmp): \
1773$(ObjDir)/%GenSubtargetInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1774 $(Echo) "Building $(<F) subtarget information with tblgen"
1775 $(Verb) $(LLVMTableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1776
1777$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1778$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1779 $(Echo) "Building $(<F) calling convention information with tblgen"
1780 $(Verb) $(LLVMTableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1781
1782$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1783$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1784 $(Echo) "Building $(<F) intrinsics information with tblgen"
1785 $(Verb) $(LLVMTableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1786
1787$(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1788 $(Echo) "Building $(<F) decoder tables with tblgen"
1789 $(Verb) $(LLVMTableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
1790
1791
1792clean-local::
1793 -$(Verb) $(RM) -f $(INCFiles)
1794
1795endif # TARGET
1796
1797###############################################################################
1798# OTHER RULES: Other rules needed
1799###############################################################################
1800
1801# To create postscript files from dot files...
1802ifneq ($(DOT),false)
1803%.ps: %.dot
1804 $(DOT) -Tps < $< > $@
1805else
1806%.ps: %.dot
1807 $(Echo) "Cannot build $@: The program dot is not installed"
1808endif
1809
1810# This rules ensures that header files that are removed still have a rule for
1811# which they can be "generated." This allows make to ignore them and
1812# reproduce the dependency lists.
1813%.h:: ;
1814%.hpp:: ;
1815
1816# Define clean-local to clean the current directory. Note that this uses a
1817# very conservative approach ensuring that empty variables do not cause
1818# errors or disastrous removal.
1819clean-local::
1820ifneq ($(strip $(ObjRootDir)),)
1821 -$(Verb) $(RM) -rf $(ObjRootDir)
1822endif
1823 -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1824ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1825 -$(Verb) $(RM) -f *$(SHLIBEXT)
1826endif
1827
1828clean-all-local::
1829 -$(Verb) $(RM) -rf Debug Release Profile
1830
1831
1832###############################################################################
1833# DEPENDENCIES: Include the dependency files if we should
1834###############################################################################
1835ifndef DISABLE_AUTO_DEPENDENCIES
1836
1837# If its not one of the cleaning targets
1838ifndef IS_CLEANING_TARGET
1839
1840# Get the list of dependency files
1841DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
1842DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1843
1844# Include bitcode dependency files if using bitcode libraries
1845ifdef BYTECODE_LIBRARY
1846DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1847endif
1848
1849-include $(DependFiles) ""
1850
1851endif
1852
1853endif
1854
1855###############################################################################
1856# CHECK: Running the test suite
1857###############################################################################
1858
1859check::
1860 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1861 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1862 $(EchoCmd) Running test suite ; \
1863 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1864 TESTSUITE=$(TESTSUITE) ; \
1865 else \
1866 $(EchoCmd) No Makefile in test directory ; \
1867 fi ; \
1868 else \
1869 $(EchoCmd) No test directory ; \
1870 fi
1871
1872check-lit:: check
1873
1874check-dg::
1875 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1876 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1877 $(EchoCmd) Running test suite ; \
1878 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
1879 else \
1880 $(EchoCmd) No Makefile in test directory ; \
1881 fi ; \
1882 else \
1883 $(EchoCmd) No test directory ; \
1884 fi
1885
1886check-all::
1887 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1888 if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1889 $(EchoCmd) Running test suite ; \
1890 $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1891 else \
1892 $(EchoCmd) No Makefile in test directory ; \
1893 fi ; \
1894 else \
1895 $(EchoCmd) No test directory ; \
1896 fi
1897
1898###############################################################################
1899# UNITTESTS: Running the unittests test suite
1900###############################################################################
1901
1902unittests::
1903 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1904 if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1905 $(EchoCmd) Running unittests test suite ; \
1906 $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
1907 else \
1908 $(EchoCmd) No Makefile in unittests directory ; \
1909 fi ; \
1910 else \
1911 $(EchoCmd) No unittests directory ; \
1912 fi
1913
1914###############################################################################
1915# DISTRIBUTION: Handle construction of a distribution tarball
1916###############################################################################
1917
1918#------------------------------------------------------------------------
1919# Define distribution related variables
1920#------------------------------------------------------------------------
1921DistName := $(PROJECT_NAME)-$(PROJ_VERSION)
1922DistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1923TopDistDir := $(PROJ_OBJ_ROOT)/$(DistName)
1924DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1925DistZip := $(PROJ_OBJ_ROOT)/$(DistName).zip
1926DistTarBZ2 := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1927DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1928 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1929 Makefile.config.in configure autoconf
1930DistOther := $(notdir $(wildcard \
1931 $(PROJ_SRC_DIR)/*.h \
1932 $(PROJ_SRC_DIR)/*.td \
1933 $(PROJ_SRC_DIR)/*.def \
1934 $(PROJ_SRC_DIR)/*.ll \
1935 $(PROJ_SRC_DIR)/*.in))
1936DistSubDirs := $(SubDirs)
1937DistSources = $(Sources) $(EXTRA_DIST)
1938DistFiles = $(DistAlways) $(DistSources) $(DistOther)
1939
1940#------------------------------------------------------------------------
1941# We MUST build distribution with OBJ_DIR != SRC_DIR
1942#------------------------------------------------------------------------
1943ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1944dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1945 $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1946
1947else
1948
1949#------------------------------------------------------------------------
1950# Prevent attempt to run dist targets from anywhere but the top level
1951#------------------------------------------------------------------------
1952ifneq ($(LEVEL),.)
1953dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1954 $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1955else
1956
1957#------------------------------------------------------------------------
1958# Provide the top level targets
1959#------------------------------------------------------------------------
1960
1961dist-gzip:: $(DistTarGZip)
1962
1963$(DistTarGZip) : $(TopDistDir)/.makedistdir
1964 $(Echo) Packing gzipped distribution tar file.
1965 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1966 $(GZIP) -c > "$(DistTarGZip)"
1967
1968dist-bzip2:: $(DistTarBZ2)
1969
1970$(DistTarBZ2) : $(TopDistDir)/.makedistdir
1971 $(Echo) Packing bzipped distribution tar file.
1972 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1973 $(BZIP2) -c >$(DistTarBZ2)
1974
1975dist-zip:: $(DistZip)
1976
1977$(DistZip) : $(TopDistDir)/.makedistdir
1978 $(Echo) Packing zipped distribution file.
1979 $(Verb) rm -f $(DistZip)
1980 $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1981
1982dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1983 $(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
1984
1985DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1986
1987dist-check:: $(DistTarGZip)
1988 $(Echo) Checking distribution tar file.
1989 $(Verb) if test -d $(DistCheckDir) ; then \
1990 $(RM) -rf $(DistCheckDir) ; \
1991 fi
1992 $(Verb) $(MKDIR) $(DistCheckDir)
1993 $(Verb) cd $(DistCheckDir) && \
1994 $(MKDIR) $(DistCheckDir)/build && \
1995 $(MKDIR) $(DistCheckDir)/install && \
1996 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1997 cd build && \
1998 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1999 --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
2000 $(MAKE) all && \
2001 $(MAKE) check && \
2002 $(MAKE) unittests && \
2003 $(MAKE) install && \
2004 $(MAKE) uninstall && \
2005 $(MAKE) dist-clean && \
2006 $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
2007
2008dist-clean::
2009 $(Echo) Cleaning distribution files
2010 -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2011 $(DistCheckDir)
2012
2013endif
2014
2015#------------------------------------------------------------------------
2016# Provide the recursive distdir target for building the distribution directory
2017#------------------------------------------------------------------------
2018distdir: $(DistDir)/.makedistdir
2019$(DistDir)/.makedistdir: $(DistSources)
2020 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2021 if test -d "$(DistDir)" ; then \
2022 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
2023 exit 1 ; \
2024 fi ; \
2025 $(EchoCmd) Removing old $(DistDir) ; \
2026 $(RM) -rf $(DistDir); \
2027 $(EchoCmd) Making 'all' to verify build ; \
2028 $(MAKE) ENABLE_OPTIMIZED=1 all ; \
2029 fi
2030 $(Echo) Building Distribution Directory $(DistDir)
2031 $(Verb) $(MKDIR) $(DistDir)
2032 $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2033 srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
2034 for file in $(DistFiles) ; do \
2035 case "$$file" in \
2036 $(PROJ_SRC_DIR)/*) \
2037 file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2038 ;; \
2039 $(PROJ_SRC_ROOT)/*) \
2040 file=`echo "$$file" | \
2041 sed "s#^$$srcrootstrip/##"` \
2042 ;; \
2043 esac; \
2044 if test -f "$(PROJ_SRC_DIR)/$$file" || \
2045 test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2046 from_dir="$(PROJ_SRC_DIR)" ; \
2047 elif test -f "$$file" || test -d "$$file" ; then \
2048 from_dir=. ; \
2049 fi ; \
2050 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
2051 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2052 to_dir="$(DistDir)/$$dir"; \
2053 $(MKDIR) "$$to_dir" ; \
2054 else \
2055 to_dir="$(DistDir)"; \
2056 fi; \
2057 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2058 if test -n "$$mid_dir" ; then \
2059 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
2060 fi ; \
2061 if test -d "$$from_dir/$$file"; then \
2062 if test -d "$(PROJ_SRC_DIR)/$$file" && \
2063 test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
2064 cd $(PROJ_SRC_DIR) ; \
2065 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2066 ( cd $$to_dir ; $(TAR) xf - ) ; \
2067 cd $(PROJ_OBJ_DIR) ; \
2068 else \
2069 cd $$from_dir ; \
2070 $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2071 ( cd $$to_dir ; $(TAR) xf - ) ; \
2072 cd $(PROJ_OBJ_DIR) ; \
2073 fi; \
2074 elif test -f "$$from_dir/$$file" ; then \
2075 $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
2076 elif test -L "$$from_dir/$$file" ; then \
2077 $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
2078 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
2079 $(EchoCmd) "===== WARNING: Distribution Source " \
2080 "$$from_dir/$$file Not Found!" ; \
2081 elif test "$(Verb)" != '@' ; then \
2082 $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
2083 fi; \
2084 done
2085 $(Verb) for subdir in $(DistSubDirs) ; do \
2086 if test "$$subdir" \!= "." ; then \
2087 new_distdir="$(DistDir)/$$subdir" ; \
2088 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
2089 ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
2090 DistDir="$$new_distdir" distdir ) || exit 1; \
2091 fi; \
2092 done
2093 $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2094 $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
2095 $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2096 -name .svn \) -print` ;\
2097 $(MAKE) dist-hook ; \
2098 $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2099 -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2100 -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2101 -o ! -type d ! -perm -444 -exec \
2102 $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2103 || chmod -R a+r $(DistDir) ; \
2104 fi
2105
2106# This is invoked by distdir target, define it as a no-op to avoid errors if not
2107# defined by user.
2108dist-hook::
2109
2110endif
2111
2112###############################################################################
2113# TOP LEVEL - targets only to apply at the top level directory
2114###############################################################################
2115
2116ifeq ($(LEVEL),.)
2117
2118#------------------------------------------------------------------------
2119# Install support for the project's include files:
2120#------------------------------------------------------------------------
2121ifdef NO_INSTALL
2122install-local::
2123 $(Echo) Install circumvented with NO_INSTALL
2124uninstall-local::
2125 $(Echo) Uninstall circumvented with NO_INSTALL
2126else
2127install-local::
2128 $(Echo) Installing include files
2129 $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
2130 $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
2131 cd $(PROJ_SRC_ROOT)/include && \
2132 for hdr in `find . -type f \
2133 '(' -name LICENSE.TXT \
2134 -o -name '*.def' \
2135 -o -name '*.h' \
2136 -o -name '*.inc' \
2137 -o -name '*.td' \
2138 ')' -print | grep -v CVS | \
2139 grep -v .svn` ; do \
2140 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2141 if test \! -d "$$instdir" ; then \
2142 $(EchoCmd) Making install directory $$instdir ; \
2143 $(MKDIR) $$instdir ;\
2144 fi ; \
2145 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2146 done ; \
2147 fi
2148ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
2149 $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
2150 cd $(PROJ_OBJ_ROOT)/include && \
2151 for hdr in `find . -type f \
2152 '(' -name LICENSE.TXT \
2153 -o -name '*.def' \
2154 -o -name '*.h' \
2155 -o -name '*.inc' \
2156 -o -name '*.td' \
2157 ')' -print | grep -v CVS | \
2158 grep -v .svn` ; do \
2159 instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2160 if test \! -d "$$instdir" ; then \
2161 $(EchoCmd) Making install directory $$instdir ; \
2162 $(MKDIR) $$instdir ;\
2163 fi ; \
2164 $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2165 done ; \
2166 fi
2167endif
2168
2169uninstall-local::
2170 $(Echo) Uninstalling include files
2171 $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2172 cd $(PROJ_SRC_ROOT)/include && \
2173 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
2174 '!' '(' -name '*~' -o -name '.#*' \
2175 -o -name '*.in' ')' -print ')' | \
2176 grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2177 cd $(PROJ_SRC_ROOT)/include && \
2178 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
2179 -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2180 fi
2181endif
2182endif
2183
2184check-line-length:
2185 @echo searching for overlength lines in files: $(Sources)
2186 @echo
2187 @echo
2188 egrep -n '.{81}' $(Sources) /dev/null
2189
2190check-for-tabs:
2191 @echo searching for tabs in files: $(Sources)
2192 @echo
2193 @echo
2194 egrep -n ' ' $(Sources) /dev/null
2195
2196check-footprint:
2197 @ls -l $(LibDir) | awk '\
2198 BEGIN { sum = 0; } \
2199 { sum += $$5; } \
2200 END { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2201 @ls -l $(ToolDir) | awk '\
2202 BEGIN { sum = 0; } \
2203 { sum += $$5; } \
2204 END { printf("Programs: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2205#------------------------------------------------------------------------
2206# Print out the directories used for building
2207#------------------------------------------------------------------------
2208printvars::
2209 $(Echo) "BuildMode : " '$(BuildMode)'
2210 $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2211 $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2212 $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2213 $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2214 $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2215 $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2216 $(Echo) "PROJ_prefix : " '$(PROJ_prefix)'
2217 $(Echo) "PROJ_bindir : " '$(PROJ_bindir)'
2218 $(Echo) "PROJ_libdir : " '$(PROJ_libdir)'
2219 $(Echo) "PROJ_etcdir : " '$(PROJ_etcdir)'
2220 $(Echo) "PROJ_includedir : " '$(PROJ_includedir)'
2221 $(Echo) "UserTargets : " '$(UserTargets)'
2222 $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2223 $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2224 $(Echo) "ObjDir : " '$(ObjDir)'
2225 $(Echo) "LibDir : " '$(LibDir)'
2226 $(Echo) "ToolDir : " '$(ToolDir)'
2227 $(Echo) "ExmplDir : " '$(ExmplDir)'
2228 $(Echo) "Sources : " '$(Sources)'
2229 $(Echo) "TDFiles : " '$(TDFiles)'
2230 $(Echo) "INCFiles : " '$(INCFiles)'
2231 $(Echo) "INCTMPFiles : " '$(INCTMPFiles)'
2232 $(Echo) "PreConditions: " '$(PreConditions)'
2233 $(Echo) "Compile.CXX : " '$(Compile.CXX)'
2234 $(Echo) "Compile.C : " '$(Compile.C)'
2235 $(Echo) "Archive : " '$(Archive)'
2236 $(Echo) "YaccFiles : " '$(YaccFiles)'
2237 $(Echo) "LexFiles : " '$(LexFiles)'
2238 $(Echo) "Module : " '$(Module)'
2239 $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
2240 $(Echo) "SubDirs : " '$(SubDirs)'
2241 $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2242 $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
2243
2244###
2245# Debugging
2246
2247# General debugging rule, use 'make dbg-print-XXX' to print the
2248# definition, value and origin of XXX.
2249make-print-%:
2250 $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))