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