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