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