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