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