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