Correct tag usage for HTML 4.01 Strict compliance
[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 check install uninstall
23 LocalTargets     := all-local clean-local check-local install-local printvars \
24                     uninstall-local
25 TopLevelTargets  := dist dist-check dist-clean tags dist-gzip dist-bzip2 \
26                     dist-zip
27 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
28 InternalTargets  := preconditions distdir dist-hook
29
30 ################################################################################
31 # INITIALIZATION: Basic things the makefile needs
32 ################################################################################
33
34 #--------------------------------------------------------------------
35 # Set the VPATH so that we can find source files.
36 #--------------------------------------------------------------------
37 VPATH=$(BUILD_SRC_DIR)
38
39 #--------------------------------------------------------------------
40 # Reset the list of suffixes we know how to build
41 #--------------------------------------------------------------------
42 .SUFFIXES:
43 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot 
44 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
45
46 #--------------------------------------------------------------------
47 # Mark all of these targets as phony to avoid implicit rule search
48 #--------------------------------------------------------------------
49 .PHONY: $(UserTargets) $(InternalTargets)
50
51 #--------------------------------------------------------------------
52 # Make sure all the user-target rules are double colon rules and 
53 # they are defined first.
54 #--------------------------------------------------------------------
55
56 $(UserTargets)::
57
58 ################################################################################
59 # PRECONDITIONS: that which must be built/checked first
60 ################################################################################
61
62 SrcMakefiles       := $(filter %Makefile %Makefile.rules %Makefile.tests \
63                       %Makefile.JIT,$(wildcard $(BUILD_SRC_DIR)/Makefile*))
64 ObjMakefiles       := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
65 ConfigureScript    := $(LLVM_SRC_ROOT)/configure
66 ConfigStatusScript := $(LLVM_OBJ_ROOT)/config.status
67 MakefileConfigIn   := $(LLVM_SRC_ROOT)/Makefile.config.in
68 MakefileConfig     := $(LLVM_OBJ_ROOT)/Makefile.config
69 PreConditions      := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
70
71 preconditions : $(PreConditions)
72
73 #------------------------------------------------------------------------
74 # Make sure the BUILT_SOURCES are built first
75 #------------------------------------------------------------------------
76 $(filter-out clean clean-local,UserTargets):: $(BUILT_SOURCES)
77
78 clean-local::
79 ifneq ($(strip $(BUILT_SOURCES)),)
80         $(Verb) $(RM) -f $(BUILT_SOURCES)
81 endif
82
83 $(BUILT_SOURCES) : $(ObjMakefiles)
84
85 #------------------------------------------------------------------------
86 # Make sure we're not using a stale configuration
87 #------------------------------------------------------------------------
88 .PRECIOUS: $(ConfigStatusScript)
89 $(ConfigStatusScript): $(ConfigureScript)
90         $(Echo) Reconfiguring with $<
91         $(Verb) $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS)
92         $(Verb) $(ConfigStatusScript)
93
94 #------------------------------------------------------------------------
95 # Make sure the configuration makefile is up to date
96 #------------------------------------------------------------------------
97 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
98         $(Echo) Regenerating $@
99         $(Verb) cd $(LLVM_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
100
101 #------------------------------------------------------------------------
102 # If the Makefile in the source tree has been updated, copy it over into the
103 # build tree. But, only do this if the source and object makefiles differ
104 #------------------------------------------------------------------------
105 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
106
107 $(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
108         $(Echo) "Updating Makefile"
109         $(Verb) $(MKDIR) $(@D)
110         $(Verb) cp -f $< $@
111
112 # Copy the Makefile.* files unless we're in the root directory which avoids
113 # the copying of Makefile.config.in or other things that should be explicitly
114 # taken care of.
115 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
116         @case '$?' in \
117           *Makefile.rules) ;; \
118           *.in) ;; \
119           *) $(Echo) "Updating $(@F)" ; \
120              $(MKDIR) $(@D) ; \
121              cp -f $< $@ ;; \
122         esac
123          
124 endif
125
126 #------------------------------------------------------------------------
127 # Set up the basic dependencies
128 #------------------------------------------------------------------------
129 $(UserTargets):: $(PreConditions)
130
131 all:: all-local
132 check:: check-local
133 clean:: clean-local 
134 install:: install-local
135 uninstall:: uninstall-local
136 check-local:: all-local
137 install-local:: all-local 
138
139 ###############################################################################
140 # VARIABLES: Set up various variables based on configuration data
141 ###############################################################################
142
143 #--------------------------------------------------------------------
144 # Variables derived from configuration we are building
145 #--------------------------------------------------------------------
146
147 ifdef ENABLE_PROFILING
148   Configuration := Profile
149   CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
150   C.Flags   := -O3 -DNDEBUG -pg
151   LD.Flags  := -O3 -DNDEBUG -pg 
152 else
153   ifdef ENABLE_OPTIMIZED
154     Configuration := Release
155     CXX.Flags  := -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
156     C.Flags    := -O3 -DNDEBUG -fomit-frame-pointer
157     LD.Flags   := -O3 -DNDEBUG 
158   else
159     Configuration := Debug
160     CXX.Flags := -g -D_DEBUG 
161     C.Flags   := -g -D_DEBUG
162     LD.Flags  := -g -D_DEBUG 
163     KEEP_SYMBOLS := 1
164   endif
165 endif
166
167 CXX.Flags += $(CXXFLAGS)
168 C.Flags   += $(CFLAGS)
169 CPP.Flags += $(CPPFLAGS)
170 LD.Flags  += $(LDFLAGS)
171 AR.Flags  := cru
172 LibTool.Flags := --tag=CXX
173
174 #--------------------------------------------------------------------
175 # Directory locations
176 #--------------------------------------------------------------------
177 ObjDir      := $(BUILD_OBJ_DIR)/$(Configuration)
178 LibDir      := $(BUILD_OBJ_ROOT)/lib/$(Configuration)
179 ToolDir     := $(BUILD_OBJ_ROOT)/tools/$(Configuration)
180 LLVMLibDir  := $(LLVM_OBJ_ROOT)/lib/$(Configuration)
181 LLVMToolDir := $(LLVM_OBJ_ROOT)/tools/$(Configuration)
182
183 #--------------------------------------------------------------------
184 # Full Paths To Compiled Tools and Utilities
185 #--------------------------------------------------------------------
186 EchoCmd  := $(ECHO) llvm[$(MAKELEVEL)]:
187 Echo     := @$(EchoCmd)
188 ifndef LIBTOOL
189 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
190 endif
191 ifndef LLVMAS
192 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
193 endif
194 ifndef BURG
195 BURG     := $(LLVMToolDir)/burg$(EXEEXT)
196 endif
197 ifndef TBLGEN
198 TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
199 endif
200 ifndef GCCLD
201 GCCLD    := $(LLVMToolDir)/gccld$(EXEEXT)
202 endif
203 ifndef LLVMGCC
204 LLVMGCC  := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/gcc
205 endif
206 ifndef LLVMGXX
207 LLVMGXX  := PATH=$(LLVMToolDir):$(PATH) $(LLVMGCCDIR)/bin/g++
208 endif
209
210 # Need a better way to compute this.
211 LLVMGCCLibDir := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
212
213 #--------------------------------------------------------------------
214 # Adjust to user's request
215 #--------------------------------------------------------------------
216
217 # Adjust LIBTOOL flags for shared libraries, or not.
218 ifndef SHARED_LIBRARY
219   LibTool.Flags += --tag=disable-shared
220 else
221   LD.Flags += -rpath $(LibDir)
222 endif
223
224 # Adjust settings for verbose mode
225 ifndef VERBOSE
226   Verb := @
227   LibTool.Flags += --silent
228   AR.Flags += >/dev/null 2>/dev/null
229   ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
230 else
231   ConfigureScriptFLAGS := 
232 endif
233
234 # By default, strip symbol information from executable
235 ifndef KEEP_SYMBOLS
236   Strip := $(PLATFORMSTRIPOPTS)
237   StripWarnMsg := "(without symbols)"
238 endif
239
240 # Adjust linker flags for building an executable
241 ifdef TOOLNAME
242   LD.Flags += -rpath $(ToolDir) -export-dynamic
243 endif
244
245 #----------------------------------------------------------
246 # Options To Invoke Tools
247 #----------------------------------------------------------
248
249 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
250
251 LD.Flags  += -L$(LibDir) -L$(LLVMLibDir)
252 CPP.Flags += -I$(BUILD_OBJ_DIR) \
253             -I$(BUILD_SRC_DIR) \
254             -I$(BUILD_SRC_ROOT)/include \
255             -I$(BUILD_OBJ_ROOT)/include \
256             -I$(LLVM_OBJ_ROOT)/include \
257             -I$(LLVM_SRC_ROOT)/include \
258             -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
259
260 Compile.C     = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
261 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
262 BCCompile.C   = $(LLVMGCC) $(CPP.Flags) $(CompileCommonOpts) $(C.Flags) -c
263 Compile.CXX   = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
264 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
265 BCCompile.CXX = $(LLVMGXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
266 Link          = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
267                 $(CompileCommonOpts) $(LD.Flags) $(Strip)
268 Relink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
269                 $(CompileCommonOpts)
270 BCLinkLib     = $(LLVMGCC) -shared -nostdlib
271 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
272 Burg          = $(BURG) -I $(BUILD_SRC_DIR)
273 TableGen      = $(TBLGEN) -I $(BUILD_SRC_DIR)
274 Archive       = $(AR) $(AR.Flags)
275 ifdef RANLIB
276 Ranlib        = $(RANLIB)
277 else
278 Ranlib        = ranlib
279 endif
280
281 #----------------------------------------------------------
282 # Get the list of source files
283 #----------------------------------------------------------
284 ifndef SOURCES
285   Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
286              $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
287              $(BUILD_SRC_DIR)/*.l))
288 else
289   Sources := $(SOURCES)
290 endif
291
292 ifdef BUILT_SOURCES
293 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
294 endif
295
296 #----------------------------------------------------------
297 # Types of objects that can be built from sources
298 #----------------------------------------------------------
299 BaseNameSources := $(sort $(basename $(Sources)))
300 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
301 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
302 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
303
304 ###############################################################################
305 # DIRECTORIES: Handle recursive descent of directory structure
306 ###############################################################################
307
308 #---------------------------------------------------------
309 # Provide rules to make install dirs. This must be early
310 # in the file so they get built before dependencies
311 #---------------------------------------------------------
312
313 $(bindir):
314         $(Verb) $(MKDIR) $(bindir)
315         
316 $(libdir):
317         $(Verb) $(MKDIR) $(libdir)
318
319 $(bytecode_libdir):
320         $(Verb) $(MKDIR) $(bytecode_libdir)
321
322 $(sysconfdir):
323         $(Verb) $(MKDIR) $(sysconfdir)
324
325 # To create other directories, as needed, and timestamp their creation
326 %/.dir:
327         $(Verb) $(MKDIR) $* > /dev/null
328         @$(DATE) > $@
329
330 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(LLVMLibDir)/.dir
331 .PRECIOUS: $(LLVMToolDir)/.dir
332
333 #---------------------------------------------------------
334 # Handle the DIRS options for sequential construction
335 #---------------------------------------------------------
336
337 SubDirs := 
338 ifdef DIRS
339 SubDirs += $(DIRS)
340 $(RecursiveTargets)::
341         $(Verb) for dir in $(DIRS); do \
342           if [ ! -f $$dir/Makefile ]; then \
343             $(MKDIR) $$dir; \
344             cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
345           fi; \
346           ($(MAKE) -C $$dir $@ ) || exit 1; \
347         done
348 endif
349
350 #---------------------------------------------------------
351 # Handle the EXPERIMENTAL_DIRS options ensuring success
352 # after each directory is built.
353 #---------------------------------------------------------
354 ifdef EXPERIMENTAL_DIRS
355 $(RecursiveTargets)::
356         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
357           if [ ! -f $$dir/Makefile ]; then \
358             $(MKDIR) $$dir; \
359             cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
360           fi; \
361           ($(MAKE) -C $$dir $@ ) || exit 0; \
362         done
363 endif
364
365 #---------------------------------------------------------
366 # Handle the PARALLEL_DIRS options for parallel construction
367 #---------------------------------------------------------
368 ifdef PARALLEL_DIRS
369
370 SubDirs += $(PARALLEL_DIRS)
371
372 # Unfortunately, this list must be maintained if new 
373 # recursive targets are added.
374 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
375 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
376 check    :: $(addsuffix /.makecheck    ,$(PARALLEL_DIRS))
377 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
378 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
379
380 Parallel_Targets := $(foreach T,$(RecursiveTargets),%/.make$(T))
381
382 $(Parallel_Targets) :
383         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
384           $(MKDIR) $(@D); \
385           cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
386         fi; \
387         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
388 endif
389
390 #---------------------------------------------------------
391 # Handle the OPTIONAL_DIRS options for directores that may
392 # or may not exist.
393 #---------------------------------------------------------
394 ifdef OPTIONAL_DIRS
395
396 SubDirs += $(OPTIONAL_DIRS)
397
398 $(RecursiveTargets)::
399         $(Verb) for dir in $(OPTIONAL_DIRS); do \
400           if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
401             if [ ! -f $$dir/Makefile ]; then \
402               $(MKDIR) $$dir; \
403               cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
404             fi; \
405             ($(MAKE) -C$$dir $@ ) || exit 1; \
406           fi \
407         done
408 endif
409
410 #---------------------------------------------------------
411 # Handle the CONFIG_FILES options
412 #---------------------------------------------------------
413 ifdef CONFIG_FILES
414
415 install-local:: $(sysconfdir) $(CONFIG_FILES)
416         $(Echo) Installing Configuration Files To $(sysconfdir)
417         $(Verb)for file in $(CONFIG_FILES); do \
418                 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
419         done
420
421 uninstall-local::
422         $(Echo) Uninstalling Configuration Files From $(sysconfdir)
423         $(Verb)for file in $(CONFIG_FILES); do \
424           $(RM) -f $(sysconfdir)/$${file} ; \
425         done
426
427 endif
428
429 ###############################################################################
430 # Library Build Rules: Four ways to build a library
431 ###############################################################################
432
433
434 # if we're building a library ...
435 ifdef LIBRARYNAME
436
437 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
438 LIBRARYNAME := $(strip $(LIBRARYNAME))
439 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
440 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
441 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
442 LibName.BC := $(LibDir)/lib$(LIBRARYNAME).bc
443
444 #---------------------------------------------------------
445 # Shared Library Targets:
446 #   If the user asked for a shared library to be built
447 #   with the SHARED_LIBRARY variable, then we provide
448 #   targets for building them.
449 #---------------------------------------------------------
450 ifdef SHARED_LIBRARY
451
452 all-local:: $(LibName.LA)
453
454 $(LibName.LA): $(BUILT_SOURCES) $(ObjectsLO) $(LibDir)/.dir
455         $(Echo) Linking $(Configuration) Shared Library $(notdir $@)
456         $(Verb) $(Link) -o $@ $(ObjectsLO)
457         $(Verb) $(LTInstall) $@ $(LibDir)
458
459 clean-local::
460 ifneq ($(strip $(LibName.LA)),)
461         $(Verb) $(RM) -f $(LibName.LA)
462 endif
463
464 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
465
466 install-local:: $(DestSharedLib)
467
468 $(DestSharedLib): $(libdir) $(LibName.LA)
469         $(Echo) Installing $(Configuration) Shared Library $(DestSharedLib)
470         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
471         $(Verb) $(LIBTOOL) --finish $(libdir)
472
473 uninstall-local:: 
474         $(Echo) Uninstalling $(Configuration) Shared Library $(DestSharedLib)
475         $(Verb) $(RM) -f $(DestSharedLib)
476
477 endif
478
479 #---------------------------------------------------------
480 # Bytecode Library Targets:
481 #   If the user asked for a bytecode library to be built
482 #   with the BYTECODE_LIBRARY variable, then we provide 
483 #   targets for building them.
484 #---------------------------------------------------------
485 ifdef BYTECODE_LIBRARY
486
487 ifdef EXPORTED_SYMBOL_LIST
488   BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
489 else
490   ifdef EXPORTED_SYMBOL_FILE
491     BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
492   else
493     BCLinkLib += -Xlinker -disable-internalize
494   endif
495 endif
496
497 all-local:: $(LibName.BC)
498
499 $(LibName.BC): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir
500         $(Echo) Linking $(Configuration) Bytecode Library $(notdir $@)
501         $(Verb) $(BCLinkLib) -o $@ $(ObjectsBC)
502
503 clean-local::
504 ifneq ($(strip $(LibName.BC)),)
505         $(Verb) $(RM) -f $(LibName.BC)
506 endif
507
508 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
509
510 install-local:: $(DestBytecodeLib)
511
512 $(DestBytecodeLib): $(bytecode_libdir) $(LibName.BC) 
513         $(Echo) Installing $(Configuration) Bytecode Library $(DestBytecodeLib)
514         $(Verb) $(INSTALL) $(LibName.BC) $@
515
516 uninstall-local::
517         $(Echo) Uninstalling $(Configuration) Bytecode Library $(DestBytecodeLib)
518         $(Verb) $(RM) -f $(DestBytecodeLib)
519
520 endif
521
522 #---------------------------------------------------------
523 # ReLinked Library Targets:
524 #   If the user didn't explicitly forbid building a 
525 #   relinked then we provide targets for building them.
526 #---------------------------------------------------------
527 ifndef DONT_BUILD_RELINKED
528
529 all-local:: $(LibName.O)
530
531 $(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
532         $(Echo) Linking $(Configuration) Object Library $(notdir $@)
533         $(Verb) $(Relink) -o $@ $(ObjectsO)
534
535 clean-local::
536 ifneq ($(strip $(LibName.O)),)
537         $(Verb) $(RM) -f $(LibName.O)
538 endif
539
540 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
541
542 install-local:: $(DestRelinkedLib)
543
544 $(DestRelinkedLib): $(libdir) $(LibName.O)
545         $(Echo) Installing $(Configuration) Object Library $(DestRelinkedLib)
546         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
547
548 uninstall-local::
549         $(Echo) Uninstalling $(Configuration) Object Library $(DestRelinkedLib)
550         $(Verb) $(RM) -f $(DestRelinkedLib)
551
552 endif
553
554 #---------------------------------------------------------
555 # Archive Library Targets:
556 #   If the user wanted a regular archive library built, 
557 #   then we provide targets for building them.
558 #---------------------------------------------------------
559 ifdef BUILD_ARCHIVE
560
561 all-local:: $(LibName.A)
562
563 $(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
564         $(Echo) Building $(Configuration) Archive Library $(notdir $@)
565         $(Verb)$(RM) -f $@
566         $(Verb) $(Archive) $@ $(ObjectsO)
567         $(Verb) $(Ranlib) $@
568
569 clean-local::
570 ifneq ($(strip $(LibName.A)),)
571         $(Verb) $(RM) -f $(LibName.A)
572 endif
573
574 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
575
576 install-local:: $(DestArchiveLib)
577
578 $(DestArchiveLib): $(libdir) $(LibName.A)
579         $(Echo) Installing $(Configuration) Archive Library $(DestArchiveLib)
580         $(Verb) $(MKDIR) $(libdir)
581         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
582
583 uninstall-local::
584         $(Echo) Uninstalling $(Configuration) Archive Library $(DestArchiveLib)
585         $(Verb) $(RM) -f $(DestArchiveLib)
586
587 endif
588
589 # endif LIBRARYNAME
590 endif 
591
592 ###############################################################################
593 # Tool Build Rules: Build executable tool based on TOOLNAME option
594 ###############################################################################
595
596 ifdef TOOLNAME
597
598 #---------------------------------------------------------
599 # Set up variables for building a tool.
600 #---------------------------------------------------------
601 ToolBuildPath   := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
602 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
603 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
604 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
605 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
606 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
607 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
608 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
609 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
610
611 #---------------------------------------------------------
612 # Handle optional compression libraries automatically
613 #---------------------------------------------------------
614 ExtraLibs := $(LIBS)
615 ifeq ($(HAVE_BZIP2),1)
616 ExtraLibs += -lbz2
617 endif
618 ifeq ($(HAVE_ZLIB),1)
619 ExtraLibs += -lz
620 endif
621
622 #---------------------------------------------------------
623 # Tell make that we need to rebuild subdirectories before 
624 # we can link the tool. This affects things like LLI which 
625 # has library subdirectories.
626 #---------------------------------------------------------
627 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
628
629 #---------------------------------------------------------
630 # Provide targets for building the tools
631 #---------------------------------------------------------
632 all-local:: $(ToolBuildPath)
633
634 clean-local::
635 ifneq ($(strip $(ToolBuildPath)),)
636         $(Verb) $(RM) -f $(ToolBuildPath)
637 endif
638
639 $(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)\
640                   $(ToolDir)/.dir
641         $(Echo) Linking $(Configuration) executable $(TOOLNAME) $(StripWarnMsg)
642         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
643           $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
644         $(Echo) ======= Finished Linking $(Configuration) Executable $(TOOLNAME) $(StripWarnMsg) 
645
646 DestTool = $(bindir)/$(TOOLNAME)
647
648 install-local:: $(DestTool)
649
650 $(DestTool): $(bindir) $(ToolBuildPath)
651         $(Echo) Installing $(Configuration) $(DestTool)
652         $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
653
654 uninstall-local::
655         $(Echo) Uninstalling $(Configuration) $(DestTool)
656         $(Verb) $(RM) -f $(DestTool)
657
658 endif
659
660 ###############################################################################
661 # Object Build Rules: Build object files based on sources 
662 ###############################################################################
663
664 # Provide rule sets for when dependency generation is enabled
665 ifndef DISABLE_AUTO_DEPENDENCIES
666
667 #---------------------------------------------------------
668 # Create .lo files in the ObjDir directory from the .cpp and .c files...
669 #---------------------------------------------------------
670 ifdef SHARED_LIBRARY
671
672 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
673         $(Echo) "Compiling $*.cpp (PIC)"
674         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
675         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
676         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
677
678 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
679         $(Echo) "Compiling $*.c (PIC)"
680         $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
681         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
682         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
683
684 #---------------------------------------------------------
685 # Create .o files in the ObjDir directory from the .cpp and .c files...
686 #---------------------------------------------------------
687 else
688
689 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
690         $(Echo) "Compiling $*.cpp"
691         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
692         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
693         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
694
695 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
696         $(Echo) "Compiling $*.c"
697         $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
698         then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
699         else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
700
701 endif
702
703 #---------------------------------------------------------
704 # Create .bc files in the ObjDir directory from .cpp and .c files...
705 #---------------------------------------------------------
706 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
707         $(Echo) "Compiling $*.cpp (bytecode)"
708         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
709         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
710         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
711
712 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
713         $(Echo) "Compiling $*.c (bytecode)"
714         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
715         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
716         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
717
718 # Provide alternate rule sets if dependencies are disabled
719 else
720
721 ifdef SHARED_LIBRARY
722
723 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir 
724         $(Echo) "Compiling $*.cpp (PIC)"
725         $(LTCompile.CXX) $< -o $@ 
726
727 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
728         $(Echo) "Compiling $*.cpp (PIC)"
729         $(LTCompile.C) $< -o $@ 
730
731 else
732
733 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
734         $(Echo) "Compiling $*.cpp"
735         $(Compile.CXX) $< -o $@ 
736
737 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
738         $(Echo) "Compiling $*.cpp"
739         $(Compile.C) $< -o $@ 
740 endif
741
742 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir
743         $(Echo) "Compiling $*.cpp (bytecode)"
744         $(BCCompileCPP) $< -o $@ 
745
746 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir
747         $(Echo) "Compiling $*.c (bytecode)"
748         $(BCCompileC) $< -o $@
749
750 endif
751
752 #---------------------------------------------------------
753 # Provide rule to build .bc files from .ll sources,
754 # regardless of dependencies
755 #---------------------------------------------------------
756 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
757         $(Echo) "Compiling $*.ll"
758         $(Verb) $(LLVMAS) $< -f -o $@
759
760 ###############################################################################
761 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
762 ###############################################################################
763
764 ifdef TARGET
765
766 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
767 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
768
769 $(INCFiles) : $(TBLGEN) $(TDFiles)
770
771 %GenRegisterNames.inc : %.td 
772         $(Echo) "Building $(<F) register names with tblgen"
773         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
774
775 %GenRegisterInfo.h.inc : %.td 
776         $(Echo) "Building $(<F) register information header with tblgen"
777         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
778
779 %GenRegisterInfo.inc : %.td
780         $(Echo) "Building $(<F) register info implementation with tblgen"
781         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
782
783 %GenInstrNames.inc : %.td
784         $(Echo) "Building $(<F) instruction names with tblgen"
785         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
786
787 %GenInstrInfo.inc : %.td
788         $(Echo) "Building $(<F) instruction information with tblgen"
789         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
790
791 %GenAsmWriter.inc : %.td
792         $(Echo) "Building $(<F) assembly writer with tblgen"
793         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
794
795 %GenATTAsmWriter.inc : %.td
796         $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
797         $(Verb) $(TableGen) -gen-asm-writer -o $@ $< 
798
799 %GenIntelAsmWriter.inc : %.td
800         $(Echo) "Building $(<F) Intel assembly writer with tblgen"
801         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
802
803 %GenInstrSelector.inc: %.td
804         $(Echo) "Building $(<F) instruction selector with tblgen"
805         $(Verb) $(TableGen) -gen-instr-selector -o $@ $< 
806
807 %GenCodeEmitter.inc:: %.td
808         $(Echo) "Building $(<F) code emitter with tblgen"
809         $(Verb) $(TableGen) -gen-emitter -o $@ $<
810
811 clean-local::
812         $(Verb) $(RM) -f $(INCFiles)
813
814 endif
815
816 ###############################################################################
817 # LEX AND YACC: Provide rules for generating sources with lex and yacc
818 ###############################################################################
819
820 #---------------------------------------------------------
821 # Provide rules for generating a .cpp source file from 
822 # (f)lex input sources. 
823 #---------------------------------------------------------
824
825 LexOutput   := $(strip $(subst %.l,%.cpp,$(filter %.l,$(Sources))))
826
827 ifneq ($(LexOutput),)
828
829 .PRECIOUS: $(LexOutput)
830
831 # Note the extra sed filtering here, used to cut down on the warnings emited 
832 # by GCC.  The last line is a gross hack to work around flex aparently not 
833 # being able to resize the buffer on a large token input.  Currently, for 
834 # uninitialized string buffers in LLVM we can generate very long tokens, so 
835 # this is a hack around it.
836 # FIXME.  (f.e. char Buffer[10000] )
837 %.cpp: %.l
838         $(Echo) Flexing $<
839         $(Verb) $(FLEX) -t $< | \
840         $(SED) 's/void yyunput/inline void yyunput/' | \
841         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
842         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
843           > $@
844
845 endif
846
847 #---------------------------------------------------------
848 # Provide rules for generating a .cpp and .h source files 
849 # from yacc (bison) input sources.
850 #---------------------------------------------------------
851
852 YaccOutput  := $(strip $(addprefix $(subst %.y,%,$(filter %.y,$(Sources))),\
853                .h .cpp .output))
854
855 ifneq ($(YaccOutput),)
856
857 .PRECIOUS: $(YaccOutput)
858
859 # Cancel built-in rules for yacc
860 %.c: %.y 
861 %.cpp: %.y
862 %.h: %.y
863
864 # Rule for building the bison parsers...
865 %.cpp %.h : %.y
866         $(Echo) "Bisoning $*.y"
867         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
868         $(Verb) $(MV) -f $*.tab.c $*.cpp
869         $(Verb) $(MV) -f $*.tab.h $*.h
870
871 endif
872
873 ###############################################################################
874 # OTHER RULES: Other rules needed
875 ###############################################################################
876
877 # To create postscript files from dot files...
878 ifneq ($(DOT),false)
879 %.ps: %.dot
880         $(DOT) -Tps < $< > $@
881 else
882 %.ps: %.dot
883         $(Echo) "Cannot build $@: The program dot is not installed"
884 endif
885
886 # This rules ensures that header files that are removed still have a rule for
887 # which they can be "generated."  This allows make to ignore them and
888 # reproduce the dependency lists.
889 %.h:: ;
890
891 # Define clean-local to clean the current directory. Note that this uses a
892 # very conservative approach ensuring that empty variables do not cause 
893 # errors or disastrous removal.
894 clean-local::
895 ifneq ($(strip $(ObjDir)),)
896         $(Verb) $(RM) -rf $(ObjDir)
897 endif
898         $(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
899 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
900         $(Verb) $(RM) -f *$(SHLIBEXT)
901 endif
902 ifneq ($(strip $(LexOutput)),)
903         $(Verb) $(RM) -f $(LexOutput) 
904 endif
905 ifneq ($(strip $(YaccOutput)),)
906         $(Verb) $(RM) -f $(YaccOutput)
907 endif
908
909 # Build tags database for Emacs/Xemacs:
910 tags:: TAGS
911 TAGS: 
912         find include lib tools examples -name '*.cpp' -o -name '*.h' | \
913         $(ETAGS) $(ETAGSFLAGS) -
914
915 ###############################################################################
916 # DEPENDENCIES: Include the dependency files if we should
917 ###############################################################################
918 ifndef DISABLE_AUTO_DEPENDENCIES
919
920 # If its not one of the cleaning targets
921 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
922
923 # Get the list of dependency files
924 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
925 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(Configuration)/%.d,$(DependFiles))
926
927 -include /dev/null $(DependFiles)
928
929 endif
930
931 endif 
932
933 ###############################################################################
934 # DISTRIBUTION: Handle construction of a distribution tarball
935 ###############################################################################
936
937 #------------------------------------------------------------------------
938 # Define distribution related variables
939 #------------------------------------------------------------------------
940 DistName    := $(LLVM_TARBALL_NAME)
941 DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
942 TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
943 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
944 DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
945 DistTarBZ2  := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
946 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
947                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
948                Makefile.config.in configure autoconf
949 DistOther   := $(notdir $(wildcard \
950                $(BUILD_SRC_DIR)/*.h \
951                $(BUILD_SRC_DIR)/*.td \
952                $(BUILD_SRC_DIR)/*.def \
953                $(BUILD_SRC_DIR)/*.ll \
954                $(BUILD_SRC_DIR)/*.in))
955 DistSources := $(Sources) $(EXTRA_DIST)
956 DistSubDirs := $(SubDirs)
957 DistFiles   := $(DistAlways) $(DistSources) $(DistOther)
958
959 #------------------------------------------------------------------------
960 # We MUST build distribution with OBJ_DIR != SRC_DIR
961 #------------------------------------------------------------------------
962 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
963 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
964         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
965
966 DistCheckTop := 
967 else
968
969 DistCheckTop := check
970
971 #------------------------------------------------------------------------
972 # Prevent catastrophic remove
973 #------------------------------------------------------------------------
974 ifeq ($(LLVM_TARBALL_NAME),)
975 $(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
976 endif
977
978 #------------------------------------------------------------------------
979 # Prevent attempt to run dist targets from anywhere but the top level
980 #------------------------------------------------------------------------
981 ifneq ($(LEVEL),.)
982
983 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
984         $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
985
986 else
987
988 #------------------------------------------------------------------------
989 # Provide the top level targets
990 #------------------------------------------------------------------------
991
992 dist-gzip:: $(DistTarGZip)
993
994 $(DistTarGZip) : distdir
995         $(Echo) Packing gzipped distribution tar file.
996         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
997
998 dist-bzip2:: $(DistTarBZ2)
999
1000 $(DistTarBZ2) : distdir
1001         $(Echo) Packing bzipped distribution tar file.
1002         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
1003
1004 dist-zip:: $(DistZip)
1005
1006 $(DistZip) : distdir
1007         $(Echo) Packing zipped distribution file.
1008         $(Verb) rm -f $(DistZip)
1009         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1010
1011 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1012         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1013
1014 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1015
1016 dist-check:: $(DistCheckTop) $(DistTarGZip)
1017         $(Echo) Checking distribution tar file.
1018         $(Verb) if test -d $(DistCheckDir) ; then \
1019           $(RM) -rf $(DistCheckDir) ; \
1020         fi
1021         $(Verb) $(MKDIR) $(DistCheckDir)
1022         $(Verb) cd $(DistCheckDir) && \
1023           $(MKDIR) $(DistCheckDir)/build && \
1024           $(MKDIR) $(DistCheckDir)/install && \
1025           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1026           cd build && \
1027           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1028             --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1029           $(MAKE) check && \
1030           $(MAKE) install && \
1031           $(MAKE) uninstall && \
1032           $(MAKE) dist && \
1033           $(MAKE) clean && \
1034           $(MAKE) dist-clean && \
1035           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1036
1037 dist-clean::
1038         $(Echo) Cleaning distribution files
1039         $(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
1040
1041 endif
1042
1043 #------------------------------------------------------------------------
1044 # Provide the recursive distdir target for building the distribution directory
1045 #------------------------------------------------------------------------
1046 distdir : $(DistSources)
1047         $(Echo) Building Distribution Directory $(DistDir)
1048         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1049           if test -d "$(DistDir)" ; then \
1050             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1051               exit 1 ; \
1052           fi ; \
1053           $(EchoCmd) Removing $(DistDir) ; \
1054           $(RM) -rf $(DistDir); \
1055         fi
1056         $(Verb) $(MKDIR) $(DistDir) 
1057         $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1058         srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1059         for file in $(DistFiles) ; do \
1060           case "$$file" in \
1061             $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
1062             $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
1063           esac; \
1064           if test -f "$$file" || test -d "$$file" ; then \
1065             from_dir=. ; \
1066           else \
1067             from_dir=$(BUILD_SRC_DIR); \
1068           fi; \
1069           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1070           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1071             to_dir="$(DistDir)/$$dir"; \
1072             $(MKDIR) "$$to_dir" ; \
1073           else \
1074             to_dir="$(DistDir)"; \
1075           fi; \
1076           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1077           if test -n "$$mid_dir" ; then \
1078             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1079           fi ; \
1080           if test -d "$$from_dir/$$file"; then \
1081             if test -d "$(BUILD_SRC_DIR)/$$file" && \
1082                test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1083               cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1084             fi; \
1085             cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1086           elif test -f "$$from_dir/$$file" ; then \
1087             cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1088           elif test -L "$$from_dir/$$file" ; then \
1089             cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1090           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1091             $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1092           elif test "$(Verb)" != '@' ; then \
1093             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1094           fi; \
1095         done
1096         $(Verb) for subdir in $(DistSubDirs) ; do \
1097           if test "$$subdir" \!= "." ; then \
1098             new_distdir="$(DistDir)/$$subdir" ; \
1099             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1100             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1101           fi; \
1102         done
1103         $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1104         -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1105           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1106           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1107           ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1108         || chmod -R a+r $(DistDir)
1109
1110 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1111 # defined by user.
1112 dist-hook::
1113
1114 endif
1115
1116 ###############################################################################
1117 # TOP LEVEL - targets only to apply at the top level directory
1118 ###############################################################################
1119
1120 ifeq ($(LEVEL),.)
1121
1122 #------------------------------------------------------------------------
1123 # Install support for project's include files:
1124 #------------------------------------------------------------------------
1125 install-local::
1126         $(Echo) Installing include files
1127         $(Verb) $(MKDIR) $(includedir)
1128         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1129           cd $(BUILD_SRC_ROOT)/include && \
1130             find . -path '*/Internal' -prune -o '(' -type f \
1131               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1132               -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1133         fi
1134
1135 uninstall-local::
1136         $(Echo) Uninstalling include files
1137         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1138           cd $(BUILD_SRC_ROOT)/include && \
1139             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1140               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1141               -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1142         fi 
1143
1144 endif
1145
1146 #------------------------------------------------------------------------
1147 # Print out the directories used for building
1148 #------------------------------------------------------------------------
1149 printvars::
1150         $(Echo) "Configuration  : " '$(Configuration)'
1151         $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1152         $(Echo) "BUILD_SRC_DIR  : " '$(BUILD_SRC_DIR)'
1153         $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1154         $(Echo) "BUILD_OBJ_DIR  : " '$(BUILD_OBJ_DIR)'
1155         $(Echo) "LLVM_SRC_ROOT  : " '$(LLVM_SRC_ROOT)'
1156         $(Echo) "LLVM_OBJ_ROOT  : " '$(LLVM_OBJ_ROOT)'
1157         $(Echo) "libdir         : " '$(libdir)'
1158         $(Echo) "bindir         : " '$(bindir)'
1159         $(Echo) "sysconfdir     : " '$(sysconfdir)'
1160         $(Echo) "bytecode_libdir: " '$(bytecode_libdir)'
1161         $(Echo) "UserTargets    : " '$(UserTargets)'
1162         $(Echo) "ObjMakefiles   : " '$(ObjMakefiles)'
1163         $(Echo) "SrcMakefiles   : " '$(SrcMakefiles)'
1164         $(Echo) "ObjDir         : " '$(ObjDir)'
1165         $(Echo) "LibDir         : " '$(LibDir)'
1166         $(Echo) "ToolDir        : " '$(ToolDir)'
1167         $(Echo) "TDFiles        : " '$(TDFiles)'
1168         $(Echo) "INCFiles       : " '$(INCFiles)'
1169         $(Echo) "Compile.CXX    : " '$(Compile.CXX)'
1170         $(Echo) "Compile.C      : " '$(Compile.C)'
1171         $(Echo) "Archive        : " '$(Archive)'