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 ifdef MACOSX_DEPLOYMENT_TARGET
575  DARWIN_VERSION := $(MACOSX_DEPLOYMENT_TARGET)
576 else
577  DARWIN_VERSION := `sw_vers -productVersion`
578 endif
579  # Strip a number like 10.4.7 to 10.4
580  DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]*).*/\1/')
581  # Get "4" out of 10.4 for later pieces in the makefile.
582  DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]*).*/\1/')
583
584  LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
585  SharedLinkOptions := -dynamiclib
586  ifneq ($(ARCH),ARM)
587    SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
588  endif
589else
590  SharedLinkOptions=-shared
591endif
592
593ifeq ($(TARGET_OS),Darwin)
594  ifneq ($(ARCH),ARM)
595    TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
596  endif
597endif
598
599ifdef SHARED_LIBRARY
600ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
601ifneq ($(HOST_OS),Darwin)
602  LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
603endif
604endif
605endif
606
607ifdef TOOL_VERBOSE
608  C.Flags += -v
609  CXX.Flags += -v
610  LD.Flags += -v
611  VERBOSE := 1
612endif
613
614# Adjust settings for verbose mode
615ifndef VERBOSE
616  Verb := @
617  AR.Flags += >/dev/null 2>/dev/null
618  ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
619else
620  ConfigureScriptFLAGS :=
621endif
622
623# By default, strip symbol information from executable
624ifndef KEEP_SYMBOLS
625  Strip := $(PLATFORMSTRIPOPTS)
626  StripWarnMsg := "(without symbols)"
627  Install.StripFlag += -s
628endif
629
630ifdef TOOL_NO_EXPORTS
631  DynamicFlags :=
632else
633  DynamicFlag := $(RDYNAMIC)
634endif
635
636# Adjust linker flags for building an executable
637ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
638  ifneq ($(HOST_OS), Darwin)
639    ifdef TOOLNAME
640      LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
641      ifdef EXAMPLE_TOOL
642        LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
643      else
644        LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
645    endif
646  endif
647else
648  ifneq ($(DARWIN_MAJVERS),4)
649    LD.Flags += $(RPATH) -Wl,@executable_path/../lib
650  endif
651  ifeq ($(RC_BUILDIT),YES)
652    TempFile := $(shell mkdir -p ${OBJROOT}/dSYMs ; mktemp ${OBJROOT}/dSYMs/llvm-lto.XXXXXX)
653    LD.Flags += -Wl,-object_path_lto -Wl,$(TempFile)
654  endif
655endif
656endif
657
658
659#----------------------------------------------------------
660# Options To Invoke Tools
661#----------------------------------------------------------
662
663ifdef EXTRA_LD_OPTIONS
664LD.Flags += $(EXTRA_LD_OPTIONS)
665endif
666
667ifndef NO_PEDANTIC
668CompileCommonOpts += -pedantic -Wno-long-long
669endif
670CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
671                     $(EXTRA_OPTIONS) $(COVERED_SWITCH_DEFAULT)
672# Enable cast-qual for C++; the workaround is to use const_cast.
673CXX.Flags += -Wcast-qual
674
675ifeq ($(HOST_OS),HP-UX)
676  CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
677endif
678
679# If we are building a universal binary on Mac OS/X, pass extra options.  This
680# is useful to people that want to link the LLVM libraries into their universal
681# apps.
682#
683# The following can be optionally specified:
684#   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
685#      For Mac OS/X 10.4 Intel machines, the traditional one is:
686#      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
687#   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
688#      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
689#      i386/ppc only.
690ifdef UNIVERSAL
691  ifndef UNIVERSAL_ARCH
692    UNIVERSAL_ARCH := i386 ppc
693  endif
694  UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
695  CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
696  ifdef UNIVERSAL_SDK_PATH
697    CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
698  endif
699
700  # Building universal cannot compute dependencies automatically.
701  DISABLE_AUTO_DEPENDENCIES=1
702else
703  ifeq ($(TARGET_OS),Darwin)
704    ifeq ($(ARCH),x86_64)
705      TargetCommonOpts = -m64
706    else
707      ifeq ($(ARCH),x86)
708        TargetCommonOpts = -m32
709      endif
710    endif
711  endif
712endif
713
714ifeq ($(HOST_OS),SunOS)
715CPP.BaseFlags += -include llvm/Support/Solaris.h
716endif
717
718ifeq ($(HOST_OS),AuroraUX)
719CPP.BaseFlags += -include llvm/Support/Solaris.h
720endif # !HOST_OS - AuroraUX.
721
722# On Windows, SharedLibDir != LibDir. The order is important.
723ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
724  LD.Flags    += -L$(SharedLibDir) -L$(LibDir) -L$(LLVMToolDir) -L$(LLVMLibDir)
725else
726  LD.Flags    += -L$(LibDir) -L$(LLVMLibDir)
727endif
728
729CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
730# All -I flags should go here, so that they don't confuse llvm-config.
731CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
732	         $(patsubst %,-I%/include,\
733	         $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
734	         $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
735	         $(CPP.BaseFlags)
736
737ifeq ($(INCLUDE_BUILD_DIR),1)
738  CPP.Flags   += -I$(ObjDir)
739endif
740
741# SHOW_DIAGNOSTICS support.
742ifeq ($(SHOW_DIAGNOSTICS),1)
743  Compile.Wrapper := env CC_LOG_DIAGNOSTICS=1 \
744	                  CC_LOG_DIAGNOSTICS_FILE="$(LLVM_OBJ_ROOT)/$(BuildMode)/diags"
745else
746  Compile.Wrapper :=
747endif
748
749Compile.C     = $(Compile.Wrapper) \
750	          $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
751                $(TargetCommonOpts) $(CompileCommonOpts) -c
752Compile.CXX   = $(Compile.Wrapper) \
753	          $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
754                $(TargetCommonOpts) $(CompileCommonOpts) -c
755Preprocess.CXX= $(Compile.Wrapper) \
756	          $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
757                $(CompileCommonOpts) $(CXX.Flags) -E
758Link          = $(Compile.Wrapper) \
759	          $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
760                $(LDFLAGS) $(TargetCommonOpts)  $(CompileCommonOpts) $(Strip)
761
762BCCompile.C   = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
763                $(TargetCommonOpts) $(CompileCommonOpts)
764Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
765                $(TargetCommonOpts) $(CompileCommonOpts) -E
766
767BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
768                $(TargetCommonOpts) $(CompileCommonOpts)
769
770ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
771ScriptInstall = $(INSTALL) -m 0755
772DataInstall   = $(INSTALL) -m 0644
773
774# When compiling under Mingw/Cygwin, the tblgen tool expects Windows
775# paths. In this case, the SYSPATH function (defined in
776# Makefile.config) transforms Unix paths into Windows paths.
777TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
778                -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
779                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
780                -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
781LLVMTableGen  = $(LLVM_TBLGEN) $(TableGen.Flags)
782
783Archive       = $(AR) $(AR.Flags)
784LArchive      = $(LLVMToolDir)/llvm-ar rcsf
785ifdef RANLIB
786Ranlib        = $(RANLIB)
787else
788Ranlib        = ranlib
789endif
790
791AliasTool     = ln -s
792
793#----------------------------------------------------------
794# Get the list of source files and compute object file
795# names from them.
796#----------------------------------------------------------
797
798ifndef SOURCES
799  Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
800             $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
801else
802  Sources := $(SOURCES)
803endif
804
805ifdef BUILT_SOURCES
806Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
807endif
808
809BaseNameSources := $(sort $(basename $(Sources)))
810
811ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
812ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
813
814#----------------------------------------------------------
815# For Mingw MSYS bash and Python/w32:
816#
817# $(ECHOPATH) prints DOSish pathstring.
818#   ex) $(ECHOPATH) /include/sys/types.h
819#   --> C:/mingw/include/sys/types.h
820# built-in "echo" does not transform path to DOSish path.
821#
822# FIXME: It would not be needed when MSYS's python
823# were provided.
824#----------------------------------------------------------
825
826ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
827  ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
828else
829  ECHOPATH := $(Verb)$(ECHO)
830endif
831
832###############################################################################
833# DIRECTORIES: Handle recursive descent of directory structure
834###############################################################################
835
836#---------------------------------------------------------
837# Provide rules to make install dirs. This must be early
838# in the file so they get built before dependencies
839#---------------------------------------------------------
840
841$(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
842	$(Verb) $(MKDIR) $@
843
844# To create other directories, as needed, and timestamp their creation
845%/.dir:
846	$(Verb) $(MKDIR) $* > /dev/null
847	$(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
848
849.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
850.PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
851
852#---------------------------------------------------------
853# Handle the DIRS options for sequential construction
854#---------------------------------------------------------
855
856SubDirs :=
857ifdef DIRS
858SubDirs += $(DIRS)
859
860ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
861$(RecursiveTargets)::
862	$(Verb) for dir in $(DIRS); do \
863	  if ([ ! -f $$dir/Makefile ] || \
864	      command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
865	    $(MKDIR) $$dir; \
866	    $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
867	  fi; \
868	  ($(MAKE) -C $$dir $@ ) || exit 1; \
869	done
870else
871$(RecursiveTargets)::
872	$(Verb) for dir in $(DIRS); do \
873	  ($(MAKE) -C $$dir $@ ) || exit 1; \
874	done
875endif
876
877endif
878
879#---------------------------------------------------------
880# Handle the EXPERIMENTAL_DIRS options ensuring success
881# after each directory is built.
882#---------------------------------------------------------
883ifdef EXPERIMENTAL_DIRS
884$(RecursiveTargets)::
885	$(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
886	  if ([ ! -f $$dir/Makefile ] || \
887	      command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
888	    $(MKDIR) $$dir; \
889	    $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
890	  fi; \
891	  ($(MAKE) -C $$dir $@ ) || exit 0; \
892	done
893endif
894
895#-----------------------------------------------------------
896# Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
897#-----------------------------------------------------------
898ifdef OPTIONAL_PARALLEL_DIRS
899  PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) -o -f $(T)/Makefile && echo "$(T)"))
900endif
901
902#-----------------------------------------------------------
903# Handle the PARALLEL_DIRS options for parallel construction
904#-----------------------------------------------------------
905ifdef PARALLEL_DIRS
906
907SubDirs += $(PARALLEL_DIRS)
908
909# Unfortunately, this list must be maintained if new recursive targets are added
910all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
911clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
912clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
913install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
914uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
915install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
916unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
917
918ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
919
920$(ParallelTargets) :
921	$(Verb) \
922	  SD=$(PROJ_SRC_DIR)/$(@D); \
923	  DD=$(@D); \
924	  if [ ! -f $$SD/Makefile ]; then \
925	    SD=$(@D); \
926	    DD=$(notdir $(@D)); \
927	  fi; \
928	  if ([ ! -f $$DD/Makefile ] || \
929	            command test $$DD/Makefile -ot \
930                      $$SD/Makefile ); then \
931	  $(MKDIR) $$DD; \
932	  $(CP) $$SD/Makefile $$DD/Makefile; \
933	fi; \
934	$(MAKE) -C $$DD $(subst $(@D)/.make,,$@)
935endif
936
937#---------------------------------------------------------
938# Handle the OPTIONAL_DIRS options for directores that may
939# or may not exist.
940#---------------------------------------------------------
941ifdef OPTIONAL_DIRS
942
943SubDirs += $(OPTIONAL_DIRS)
944
945ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
946$(RecursiveTargets)::
947	$(Verb) for dir in $(OPTIONAL_DIRS); do \
948	  if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
949	    if ([ ! -f $$dir/Makefile ] || \
950	        command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
951	      $(MKDIR) $$dir; \
952	      $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
953	    fi; \
954	    ($(MAKE) -C$$dir $@ ) || exit 1; \
955	  fi \
956	done
957else
958$(RecursiveTargets)::
959	$(Verb) for dir in $(OPTIONAL_DIRS); do \
960	  if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
961	    ($(MAKE) -C$$dir $@ ) || exit 1; \
962	  fi \
963	done
964endif
965endif
966
967#---------------------------------------------------------
968# Handle the CONFIG_FILES options
969#---------------------------------------------------------
970ifdef CONFIG_FILES
971
972ifdef NO_INSTALL
973install-local::
974	$(Echo) Install circumvented with NO_INSTALL
975uninstall-local::
976	$(Echo) UnInstall circumvented with NO_INSTALL
977else
978install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
979	$(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
980	$(Verb)for file in $(CONFIG_FILES); do \
981          if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
982            $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
983          elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
984            $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
985          else \
986            $(ECHO) Error: cannot find config file $${file}. ; \
987          fi \
988	done
989
990uninstall-local::
991	$(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
992	$(Verb)for file in $(CONFIG_FILES); do \
993	  $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
994	done
995endif
996
997endif
998
999###############################################################################
1000# Set up variables for building libraries
1001###############################################################################
1002
1003#---------------------------------------------------------
1004# Define various command line options pertaining to the
1005# libraries needed when linking. There are "Proj" libs
1006# (defined by the user's project) and "LLVM" libs (defined
1007# by the LLVM project).
1008#---------------------------------------------------------
1009
1010ifdef USEDLIBS
1011ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
1012ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
1013ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
1014ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
1015endif
1016
1017ifdef LLVMLIBS
1018LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
1019LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
1020LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
1021LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
1022endif
1023
1024# Loadable module for Win32 requires all symbols resolved for linking.
1025# Then all symbols in LLVM.dll will be available.
1026ifeq ($(ENABLE_SHARED),1)
1027  ifdef LOADABLE_MODULE
1028    ifneq (,$(filter $(HOST_OS),Cygwin MingW))
1029      LINK_COMPONENTS += all
1030    endif
1031  endif
1032endif
1033
1034ifndef IS_CLEANING_TARGET
1035ifdef LINK_COMPONENTS
1036
1037# If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
1038# clean in tools, then do a make in tools (instead of at the top level).
1039$(LLVM_CONFIG):
1040	@echo "*** llvm-config doesn't exist - rebuilding it."
1041	@$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
1042
1043$(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
1044
1045ifeq ($(ENABLE_SHARED), 1)
1046# We can take the "auto-import" feature to get rid of using dllimport.
1047ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1048LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
1049                   -L $(SharedLibDir)
1050endif
1051LLVMLibsOptions += -lLLVM-$(LLVMVersion)
1052LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
1053else
1054
1055ifndef NO_LLVM_CONFIG
1056LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
1057ifeq ($(LLVMConfigLibs),Error)
1058$(error llvm-config --libs failed)
1059endif
1060LLVMLibsOptions += $(LLVMConfigLibs)
1061LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
1062ifeq ($(LLVMConfigLibfiles),Error)
1063$(error llvm-config --libfiles failed)
1064endif
1065LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
1066endif
1067
1068endif
1069endif
1070endif
1071
1072# Set up the library exports file.
1073ifdef EXPORTED_SYMBOL_FILE
1074
1075# First, set up the native export file, which may differ from the source
1076# export file.
1077
1078ifeq ($(HOST_OS),Darwin)
1079# Darwin convention prefixes symbols with underscores.
1080NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
1081$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1082	$(Verb) sed -e 's/^/_/' < $< > $@
1083clean-local::
1084	-$(Verb) $(RM) -f $(NativeExportsFile)
1085else
1086ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1087# Gold and BFD ld require a version script rather than a plain list.
1088NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
1089$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1090	$(Verb) echo "{" > $@
1091	$(Verb) grep -q '[[:alnum:]_]' $< && echo "  global:" >> $@ || :
1092	$(Verb) sed -e 's/$$/;/' -e 's/^/    /' < $< >> $@
1093ifneq ($(HOST_OS),OpenBSD)
1094	$(Verb) echo "  local: *;" >> $@
1095endif
1096	$(Verb) echo "};" >> $@
1097clean-local::
1098	-$(Verb) $(RM) -f $(NativeExportsFile)
1099else
1100ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1101# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
1102NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
1103$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
1104	$(Echo) Generating $(notdir $@)
1105	$(Verb) $(ECHO) "EXPORTS" > $@
1106	$(Verb) $(CAT) $< >> $@
1107clean-local::
1108	-$(Verb) $(RM) -f $(NativeExportsFile)
1109else
1110# Default behavior: just use the exports file verbatim.
1111NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
1112endif
1113endif
1114endif
1115
1116# Now add the linker command-line options to use the native export file.
1117
1118# Darwin
1119ifeq ($(HOST_OS),Darwin)
1120LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
1121endif
1122
1123# gold, bfd ld, etc.
1124ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
1125LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
1126endif
1127
1128# Windows
1129ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1130# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
1131SharedLinkOptions += $(NativeExportsFile)
1132endif
1133
1134endif
1135
1136###############################################################################
1137# Library Build Rules: Four ways to build a library
1138###############################################################################
1139
1140#---------------------------------------------------------
1141# Bytecode Module Targets:
1142#   If the user set MODULE_NAME then they want to build a
1143#   bytecode module from the sources. We compile all the
1144#   sources and link it together into a single bytecode
1145#   module.
1146#---------------------------------------------------------
1147
1148ifdef MODULE_NAME
1149ifeq ($(strip $(LLVMCC)),)
1150$(warning Modules require LLVM capable compiler but none is available ****)
1151else
1152
1153Module     := $(LibDir)/$(MODULE_NAME).bc
1154LinkModule := $(LLVMLINK)
1155
1156
1157ifdef EXPORTED_SYMBOL_FILE
1158LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1159endif
1160
1161$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLINK)
1162	$(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
1163	$(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1164
1165all-local:: $(Module)
1166
1167clean-local::
1168ifneq ($(strip $(Module)),)
1169	-$(Verb) $(RM) -f $(Module)
1170endif
1171
1172ifdef BYTECODE_DESTINATION
1173ModuleDestDir := $(BYTECODE_DESTINATION)
1174else
1175ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
1176endif
1177
1178ifdef NO_INSTALL
1179install-local::
1180	$(Echo) Install circumvented with NO_INSTALL
1181uninstall-local::
1182	$(Echo) Uninstall circumvented with NO_INSTALL
1183else
1184DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1185
1186install-module:: $(DestModule)
1187install-local:: $(DestModule)
1188
1189$(DestModule): $(ModuleDestDir) $(Module)
1190	$(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
1191	$(Verb) $(DataInstall) $(Module) $(DestModule)
1192
1193uninstall-local::
1194	$(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1195	-$(Verb) $(RM) -f $(DestModule)
1196endif
1197
1198endif
1199endif
1200
1201# if we're building a library ...
1202ifdef LIBRARYNAME
1203
1204# Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
1205LIBRARYNAME := $(strip $(LIBRARYNAME))
1206ifdef LOADABLE_MODULE
1207BaseLibName.A  := $(LIBRARYNAME).a
1208BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
1209else
1210BaseLibName.A  := lib$(LIBRARYNAME).a
1211BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
1212endif
1213LibName.A  := $(LibDir)/$(BaseLibName.A)
1214LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
1215LibName.O  := $(LibDir)/$(LIBRARYNAME).o
1216LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
1217
1218#---------------------------------------------------------
1219# Shared Library Targets:
1220#   If the user asked for a shared library to be built
1221#   with the SHARED_LIBRARY variable, then we provide
1222#   targets for building them.
1223#---------------------------------------------------------
1224ifdef SHARED_LIBRARY
1225
1226all-local:: $(LibName.SO)
1227
1228ifdef EXPORTED_SYMBOL_FILE
1229$(LibName.SO): $(NativeExportsFile)
1230endif
1231
1232ifdef LINK_LIBS_IN_SHARED
1233ifdef LOADABLE_MODULE
1234SharedLibKindMessage := "Loadable Module"
1235SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
1236else
1237SharedLibKindMessage := "Shared Library"
1238endif
1239$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
1240	$(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1241	  $(notdir $@)
1242	$(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
1243	  $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
1244else
1245$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
1246	$(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
1247	$(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
1248endif
1249
1250clean-local::
1251ifneq ($(strip $(LibName.SO)),)
1252	-$(Verb) $(RM) -f $(LibName.SO)
1253endif
1254
1255ifdef NO_INSTALL
1256install-local::
1257	$(Echo) Install circumvented with NO_INSTALL
1258uninstall-local::
1259	$(Echo) Uninstall circumvented with NO_INSTALL
1260else
1261
1262# Win32.DLL prefers to be located on the "PATH" of binaries.
1263ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1264DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
1265else
1266DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
1267endif
1268DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
1269
1270install-local:: $(DestSharedLib)
1271
1272$(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
1273	$(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
1274	$(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
1275
1276uninstall-local::
1277	$(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
1278	-$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
1279endif
1280endif
1281
1282#---------------------------------------------------------
1283# Bytecode Library Targets:
1284#   If the user asked for a bytecode library to be built
1285#   with the BYTECODE_LIBRARY variable, then we provide
1286#   targets for building them.
1287#---------------------------------------------------------
1288ifdef BYTECODE_LIBRARY
1289ifeq ($(strip $(LLVMCC)),)
1290$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
1291else
1292
1293all-local:: $(LibName.BCA)
1294
1295ifdef EXPORTED_SYMBOL_FILE
1296BCLinkLib = $(LLVMLINK) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1297
1298$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLINK) \
1299                $(LLVMToolDir)/llvm-ar
1300	$(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1301	  "(internalize)"
1302	$(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
1303	$(Verb) $(RM) -f $@
1304	$(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
1305else
1306$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
1307                $(LLVMToolDir)/llvm-ar
1308	$(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
1309	$(Verb) $(RM) -f $@
1310	$(Verb) $(LArchive) $@ $(ObjectsBC)
1311
1312endif
1313
1314clean-local::
1315ifneq ($(strip $(LibName.BCA)),)
1316	-$(Verb) $(RM) -f $(LibName.BCA)
1317endif
1318
1319ifdef BYTECODE_DESTINATION
1320BytecodeDestDir := $(BYTECODE_DESTINATION)
1321else
1322BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
1323endif
1324
1325DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
1326
1327install-bytecode-local:: $(DestBytecodeLib)
1328
1329ifdef NO_INSTALL
1330install-local::
1331	$(Echo) Install circumvented with NO_INSTALL
1332uninstall-local::
1333	$(Echo) Uninstall circumvented with NO_INSTALL
1334else
1335install-local:: $(DestBytecodeLib)
1336
1337$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
1338	$(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1339	$(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1340
1341uninstall-local::
1342	$(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1343	-$(Verb) $(RM) -f $(DestBytecodeLib)
1344endif
1345endif
1346endif
1347
1348#---------------------------------------------------------
1349# Library Targets:
1350#   If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1351#   building an archive.
1352#---------------------------------------------------------
1353ifndef NO_BUILD_ARCHIVE
1354ifndef BUILD_ARCHIVE
1355ifndef LOADABLE_MODULE
1356BUILD_ARCHIVE = 1
1357endif
1358endif
1359endif
1360
1361#---------------------------------------------------------
1362# Archive Library Targets:
1363#   If the user wanted a regular archive library built,
1364#   then we provide targets for building them.
1365#---------------------------------------------------------
1366ifdef BUILD_ARCHIVE
1367
1368all-local:: $(LibName.A)
1369
1370$(LibName.A): $(ObjectsO) $(LibDir)/.dir
1371	$(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1372	-$(Verb) $(RM) -f $@
1373	$(Verb) $(Archive) $@ $(ObjectsO)
1374	$(Verb) $(Ranlib) $@
1375
1376clean-local::
1377ifneq ($(strip $(LibName.A)),)
1378	-$(Verb) $(RM) -f $(LibName.A)
1379endif
1380
1381ifdef NO_INSTALL
1382install-local::
1383	$(Echo) Install circumvented with NO_INSTALL
1384uninstall-local::
1385	$(Echo) Uninstall circumvented with NO_INSTALL
1386else
1387ifdef NO_INSTALL_ARCHIVES
1388install-local::
1389	$(Echo) Install circumvented with NO_INSTALL
1390uninstall-local::
1391	$(Echo) Uninstall circumvented with NO_INSTALL
1392else
1393DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
1394
1395install-local:: $(DestArchiveLib)
1396
1397$(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
1398	$(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1399	$(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
1400	$(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1401
1402uninstall-local::
1403	$(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1404	-$(Verb) $(RM) -f $(DestArchiveLib)
1405endif
1406endif
1407endif
1408
1409# endif LIBRARYNAME
1410endif
1411
1412###############################################################################
1413# Tool Build Rules: Build executable tool based on TOOLNAME option
1414###############################################################################
1415
1416ifdef TOOLNAME
1417
1418#---------------------------------------------------------
1419# Set up variables for building a tool.
1420#---------------------------------------------------------
1421TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
1422ifdef EXAMPLE_TOOL
1423ToolBuildPath   := $(ExmplDir)/$(TOOLEXENAME)
1424else
1425ToolBuildPath   := $(ToolDir)/$(TOOLEXENAME)
1426endif
1427
1428# TOOLALIAS is a name to symlink (or copy) the tool to.
1429ifdef TOOLALIAS
1430ifdef EXAMPLE_TOOL
1431ToolAliasBuildPath   := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1432else
1433ToolAliasBuildPath   := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1434endif
1435endif
1436
1437#---------------------------------------------------------
1438# Prune Exports
1439#---------------------------------------------------------
1440
1441# If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1442# not exporting all of the weak symbols from the binary.  This reduces dyld
1443# startup time by 4x on darwin in some cases.
1444ifdef TOOL_NO_EXPORTS
1445ifeq ($(HOST_OS),Darwin)
1446
1447# Tiger tools don't support this.
1448ifneq ($(DARWIN_MAJVERS),4)
1449LD.Flags += -Wl,-exported_symbol,_main
1450endif
1451endif
1452
1453ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD GNU))
1454ifneq ($(ARCH), Mips)
1455  LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
1456endif
1457endif
1458endif
1459
1460#---------------------------------------------------------
1461# Tool Order File Support
1462#---------------------------------------------------------
1463
1464ifeq ($(HOST_OS),Darwin)
1465ifdef TOOL_ORDER_FILE
1466
1467LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
1468
1469endif
1470endif
1471
1472#---------------------------------------------------------
1473# Tool Version Info Support
1474#---------------------------------------------------------
1475
1476ifeq ($(HOST_OS),Darwin)
1477ifdef TOOL_INFO_PLIST
1478
1479LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1480
1481$(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1482
1483$(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
1484	$(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1485	$(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1486	           -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1487	           -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1488	         -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1489	           $< > $@
1490
1491endif
1492endif
1493
1494#---------------------------------------------------------
1495# Provide targets for building the tools
1496#---------------------------------------------------------
1497all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
1498
1499clean-local::
1500ifneq ($(strip $(ToolBuildPath)),)
1501	-$(Verb) $(RM) -f $(ToolBuildPath)
1502endif
1503ifneq ($(strip $(ToolAliasBuildPath)),)
1504	-$(Verb) $(RM) -f $(ToolAliasBuildPath)
1505endif
1506
1507ifdef EXAMPLE_TOOL
1508$(ToolBuildPath): $(ExmplDir)/.dir
1509else
1510$(ToolBuildPath): $(ToolDir)/.dir
1511endif
1512
1513ifdef CODESIGN_TOOLS
1514$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1515	$(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1516	$(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1517	$(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1518	$(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1519          $(StripWarnMsg)
1520	$(Echo) ======= Code-Signing $(BuildMode) Executable $(TOOLNAME)
1521	$(Verb) codesign -s - $@
1522else
1523$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1524	$(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1525	$(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1526	$(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1527	$(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1528          $(StripWarnMsg)
1529endif
1530
1531ifneq ($(strip $(ToolAliasBuildPath)),)
1532$(ToolAliasBuildPath): $(ToolBuildPath)
1533	$(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1534	$(Verb) $(RM) -f $(ToolAliasBuildPath)
1535	$(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
1536	$(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
1537          $(StripWarnMsg)
1538endif
1539
1540ifdef NO_INSTALL
1541install-local::
1542	$(Echo) Install circumvented with NO_INSTALL
1543uninstall-local::
1544	$(Echo) Uninstall circumvented with NO_INSTALL
1545else
1546
1547ifdef INTERNAL_TOOL
1548ToolBinDir = $(DESTDIR)$(PROJ_internal_prefix)/bin
1549else
1550ToolBinDir = $(DESTDIR)$(PROJ_bindir)
1551endif
1552DestTool = $(ToolBinDir)/$(program_prefix)$(TOOLEXENAME)
1553
1554install-local:: $(DestTool)
1555
1556$(DestTool): $(ToolBuildPath)
1557	$(Echo) Installing $(BuildMode) $(DestTool)
1558	$(Verb) $(MKDIR) $(ToolBinDir)
1559	$(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1560
1561uninstall-local::
1562	$(Echo) Uninstalling $(BuildMode) $(DestTool)
1563	-$(Verb) $(RM) -f $(DestTool)
1564
1565# TOOLALIAS install.
1566ifdef TOOLALIAS
1567DestToolAlias = $(ToolBinDir)/$(program_prefix)$(TOOLALIAS)$(EXEEXT)
1568
1569install-local:: $(DestToolAlias)
1570
1571$(DestToolAlias): $(DestTool)
1572	$(Echo) Installing $(BuildMode) $(DestToolAlias)
1573	$(Verb) $(RM) -f $(DestToolAlias)
1574	$(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1575
1576uninstall-local::
1577	$(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1578	-$(Verb) $(RM) -f $(DestToolAlias)
1579endif
1580
1581endif
1582endif
1583
1584###############################################################################
1585# Object Build Rules: Build object files based on sources
1586###############################################################################
1587
1588# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1589ifeq ($(HOST_OS),HP-UX)
1590  DISABLE_AUTO_DEPENDENCIES=1
1591endif
1592
1593# Provide rule sets for when dependency generation is enabled
1594ifndef DISABLE_AUTO_DEPENDENCIES
1595
1596#---------------------------------------------------------
1597# Create .o files in the ObjDir directory from the .cpp and .c files...
1598#---------------------------------------------------------
1599
1600DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1601         -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1602
1603# If the build succeeded, move the dependency file over, otherwise
1604# remove it.
1605DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1606                  else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1607
1608$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1609	$(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1610	$(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1611	        $(DEPEND_MOVEFILE)
1612
1613$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1614	$(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1615	$(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1616	        $(DEPEND_MOVEFILE)
1617
1618$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1619	$(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1620	$(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1621	        $(DEPEND_MOVEFILE)
1622
1623$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1624	$(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1625	$(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1626	        $(DEPEND_MOVEFILE)
1627
1628$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
1629	$(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1630	$(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1631	        $(DEPEND_MOVEFILE)
1632
1633#---------------------------------------------------------
1634# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1635#---------------------------------------------------------
1636
1637BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1638	-MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1639
1640# If the build succeeded, move the dependency file over, otherwise
1641# remove it.
1642BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1643                     else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1644
1645$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1646	$(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1647	$(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1648			$< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1649	        $(BC_DEPEND_MOVEFILE)
1650
1651$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1652	$(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1653	$(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1654			$< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1655	        $(BC_DEPEND_MOVEFILE)
1656
1657$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1658	$(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1659	$(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1660			$< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1661	        $(BC_DEPEND_MOVEFILE)
1662
1663$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1664	$(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1665	$(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1666			$< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1667	        $(BC_DEPEND_MOVEFILE)
1668
1669$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1670	$(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1671	$(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1672			$< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
1673	        $(BC_DEPEND_MOVEFILE)
1674
1675# Provide alternate rule sets if dependencies are disabled
1676else
1677
1678$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1679	$(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1680	$(Compile.CXX) $< -o $@
1681
1682$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1683	$(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1684	$(Compile.CXX) $< -o $@
1685
1686$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1687	$(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1688	$(Compile.CXX) $< -o $@
1689
1690$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1691	$(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1692	$(Compile.C) $< -o $@
1693
1694$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1695	$(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1696	$(Compile.C) $< -o $@
1697
1698$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1699	$(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1700	$(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1701
1702$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1703	$(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1704	$(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1705
1706$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1707	$(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1708	$(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1709
1710$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1711	$(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1712	$(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1713
1714$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1715	$(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1716	$(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
1717
1718endif
1719
1720
1721## Rules for building preprocessed (.i/.ii) outputs.
1722$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1723	$(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1724	$(Verb) $(Preprocess.CXX) $< -o $@
1725
1726$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1727	$(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1728	$(Verb) $(Preprocess.CXX) $< -o $@
1729
1730$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1731	$(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1732	$(Verb) $(Preprocess.CXX) $< -o $@
1733
1734$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1735	$(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1736	$(Verb) $(Preprocess.C) $< -o $@
1737
1738$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1739	$(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1740	$(Verb) $(Preprocess.C) $< -o $@
1741
1742
1743$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1744	$(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1745	$(Compile.CXX) $< -o $@ -S
1746
1747$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1748	$(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1749	$(Compile.CXX) $< -o $@ -S
1750
1751$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1752	$(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1753	$(Compile.CXX) $< -o $@ -S
1754
1755$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1756	$(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1757	$(Compile.C) $< -o $@ -S
1758
1759$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1760	$(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1761	$(Compile.C) $< -o $@ -S
1762
1763
1764# make the C and C++ compilers strip debug info out of bytecode libraries.
1765ifdef DEBUG_RUNTIME
1766$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1767	$(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1768	$(Verb) $(LOPT) $< -std-compile-opts -o $@
1769else
1770$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1771	$(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1772	$(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
1773endif
1774
1775
1776#---------------------------------------------------------
1777# Provide rule to build .bc files from .ll sources,
1778# regardless of dependencies
1779#---------------------------------------------------------
1780$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1781	$(Echo) "Compiling $*.ll for $(BuildMode) build"
1782	$(Verb) $(LLVMAS) $< -f -o $@
1783
1784###############################################################################
1785# TABLEGEN: Provide rules for running tblgen to produce *.inc files
1786###############################################################################
1787
1788ifdef TARGET
1789TABLEGEN_INC_FILES_COMMON = 1
1790endif
1791
1792ifdef TABLEGEN_INC_FILES_COMMON
1793
1794INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1795INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1796.PRECIOUS: $(INCTMPFiles) $(INCFiles)
1797
1798# INCFiles rule: All of the tblgen generated files are emitted to
1799# $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1800# us to only "touch" the real file if the contents of it change.  IOW, if
1801# tblgen is modified, all of the .inc.tmp files are regenerated, but no
1802# dependencies of the .inc files are, unless the contents of the .inc file
1803# changes.
1804$(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1805	$(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1806
1807endif # TABLEGEN_INC_FILES_COMMON
1808
1809ifdef TARGET
1810
1811TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1812           $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1813           $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1814           $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1815           $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1816           $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1817           $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1818
1819# All .inc.tmp files depend on the .td files.
1820$(INCTMPFiles) : $(TDFiles)
1821
1822$(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1823$(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1824	$(Echo) "Building $(<F) register info implementation with tblgen"
1825	$(Verb) $(LLVMTableGen) -gen-register-info -o $(call SYSPATH, $@) $<
1826
1827$(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1828$(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1829	$(Echo) "Building $(<F) instruction information with tblgen"
1830	$(Verb) $(LLVMTableGen) -gen-instr-info -o $(call SYSPATH, $@) $<
1831
1832$(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1833$(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1834	$(Echo) "Building $(<F) assembly writer with tblgen"
1835	$(Verb) $(LLVMTableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1836
1837$(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1838$(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1839	$(Echo) "Building $(<F) assembly writer #1 with tblgen"
1840	$(Verb) $(LLVMTableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1841
1842$(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1843$(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1844	$(Echo) "Building $(<F) assembly matcher with tblgen"
1845	$(Verb) $(LLVMTableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1846
1847$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
1848$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1849	$(Echo) "Building $(<F) MC code emitter with tblgen"
1850	$(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
1851
1852$(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
1853$(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1854	$(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
1855	$(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
1856
1857$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1858$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1859	$(Echo) "Building $(<F) code emitter with tblgen"
1860	$(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1861
1862$(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1863$(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1864	$(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1865	$(Verb) $(LLVMTableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1866
1867$(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1868$(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1869	$(Echo) "Building $(<F) disassembly tables with tblgen"
1870	$(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1871
1872$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1873$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1874	$(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1875	$(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1876
1877$(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1878$(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1879	$(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1880	$(Verb) $(LLVMTableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1881
1882$(TARGET:%=$(ObjDir)/%GenSubtargetInfo.inc.tmp): \
1883$(ObjDir)/%GenSubtargetInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1884	$(Echo) "Building $(<F) subtarget information with tblgen"
1885	$(Verb) $(LLVMTableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1886
1887$(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1888$(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1889	$(Echo) "Building $(<F) calling convention information with tblgen"
1890	$(Verb) $(LLVMTableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1891
1892$(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1893$(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1894	$(Echo) "Building $(<F) intrinsics information with tblgen"
1895	$(Verb) $(LLVMTableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1896
1897$(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1898	$(Echo) "Building $(<F) decoder tables with tblgen"
1899	$(Verb) $(LLVMTableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
1900
1901$(ObjDir)/%GenDFAPacketizer.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
1902	$(Echo) "Building $(<F) DFA packetizer tables with tblgen"
1903	$(Verb) $(LLVMTableGen) -gen-dfa-packetizer -o $(call SYSPATH, $@) $<
1904
1905clean-local::
1906	-$(Verb) $(RM) -f $(INCFiles)
1907
1908endif # TARGET
1909
1910###############################################################################
1911# OTHER RULES: Other rules needed
1912###############################################################################
1913
1914# To create postscript files from dot files...
1915ifneq ($(DOT),false)
1916%.ps: %.dot
1917	$(DOT) -Tps < $< > $@
1918else
1919%.ps: %.dot
1920	$(Echo) "Cannot build $@: The program dot is not installed"
1921endif
1922
1923# This rules ensures that header files that are removed still have a rule for
1924# which they can be "generated."  This allows make to ignore them and
1925# reproduce the dependency lists.
1926%.h:: ;
1927%.hpp:: ;
1928
1929# Define clean-local to clean the current directory. Note that this uses a
1930# very conservative approach ensuring that empty variables do not cause
1931# errors or disastrous removal.
1932clean-local::
1933ifneq ($(strip $(ObjRootDir)),)
1934	-$(Verb) $(RM) -rf $(ObjRootDir)
1935endif
1936ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1937	-$(Verb) $(RM) -f *$(SHLIBEXT)
1938endif
1939
1940clean-all-local::
1941	-$(Verb) $(RM) -rf Debug Release Profile
1942
1943
1944###############################################################################
1945# DEPENDENCIES: Include the dependency files if we should
1946###############################################################################
1947ifndef DISABLE_AUTO_DEPENDENCIES
1948
1949# If its not one of the cleaning targets
1950ifndef IS_CLEANING_TARGET
1951
1952# Get the list of dependency files
1953DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
1954DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1955
1956# Include bitcode dependency files if using bitcode libraries
1957ifdef BYTECODE_LIBRARY
1958DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1959endif
1960
1961-include $(DependFiles) ""
1962
1963endif
1964
1965endif
1966
1967###############################################################################
1968# CHECK: Running the test suite
1969###############################################################################
1970
1971check::
1972	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1973	  if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1974	    $(EchoCmd) Running test suite ; \
1975	    $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1976	      TESTSUITE=$(TESTSUITE) ; \
1977	  else \
1978	    $(EchoCmd) No Makefile in test directory ; \
1979	  fi ; \
1980	else \
1981	  $(EchoCmd) No test directory ; \
1982	fi
1983
1984# An alias dating from when both lit and DejaGNU test runners were used.
1985check-lit:: check
1986
1987check-all::
1988	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1989	  if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1990	    $(EchoCmd) Running test suite ; \
1991	    $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1992	  else \
1993	    $(EchoCmd) No Makefile in test directory ; \
1994	  fi ; \
1995	else \
1996	  $(EchoCmd) No test directory ; \
1997	fi
1998
1999###############################################################################
2000# UNITTESTS: Running the unittests test suite
2001###############################################################################
2002
2003unittests::
2004	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
2005	  if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
2006	    $(EchoCmd) Running unittests test suite ; \
2007	    $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
2008	  else \
2009	    $(EchoCmd) No Makefile in unittests directory ; \
2010	  fi ; \
2011	else \
2012	  $(EchoCmd) No unittests directory ; \
2013	fi
2014
2015###############################################################################
2016# DISTRIBUTION: Handle construction of a distribution tarball
2017###############################################################################
2018
2019#------------------------------------------------------------------------
2020# Define distribution related variables
2021#------------------------------------------------------------------------
2022DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
2023DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
2024TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
2025DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
2026DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
2027DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
2028DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
2029	       ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
2030	       Makefile.config.in configure autoconf
2031DistOther   := $(notdir $(wildcard \
2032               $(PROJ_SRC_DIR)/*.h \
2033               $(PROJ_SRC_DIR)/*.td \
2034               $(PROJ_SRC_DIR)/*.def \
2035               $(PROJ_SRC_DIR)/*.ll \
2036               $(PROJ_SRC_DIR)/*.in))
2037DistSubDirs := $(SubDirs)
2038DistSources  = $(Sources) $(EXTRA_DIST)
2039DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
2040
2041#------------------------------------------------------------------------
2042# We MUST build distribution with OBJ_DIR != SRC_DIR
2043#------------------------------------------------------------------------
2044ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
2045dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
2046	$(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
2047
2048else
2049
2050#------------------------------------------------------------------------
2051# Prevent attempt to run dist targets from anywhere but the top level
2052#------------------------------------------------------------------------
2053ifneq ($(LEVEL),.)
2054dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
2055	$(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
2056else
2057
2058#------------------------------------------------------------------------
2059# Provide the top level targets
2060#------------------------------------------------------------------------
2061
2062dist-gzip:: $(DistTarGZip)
2063
2064$(DistTarGZip) : $(TopDistDir)/.makedistdir
2065	$(Echo) Packing gzipped distribution tar file.
2066	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
2067	  $(GZIP) -c > "$(DistTarGZip)"
2068
2069dist-bzip2:: $(DistTarBZ2)
2070
2071$(DistTarBZ2) : $(TopDistDir)/.makedistdir
2072	$(Echo) Packing bzipped distribution tar file.
2073	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
2074	  $(BZIP2) -c >$(DistTarBZ2)
2075
2076dist-zip:: $(DistZip)
2077
2078$(DistZip) : $(TopDistDir)/.makedistdir
2079	$(Echo) Packing zipped distribution file.
2080	$(Verb) rm -f $(DistZip)
2081	$(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
2082
2083dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
2084	$(Echo) ===== DISTRIBUTION PACKAGING SUCCESSFUL =====
2085
2086DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
2087
2088dist-check:: $(DistTarGZip)
2089	$(Echo) Checking distribution tar file.
2090	$(Verb) if test -d $(DistCheckDir) ; then \
2091	  $(RM) -rf $(DistCheckDir) ; \
2092	fi
2093	$(Verb) $(MKDIR) $(DistCheckDir)
2094	$(Verb) cd $(DistCheckDir) && \
2095	  $(MKDIR) $(DistCheckDir)/build && \
2096	  $(MKDIR) $(DistCheckDir)/install && \
2097	  gunzip -c $(DistTarGZip) | $(TAR) xf - && \
2098	  cd build && \
2099	  ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
2100	    --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
2101	  $(MAKE) all && \
2102	  $(MAKE) check && \
2103	  $(MAKE) unittests && \
2104	  $(MAKE) install && \
2105	  $(MAKE) uninstall && \
2106	  $(MAKE) dist-clean && \
2107	  $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
2108
2109dist-clean::
2110	$(Echo) Cleaning distribution files
2111	-$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
2112	  $(DistCheckDir)
2113
2114endif
2115
2116#------------------------------------------------------------------------
2117# Provide the recursive distdir target for building the distribution directory
2118#------------------------------------------------------------------------
2119distdir: $(DistDir)/.makedistdir
2120$(DistDir)/.makedistdir: $(DistSources)
2121	$(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2122	  if test -d "$(DistDir)" ; then \
2123	    find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
2124	      exit 1 ; \
2125	  fi ; \
2126	  $(EchoCmd) Removing old $(DistDir) ; \
2127	  $(RM) -rf $(DistDir); \
2128	  $(EchoCmd) Making 'all' to verify build ; \
2129	  $(MAKE) ENABLE_OPTIMIZED=1 all ; \
2130	fi
2131	$(Echo) Building Distribution Directory $(DistDir)
2132	$(Verb) $(MKDIR) $(DistDir)
2133	$(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2134	srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
2135	for file in $(DistFiles) ; do \
2136	  case "$$file" in \
2137	    $(PROJ_SRC_DIR)/*) \
2138	      file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2139	      ;; \
2140	    $(PROJ_SRC_ROOT)/*) \
2141	      file=`echo "$$file" | \
2142		sed "s#^$$srcrootstrip/##"` \
2143	      ;; \
2144	  esac; \
2145	  if test -f "$(PROJ_SRC_DIR)/$$file" || \
2146	     test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2147	    from_dir="$(PROJ_SRC_DIR)" ; \
2148	  elif test -f "$$file" || test -d "$$file" ; then \
2149	    from_dir=. ; \
2150	  fi ; \
2151	  to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
2152	  if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2153	    to_dir="$(DistDir)/$$dir"; \
2154	    $(MKDIR) "$$to_dir" ; \
2155	  else \
2156	    to_dir="$(DistDir)"; \
2157	  fi; \
2158	  mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2159	  if test -n "$$mid_dir" ; then \
2160            $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
2161          fi ; \
2162	  if test -d "$$from_dir/$$file"; then \
2163	    if test -d "$(PROJ_SRC_DIR)/$$file" && \
2164	       test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
2165	       cd $(PROJ_SRC_DIR) ; \
2166	       $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2167	         ( cd $$to_dir ; $(TAR) xf - ) ; \
2168	       cd $(PROJ_OBJ_DIR) ; \
2169	    else \
2170	       cd $$from_dir ; \
2171	       $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2172	         ( cd $$to_dir ; $(TAR) xf - ) ; \
2173	       cd $(PROJ_OBJ_DIR) ; \
2174	    fi; \
2175	  elif test -f "$$from_dir/$$file" ; then \
2176	    $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
2177	  elif test -L "$$from_dir/$$file" ; then \
2178	    $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
2179	  elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
2180	    $(EchoCmd) "===== WARNING: Distribution Source " \
2181	      "$$from_dir/$$file Not Found!" ; \
2182	  elif test "$(Verb)" != '@' ; then \
2183	    $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
2184	  fi; \
2185	done
2186	$(Verb) for subdir in $(DistSubDirs) ; do \
2187	  if test "$$subdir" \!= "." ; then \
2188	    new_distdir="$(DistDir)/$$subdir" ; \
2189	    test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
2190	    ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
2191	      DistDir="$$new_distdir" distdir ) || exit 1; \
2192	  fi; \
2193	done
2194	$(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2195	  $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
2196	  $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2197                                  -name .svn \) -print` ;\
2198	  $(MAKE) dist-hook ; \
2199	  $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2200	    -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2201	    -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2202	    -o ! -type d ! -perm -444 -exec \
2203	      $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2204	    || chmod -R a+r $(DistDir) ; \
2205	fi
2206
2207# This is invoked by distdir target, define it as a no-op to avoid errors if not
2208# defined by user.
2209dist-hook::
2210
2211endif
2212
2213###############################################################################
2214# TOP LEVEL - targets only to apply at the top level directory
2215###############################################################################
2216
2217ifeq ($(LEVEL),.)
2218
2219#------------------------------------------------------------------------
2220# Install support for the project's include files:
2221#------------------------------------------------------------------------
2222ifdef NO_INSTALL
2223install-local::
2224	$(Echo) Install circumvented with NO_INSTALL
2225uninstall-local::
2226	$(Echo) Uninstall circumvented with NO_INSTALL
2227else
2228install-local::
2229	$(Echo) Installing include files
2230	$(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
2231	$(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
2232	  cd $(PROJ_SRC_ROOT)/include && \
2233	  for hdr in `find . -type f \
2234	      '(' -name LICENSE.TXT \
2235	       -o -name '*.def' \
2236	       -o -name '*.h' \
2237	       -o -name '*.inc' \
2238	       -o -name '*.td' \
2239	      ')' -print | grep -v CVS | \
2240	      grep -v .svn` ; do \
2241	    instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2242	    if test \! -d "$$instdir" ; then \
2243	      $(EchoCmd) Making install directory $$instdir ; \
2244	      $(MKDIR) $$instdir ;\
2245	    fi ; \
2246	    $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2247	  done ; \
2248	fi
2249ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
2250	$(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
2251	  cd $(PROJ_OBJ_ROOT)/include && \
2252	  for hdr in `find . -type f \
2253	      '(' -name LICENSE.TXT \
2254	       -o -name '*.def' \
2255	       -o -name '*.h' \
2256	       -o -name '*.inc' \
2257	       -o -name '*.td' \
2258	      ')' -print | grep -v CVS | \
2259	      grep -v .svn` ; do \
2260	    instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2261	    if test \! -d "$$instdir" ; then \
2262	      $(EchoCmd) Making install directory $$instdir ; \
2263	      $(MKDIR) $$instdir ;\
2264	    fi ; \
2265	    $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2266	  done ; \
2267	fi
2268endif
2269
2270uninstall-local::
2271	$(Echo) Uninstalling include files
2272	$(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2273	  cd $(PROJ_SRC_ROOT)/include && \
2274	    $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
2275	      '!' '(' -name '*~' -o -name '.#*' \
2276        -o -name '*.in' ')' -print ')' | \
2277        grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2278	  cd $(PROJ_SRC_ROOT)/include && \
2279	    $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
2280      -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2281	fi
2282endif
2283endif
2284
2285check-line-length:
2286	@echo searching for overlength lines in files: $(Sources)
2287	@echo
2288	@echo
2289	egrep -n '.{81}' $(Sources) /dev/null
2290
2291check-for-tabs:
2292	@echo searching for tabs in files: $(Sources)
2293	@echo
2294	@echo
2295	egrep -n '	' $(Sources) /dev/null
2296
2297check-footprint:
2298	@ls -l $(LibDir) | awk '\
2299	  BEGIN { sum = 0; } \
2300	        { sum += $$5; } \
2301	  END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2302	@ls -l $(ToolDir) | awk '\
2303	  BEGIN { sum = 0; } \
2304	        { sum += $$5; } \
2305	  END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2306#------------------------------------------------------------------------
2307# Print out the directories used for building
2308#------------------------------------------------------------------------
2309printvars::
2310	$(Echo) "BuildMode    : " '$(BuildMode)'
2311	$(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2312	$(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2313	$(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2314	$(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2315	$(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2316	$(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2317	$(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
2318	$(Echo) "PROJ_internal_prefix  : " '$(PROJ_internal_prefix)'
2319	$(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
2320	$(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
2321	$(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
2322	$(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
2323	$(Echo) "UserTargets  : " '$(UserTargets)'
2324	$(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2325	$(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2326	$(Echo) "ObjDir       : " '$(ObjDir)'
2327	$(Echo) "LibDir       : " '$(LibDir)'
2328	$(Echo) "ToolDir      : " '$(ToolDir)'
2329	$(Echo) "ExmplDir     : " '$(ExmplDir)'
2330	$(Echo) "Sources      : " '$(Sources)'
2331	$(Echo) "TDFiles      : " '$(TDFiles)'
2332	$(Echo) "INCFiles     : " '$(INCFiles)'
2333	$(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
2334	$(Echo) "PreConditions: " '$(PreConditions)'
2335	$(Echo) "Compile.CXX  : " '$(Compile.CXX)'
2336	$(Echo) "Compile.C    : " '$(Compile.C)'
2337	$(Echo) "Archive      : " '$(Archive)'
2338	$(Echo) "YaccFiles    : " '$(YaccFiles)'
2339	$(Echo) "LexFiles     : " '$(LexFiles)'
2340	$(Echo) "Module       : " '$(Module)'
2341	$(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
2342	$(Echo) "SubDirs      : " '$(SubDirs)'
2343	$(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2344	$(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
2345
2346###
2347# Debugging
2348
2349# General debugging rule, use 'make dbg-print-XXX' to print the
2350# definition, value and origin of XXX.
2351make-print-%:
2352	$(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))
2353