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