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