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