'make check' at the top level shouldn't recurse through the sourcedirs
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file was developed by the LLVM research group and is distributed under
6 # the University of Illinois Open Source License. See LICENSE.TXT for details.
7
8 #===------------------------------------------------------------------------===#
9 #
10 # This file is included by all of the LLVM makefiles.  For details on how to use
11 # it properly, please see the document MakefileGuide.html in the docs directory.
12 #
13 #===-----------------------------------------------------------------------====
14
15 ################################################################################
16 # TARGETS: Define standard targets that can be invoked
17 ################################################################################
18
19 #--------------------------------------------------------------------
20 # Define the various target sets
21 #--------------------------------------------------------------------
22 RecursiveTargets := all clean clean-all install uninstall install-bytecode
23 LocalTargets     := all-local clean-local clean-all-local check-local \
24                     install-local printvars uninstall-local \
25                     install-bytecode-local
26 TopLevelTargets  := 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 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
398 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
399 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
400
401 Parallel_Targets := $(foreach T,$(RecursiveTargets),%/.make$(T))
402
403 $(Parallel_Targets) :
404         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
405           $(MKDIR) $(@D); \
406           cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
407         fi; \
408         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
409 endif
410
411 #---------------------------------------------------------
412 # Handle the OPTIONAL_DIRS options for directores that may
413 # or may not exist.
414 #---------------------------------------------------------
415 ifdef OPTIONAL_DIRS
416
417 SubDirs += $(OPTIONAL_DIRS)
418
419 $(RecursiveTargets)::
420         $(Verb) for dir in $(OPTIONAL_DIRS); do \
421           if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
422             if [ ! -f $$dir/Makefile ]; then \
423               $(MKDIR) $$dir; \
424               cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
425             fi; \
426             ($(MAKE) -C$$dir $@ ) || exit 1; \
427           fi \
428         done
429 endif
430
431 #---------------------------------------------------------
432 # Handle the CONFIG_FILES options
433 #---------------------------------------------------------
434 ifdef CONFIG_FILES
435
436 install-local:: $(sysconfdir) $(CONFIG_FILES)
437         $(Echo) Installing Configuration Files To $(sysconfdir)
438         $(Verb)for file in $(CONFIG_FILES); do \
439           if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
440             $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
441           elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
442             $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
443           else \
444             $(ECHO) Error: cannot find config file $${file}. ; \
445           fi \
446         done
447
448 uninstall-local::
449         $(Echo) Uninstalling Configuration Files From $(sysconfdir)
450         $(Verb)for file in $(CONFIG_FILES); do \
451           $(RM) -f $(sysconfdir)/$${file} ; \
452         done
453
454 endif
455
456 ###############################################################################
457 # Library Build Rules: Four ways to build a library
458 ###############################################################################
459
460
461 # if we're building a library ...
462 ifdef LIBRARYNAME
463
464 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
465 LIBRARYNAME := $(strip $(LIBRARYNAME))
466 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
467 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
468 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
469 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
470
471 #---------------------------------------------------------
472 # Shared Library Targets:
473 #   If the user asked for a shared library to be built
474 #   with the SHARED_LIBRARY variable, then we provide
475 #   targets for building them.
476 #---------------------------------------------------------
477 ifdef SHARED_LIBRARY
478
479 all-local:: $(LibName.LA)
480
481 $(LibName.LA): $(BUILT_SOURCES) $(ObjectsLO) $(LibDir)/.dir
482         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
483         $(Verb) $(Link) -o $@ $(ObjectsLO)
484         $(Verb) $(LTInstall) $@ $(LibDir)
485
486 clean-local::
487 ifneq ($(strip $(LibName.LA)),)
488         -$(Verb) $(RM) -f $(LibName.LA)
489 endif
490
491 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
492
493 install-local:: $(DestSharedLib)
494
495 $(DestSharedLib): $(libdir) $(LibName.LA)
496         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
497         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
498         $(Verb) $(LIBTOOL) --finish $(libdir)
499
500 uninstall-local:: 
501         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
502         -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
503
504 endif
505
506 #---------------------------------------------------------
507 # Bytecode Library Targets:
508 #   If the user asked for a bytecode library to be built
509 #   with the BYTECODE_LIBRARY variable, then we provide 
510 #   targets for building them.
511 #---------------------------------------------------------
512 ifdef BYTECODE_LIBRARY
513
514 # make the C and C++ compilers strip debug info out of bytecode libraries.
515 BCCompile.C += -Wa,-strip-debug
516 BCCompile.CXX += -Wa,-strip-debug
517
518 all-local:: $(LibName.BCA)
519
520 ifdef EXPORTED_SYMBOL_FILE
521 BCLinkLib = $(LLVMGCC) -shared -nostdlib -Xlinker \
522             -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
523
524 $(LibName.BCA): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
525         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
526           "(internalize)"
527         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
528         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
529 else
530 $(LibName.BCA): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
531         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
532         $(Verb) $(LArchive) $@ $(ObjectsBC)
533
534 endif
535
536 clean-local::
537 ifneq ($(strip $(LibName.BCA)),)
538         -$(Verb) $(RM) -f $(LibName.BCA)
539 endif
540
541 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).a
542
543 install-bytecode-local:: $(DestBytecodeLib)
544
545 install-local:: $(DestBytecodeLib)
546
547 $(DestBytecodeLib): $(bytecode_libdir) $(LibName.BCA) 
548         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
549         $(Verb) $(INSTALL) $(LibName.BCA) $@
550
551 uninstall-local::
552         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
553         -$(Verb) $(RM) -f $(DestBytecodeLib)
554
555 endif
556
557 #---------------------------------------------------------
558 # ReLinked Library Targets:
559 #   If the user didn't explicitly forbid building a 
560 #   relinked then we provide targets for building them.
561 #---------------------------------------------------------
562 ifndef DONT_BUILD_RELINKED
563
564 all-local:: $(LibName.O)
565
566 $(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
567         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
568         $(Verb) $(Relink) -o $@ $(ObjectsO)
569
570 clean-local::
571 ifneq ($(strip $(LibName.O)),)
572         -$(Verb) $(RM) -f $(LibName.O)
573 endif
574
575 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
576
577 install-local:: $(DestRelinkedLib)
578
579 $(DestRelinkedLib): $(libdir) $(LibName.O)
580         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
581         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
582
583 uninstall-local::
584         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
585         -$(Verb) $(RM) -f $(DestRelinkedLib)
586
587 endif
588
589 #---------------------------------------------------------
590 # Archive Library Targets:
591 #   If the user wanted a regular archive library built, 
592 #   then we provide targets for building them.
593 #---------------------------------------------------------
594 ifdef BUILD_ARCHIVE
595
596 all-local:: $(LibName.A)
597
598 $(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
599         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
600         -$(Verb) $(RM) -f $@
601         $(Verb) $(Archive) $@ $(ObjectsO)
602         $(Verb) $(Ranlib) $@
603
604 clean-local::
605 ifneq ($(strip $(LibName.A)),)
606         -$(Verb) $(RM) -f $(LibName.A)
607 endif
608
609 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
610
611 install-local:: $(DestArchiveLib)
612
613 $(DestArchiveLib): $(libdir) $(LibName.A)
614         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
615         $(Verb) $(MKDIR) $(libdir)
616         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
617
618 uninstall-local::
619         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
620         -$(Verb) $(RM) -f $(DestArchiveLib)
621
622 endif
623
624 # endif LIBRARYNAME
625 endif 
626
627 ###############################################################################
628 # Tool Build Rules: Build executable tool based on TOOLNAME option
629 ###############################################################################
630
631 ifdef TOOLNAME
632
633 #---------------------------------------------------------
634 # Handle the special "JIT" value for LLVM_LIBS which is a
635 # shorthand for a bunch of libraries that get the correct
636 # JIT support for a tool that runs JIT.
637 #---------------------------------------------------------
638 ifeq ($(LLVMLIBS),JIT)
639
640 # Make sure we can get our own symbols in the tool
641 Link += -dlopen self
642
643 # Generic JIT libraries
644 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
645
646 # You can enable the X86 JIT on a non-X86 host by setting the flag
647 # ENABLE_X86_JIT on the make command line. If not, it will still be
648 # enabled automagically on an X86 host.
649 ifeq ($(ARCH), x86)
650   ENABLE_X86_JIT = 1
651 endif
652
653 # What the X86 JIT requires
654 ifdef ENABLE_X86_JIT
655   JIT_LIBS  += LLVMX86 LLVMSelectionDAG
656 endif
657
658 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
659 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
660 # enabled automagically on an SparcV9 host.
661 ifeq ($(ARCH), Sparc)
662   ENABLE_SPARCV9_JIT = 1
663 endif
664
665 # What the Sparc JIT requires
666 ifdef ENABLE_SPARCV9_JIT
667   JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
668               LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
669               LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
670               LLVMDataStructure.a LLVMSparcV9RegAlloc
671 endif
672
673 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
674 # ENABLE_PPC_JIT on the make command line. If not, it will still be
675 # enabled automagically on an PowerPC host.
676 ifeq ($(ARCH), PowerPC)
677   ENABLE_PPC_JIT = 1
678 endif
679
680 # What the PowerPC JIT requires
681 ifdef ENABLE_PPC_JIT
682   JIT_LIBS  += LLVMPowerPC
683 endif
684
685 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
686              LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
687              LLVMSystem.a $(PLATFORMLIBDL)
688 endif
689
690 #---------------------------------------------------------
691 # Set up variables for building a tool.
692 #---------------------------------------------------------
693 ifdef EXAMPLE_TOOL
694 ToolBuildPath   := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
695 else
696 ToolBuildPath   := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
697 endif
698 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
699 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
700 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
701 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
702 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
703 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
704 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
705 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
706
707 #---------------------------------------------------------
708 # Tell make that we need to rebuild subdirectories before 
709 # we can link the tool. This affects things like LLI which 
710 # has library subdirectories.
711 #---------------------------------------------------------
712 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
713
714 #---------------------------------------------------------
715 # Provide targets for building the tools
716 #---------------------------------------------------------
717 all-local:: $(ToolBuildPath)
718
719 clean-local::
720 ifneq ($(strip $(ToolBuildPath)),)
721         -$(Verb) $(RM) -f $(ToolBuildPath)
722 endif
723
724 ifdef EXAMPLE_TOOL
725 $(ToolBuildPath): $(ExmplDir)/.dir
726 else
727 $(ToolBuildPath): $(ToolDir)/.dir
728 endif
729
730 $(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
731         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
732         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
733           $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
734         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg) 
735
736 DestTool = $(bindir)/$(TOOLNAME)
737
738 install-local:: $(DestTool)
739
740 $(DestTool): $(bindir) $(ToolBuildPath)
741         $(Echo) Installing $(BuildMode) $(DestTool)
742         $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
743
744 uninstall-local::
745         $(Echo) Uninstalling $(BuildMode) $(DestTool)
746         -$(Verb) $(RM) -f $(DestTool)
747
748 endif
749
750 ###############################################################################
751 # Object Build Rules: Build object files based on sources 
752 ###############################################################################
753
754 # Provide rule sets for when dependency generation is enabled
755 ifndef DISABLE_AUTO_DEPENDENCIES
756
757 #---------------------------------------------------------
758 # Create .lo files in the ObjDir directory from the .cpp and .c files...
759 #---------------------------------------------------------
760 ifdef SHARED_LIBRARY
761
762 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
763         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
764         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
765         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
766         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
767
768 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
769         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
770         $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
771         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
772         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
773
774 #---------------------------------------------------------
775 # Create .o files in the ObjDir directory from the .cpp and .c files...
776 #---------------------------------------------------------
777 else
778
779 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
780         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
781         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
782         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
783         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
784
785 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
786         $(Echo) "Compiling $*.c for $(BuildMode) build"
787         $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
788         then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
789         else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
790
791 endif
792
793 #---------------------------------------------------------
794 # Create .bc files in the ObjDir directory from .cpp and .c files...
795 #---------------------------------------------------------
796 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS)
797         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
798         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
799         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
800         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
801
802 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS)
803         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
804         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
805         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
806         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
807
808 # Provide alternate rule sets if dependencies are disabled
809 else
810
811 ifdef SHARED_LIBRARY
812
813 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir 
814         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
815         $(LTCompile.CXX) $< -o $@ 
816
817 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
818         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
819         $(LTCompile.C) $< -o $@ 
820
821 else
822
823 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
824         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
825         $(Compile.CXX) $< -o $@ 
826
827 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
828         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
829         $(Compile.C) $< -o $@ 
830 endif
831
832 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS)
833         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
834         $(BCCompile.CXX) $< -o $@ 
835
836 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS)
837         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
838         $(BCCompile.C) $< -o $@
839
840 endif
841
842 #---------------------------------------------------------
843 # Provide rule to build .bc files from .ll sources,
844 # regardless of dependencies
845 #---------------------------------------------------------
846 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
847         $(Echo) "Compiling $*.ll for $(BuildMode) build"
848         $(Verb) $(LLVMAS) $< -f -o $@
849
850 ###############################################################################
851 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
852 ###############################################################################
853
854 ifdef TARGET
855
856 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
857 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
858
859 $(INCFiles) : $(TBLGEN) $(TDFiles)
860
861 %GenRegisterNames.inc : %.td 
862         $(Echo) "Building $(<F) register names with tblgen"
863         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
864
865 %GenRegisterInfo.h.inc : %.td 
866         $(Echo) "Building $(<F) register information header with tblgen"
867         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
868
869 %GenRegisterInfo.inc : %.td
870         $(Echo) "Building $(<F) register info implementation with tblgen"
871         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
872
873 %GenInstrNames.inc : %.td
874         $(Echo) "Building $(<F) instruction names with tblgen"
875         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
876
877 %GenInstrInfo.inc : %.td
878         $(Echo) "Building $(<F) instruction information with tblgen"
879         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
880
881 %GenAsmWriter.inc : %.td
882         $(Echo) "Building $(<F) assembly writer with tblgen"
883         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
884
885 %GenATTAsmWriter.inc : %.td
886         $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
887         $(Verb) $(TableGen) -gen-asm-writer -o $@ $< 
888
889 %GenIntelAsmWriter.inc : %.td
890         $(Echo) "Building $(<F) Intel assembly writer with tblgen"
891         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
892
893 %GenInstrSelector.inc: %.td
894         $(Echo) "Building $(<F) instruction selector with tblgen"
895         $(Verb) $(TableGen) -gen-instr-selector -o $@ $< 
896
897 %GenCodeEmitter.inc:: %.td
898         $(Echo) "Building $(<F) code emitter with tblgen"
899         $(Verb) $(TableGen) -gen-emitter -o $@ $<
900
901 clean-local::
902         -$(Verb) $(RM) -f $(INCFiles)
903
904 endif
905
906 ###############################################################################
907 # LEX AND YACC: Provide rules for generating sources with lex and yacc
908 ###############################################################################
909
910 #---------------------------------------------------------
911 # Provide rules for generating a .cpp source file from 
912 # (f)lex input sources. 
913 #---------------------------------------------------------
914
915 LexFiles  := $(filter %.l,$(Sources))
916
917 ifneq ($(LexFiles),)
918
919 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
920
921 .PRECIOUS: $(LexOutput)
922
923 # Note the extra sed filtering here, used to cut down on the warnings emited 
924 # by GCC.  The last line is a gross hack to work around flex aparently not 
925 # being able to resize the buffer on a large token input.  Currently, for 
926 # uninitialized string buffers in LLVM we can generate very long tokens, so 
927 # this is a hack around it.
928 # FIXME.  (f.e. char Buffer[10000] )
929 %.cpp: %.l
930         $(Echo) Flexing $<
931         $(Verb) $(FLEX) -t $< | \
932         $(SED) 's/void yyunput/inline void yyunput/' | \
933         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
934         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
935           > $@
936
937 clean-local::
938         -$(Verb) $(RM) -f $(LexOutput)
939         $(Verb) $(RM) -f $(LexOutput)
940
941 endif
942
943 #---------------------------------------------------------
944 # Provide rules for generating a .cpp and .h source files 
945 # from yacc (bison) input sources.
946 #---------------------------------------------------------
947
948 YaccFiles  := $(filter %.y,$(Sources))
949 ifneq ($(YaccFiles),)
950 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
951
952 .PRECIOUS: $(YaccOutput)
953
954 # Cancel built-in rules for yacc
955 %.c: %.y 
956 %.cpp: %.y
957 %.h: %.y
958
959 # Rule for building the bison parsers...
960 %.cpp %.h : %.y
961         $(Echo) "Bisoning $*.y"
962         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
963         $(Verb) $(MV) -f $*.tab.c $*.cpp
964         $(Verb) $(MV) -f $*.tab.h $*.h
965
966 clean-local::
967         -$(Verb) $(RM) -f $(YaccOutput)
968         $(Verb) $(RM) -f $(YaccOutput)
969 endif
970
971 ###############################################################################
972 # OTHER RULES: Other rules needed
973 ###############################################################################
974
975 # To create postscript files from dot files...
976 ifneq ($(DOT),false)
977 %.ps: %.dot
978         $(DOT) -Tps < $< > $@
979 else
980 %.ps: %.dot
981         $(Echo) "Cannot build $@: The program dot is not installed"
982 endif
983
984 # This rules ensures that header files that are removed still have a rule for
985 # which they can be "generated."  This allows make to ignore them and
986 # reproduce the dependency lists.
987 %.h:: ;
988
989 # Define clean-local to clean the current directory. Note that this uses a
990 # very conservative approach ensuring that empty variables do not cause 
991 # errors or disastrous removal.
992 clean-local::
993 ifneq ($(strip $(ObjDir)),)
994         -$(Verb) $(RM) -rf $(ObjDir)
995 endif
996         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
997 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
998         -$(Verb) $(RM) -f *$(SHLIBEXT)
999 endif
1000
1001 clean-all-local::
1002         -$(Verb) $(RM) -rf Debug Release Profile
1003
1004 # Build tags database for Emacs/Xemacs:
1005 tags:: TAGS CTAGS
1006
1007 TAGS: 
1008         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1009           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1010           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1011           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1012         -name '*.cpp' -o -name '*.h' | \
1013         $(ETAGS) $(ETAGSFLAGS) -
1014
1015 CTAGS:
1016         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1017           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1018           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1019           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1020           \( -name '*.cpp' -o -name '*.h' \) -print | \
1021           ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1022
1023
1024 ###############################################################################
1025 # DEPENDENCIES: Include the dependency files if we should
1026 ###############################################################################
1027 ifndef DISABLE_AUTO_DEPENDENCIES
1028
1029 # If its not one of the cleaning targets
1030 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1031
1032 # Get the list of dependency files
1033 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1034 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1035
1036 -include /dev/null $(DependFiles)
1037
1038 endif
1039
1040 endif 
1041
1042 ###############################################################################
1043 # DISTRIBUTION: Handle construction of a distribution tarball
1044 ###############################################################################
1045
1046 #------------------------------------------------------------------------
1047 # Define distribution related variables
1048 #------------------------------------------------------------------------
1049 DistName    := $(LLVM_TARBALL_NAME)
1050 DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
1051 TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
1052 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1053 DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
1054 DistTarBZ2  := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1055 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1056                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1057                Makefile.config.in configure autoconf
1058 DistOther   := $(notdir $(wildcard \
1059                $(BUILD_SRC_DIR)/*.h \
1060                $(BUILD_SRC_DIR)/*.td \
1061                $(BUILD_SRC_DIR)/*.def \
1062                $(BUILD_SRC_DIR)/*.ll \
1063                $(BUILD_SRC_DIR)/*.in))
1064 DistSubDirs := $(SubDirs)
1065 DistSources  = $(Sources) $(EXTRA_DIST)
1066 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1067
1068 #------------------------------------------------------------------------
1069 # We MUST build distribution with OBJ_DIR != SRC_DIR
1070 #------------------------------------------------------------------------
1071 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1072 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1073         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1074
1075 DistCheckTop := 
1076 else
1077
1078 DistCheckTop := check
1079
1080 #------------------------------------------------------------------------
1081 # Prevent catastrophic remove
1082 #------------------------------------------------------------------------
1083 ifeq ($(LLVM_TARBALL_NAME),)
1084 $(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
1085 endif
1086
1087 #------------------------------------------------------------------------
1088 # Prevent attempt to run dist targets from anywhere but the top level
1089 #------------------------------------------------------------------------
1090 ifneq ($(LEVEL),.)
1091
1092 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1093         $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
1094
1095 else
1096
1097 #------------------------------------------------------------------------
1098 # Provide the top level targets
1099 #------------------------------------------------------------------------
1100
1101 dist-gzip:: $(DistTarGZip)
1102
1103 $(DistTarGZip) : distdir
1104         $(Echo) Packing gzipped distribution tar file.
1105         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1106           $(GZIP) -c > "$(DistTarGZip)"
1107
1108 dist-bzip2:: $(DistTarBZ2)
1109
1110 $(DistTarBZ2) : distdir
1111         $(Echo) Packing bzipped distribution tar file.
1112         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1113           $(BZIP2) -c >$(DistTarBZ2)
1114
1115 dist-zip:: $(DistZip)
1116
1117 $(DistZip) : distdir
1118         $(Echo) Packing zipped distribution file.
1119         $(Verb) rm -f $(DistZip)
1120         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1121
1122 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1123         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1124
1125 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1126
1127 dist-check:: $(DistCheckTop) $(DistTarGZip)
1128         $(Echo) Checking distribution tar file.
1129         $(Verb) if test -d $(DistCheckDir) ; then \
1130           $(RM) -rf $(DistCheckDir) ; \
1131         fi
1132         $(Verb) $(MKDIR) $(DistCheckDir)
1133         $(Verb) cd $(DistCheckDir) && \
1134           $(MKDIR) $(DistCheckDir)/build && \
1135           $(MKDIR) $(DistCheckDir)/install && \
1136           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1137           cd build && \
1138           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1139             --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1140           $(MAKE) check && \
1141           $(MAKE) install && \
1142           $(MAKE) uninstall && \
1143           $(MAKE) dist && \
1144           $(MAKE) clean && \
1145           $(MAKE) dist-clean && \
1146           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1147
1148 dist-clean::
1149         $(Echo) Cleaning distribution files
1150         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
1151
1152 endif
1153
1154 #------------------------------------------------------------------------
1155 # Provide the recursive distdir target for building the distribution directory
1156 #------------------------------------------------------------------------
1157 distdir : $(DistSources)
1158         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1159           if test -d "$(DistDir)" ; then \
1160             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1161               exit 1 ; \
1162           fi ; \
1163           $(EchoCmd) Removing $(DistDir) ; \
1164           $(RM) -rf $(DistDir); \
1165         fi
1166         $(Echo) Building Distribution Directory $(DistDir)
1167         $(Verb) $(MKDIR) $(DistDir) 
1168         $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1169         srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1170         for file in $(DistFiles) ; do \
1171           case "$$file" in \
1172             $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
1173             $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
1174           esac; \
1175           if test -f "$$file" || test -d "$$file" ; then \
1176             from_dir=. ; \
1177           else \
1178             from_dir=$(BUILD_SRC_DIR); \
1179           fi; \
1180           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1181           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1182             to_dir="$(DistDir)/$$dir"; \
1183             $(MKDIR) "$$to_dir" ; \
1184           else \
1185             to_dir="$(DistDir)"; \
1186           fi; \
1187           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1188           if test -n "$$mid_dir" ; then \
1189             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1190           fi ; \
1191           if test -d "$$from_dir/$$file"; then \
1192             if test -d "$(BUILD_SRC_DIR)/$$file" && \
1193                test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1194               cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1195             fi; \
1196             cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1197           elif test -f "$$from_dir/$$file" ; then \
1198             cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1199           elif test -L "$$from_dir/$$file" ; then \
1200             cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1201           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1202             $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1203           elif test "$(Verb)" != '@' ; then \
1204             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1205           fi; \
1206         done
1207         $(Verb) for subdir in $(DistSubDirs) ; do \
1208           if test "$$subdir" \!= "." ; then \
1209             new_distdir="$(DistDir)/$$subdir" ; \
1210             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1211             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1212           fi; \
1213         done
1214         $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1215         -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1216           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1217           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1218           ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1219         || chmod -R a+r $(DistDir)
1220
1221 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1222 # defined by user.
1223 dist-hook::
1224
1225 endif
1226
1227 ###############################################################################
1228 # TOP LEVEL - targets only to apply at the top level directory
1229 ###############################################################################
1230
1231 ifeq ($(LEVEL),.)
1232
1233 #------------------------------------------------------------------------
1234 # Install support for project's include files:
1235 #------------------------------------------------------------------------
1236 install-local::
1237         $(Echo) Installing include files
1238         $(Verb) $(MKDIR) $(includedir)
1239         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1240           cd $(BUILD_SRC_ROOT)/include && \
1241             find . -path '*/Internal' -prune -o '(' -type f \
1242               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1243               -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1244         fi
1245
1246 uninstall-local::
1247         $(Echo) Uninstalling include files
1248         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1249           cd $(BUILD_SRC_ROOT)/include && \
1250             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1251               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1252               -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1253         fi 
1254
1255 endif
1256
1257 #------------------------------------------------------------------------
1258 # Print out the directories used for building
1259 #------------------------------------------------------------------------
1260 printvars::
1261         $(Echo) "BuildMode      : " '$(BuildMode)'
1262         $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1263         $(Echo) "BUILD_SRC_DIR  : " '$(BUILD_SRC_DIR)'
1264         $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1265         $(Echo) "BUILD_OBJ_DIR  : " '$(BUILD_OBJ_DIR)'
1266         $(Echo) "LLVM_SRC_ROOT  : " '$(LLVM_SRC_ROOT)'
1267         $(Echo) "LLVM_OBJ_ROOT  : " '$(LLVM_OBJ_ROOT)'
1268         $(Echo) "libdir         : " '$(libdir)'
1269         $(Echo) "bindir         : " '$(bindir)'
1270         $(Echo) "sysconfdir     : " '$(sysconfdir)'
1271         $(Echo) "bytecode_libdir: " '$(bytecode_libdir)'
1272         $(Echo) "UserTargets    : " '$(UserTargets)'
1273         $(Echo) "ObjMakefiles   : " '$(ObjMakefiles)'
1274         $(Echo) "SrcMakefiles   : " '$(SrcMakefiles)'
1275         $(Echo) "ObjDir         : " '$(ObjDir)'
1276         $(Echo) "LibDir         : " '$(LibDir)'
1277         $(Echo) "ToolDir        : " '$(ToolDir)'
1278         $(Echo) "ExmplDir       : " '$(ExmplDir)'
1279         $(Echo) "TDFiles        : " '$(TDFiles)'
1280         $(Echo) "INCFiles       : " '$(INCFiles)'
1281         $(Echo) "Compile.CXX    : " '$(Compile.CXX)'
1282         $(Echo) "Compile.C      : " '$(Compile.C)'
1283         $(Echo) "Archive        : " '$(Archive)'
1284         $(Echo) "YaccFiles      : " '$(YaccFiles)'
1285         $(Echo) "LexFiles       : " '$(LexFiles)'