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