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