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