A backwards compatible bc format for packed structs
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file was developed by the LLVM research group and is distributed under
6 # the University of Illinois Open Source 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
26 TopLevelTargets  := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
27                     dist-zip
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 .y .l .lo .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-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
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           *) $(Echo) "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 # VARIABLES: Set up various variables based on configuration data
196 ###############################################################################
197
198 #--------------------------------------------------------------------
199 # Variables derived from configuration we are building
200 #--------------------------------------------------------------------
201
202 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
203 # this can be overridden on the make command line.
204 ifneq ($(OS),MingW)
205   OPTIMIZE_OPTION := -O3
206 else
207   OPTIMIZE_OPTION := -O2
208 endif
209
210 ifdef ENABLE_PROFILING
211   BuildMode := Profile
212   CXX.Flags := $(OPTIMIZE_OPTION) -pg -g
213   C.Flags   := $(OPTIMIZE_OPTION) -pg -g
214   LD.Flags  := $(OPTIMIZE_OPTION) -pg -g
215 else
216   ifeq ($(ENABLE_OPTIMIZED),1)
217     BuildMode := Release
218     # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
219     ifneq ($(OS),FreeBSD)
220     ifneq ($(OS),Darwin)
221       OmitFramePointer := -fomit-frame-pointer
222     endif
223     endif
224
225     # Darwin requires -fstrict-aliasing to be explicitly enabled.
226     ifeq ($(OS),Darwin)
227       EXTRA_OPTIONS += -fstrict-aliasing
228     endif
229
230     CXX.Flags := $(OPTIMIZE_OPTION) $(OmitFramePointer)
231     C.Flags   := $(OPTIMIZE_OPTION) $(OmitFramePointer)
232     LD.Flags  := $(OPTIMIZE_OPTION)
233   else
234     BuildMode := Debug
235     CXX.Flags := -g
236     C.Flags   := -g
237     LD.Flags  := -g
238     KEEP_SYMBOLS := 1
239   endif
240 endif
241
242 # IF REQUIRES_EH=1 is specified then don't disable exceptions
243 ifndef REQUIRES_EH
244   CXX.Flags += -fno-exceptions
245 endif
246
247 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
248 # then disable assertions by defining the appropriate preprocessor symbols.
249 ifdef DISABLE_ASSERTIONS
250   BuildMode := $(BuildMode)-Asserts
251   CXX.Flags += -DNDEBUG
252   C.Flags   += -DNDEBUG
253 else
254   CXX.Flags += -D_DEBUG
255   C.Flags   += -D_DEBUG
256 endif
257
258 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
259 C.Flags       += $(CFLAGS)
260 CPP.BaseFlags += $(CPPFLAGS)
261 LD.Flags      += $(LDFLAGS)
262 AR.Flags      := cru
263 LibTool.Flags := --tag=CXX
264
265 # Make Floating point IEEE compliant on Alpha.
266 ifeq ($(ARCH),Alpha)
267   CXX.Flags     += -mieee -fPIC
268   CPP.BaseFlags += -mieee -fPIC
269 endif
270
271 #--------------------------------------------------------------------
272 # Directory locations
273 #--------------------------------------------------------------------
274 ObjDir      := $(PROJ_OBJ_DIR)/$(BuildMode)
275 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
276 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
277 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
278 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
279 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
280 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
281 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
282
283 #--------------------------------------------------------------------
284 # Full Paths To Compiled Tools and Utilities
285 #--------------------------------------------------------------------
286 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
287 Echo     = @$(EchoCmd)
288 ifndef LIBTOOL
289 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
290 endif
291 ifndef LLVMAS
292 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
293 endif
294 ifndef TBLGEN
295   ifeq ($(LLVM_CROSS_COMPILING),1)
296     TBLGEN   := $(LLVMToolDir)/tblgen$(BUILD_EXEEXT)
297   else
298     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
299   endif
300 endif
301 LLVM_CONFIG := $(LLVMToolDir)/llvm-config 
302 ifndef GCCAS
303 GCCAS    := $(LLVMToolDir)/gccas$(EXEEXT)
304 endif
305 ifndef GCCLD
306 GCCLD    := $(LLVMToolDir)/gccld$(EXEEXT)
307 endif
308 ifndef LLVMDIS
309 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
310 endif
311 ifndef LLI
312 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
313 endif
314 ifndef LLC
315 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
316 endif
317 ifndef LOPT
318 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
319 endif
320 ifndef LBUGPOINT
321 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
322 endif
323 ifndef LUPGRADE
324 LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
325 endif
326 ifeq ($(LLVMGCC_MAJVERS),3)
327 UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
328 UPGRADE_LL  = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
329 else
330 UPGRADE_MSG =
331 UPGRADE_LL  =
332 endif
333
334 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
335 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
336
337 #--------------------------------------------------------------------
338 # Adjust to user's request
339 #--------------------------------------------------------------------
340
341 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
342 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
343 # shared library can be opened with dlopen. Also, LOADABLE_MODULE implies 
344 # several other things so we force them to be defined/on.
345 ifdef LOADABLE_MODULE
346   SHARED_LIBRARY := 1
347   DONT_BUILD_RELINKED := 1
348   LINK_LIBS_IN_SHARED := 1
349   LD.Flags += -module
350 endif
351
352 ifdef SHARED_LIBRARY
353   LD.Flags += -rpath $(LibDir)
354 else
355   LibTool.Flags += --tag=disable-shared
356 endif
357
358 ifdef TOOL_VERBOSE
359   C.Flags += -v
360   CXX.Flags += -v
361   LD.Flags += -v
362   VERBOSE := 1
363 endif
364
365 # Adjust settings for verbose mode
366 ifndef VERBOSE
367   Verb := @
368   LibTool.Flags += --silent
369   AR.Flags += >/dev/null 2>/dev/null
370   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
371 else
372   ConfigureScriptFLAGS := 
373 endif
374
375 # By default, strip symbol information from executable
376 ifndef KEEP_SYMBOLS
377   Strip := $(PLATFORMSTRIPOPTS)
378   StripWarnMsg := "(without symbols)"
379   Install.StripFlag += -s
380 endif
381
382 # Adjust linker flags for building an executable
383 ifdef TOOLNAME
384 ifdef EXAMPLE_TOOL
385   LD.Flags += -rpath $(ExmplDir) -export-dynamic
386 else
387   LD.Flags += -rpath $(ToolDir) -export-dynamic
388 endif
389 endif
390
391 #----------------------------------------------------------
392 # Options To Invoke Tools
393 #----------------------------------------------------------
394
395 CompileCommonOpts := -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
396                      -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
397
398 ifeq ($(OS),HP-UX)
399   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
400 endif
401
402 # If we are building a universal binary on Mac OS/X, pass extra options.  This
403 # is useful to people that want to link the LLVM libraries into their universal
404 # apps.
405 #
406 # The following can be optionally specified:
407 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
408 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
409 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
410 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
411 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
412 #      i386/ppc only.
413 ifdef UNIVERSAL
414   ifndef UNIVERSAL_ARCH
415     UNIVERSAL_ARCH := i386 ppc
416   endif
417   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
418   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
419   Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS:%=-XCClinker %)
420   ifdef UNIVERSAL_SDK_PATH
421     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
422     Relink.Flags      += -XCClinker -isysroot -XCClinker $(UNIVERSAL_SDK_PATH)
423   endif
424
425   # Building universal cannot compute dependencies automatically.
426   DISABLE_AUTO_DEPENDENCIES=1
427 endif
428
429 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir) 
430 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
431 # All -I flags should go here, so that they don't confuse llvm-config.
432 CPP.Flags     += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
433                  -I$(PROJ_OBJ_ROOT)/include \
434                  -I$(PROJ_SRC_ROOT)/include \
435                  -I$(LLVM_OBJ_ROOT)/include \
436                  -I$(LLVM_SRC_ROOT)/include \
437                  $(CPP.BaseFlags)
438
439 Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
440 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
441 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
442 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
443
444 Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
445 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
446 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
447                 $(CompileCommonOpts)
448
449 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
450 Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
451                 $(LD.Flags) $(Strip)
452 LTLink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Link)
453 Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
454                 $(Relink.Flags)
455 LTRelink      = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Relink)
456 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
457                 $(Install.Flags)
458 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
459 ScriptInstall = $(INSTALL) -m 0755 
460 DataInstall   = $(INSTALL) -m 0644
461 TableGen      = $(TBLGEN) -I $(PROJ_SRC_DIR) -I$(PROJ_SRC_ROOT)/include \
462                 -I $(PROJ_SRC_ROOT)/lib/Target      
463 Archive       = $(AR) $(AR.Flags)
464 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
465 ifdef RANLIB
466 Ranlib        = $(RANLIB)
467 else
468 Ranlib        = ranlib
469 endif
470
471 #----------------------------------------------------------
472 # Get the list of source files and compute object file 
473 # names from them. 
474 #----------------------------------------------------------
475
476 ifndef SOURCES
477   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
478              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
479              $(PROJ_SRC_DIR)/*.l))
480 else
481   Sources := $(SOURCES)
482 endif 
483
484 ifdef BUILT_SOURCES
485 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
486 endif
487
488 BaseNameSources := $(sort $(basename $(Sources)))
489
490 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
491 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
492 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
493
494 ###############################################################################
495 # DIRECTORIES: Handle recursive descent of directory structure
496 ###############################################################################
497
498 #---------------------------------------------------------
499 # Provide rules to make install dirs. This must be early
500 # in the file so they get built before dependencies
501 #---------------------------------------------------------
502
503 $(PROJ_bindir): $(PROJ_bindir)/.dir
504 $(PROJ_libdir): $(PROJ_libdir)/.dir
505 $(PROJ_includedir): $(PROJ_includedir)/.dir
506 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
507
508 # To create other directories, as needed, and timestamp their creation
509 %/.dir:
510         $(Verb) $(MKDIR) $* > /dev/null
511         $(Verb) $(DATE) > $@
512
513 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
514 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
515
516 #---------------------------------------------------------
517 # Handle the DIRS options for sequential construction
518 #---------------------------------------------------------
519
520 SubDirs := 
521 ifdef DIRS
522 SubDirs += $(DIRS)
523
524 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
525 $(RecursiveTargets)::
526         $(Verb) for dir in $(DIRS); do \
527           if [ ! -f $$dir/Makefile ]; then \
528             $(MKDIR) $$dir; \
529             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
530           fi; \
531           ($(MAKE) -C $$dir $@ ) || exit 1; \
532         done
533 else
534 $(RecursiveTargets)::
535         $(Verb) for dir in $(DIRS); do \
536           ($(MAKE) -C $$dir $@ ) || exit 1; \
537         done
538 endif
539
540 endif
541
542 #---------------------------------------------------------
543 # Handle the EXPERIMENTAL_DIRS options ensuring success
544 # after each directory is built.
545 #---------------------------------------------------------
546 ifdef EXPERIMENTAL_DIRS
547 $(RecursiveTargets)::
548         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
549           if [ ! -f $$dir/Makefile ]; then \
550             $(MKDIR) $$dir; \
551             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
552           fi; \
553           ($(MAKE) -C $$dir $@ ) || exit 0; \
554         done
555 endif
556
557 #-----------------------------------------------------------
558 # Handle the PARALLEL_DIRS options for parallel construction
559 #-----------------------------------------------------------
560 ifdef PARALLEL_DIRS
561
562 SubDirs += $(PARALLEL_DIRS)
563
564 # Unfortunately, this list must be maintained if new recursive targets are added
565 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
566 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
567 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
568 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
569 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
570 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
571
572 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
573
574 $(ParallelTargets) :
575         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
576           $(MKDIR) $(@D); \
577           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
578         fi; \
579         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ;
580 endif
581
582 #---------------------------------------------------------
583 # Handle the OPTIONAL_DIRS options for directores that may
584 # or may not exist.
585 #---------------------------------------------------------
586 ifdef OPTIONAL_DIRS
587
588 SubDirs += $(OPTIONAL_DIRS)
589
590 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
591 $(RecursiveTargets)::
592         $(Verb) for dir in $(OPTIONAL_DIRS); do \
593           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
594             if [ ! -f $$dir/Makefile ]; then \
595               $(MKDIR) $$dir; \
596               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
597             fi; \
598             ($(MAKE) -C$$dir $@ ) || exit 1; \
599           fi \
600         done
601 else
602 $(RecursiveTargets)::
603         $(Verb) for dir in $(OPTIONAL_DIRS); do \
604           ($(MAKE) -C$$dir $@ ) || exit 1; \
605         done
606 endif
607 endif
608
609 #---------------------------------------------------------
610 # Handle the CONFIG_FILES options
611 #---------------------------------------------------------
612 ifdef CONFIG_FILES
613
614 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
615         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
616         $(Verb)for file in $(CONFIG_FILES); do \
617           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
618             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
619           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
620             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
621           else \
622             $(ECHO) Error: cannot find config file $${file}. ; \
623           fi \
624         done
625
626 uninstall-local::
627         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
628         $(Verb)for file in $(CONFIG_FILES); do \
629           $(RM) -f $(PROJ_etcdir)/$${file} ; \
630         done
631
632 endif
633
634 ###############################################################################
635 # Set up variables for building libararies
636 ###############################################################################
637
638 #---------------------------------------------------------
639 # Define various command line options pertaining to the
640 # libraries needed when linking. There are "Proj" libs 
641 # (defined by the user's project) and "LLVM" libs (defined 
642 # by the LLVM project).
643 #---------------------------------------------------------
644
645 ifdef USEDLIBS
646 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
647 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
648 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
649 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
650 endif
651
652 ifdef LLVMLIBS
653 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
654 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
655 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
656 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
657 endif
658
659 ifeq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
660 ifdef LINK_COMPONENTS
661
662 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
663 # clean in tools, then do a make in tools (instead of at the top level).
664 $(LLVM_CONFIG):
665         @echo "*** llvm-config doesn't exist - rebuilding it."
666         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
667         
668 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
669
670 ProjLibsOptions = $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
671 ProjLibsPaths   = $(LLVM_CONFIG) \
672                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
673 endif
674 endif
675
676 ###############################################################################
677 # Library Build Rules: Four ways to build a library
678 ###############################################################################
679
680 #---------------------------------------------------------
681 # Bytecode Module Targets:
682 #   If the user set MODULE_NAME then they want to build a
683 #   bytecode module from the sources. We compile all the
684 #   sources and link it together into a single bytecode
685 #   module.
686 #---------------------------------------------------------
687
688 ifdef MODULE_NAME
689 ifeq ($(strip $(LLVMGCC)),)
690 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
691 else
692
693 Module     := $(LibDir)/$(MODULE_NAME).bc
694 LinkModule := $(GCCLD) -L$(CFERuntimeLibDir)
695
696
697 ifdef EXPORTED_SYMBOL_FILE
698 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
699 endif
700
701 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
702         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
703         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
704
705 all-local:: $(Module)
706
707 clean-local::
708 ifneq ($(strip $(Module)),)
709         -$(Verb) $(RM) -f $(Module)
710 endif
711
712 ifdef BYTECODE_DESTINATION
713 ModuleDestDir := $(BYTECODE_DESTINATION)
714 else
715 ModuleDestDir := $(PROJ_libdir)
716 endif
717
718 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
719
720 install-module:: $(DestModule)
721 install-local:: $(DestModule)
722
723 $(DestModule): $(ModuleDestDir) $(Module) 
724         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
725         $(Verb) $(DataInstall) $(Module) $(DestModule)
726
727 uninstall-local::
728         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
729         -$(Verb) $(RM) -f $(DestModule)
730
731 endif
732 endif
733
734 # if we're building a library ...
735 ifdef LIBRARYNAME
736
737 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
738 LIBRARYNAME := $(strip $(LIBRARYNAME))
739 ifdef LOADABLE_MODULE
740 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
741 else
742 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
743 endif
744 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
745 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
746 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
747
748 #---------------------------------------------------------
749 # Shared Library Targets:
750 #   If the user asked for a shared library to be built
751 #   with the SHARED_LIBRARY variable, then we provide
752 #   targets for building them.
753 #---------------------------------------------------------
754 ifdef SHARED_LIBRARY
755
756 all-local:: $(LibName.LA)
757
758 ifdef LINK_LIBS_IN_SHARED
759 ifdef LOADABLE_MODULE
760 SharedLibKindMessage := "Loadable Module"
761 else
762 SharedLibKindMessage := "Shared Library"
763 endif
764 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
765         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
766           $(LIBRARYNAME)$(SHLIBEXT)
767         $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
768           $(LLVMLibsOptions)
769         $(Verb) $(LTInstall) $@ $(LibDir)
770 else
771 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
772         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
773         $(Verb) $(LTLink) -o $@ $(ObjectsLO)
774         $(Verb) $(LTInstall) $@ $(LibDir)
775 endif
776
777 clean-local::
778 ifneq ($(strip $(LibName.LA)),)
779         -$(Verb) $(RM) -f $(LibName.LA)
780 endif
781
782 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
783
784 install-local:: $(DestSharedLib)
785
786 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
787         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
788         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
789         $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
790
791 uninstall-local:: 
792         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
793         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
794
795 endif
796
797 #---------------------------------------------------------
798 # Bytecode Library Targets:
799 #   If the user asked for a bytecode library to be built
800 #   with the BYTECODE_LIBRARY variable, then we provide 
801 #   targets for building them.
802 #---------------------------------------------------------
803 ifdef BYTECODE_LIBRARY
804 ifeq ($(strip $(LLVMGCC)),)
805 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
806 else
807
808 all-local:: $(LibName.BCA)
809
810 ifdef EXPORTED_SYMBOL_FILE
811 BCLinkLib = $(GCCLD) -L$(CFERuntimeLibDir) \
812                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
813
814 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
815                 $(LLVMToolDir)/llvm-ar
816         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
817           "(internalize)"
818         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
819         $(Verb) $(RM) -f $@
820         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
821 else
822 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
823                 $(LLVMToolDir)/llvm-ar
824         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
825         $(Verb) $(RM) -f $@
826         $(Verb) $(LArchive) $@ $(ObjectsBC)
827
828 endif
829
830 clean-local::
831 ifneq ($(strip $(LibName.BCA)),)
832         -$(Verb) $(RM) -f $(LibName.BCA)
833 endif
834
835 ifdef BYTECODE_DESTINATION
836 BytecodeDestDir := $(BYTECODE_DESTINATION)
837 else
838 BytecodeDestDir := $(PROJ_libdir)
839 endif
840
841 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
842
843 install-bytecode-local:: $(DestBytecodeLib)
844
845 install-local:: $(DestBytecodeLib)
846
847 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
848         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
849         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
850
851 uninstall-local::
852         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
853         -$(Verb) $(RM) -f $(DestBytecodeLib)
854
855 endif
856 endif
857
858 #---------------------------------------------------------
859 # ReLinked Library Targets:
860 #   If the user explicitly requests a relinked library with
861 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
862 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
863 #   them one.
864 #---------------------------------------------------------
865 ifndef BUILD_ARCHIVE
866 ifndef DONT_BUILD_RELINKED
867 BUILD_RELINKED = 1
868 endif
869 endif
870
871 ifdef BUILD_RELINKED
872
873 all-local:: $(LibName.O)
874
875 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
876         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
877         $(Verb) $(LTRelink) -o $@ $(ObjectsO)
878
879 clean-local::
880 ifneq ($(strip $(LibName.O)),)
881         -$(Verb) $(RM) -f $(LibName.O)
882 endif
883
884 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
885
886 install-local:: $(DestRelinkedLib)
887
888 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
889         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
890         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
891
892 uninstall-local::
893         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
894         -$(Verb) $(RM) -f $(DestRelinkedLib)
895
896 endif
897
898 #---------------------------------------------------------
899 # Archive Library Targets:
900 #   If the user wanted a regular archive library built, 
901 #   then we provide targets for building them.
902 #---------------------------------------------------------
903 ifdef BUILD_ARCHIVE
904
905 all-local:: $(LibName.A)
906
907 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
908         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
909         -$(Verb) $(RM) -f $@
910         $(Verb) $(Archive) $@ $(ObjectsO)
911         $(Verb) $(Ranlib) $@
912
913 clean-local::
914 ifneq ($(strip $(LibName.A)),)
915         -$(Verb) $(RM) -f $(LibName.A)
916 endif
917
918 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
919
920 install-local:: $(DestArchiveLib)
921
922 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
923         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
924         $(Verb) $(MKDIR) $(PROJ_libdir)
925         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
926
927 uninstall-local::
928         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
929         -$(Verb) $(RM) -f $(DestArchiveLib)
930
931 endif
932
933 # endif LIBRARYNAME
934 endif 
935
936 ###############################################################################
937 # Tool Build Rules: Build executable tool based on TOOLNAME option
938 ###############################################################################
939
940 ifdef TOOLNAME
941
942 #---------------------------------------------------------
943 # Set up variables for building a tool.
944 #---------------------------------------------------------
945 ifdef EXAMPLE_TOOL
946 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
947 else
948 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
949 endif
950
951 #---------------------------------------------------------
952 # Provide targets for building the tools
953 #---------------------------------------------------------
954 all-local:: $(ToolBuildPath)
955
956 clean-local::
957 ifneq ($(strip $(ToolBuildPath)),)
958         -$(Verb) $(RM) -f $(ToolBuildPath)
959 endif
960
961 ifdef EXAMPLE_TOOL
962 $(ToolBuildPath): $(ExmplDir)/.dir
963 else
964 $(ToolBuildPath): $(ToolDir)/.dir
965 endif
966
967 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
968         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
969         $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
970         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
971         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
972           $(StripWarnMsg) 
973
974 DestTool = $(PROJ_bindir)/$(TOOLNAME)
975
976 install-local:: $(DestTool)
977
978 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
979         $(Echo) Installing $(BuildMode) $(DestTool)
980         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
981
982 uninstall-local::
983         $(Echo) Uninstalling $(BuildMode) $(DestTool)
984         -$(Verb) $(RM) -f $(DestTool)
985
986 endif
987
988 ###############################################################################
989 # Object Build Rules: Build object files based on sources 
990 ###############################################################################
991
992 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
993 ifeq ($(OS),HP-UX)
994   DISABLE_AUTO_DEPENDENCIES=1
995 endif
996
997 ifdef SHARED_LIBRARY
998 PIC_FLAG = "(PIC)"
999 MAYBE_PIC_Compile.CXX = $(LTCompile.CXX)
1000 MAYBE_PIC_Compile.C = $(LTCompile.C)
1001 else
1002 MAYBE_PIC_Compile.CXX = $(Compile.CXX)
1003 MAYBE_PIC_Compile.C = $(Compile.C)
1004 endif
1005
1006 # Provide rule sets for when dependency generation is enabled
1007 ifndef DISABLE_AUTO_DEPENDENCIES
1008
1009 #---------------------------------------------------------
1010 # Create .lo files in the ObjDir directory from the .cpp and .c files...
1011 #---------------------------------------------------------
1012
1013 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1014         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1015         $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
1016           then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
1017           else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
1018
1019 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1020         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1021         $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
1022         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
1023         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
1024
1025 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1026         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1027         $(Verb) if $(MAYBE_PIC_Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
1028         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
1029         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
1030
1031 #---------------------------------------------------------
1032 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1033 #---------------------------------------------------------
1034
1035 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1036         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1037         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1038                               $< -o $@ -S -emit-llvm ; \
1039         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1040         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1041         $(call UPGRADE_MSG,$@) 
1042         $(call UPGRADE_LL,$@)
1043
1044 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1045         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1046         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1047                               $< -o $@ -S -emit-llvm ; \
1048         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1049         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1050         $(call UPGRADE_MSG,$@) 
1051         $(call UPGRADE_LL,$@)
1052
1053 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1054         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1055         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1056                             $< -o $@ -S -emit-llvm ; \
1057         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1058         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1059         $(call UPGRADE_MSG,$@) 
1060         $(call UPGRADE_LL,$@)
1061
1062 # Provide alternate rule sets if dependencies are disabled
1063 else
1064
1065 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1066         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1067         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1068
1069 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1070         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1071         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1072
1073 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1074         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1075         $(MAYBE_PIC_Compile.C) $< -o $@ 
1076
1077 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1078         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1079         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1080         $(call UPGRADE_MSG,$@) 
1081         $(call UPGRADE_LL,$@)
1082
1083 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1084         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1085         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1086         $(call UPGRADE_MSG,$@) 
1087         $(call UPGRADE_LL,$@)
1088
1089 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1090         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1091         $(BCCompile.C) $< -o $@ -S -emit-llvm
1092         $(call UPGRADE_MSG,@) 
1093         $(call UPGRADE_LL,@)
1094
1095 endif
1096
1097
1098 ## Rules for building preprocessed (.i/.ii) outputs.
1099 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1100         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1101         $(Verb) $(Preprocess.CXX) $< -o $@
1102
1103 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1104         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1105         $(Verb) $(Preprocess.CXX) $< -o $@
1106
1107  $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1108         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1109         $(Verb) $(Preprocess.C) $< -o $@
1110
1111
1112 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1113         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1114         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1115
1116 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1117         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1118         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1119
1120 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1121         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1122         $(MAYBE_PIC_Compile.C) $< -o $@ -S
1123
1124
1125 # make the C and C++ compilers strip debug info out of bytecode libraries.
1126 ifdef DEBUG_RUNTIME
1127 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1128         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1129         $(Verb) $(GCCAS) $< -o $@
1130 else
1131 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1132         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1133         $(Verb) $(GCCAS) -strip-debug $< -o $@
1134 endif
1135
1136
1137 #---------------------------------------------------------
1138 # Provide rule to build .bc files from .ll sources,
1139 # regardless of dependencies
1140 #---------------------------------------------------------
1141 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1142         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1143         $(Verb) $(LLVMAS) $< -f -o $@
1144
1145 ###############################################################################
1146 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1147 ###############################################################################
1148
1149 ifdef TARGET
1150
1151 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1152            $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1153            $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td \
1154            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1155            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1156 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1157 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1158 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1159
1160 # All of these files depend on tblgen and the .td files.
1161 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1162
1163 # INCFiles rule: All of the tblgen generated files are emitted to 
1164 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1165 # us to only "touch" the real file if the contents of it change.  IOW, if
1166 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1167 # dependencies of the .inc files are, unless the contents of the .inc file
1168 # changes.
1169 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1170         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1171
1172 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1173 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1174         $(Echo) "Building $(<F) register names with tblgen"
1175         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1176
1177 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1178 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1179         $(Echo) "Building $(<F) register information header with tblgen"
1180         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1181
1182 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1183 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1184         $(Echo) "Building $(<F) register info implementation with tblgen"
1185         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1186
1187 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1188 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1189         $(Echo) "Building $(<F) instruction names with tblgen"
1190         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1191
1192 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1193 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1194         $(Echo) "Building $(<F) instruction information with tblgen"
1195         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1196
1197 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1198 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1199         $(Echo) "Building $(<F) assembly writer with tblgen"
1200         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1201
1202 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1203 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1204         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1205         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
1206
1207 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1208 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1209         $(Echo) "Building $(<F) code emitter with tblgen"
1210         $(Verb) $(TableGen) -gen-emitter -o $@ $<
1211
1212 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1213 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1214         $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1215         $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1216
1217 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1218 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1219         $(Echo) "Building $(<F) subtarget information with tblgen"
1220         $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1221
1222 clean-local::
1223         -$(Verb) $(RM) -f $(INCFiles)
1224
1225 endif
1226
1227 ###############################################################################
1228 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1229 ###############################################################################
1230
1231 #---------------------------------------------------------
1232 # Provide rules for generating a .cpp source file from 
1233 # (f)lex input sources. 
1234 #---------------------------------------------------------
1235
1236 LexFiles  := $(filter %.l,$(Sources))
1237
1238 ifneq ($(LexFiles),)
1239
1240 # Cancel built-in rules for lex
1241 %.c: %.l
1242 %.cpp: %.l
1243
1244 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1245
1246 # Note the extra sed filtering here, used to cut down on the warnings emited 
1247 # by GCC.  The last line is a gross hack to work around flex aparently not 
1248 # being able to resize the buffer on a large token input.  Currently, for 
1249 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1250 # this is a hack around it.
1251 # FIXME.  (f.e. char Buffer[10000] )
1252 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1253         $(Echo) Flexing $*.l
1254         $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1255         $(SED) 's/void yyunput/inline void yyunput/' | \
1256         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1257         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1258           > $(PROJ_SRC_DIR)/$*.cpp
1259     
1260 # IFF the .l file has changed since it was last checked into CVS, copy the .l
1261 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
1262 # so that people without flex can build LLVM by copying the .cvs files to the 
1263 # source location and building them.
1264 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1265 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1266         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs || \
1267       ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1268
1269 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1270 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1271
1272 clean-local::
1273         -$(Verb) $(RM) -f $(LexOutput)
1274
1275 endif
1276
1277 #---------------------------------------------------------
1278 # Provide rules for generating a .cpp and .h source files 
1279 # from yacc (bison) input sources.
1280 #---------------------------------------------------------
1281
1282 YaccFiles  := $(filter %.y,$(Sources))
1283 ifneq ($(YaccFiles),)
1284
1285 .PRECIOUS: $(YaccOutput)
1286
1287 all:: $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs)
1288
1289 # Cancel built-in rules for yacc
1290 %.c: %.y 
1291 %.cpp: %.y
1292 %.h: %.y
1293
1294 # Rule for building the bison based parsers...
1295 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1296 ifneq ($(BISON),)
1297         $(Echo) "Bisoning $*.y"
1298         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1299         $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1300         $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1301 else
1302         $(Echo) "Bison of $*.y SKIPPED -- bison not found"
1303 endif
1304
1305 # IFF the .y file has changed since it was last checked into CVS, copy the .y
1306 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
1307 # mechanism so that people without flex can build LLVM by copying the .cvs files
1308 # to the source location and building them.
1309 $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1310 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1311         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs || \
1312       ($(CP) $< $@; \
1313        $(CP) $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs; \
1314        $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)
1315
1316
1317 $(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1318
1319 YaccOutput := $(YaccFiles:%.y=%.output)
1320
1321 clean-local::
1322         -$(Verb) $(RM) -f $(YaccOutput)
1323 endif
1324
1325 ###############################################################################
1326 # OTHER RULES: Other rules needed
1327 ###############################################################################
1328
1329 # To create postscript files from dot files...
1330 ifneq ($(DOT),false)
1331 %.ps: %.dot
1332         $(DOT) -Tps < $< > $@
1333 else
1334 %.ps: %.dot
1335         $(Echo) "Cannot build $@: The program dot is not installed"
1336 endif
1337
1338 # This rules ensures that header files that are removed still have a rule for
1339 # which they can be "generated."  This allows make to ignore them and
1340 # reproduce the dependency lists.
1341 %.h:: ;
1342 %.hpp:: ;
1343
1344 # Define clean-local to clean the current directory. Note that this uses a
1345 # very conservative approach ensuring that empty variables do not cause 
1346 # errors or disastrous removal.
1347 clean-local::
1348 ifneq ($(strip $(ObjDir)),)
1349         -$(Verb) $(RM) -rf $(ObjDir)
1350 endif
1351         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1352 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1353         -$(Verb) $(RM) -f *$(SHLIBEXT)
1354 endif
1355
1356 clean-all-local::
1357         -$(Verb) $(RM) -rf Debug Release Profile
1358
1359 # Build tags database for Emacs/Xemacs:
1360 tags:: TAGS CTAGS
1361
1362 TAGS: 
1363         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1364           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1365           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1366           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1367         -name '*.cpp' -o -name '*.h' | \
1368         $(ETAGS) $(ETAGSFLAGS) -
1369
1370 CTAGS:
1371         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1372           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1373           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1374           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1375           \( -name '*.cpp' -o -name '*.h' \) -print | \
1376           ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1377
1378
1379 ###############################################################################
1380 # DEPENDENCIES: Include the dependency files if we should
1381 ###############################################################################
1382 ifndef DISABLE_AUTO_DEPENDENCIES
1383
1384 # If its not one of the cleaning targets
1385 ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS)))),)
1386
1387 # Get the list of dependency files
1388 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1389 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1390
1391 -include /dev/null $(DependFiles)
1392
1393 endif
1394
1395 endif 
1396
1397 ###############################################################################
1398 # CHECK: Running the test suite
1399 ###############################################################################
1400
1401 check::
1402         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1403           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1404             $(EchoCmd) Running test suite ; \
1405             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1406               TESTSUITE=$(TESTSUITE) ; \
1407           else \
1408             $(EchoCmd) No Makefile in test directory ; \
1409           fi ; \
1410         else \
1411           $(EchoCmd) No test directory ; \
1412         fi
1413
1414 ###############################################################################
1415 # DISTRIBUTION: Handle construction of a distribution tarball
1416 ###############################################################################
1417
1418 #------------------------------------------------------------------------
1419 # Define distribution related variables
1420 #------------------------------------------------------------------------
1421 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1422 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1423 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1424 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1425 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1426 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1427 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1428                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1429                Makefile.config.in configure autoconf
1430 DistOther   := $(notdir $(wildcard \
1431                $(PROJ_SRC_DIR)/*.h \
1432                $(PROJ_SRC_DIR)/*.td \
1433                $(PROJ_SRC_DIR)/*.def \
1434                $(PROJ_SRC_DIR)/*.ll \
1435                $(PROJ_SRC_DIR)/*.in))
1436 DistSubDirs := $(SubDirs)
1437 DistSources  = $(Sources) $(EXTRA_DIST)
1438 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1439
1440 #------------------------------------------------------------------------
1441 # We MUST build distribution with OBJ_DIR != SRC_DIR
1442 #------------------------------------------------------------------------
1443 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1444 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1445         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1446
1447 else
1448
1449 #------------------------------------------------------------------------
1450 # Prevent attempt to run dist targets from anywhere but the top level
1451 #------------------------------------------------------------------------
1452 ifneq ($(LEVEL),.)
1453 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1454         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1455 else
1456
1457 #------------------------------------------------------------------------
1458 # Provide the top level targets
1459 #------------------------------------------------------------------------
1460
1461 dist-gzip:: $(DistTarGZip)
1462
1463 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1464         $(Echo) Packing gzipped distribution tar file.
1465         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1466           $(GZIP) -c > "$(DistTarGZip)"
1467
1468 dist-bzip2:: $(DistTarBZ2)
1469
1470 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1471         $(Echo) Packing bzipped distribution tar file.
1472         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1473           $(BZIP2) -c >$(DistTarBZ2)
1474
1475 dist-zip:: $(DistZip)
1476
1477 $(DistZip) : $(TopDistDir)/.makedistdir
1478         $(Echo) Packing zipped distribution file.
1479         $(Verb) rm -f $(DistZip)
1480         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1481
1482 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1483         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1484
1485 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1486
1487 dist-check:: $(DistTarGZip)
1488         $(Echo) Checking distribution tar file.
1489         $(Verb) if test -d $(DistCheckDir) ; then \
1490           $(RM) -rf $(DistCheckDir) ; \
1491         fi
1492         $(Verb) $(MKDIR) $(DistCheckDir)
1493         $(Verb) cd $(DistCheckDir) && \
1494           $(MKDIR) $(DistCheckDir)/build && \
1495           $(MKDIR) $(DistCheckDir)/install && \
1496           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1497           cd build && \
1498           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1499             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1500           $(MAKE) all && \
1501           $(MAKE) check && \
1502           $(MAKE) install && \
1503           $(MAKE) uninstall && \
1504           $(MAKE) dist-clean && \
1505           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1506
1507 dist-clean::
1508         $(Echo) Cleaning distribution files
1509         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1510           $(DistCheckDir)
1511
1512 endif
1513
1514 #------------------------------------------------------------------------
1515 # Provide the recursive distdir target for building the distribution directory
1516 #------------------------------------------------------------------------
1517 distdir: $(DistDir)/.makedistdir
1518 $(DistDir)/.makedistdir: $(DistSources)
1519         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1520           if test -d "$(DistDir)" ; then \
1521             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1522               exit 1 ; \
1523           fi ; \
1524           $(EchoCmd) Removing old $(DistDir) ; \
1525           $(RM) -rf $(DistDir); \
1526           $(EchoCmd) Making 'all' to verify build ; \
1527           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1528         fi
1529         $(Echo) Building Distribution Directory $(DistDir)
1530         $(Verb) $(MKDIR) $(DistDir) 
1531         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1532         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1533         for file in $(DistFiles) ; do \
1534           case "$$file" in \
1535             $(PROJ_SRC_DIR)/*) \
1536               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1537               ;; \
1538             $(PROJ_SRC_ROOT)/*) \
1539               file=`echo "$$file" | \
1540                 sed "s#^$$srcrootstrip/##"` \
1541               ;; \
1542           esac; \
1543           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1544              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1545             from_dir="$(PROJ_SRC_DIR)" ; \
1546           elif test -f "$$file" || test -d "$$file" ; then \
1547             from_dir=. ; \
1548           fi ; \
1549           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1550           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1551             to_dir="$(DistDir)/$$dir"; \
1552             $(MKDIR) "$$to_dir" ; \
1553           else \
1554             to_dir="$(DistDir)"; \
1555           fi; \
1556           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1557           if test -n "$$mid_dir" ; then \
1558             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1559           fi ; \
1560           if test -d "$$from_dir/$$file"; then \
1561             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1562                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1563                cd $(PROJ_SRC_DIR) ; \
1564                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1565                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1566                cd $(PROJ_OBJ_DIR) ; \
1567             else \
1568                cd $$from_dir ; \
1569                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1570                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1571                cd $(PROJ_OBJ_DIR) ; \
1572             fi; \
1573           elif test -f "$$from_dir/$$file" ; then \
1574             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1575           elif test -L "$$from_dir/$$file" ; then \
1576             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1577           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1578             $(EchoCmd) "===== WARNING: Distribution Source " \
1579               "$$from_dir/$$file Not Found!" ; \
1580           elif test "$(Verb)" != '@' ; then \
1581             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1582           fi; \
1583         done
1584         $(Verb) for subdir in $(DistSubDirs) ; do \
1585           if test "$$subdir" \!= "." ; then \
1586             new_distdir="$(DistDir)/$$subdir" ; \
1587             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1588             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1589               DistDir="$$new_distdir" distdir ) || exit 1; \
1590           fi; \
1591         done
1592         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1593           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1594           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1595                                   -name .svn \) -print` ;\
1596           $(MAKE) dist-hook ; \
1597           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1598             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1599             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1600             -o ! -type d ! -perm -444 -exec \
1601               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1602             || chmod -R a+r $(DistDir) ; \
1603         fi
1604
1605 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1606 # defined by user.
1607 dist-hook::
1608
1609 endif
1610
1611 ###############################################################################
1612 # TOP LEVEL - targets only to apply at the top level directory
1613 ###############################################################################
1614
1615 ifeq ($(LEVEL),.)
1616
1617 #------------------------------------------------------------------------
1618 # Install support for the project's include files:
1619 #------------------------------------------------------------------------
1620 install-local::
1621         $(Echo) Installing include files
1622         $(Verb) $(MKDIR) $(PROJ_includedir)
1623         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1624           cd $(PROJ_SRC_ROOT)/include && \
1625           for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1626               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1627             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1628             if test \! -d "$$instdir" ; then \
1629               $(EchoCmd) Making install directory $$instdir ; \
1630               $(MKDIR) $$instdir ;\
1631             fi ; \
1632             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1633           done ; \
1634         fi
1635 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1636         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1637           cd $(PROJ_OBJ_ROOT)/include && \
1638           for hdr in `find . -type f -print | grep -v CVS` ; do \
1639             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1640           done ; \
1641         fi
1642 endif
1643
1644 uninstall-local::
1645         $(Echo) Uninstalling include files
1646         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1647           cd $(PROJ_SRC_ROOT)/include && \
1648             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1649               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1650         -o -name '*.in' ')' -print ')' | \
1651         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1652           cd $(PROJ_SRC_ROOT)/include && \
1653             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1654       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1655         fi
1656
1657 endif
1658
1659 #------------------------------------------------------------------------
1660 # Print out the directories used for building
1661 #------------------------------------------------------------------------
1662 printvars::
1663         $(Echo) "BuildMode    : " '$(BuildMode)'
1664         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1665         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1666         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1667         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1668         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1669         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1670         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1671         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1672         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1673         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1674         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1675         $(Echo) "UserTargets  : " '$(UserTargets)'
1676         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1677         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1678         $(Echo) "ObjDir       : " '$(ObjDir)'
1679         $(Echo) "LibDir       : " '$(LibDir)'
1680         $(Echo) "ToolDir      : " '$(ToolDir)'
1681         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1682         $(Echo) "Sources      : " '$(Sources)'
1683         $(Echo) "TDFiles      : " '$(TDFiles)'
1684         $(Echo) "INCFiles     : " '$(INCFiles)'
1685         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1686         $(Echo) "PreConditions: " '$(PreConditions)'
1687         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1688         $(Echo) "Compile.C    : " '$(Compile.C)'
1689         $(Echo) "Archive      : " '$(Archive)'
1690         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1691         $(Echo) "LexFiles     : " '$(LexFiles)'
1692         $(Echo) "Module       : " '$(Module)'
1693         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1694         $(Echo) "SubDirs      : " '$(SubDirs)'