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