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