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