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