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