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