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