7bef65078845e62da1a2d5de960343182c389dd6
[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 ifdef BUILD_DIRS_ONLY
511 EchoCmd  := $(EchoCmd) "(build tools)":
512 endif
513
514 Echo     := @$(EchoCmd)
515 ifndef LLVMAS
516 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
517 endif
518 ifndef LLVM_TBLGEN
519   ifeq ($(LLVM_CROSS_COMPILING),1)
520     LLVM_TBLGEN   := $(BuildLLVMToolDir)/llvm-tblgen$(BUILD_EXEEXT)
521   else
522     LLVM_TBLGEN   := $(LLVMToolDir)/llvm-tblgen$(EXEEXT)
523   endif
524 endif
525 LLVM_CONFIG := $(LLVMToolDir)/llvm-config
526 ifndef LLVMLD
527 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
528 endif
529 ifndef LLVMDIS
530 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
531 endif
532 ifndef LLI
533 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
534 endif
535 ifndef LLC
536 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
537 endif
538 ifndef LOPT
539 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
540 endif
541 ifndef LBUGPOINT
542 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
543 endif
544
545 #--------------------------------------------------------------------
546 # Adjust to user's request
547 #--------------------------------------------------------------------
548
549 ifeq ($(HOST_OS),Darwin)
550   DARWIN_VERSION := `sw_vers -productVersion`
551   # Strip a number like 10.4.7 to 10.4
552   DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
553   # Get "4" out of 10.4 for later pieces in the makefile.
554   DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
555
556   LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
557   SharedLinkOptions := -dynamiclib
558   ifneq ($(ARCH),ARM)
559     SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
560   endif
561 else
562   SharedLinkOptions=-shared
563 endif
564
565 ifeq ($(TARGET_OS),Darwin)
566   ifneq ($(ARCH),ARM)
567     TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
568   endif
569 endif
570
571 ifdef SHARED_LIBRARY
572 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
573 ifneq ($(HOST_OS),Darwin)
574   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
575 endif
576 endif
577 endif
578
579 ifdef TOOL_VERBOSE
580   C.Flags += -v
581   CXX.Flags += -v
582   LD.Flags += -v
583   VERBOSE := 1
584 endif
585
586 # Adjust settings for verbose mode
587 ifndef VERBOSE
588   Verb := @
589   AR.Flags += >/dev/null 2>/dev/null
590   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
591 else
592   ConfigureScriptFLAGS :=
593 endif
594
595 # By default, strip symbol information from executable
596 ifndef KEEP_SYMBOLS
597   Strip := $(PLATFORMSTRIPOPTS)
598   StripWarnMsg := "(without symbols)"
599   Install.StripFlag += -s
600 endif
601
602 ifdef TOOL_NO_EXPORTS
603   DynamicFlags :=
604 else
605   DynamicFlag := $(RDYNAMIC)
606 endif
607
608 # Adjust linker flags for building an executable
609 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
610 ifneq ($(HOST_OS), Darwin)
611 ifdef TOOLNAME
612   LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
613   ifdef EXAMPLE_TOOL
614     LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
615   else
616     LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
617   endif
618 endif
619 else
620 ifneq ($(DARWIN_MAJVERS),4)
621   LD.Flags += $(RPATH) -Wl,@executable_path/../lib
622 endif
623 endif
624 endif
625
626
627 #----------------------------------------------------------
628 # Options To Invoke Tools
629 #----------------------------------------------------------
630
631 ifdef EXTRA_LD_OPTIONS
632 LD.Flags += $(EXTRA_LD_OPTIONS)
633 endif
634
635 ifndef NO_PEDANTIC
636 CompileCommonOpts += -pedantic -Wno-long-long
637 endif
638 CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
639                      $(EXTRA_OPTIONS)
640 # Enable cast-qual for C++; the workaround is to use const_cast.
641 CXX.Flags += -Wcast-qual
642
643 ifeq ($(HOST_OS),HP-UX)
644   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
645 endif
646
647 # If we are building a universal binary on Mac OS/X, pass extra options.  This
648 # is useful to people that want to link the LLVM libraries into their universal
649 # apps.
650 #
651 # The following can be optionally specified:
652 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
653 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
654 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
655 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
656 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
657 #      i386/ppc only.
658 ifdef UNIVERSAL
659   ifndef UNIVERSAL_ARCH
660     UNIVERSAL_ARCH := i386 ppc
661   endif
662   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
663   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
664   ifdef UNIVERSAL_SDK_PATH
665     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
666   endif
667
668   # Building universal cannot compute dependencies automatically.
669   DISABLE_AUTO_DEPENDENCIES=1
670 else
671   ifeq ($(TARGET_OS),Darwin)
672     ifeq ($(ARCH),x86_64)
673       TargetCommonOpts = -m64
674     else
675       ifeq ($(ARCH),x86)
676         TargetCommonOpts = -m32
677       endif
678     endif
679   endif
680 endif
681
682 ifeq ($(HOST_OS),SunOS)
683 CPP.BaseFlags += -include llvm/Support/Solaris.h
684 endif
685
686 ifeq ($(HOST_OS),AuroraUX)
687 CPP.BaseFlags += -include llvm/Support/Solaris.h
688 endif # !HOST_OS - AuroraUX.
689
690 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
691 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
692 # All -I flags should go here, so that they don't confuse llvm-config.
693 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
694                  $(patsubst %,-I%/include,\
695                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
696                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
697                  $(CPP.BaseFlags)
698
699 ifeq ($(INCLUDE_BUILD_DIR),1)
700   CPP.Flags   += -I$(ObjDir)
701 endif
702
703 # SHOW_DIAGNOSTICS support.
704 ifeq ($(SHOW_DIAGNOSTICS),1)
705   Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
706                           CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
707 else
708   Compile.Wrapper :=
709 endif
710
711 Compile.C     = $(Compile.Wrapper) \
712                   $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
713                 $(TargetCommonOpts) $(CompileCommonOpts) -c
714 Compile.CXX   = $(Compile.Wrapper) \
715                   $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
716                 $(TargetCommonOpts) $(CompileCommonOpts) -c
717 Preprocess.CXX= $(Compile.Wrapper) \
718                   $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
719                 $(CompileCommonOpts) $(CXX.Flags) -E
720 Link          = $(Compile.Wrapper) \
721                   $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
722                 $(LDFLAGS) $(TargetCommonOpts)  $(CompileCommonOpts) $(Strip)
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 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1878         -$(Verb) $(RM) -f *$(SHLIBEXT)
1879 endif
1880
1881 clean-all-local::
1882         -$(Verb) $(RM) -rf Debug Release Profile
1883
1884
1885 ###############################################################################
1886 # DEPENDENCIES: Include the dependency files if we should
1887 ###############################################################################
1888 ifndef DISABLE_AUTO_DEPENDENCIES
1889
1890 # If its not one of the cleaning targets
1891 ifndef IS_CLEANING_TARGET
1892
1893 # Get the list of dependency files
1894 DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
1895 DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1896
1897 # Include bitcode dependency files if using bitcode libraries
1898 ifdef BYTECODE_LIBRARY
1899 DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1900 endif
1901
1902 -include $(DependFiles) ""
1903
1904 endif
1905
1906 endif
1907
1908 ###############################################################################
1909 # CHECK: Running the test suite
1910 ###############################################################################
1911
1912 check::
1913         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1914           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1915             $(EchoCmd) Running test suite ; \
1916             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1917               TESTSUITE=$(TESTSUITE) ; \
1918           else \
1919             $(EchoCmd) No Makefile in test directory ; \
1920           fi ; \
1921         else \
1922           $(EchoCmd) No test directory ; \
1923         fi
1924
1925 check-lit:: check
1926
1927 check-dg::
1928         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1929           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1930             $(EchoCmd) Running test suite ; \
1931             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
1932           else \
1933             $(EchoCmd) No Makefile in test directory ; \
1934           fi ; \
1935         else \
1936           $(EchoCmd) No test directory ; \
1937         fi
1938
1939 check-all::
1940         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1941           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1942             $(EchoCmd) Running test suite ; \
1943             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1944           else \
1945             $(EchoCmd) No Makefile in test directory ; \
1946           fi ; \
1947         else \
1948           $(EchoCmd) No test directory ; \
1949         fi
1950
1951 ###############################################################################
1952 # UNITTESTS: Running the unittests test suite
1953 ###############################################################################
1954
1955 unittests::
1956         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1957           if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1958             $(EchoCmd) Running unittests test suite ; \
1959             $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
1960           else \
1961             $(EchoCmd) No Makefile in unittests directory ; \
1962           fi ; \
1963         else \
1964           $(EchoCmd) No unittests directory ; \
1965         fi
1966
1967 ###############################################################################
1968 # DISTRIBUTION: Handle construction of a distribution tarball
1969 ###############################################################################
1970
1971 #------------------------------------------------------------------------
1972 # Define distribution related variables
1973 #------------------------------------------------------------------------
1974 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1975 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1976 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1977 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1978 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1979 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1980 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1981                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1982                Makefile.config.in configure autoconf
1983 DistOther   := $(notdir $(wildcard \
1984                $(PROJ_SRC_DIR)/*.h \
1985                $(PROJ_SRC_DIR)/*.td \
1986                $(PROJ_SRC_DIR)/*.def \
1987                $(PROJ_SRC_DIR)/*.ll \
1988                $(PROJ_SRC_DIR)/*.in))
1989 DistSubDirs := $(SubDirs)
1990 DistSources  = $(Sources) $(EXTRA_DIST)
1991 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1992
1993 #------------------------------------------------------------------------
1994 # We MUST build distribution with OBJ_DIR != SRC_DIR
1995 #------------------------------------------------------------------------
1996 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1997 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1998         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1999
2000 else
2001
2002 #------------------------------------------------------------------------
2003 # Prevent attempt to run dist targets from anywhere but the top level
2004 #------------------------------------------------------------------------
2005 ifneq ($(LEVEL),.)
2006 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
2007         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
2008 else
2009
2010 #------------------------------------------------------------------------
2011 # Provide the top level targets
2012 #------------------------------------------------------------------------
2013
2014 dist-gzip:: $(DistTarGZip)
2015
2016 $(DistTarGZip) : $(TopDistDir)/.makedistdir
2017         $(Echo) Packing gzipped distribution tar file.
2018         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
2019           $(GZIP) -c > "$(DistTarGZip)"
2020
2021 dist-bzip2:: $(DistTarBZ2)
2022
2023 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
2024         $(Echo) Packing bzipped distribution tar file.
2025         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
2026           $(BZIP2) -c >$(DistTarBZ2)
2027
2028 dist-zip:: $(DistZip)
2029
2030 $(DistZip) : $(TopDistDir)/.makedistdir
2031         $(Echo) Packing zipped distribution file.
2032         $(Verb) rm -f $(DistZip)
2033         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
2034
2035 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
2036         $(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
2037
2038 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
2039
2040 dist-check:: $(DistTarGZip)
2041         $(Echo) Checking distribution tar file.
2042         $(Verb) if test -d $(DistCheckDir) ; then \
2043           $(RM) -rf $(DistCheckDir) ; \
2044         fi
2045         $(Verb) $(MKDIR) $(DistCheckDir)
2046         $(Verb) cd $(DistCheckDir) && \
2047           $(MKDIR) $(DistCheckDir)/build && \
2048           $(MKDIR) $(DistCheckDir)/install && \
2049           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
2050           cd build && \
2051           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
2052             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
2053           $(MAKE) all && \
2054           $(MAKE) check && \
2055           $(MAKE) unittests && \
2056           $(MAKE) install && \
2057           $(MAKE) uninstall && \
2058           $(MAKE) dist-clean && \
2059           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
2060
2061 dist-clean::
2062         $(Echo) Cleaning distribution files
2063         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2064           $(DistCheckDir)
2065
2066 endif
2067
2068 #------------------------------------------------------------------------
2069 # Provide the recursive distdir target for building the distribution directory
2070 #------------------------------------------------------------------------
2071 distdir: $(DistDir)/.makedistdir
2072 $(DistDir)/.makedistdir: $(DistSources)
2073         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2074           if test -d "$(DistDir)" ; then \
2075             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
2076               exit 1 ; \
2077           fi ; \
2078           $(EchoCmd) Removing old $(DistDir) ; \
2079           $(RM) -rf $(DistDir); \
2080           $(EchoCmd) Making 'all' to verify build ; \
2081           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
2082         fi
2083         $(Echo) Building Distribution Directory $(DistDir)
2084         $(Verb) $(MKDIR) $(DistDir)
2085         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2086         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
2087         for file in $(DistFiles) ; do \
2088           case "$$file" in \
2089             $(PROJ_SRC_DIR)/*) \
2090               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2091               ;; \
2092             $(PROJ_SRC_ROOT)/*) \
2093               file=`echo "$$file" | \
2094                 sed "s#^$$srcrootstrip/##"` \
2095               ;; \
2096           esac; \
2097           if test -f "$(PROJ_SRC_DIR)/$$file" || \
2098              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2099             from_dir="$(PROJ_SRC_DIR)" ; \
2100           elif test -f "$$file" || test -d "$$file" ; then \
2101             from_dir=. ; \
2102           fi ; \
2103           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
2104           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2105             to_dir="$(DistDir)/$$dir"; \
2106             $(MKDIR) "$$to_dir" ; \
2107           else \
2108             to_dir="$(DistDir)"; \
2109           fi; \
2110           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2111           if test -n "$$mid_dir" ; then \
2112             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
2113           fi ; \
2114           if test -d "$$from_dir/$$file"; then \
2115             if test -d "$(PROJ_SRC_DIR)/$$file" && \
2116                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
2117                cd $(PROJ_SRC_DIR) ; \
2118                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2119                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2120                cd $(PROJ_OBJ_DIR) ; \
2121             else \
2122                cd $$from_dir ; \
2123                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2124                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2125                cd $(PROJ_OBJ_DIR) ; \
2126             fi; \
2127           elif test -f "$$from_dir/$$file" ; then \
2128             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
2129           elif test -L "$$from_dir/$$file" ; then \
2130             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
2131           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
2132             $(EchoCmd) "===== WARNING: Distribution Source " \
2133               "$$from_dir/$$file Not Found!" ; \
2134           elif test "$(Verb)" != '@' ; then \
2135             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
2136           fi; \
2137         done
2138         $(Verb) for subdir in $(DistSubDirs) ; do \
2139           if test "$$subdir" \!= "." ; then \
2140             new_distdir="$(DistDir)/$$subdir" ; \
2141             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
2142             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
2143               DistDir="$$new_distdir" distdir ) || exit 1; \
2144           fi; \
2145         done
2146         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2147           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
2148           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2149                                   -name .svn \) -print` ;\
2150           $(MAKE) dist-hook ; \
2151           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2152             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2153             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2154             -o ! -type d ! -perm -444 -exec \
2155               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2156             || chmod -R a+r $(DistDir) ; \
2157         fi
2158
2159 # This is invoked by distdir target, define it as a no-op to avoid errors if not
2160 # defined by user.
2161 dist-hook::
2162
2163 endif
2164
2165 ###############################################################################
2166 # TOP LEVEL - targets only to apply at the top level directory
2167 ###############################################################################
2168
2169 ifeq ($(LEVEL),.)
2170
2171 #------------------------------------------------------------------------
2172 # Install support for the project's include files:
2173 #------------------------------------------------------------------------
2174 ifdef NO_INSTALL
2175 install-local::
2176         $(Echo) Install circumvented with NO_INSTALL
2177 uninstall-local::
2178         $(Echo) Uninstall circumvented with NO_INSTALL
2179 else
2180 install-local::
2181         $(Echo) Installing include files
2182         $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
2183         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
2184           cd $(PROJ_SRC_ROOT)/include && \
2185           for hdr in `find . -type f \
2186               '(' -name LICENSE.TXT \
2187                -o -name '*.def' \
2188                -o -name '*.h' \
2189                -o -name '*.inc' \
2190                -o -name '*.td' \
2191               ')' -print | grep -v CVS | \
2192               grep -v .svn` ; do \
2193             instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2194             if test \! -d "$$instdir" ; then \
2195               $(EchoCmd) Making install directory $$instdir ; \
2196               $(MKDIR) $$instdir ;\
2197             fi ; \
2198             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2199           done ; \
2200         fi
2201 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
2202         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
2203           cd $(PROJ_OBJ_ROOT)/include && \
2204           for hdr in `find . -type f \
2205               '(' -name LICENSE.TXT \
2206                -o -name '*.def' \
2207                -o -name '*.h' \
2208                -o -name '*.inc' \
2209                -o -name '*.td' \
2210               ')' -print | grep -v CVS | \
2211               grep -v .svn` ; do \
2212             instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2213             if test \! -d "$$instdir" ; then \
2214               $(EchoCmd) Making install directory $$instdir ; \
2215               $(MKDIR) $$instdir ;\
2216             fi ; \
2217             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2218           done ; \
2219         fi
2220 endif
2221
2222 uninstall-local::
2223         $(Echo) Uninstalling include files
2224         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2225           cd $(PROJ_SRC_ROOT)/include && \
2226             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
2227               '!' '(' -name '*~' -o -name '.#*' \
2228         -o -name '*.in' ')' -print ')' | \
2229         grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2230           cd $(PROJ_SRC_ROOT)/include && \
2231             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
2232       -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2233         fi
2234 endif
2235 endif
2236
2237 check-line-length:
2238         @echo searching for overlength lines in files: $(Sources)
2239         @echo
2240         @echo
2241         egrep -n '.{81}' $(Sources) /dev/null
2242
2243 check-for-tabs:
2244         @echo searching for tabs in files: $(Sources)
2245         @echo
2246         @echo
2247         egrep -n '      ' $(Sources) /dev/null
2248
2249 check-footprint:
2250         @ls -l $(LibDir) | awk '\
2251           BEGIN { sum = 0; } \
2252                 { sum += $$5; } \
2253           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2254         @ls -l $(ToolDir) | awk '\
2255           BEGIN { sum = 0; } \
2256                 { sum += $$5; } \
2257           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2258 #------------------------------------------------------------------------
2259 # Print out the directories used for building
2260 #------------------------------------------------------------------------
2261 printvars::
2262         $(Echo) "BuildMode    : " '$(BuildMode)'
2263         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2264         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2265         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2266         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2267         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2268         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2269         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
2270         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
2271         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
2272         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
2273         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
2274         $(Echo) "UserTargets  : " '$(UserTargets)'
2275         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2276         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2277         $(Echo) "ObjDir       : " '$(ObjDir)'
2278         $(Echo) "LibDir       : " '$(LibDir)'
2279         $(Echo) "ToolDir      : " '$(ToolDir)'
2280         $(Echo) "ExmplDir     : " '$(ExmplDir)'
2281         $(Echo) "Sources      : " '$(Sources)'
2282         $(Echo) "TDFiles      : " '$(TDFiles)'
2283         $(Echo) "INCFiles     : " '$(INCFiles)'
2284         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
2285         $(Echo) "PreConditions: " '$(PreConditions)'
2286         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
2287         $(Echo) "Compile.C    : " '$(Compile.C)'
2288         $(Echo) "Archive      : " '$(Archive)'
2289         $(Echo) "YaccFiles    : " '$(YaccFiles)'
2290         $(Echo) "LexFiles     : " '$(LexFiles)'
2291         $(Echo) "Module       : " '$(Module)'
2292         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
2293         $(Echo) "SubDirs      : " '$(SubDirs)'
2294         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2295         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
2296
2297 ###
2298 # Debugging
2299
2300 # General debugging rule, use 'make dbg-print-XXX' to print the
2301 # definition, value and origin of XXX.
2302 make-print-%:
2303         $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))