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