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