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