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