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