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