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