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