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