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