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