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