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