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