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