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