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