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