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