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