Don't use gccld or gccas
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file was developed by the LLVM research group and is distributed under
6 # the University of Illinois Open Source License. See LICENSE.TXT for details.
7
8 #===------------------------------------------------------------------------===#
9 #
10 # This file is included by all of the LLVM makefiles.  For details on how to use
11 # it properly, please see the document MakefileGuide.html in the docs directory.
12 #
13 #===-----------------------------------------------------------------------====#
14
15 ################################################################################
16 # TARGETS: Define standard targets that can be invoked
17 ################################################################################
18
19 #--------------------------------------------------------------------
20 # Define the various target sets
21 #--------------------------------------------------------------------
22 RecursiveTargets := all clean clean-all install uninstall install-bytecode
23 LocalTargets     := all-local clean-local clean-all-local check-local \
24                     install-local printvars uninstall-local \
25                     install-bytecode-local
26 TopLevelTargets  := check dist dist-check dist-clean tags dist-gzip dist-bzip2 \
27                     dist-zip
28 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29 InternalTargets  := preconditions distdir dist-hook
30
31 ################################################################################
32 # INITIALIZATION: Basic things the makefile needs
33 ################################################################################
34
35 #--------------------------------------------------------------------
36 # Set the VPATH so that we can find source files.
37 #--------------------------------------------------------------------
38 VPATH=$(PROJ_SRC_DIR)
39
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build
42 #--------------------------------------------------------------------
43 .SUFFIXES:
44 .SUFFIXES: .c .cpp .cc .h .hpp .y .l .lo .o .a .bc .td .ps .dot .ll
45 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46
47 #--------------------------------------------------------------------
48 # Mark all of these targets as phony to avoid implicit rule search
49 #--------------------------------------------------------------------
50 .PHONY: $(UserTargets) $(InternalTargets)
51
52 #--------------------------------------------------------------------
53 # Make sure all the user-target rules are double colon rules and 
54 # they are defined first.
55 #--------------------------------------------------------------------
56
57 $(UserTargets)::
58
59 ################################################################################
60 # PRECONDITIONS: that which must be built/checked first
61 ################################################################################
62
63 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
64                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
67 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
71 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
72 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
73 ifneq ($(MakefileCommonIn),)
74 PreConditions      += $(MakefileCommon)
75 endif
76
77 ifneq ($(MakefileConfigIn),)
78 PreConditions      += $(MakefileConfig)
79 endif
80
81 preconditions: $(PreConditions)
82
83 #------------------------------------------------------------------------
84 # Make sure the BUILT_SOURCES are built first
85 #------------------------------------------------------------------------
86 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
87
88 clean-all-local::
89 ifneq ($(strip $(BUILT_SOURCES)),)
90         -$(Verb) $(RM) -f $(BUILT_SOURCES)
91 endif
92
93 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94 spotless:
95         $(Verb) if test -x config.status ; then \
96           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
97           $(MKDIR) .spotless.save ; \
98           $(MV) config.status .spotless.save ; \
99           $(MV) mklib  .spotless.save ; \
100           $(MV) projects  .spotless.save ; \
101           $(RM) -rf * ; \
102           $(MV) .spotless.save/config.status . ; \
103           $(MV) .spotless.save/mklib . ; \
104           $(MV) .spotless.save/projects . ; \
105           $(RM) -rf .spotless.save ; \
106           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
107           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108           $(ConfigStatusScript) ; \
109         else \
110           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
111         fi
112 else
113 spotless:
114         $(EchoCmd) "spotless target not supported for objdir == srcdir"
115 endif
116
117 $(BUILT_SOURCES) : $(ObjMakefiles)
118
119 #------------------------------------------------------------------------
120 # Make sure we're not using a stale configuration
121 #------------------------------------------------------------------------
122 reconfigure:
123         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124         $(Verb) cd $(PROJ_OBJ_ROOT) && \
125           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127           fi ; \
128           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129           $(ConfigStatusScript)
130
131 .PRECIOUS: $(ConfigStatusScript)
132 $(ConfigStatusScript): $(ConfigureScript)
133         $(Echo) Reconfiguring with $<
134         $(Verb) cd $(PROJ_OBJ_ROOT) && \
135           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
136             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137           fi ; \
138           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
139           $(ConfigStatusScript)
140
141 #------------------------------------------------------------------------
142 # Make sure the configuration makefile is up to date
143 #------------------------------------------------------------------------
144 ifneq ($(MakefileConfigIn),)
145 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
146         $(Echo) Regenerating $@
147         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
148 endif
149
150 ifneq ($(MakefileCommonIn),)
151 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
152         $(Echo) Regenerating $@
153         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
154 endif
155
156 #------------------------------------------------------------------------
157 # If the Makefile in the source tree has been updated, copy it over into the
158 # build tree. But, only do this if the source and object makefiles differ
159 #------------------------------------------------------------------------
160 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161
162 Makefile: $(PROJ_SRC_DIR)/Makefile
163         $(Echo) "Updating Makefile"
164         $(Verb) $(MKDIR) $(@D)
165         $(Verb) $(CP) -f $< $@
166
167 # Copy the Makefile.* files unless we're in the root directory which avoids
168 # the copying of Makefile.config.in or other things that should be explicitly
169 # taken care of.
170 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171         @case '$?' in \
172           *Makefile.rules) ;; \
173           *.in) ;; \
174           *) $(Echo) "Updating $(@F)" ; \
175              $(MKDIR) $(@D) ; \
176              $(CP) -f $< $@ ;; \
177         esac
178          
179 endif
180
181 #------------------------------------------------------------------------
182 # Set up the basic dependencies
183 #------------------------------------------------------------------------
184 $(UserTargets):: $(PreConditions)
185
186 all:: all-local
187 clean:: clean-local 
188 clean-all:: clean-local clean-all-local
189 install:: install-local
190 uninstall:: uninstall-local
191 install-local:: all-local 
192 install-bytecode:: install-bytecode-local
193
194 ###############################################################################
195 # VARIABLES: Set up various variables based on configuration data
196 ###############################################################################
197
198 #--------------------------------------------------------------------
199 # Variables derived from configuration we are building
200 #--------------------------------------------------------------------
201
202 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
203 # this can be overridden on the make command line.
204 ifneq ($(OS),MingW)
205   OPTIMIZE_OPTION := -O3
206 else
207   OPTIMIZE_OPTION := -O2
208 endif
209
210 ifdef ENABLE_PROFILING
211   BuildMode := Profile
212   CXX.Flags := $(OPTIMIZE_OPTION) -pg -g
213   C.Flags   := $(OPTIMIZE_OPTION) -pg -g
214   LD.Flags  := $(OPTIMIZE_OPTION) -pg -g
215 else
216   ifeq ($(ENABLE_OPTIMIZED),1)
217     BuildMode := Release
218     # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
219     ifneq ($(OS),FreeBSD)
220     ifneq ($(OS),Darwin)
221       OmitFramePointer := -fomit-frame-pointer
222     endif
223     endif
224
225     # Darwin requires -fstrict-aliasing to be explicitly enabled.
226     ifeq ($(OS),Darwin)
227       EXTRA_OPTIONS += -fstrict-aliasing
228     endif
229
230     CXX.Flags := $(OPTIMIZE_OPTION) $(OmitFramePointer)
231     C.Flags   := $(OPTIMIZE_OPTION) $(OmitFramePointer)
232     LD.Flags  := $(OPTIMIZE_OPTION)
233   else
234     BuildMode := Debug
235     CXX.Flags := -g
236     C.Flags   := -g
237     LD.Flags  := -g
238     KEEP_SYMBOLS := 1
239   endif
240 endif
241
242 # IF REQUIRES_EH=1 is specified then don't disable exceptions
243 ifndef REQUIRES_EH
244   CXX.Flags += -fno-exceptions
245 endif
246
247 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
248 # then disable assertions by defining the appropriate preprocessor symbols.
249 ifdef DISABLE_ASSERTIONS
250   BuildMode := $(BuildMode)-Asserts
251   CXX.Flags += -DNDEBUG
252   C.Flags   += -DNDEBUG
253 else
254   CXX.Flags += -D_DEBUG
255   C.Flags   += -D_DEBUG
256 endif
257
258 ifeq ($(ENABLE_PIC),1)
259   CXX.Flags += -fPIC
260   C.Flags   += -fPIC
261 endif
262
263 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
264 C.Flags       += $(CFLAGS)
265 CPP.BaseFlags += $(CPPFLAGS)
266 LD.Flags      += $(LDFLAGS)
267 AR.Flags      := cru
268 LibTool.Flags := --tag=CXX
269
270 # Make Floating point IEEE compliant on Alpha.
271 ifeq ($(ARCH),Alpha)
272   CXX.Flags     += -mieee
273   CPP.BaseFlags += -mieee
274 ifeq ($(ENABLE_PIC),0)
275   CXX.Flags     += -fPIC
276   CPP.BaseFlags += -fPIC
277 endif
278 endif
279
280 ifeq ($(ARCH),Alpha)
281   LD.Flags += -Wl,--no-relax
282 endif
283
284 #--------------------------------------------------------------------
285 # Directory locations
286 #--------------------------------------------------------------------
287 ObjDir      := $(PROJ_OBJ_DIR)/$(BuildMode)
288 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
289 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
290 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
291 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
292 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
293 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
294 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
295
296 #--------------------------------------------------------------------
297 # Full Paths To Compiled Tools and Utilities
298 #--------------------------------------------------------------------
299 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
300 Echo     = @$(EchoCmd)
301 ifndef LIBTOOL
302 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
303 endif
304 ifndef LLVMAS
305 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
306 endif
307 ifndef TBLGEN
308   ifeq ($(LLVM_CROSS_COMPILING),1)
309     TBLGEN   := $(LLVMToolDir)/tblgen$(BUILD_EXEEXT)
310   else
311     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
312   endif
313 endif
314 LLVM_CONFIG := $(LLVMToolDir)/llvm-config 
315 ifndef LLVMLD
316 LLVMLD    := $(LLVMToolDir)/gccld$(EXEEXT)
317 endif
318 ifndef LLVMDIS
319 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
320 endif
321 ifndef LLI
322 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
323 endif
324 ifndef LLC
325 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
326 endif
327 ifndef LOPT
328 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
329 endif
330 ifndef LBUGPOINT
331 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
332 endif
333 ifndef LUPGRADE
334 LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
335 endif
336 ifeq ($(LLVMGCC_MAJVERS),3)
337 UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
338 UPGRADE_LL  = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
339 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
340 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
341 else
342 UPGRADE_MSG =
343 UPGRADE_LL  =
344 LLVMGCCWITHPATH  := $(LLVMGCC)
345 LLVMGXXWITHPATH  := $(LLVMGXX)
346 endif
347
348 #--------------------------------------------------------------------
349 # Adjust to user's request
350 #--------------------------------------------------------------------
351
352 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
353 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
354 # shared library can be opened with dlopen. Also, LOADABLE_MODULE implies 
355 # several other things so we force them to be defined/on.
356 ifdef LOADABLE_MODULE
357   SHARED_LIBRARY := 1
358   DONT_BUILD_RELINKED := 1
359   LINK_LIBS_IN_SHARED := 1
360   LD.Flags += -module
361 endif
362
363 ifdef SHARED_LIBRARY
364   LD.Flags += -rpath $(LibDir)
365 else
366   LibTool.Flags += --tag=disable-shared
367 endif
368
369 ifdef TOOL_VERBOSE
370   C.Flags += -v
371   CXX.Flags += -v
372   LD.Flags += -v
373   VERBOSE := 1
374 endif
375
376 # Adjust settings for verbose mode
377 ifndef VERBOSE
378   Verb := @
379   LibTool.Flags += --silent
380   AR.Flags += >/dev/null 2>/dev/null
381   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
382 else
383   ConfigureScriptFLAGS := 
384 endif
385
386 # By default, strip symbol information from executable
387 ifndef KEEP_SYMBOLS
388   Strip := $(PLATFORMSTRIPOPTS)
389   StripWarnMsg := "(without symbols)"
390   Install.StripFlag += -s
391 endif
392
393 # Adjust linker flags for building an executable
394 ifdef TOOLNAME
395 ifdef EXAMPLE_TOOL
396   LD.Flags += -rpath $(ExmplDir) -export-dynamic
397 else
398   LD.Flags += -rpath $(ToolDir) -export-dynamic
399 endif
400 endif
401
402 #----------------------------------------------------------
403 # Options To Invoke Tools
404 #----------------------------------------------------------
405
406 CompileCommonOpts := -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
407                      -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
408
409 ifeq ($(OS),HP-UX)
410   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
411 endif
412
413 # If we are building a universal binary on Mac OS/X, pass extra options.  This
414 # is useful to people that want to link the LLVM libraries into their universal
415 # apps.
416 #
417 # The following can be optionally specified:
418 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
419 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
420 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
421 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
422 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
423 #      i386/ppc only.
424 ifdef UNIVERSAL
425   ifndef UNIVERSAL_ARCH
426     UNIVERSAL_ARCH := i386 ppc
427   endif
428   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
429   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
430   Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS:%=-XCClinker %)
431   ifdef UNIVERSAL_SDK_PATH
432     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
433     Relink.Flags      += -XCClinker -isysroot -XCClinker $(UNIVERSAL_SDK_PATH)
434   endif
435
436   # Building universal cannot compute dependencies automatically.
437   DISABLE_AUTO_DEPENDENCIES=1
438 endif
439
440 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir) 
441 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
442 # All -I flags should go here, so that they don't confuse llvm-config.
443 CPP.Flags     += -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
444                  -I$(PROJ_OBJ_ROOT)/include \
445                  -I$(PROJ_SRC_ROOT)/include \
446                  -I$(LLVM_OBJ_ROOT)/include \
447                  -I$(LLVM_SRC_ROOT)/include \
448                  $(CPP.BaseFlags)
449
450 Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
451 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
452 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
453 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
454
455 Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
456 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
457 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
458                 $(CompileCommonOpts)
459
460 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
461 Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
462                 $(LD.Flags) $(Strip)
463 LTLink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Link)
464 Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
465                 $(Relink.Flags)
466 LTRelink      = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Relink)
467 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
468                 $(Install.Flags)
469 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
470 ScriptInstall = $(INSTALL) -m 0755 
471 DataInstall   = $(INSTALL) -m 0644
472 TableGen      = $(TBLGEN) -I $(PROJ_SRC_DIR) -I$(PROJ_SRC_ROOT)/include \
473                 -I $(PROJ_SRC_ROOT)/lib/Target      
474 Archive       = $(AR) $(AR.Flags)
475 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
476 ifdef RANLIB
477 Ranlib        = $(RANLIB)
478 else
479 Ranlib        = ranlib
480 endif
481
482 #----------------------------------------------------------
483 # Get the list of source files and compute object file 
484 # names from them. 
485 #----------------------------------------------------------
486
487 ifndef SOURCES
488   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
489              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
490              $(PROJ_SRC_DIR)/*.l))
491 else
492   Sources := $(SOURCES)
493 endif 
494
495 ifdef BUILT_SOURCES
496 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
497 endif
498
499 BaseNameSources := $(sort $(basename $(Sources)))
500
501 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
502 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
503 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
504
505 ###############################################################################
506 # DIRECTORIES: Handle recursive descent of directory structure
507 ###############################################################################
508
509 #---------------------------------------------------------
510 # Provide rules to make install dirs. This must be early
511 # in the file so they get built before dependencies
512 #---------------------------------------------------------
513
514 $(PROJ_bindir): $(PROJ_bindir)/.dir
515 $(PROJ_libdir): $(PROJ_libdir)/.dir
516 $(PROJ_includedir): $(PROJ_includedir)/.dir
517 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
518
519 # To create other directories, as needed, and timestamp their creation
520 %/.dir:
521         $(Verb) $(MKDIR) $* > /dev/null
522         $(Verb) $(DATE) > $@
523
524 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
525 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
526
527 #---------------------------------------------------------
528 # Handle the DIRS options for sequential construction
529 #---------------------------------------------------------
530
531 SubDirs := 
532 ifdef DIRS
533 SubDirs += $(DIRS)
534
535 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
536 $(RecursiveTargets)::
537         $(Verb) for dir in $(DIRS); do \
538           if [ ! -f $$dir/Makefile ]; then \
539             $(MKDIR) $$dir; \
540             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
541           fi; \
542           ($(MAKE) -C $$dir $@ ) || exit 1; \
543         done
544 else
545 $(RecursiveTargets)::
546         $(Verb) for dir in $(DIRS); do \
547           ($(MAKE) -C $$dir $@ ) || exit 1; \
548         done
549 endif
550
551 endif
552
553 #---------------------------------------------------------
554 # Handle the EXPERIMENTAL_DIRS options ensuring success
555 # after each directory is built.
556 #---------------------------------------------------------
557 ifdef EXPERIMENTAL_DIRS
558 $(RecursiveTargets)::
559         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
560           if [ ! -f $$dir/Makefile ]; then \
561             $(MKDIR) $$dir; \
562             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
563           fi; \
564           ($(MAKE) -C $$dir $@ ) || exit 0; \
565         done
566 endif
567
568 #-----------------------------------------------------------
569 # Handle the PARALLEL_DIRS options for parallel construction
570 #-----------------------------------------------------------
571 ifdef PARALLEL_DIRS
572
573 SubDirs += $(PARALLEL_DIRS)
574
575 # Unfortunately, this list must be maintained if new recursive targets are added
576 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
577 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
578 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
579 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
580 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
581 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
582
583 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
584
585 $(ParallelTargets) :
586         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
587           $(MKDIR) $(@D); \
588           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
589         fi; \
590         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
591 endif
592
593 #---------------------------------------------------------
594 # Handle the OPTIONAL_DIRS options for directores that may
595 # or may not exist.
596 #---------------------------------------------------------
597 ifdef OPTIONAL_DIRS
598
599 SubDirs += $(OPTIONAL_DIRS)
600
601 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
602 $(RecursiveTargets)::
603         $(Verb) for dir in $(OPTIONAL_DIRS); do \
604           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
605             if [ ! -f $$dir/Makefile ]; then \
606               $(MKDIR) $$dir; \
607               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
608             fi; \
609             ($(MAKE) -C$$dir $@ ) || exit 1; \
610           fi \
611         done
612 else
613 $(RecursiveTargets)::
614         $(Verb) for dir in $(OPTIONAL_DIRS); do \
615           ($(MAKE) -C$$dir $@ ) || exit 1; \
616         done
617 endif
618 endif
619
620 #---------------------------------------------------------
621 # Handle the CONFIG_FILES options
622 #---------------------------------------------------------
623 ifdef CONFIG_FILES
624
625 ifdef NO_INSTALL
626 install-local::
627         $(Echo) Install circumvented with NO_INSTALL
628 uninstall-local::
629         $(Echo) UnInstall circumvented with NO_INSTALL
630 else
631 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
632         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
633         $(Verb)for file in $(CONFIG_FILES); do \
634           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
635             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
636           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
637             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
638           else \
639             $(ECHO) Error: cannot find config file $${file}. ; \
640           fi \
641         done
642
643 uninstall-local::
644         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
645         $(Verb)for file in $(CONFIG_FILES); do \
646           $(RM) -f $(PROJ_etcdir)/$${file} ; \
647         done
648 endif
649
650 endif
651
652 ###############################################################################
653 # Set up variables for building libararies
654 ###############################################################################
655
656 #---------------------------------------------------------
657 # Define various command line options pertaining to the
658 # libraries needed when linking. There are "Proj" libs 
659 # (defined by the user's project) and "LLVM" libs (defined 
660 # by the LLVM project).
661 #---------------------------------------------------------
662
663 ifdef USEDLIBS
664 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
665 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
666 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
667 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
668 endif
669
670 ifdef LLVMLIBS
671 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
672 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
673 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
674 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
675 endif
676
677 ifeq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
678 ifdef LINK_COMPONENTS
679
680 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
681 # clean in tools, then do a make in tools (instead of at the top level).
682 $(LLVM_CONFIG):
683         @echo "*** llvm-config doesn't exist - rebuilding it."
684         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
685         
686 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
687
688 ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
689 ProjLibsPaths   += $(LLVM_CONFIG) \
690                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
691 endif
692 endif
693
694 ###############################################################################
695 # Library Build Rules: Four ways to build a library
696 ###############################################################################
697
698 #---------------------------------------------------------
699 # Bytecode Module Targets:
700 #   If the user set MODULE_NAME then they want to build a
701 #   bytecode module from the sources. We compile all the
702 #   sources and link it together into a single bytecode
703 #   module.
704 #---------------------------------------------------------
705
706 ifdef MODULE_NAME
707 ifeq ($(strip $(LLVMGCC)),)
708 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
709 else
710
711 Module     := $(LibDir)/$(MODULE_NAME).bc
712 LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir)
713
714
715 ifdef EXPORTED_SYMBOL_FILE
716 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
717 endif
718
719 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
720         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
721         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
722
723 all-local:: $(Module)
724
725 clean-local::
726 ifneq ($(strip $(Module)),)
727         -$(Verb) $(RM) -f $(Module)
728 endif
729
730 ifdef BYTECODE_DESTINATION
731 ModuleDestDir := $(BYTECODE_DESTINATION)
732 else
733 ModuleDestDir := $(PROJ_libdir)
734 endif
735
736 ifdef NO_INSTALL
737 install-local::
738         $(Echo) Install circumvented with NO_INSTALL
739 uninstall-local::
740         $(Echo) Uninstall circumvented with NO_INSTALL
741 else
742 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
743
744 install-module:: $(DestModule)
745 install-local:: $(DestModule)
746
747 $(DestModule): $(ModuleDestDir) $(Module) 
748         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
749         $(Verb) $(DataInstall) $(Module) $(DestModule)
750
751 uninstall-local::
752         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
753         -$(Verb) $(RM) -f $(DestModule)
754 endif
755
756 endif
757 endif
758
759 # if we're building a library ...
760 ifdef LIBRARYNAME
761
762 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
763 LIBRARYNAME := $(strip $(LIBRARYNAME))
764 ifdef LOADABLE_MODULE
765 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
766 else
767 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
768 endif
769 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
770 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
771 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
772
773 #---------------------------------------------------------
774 # Shared Library Targets:
775 #   If the user asked for a shared library to be built
776 #   with the SHARED_LIBRARY variable, then we provide
777 #   targets for building them.
778 #---------------------------------------------------------
779 ifdef SHARED_LIBRARY
780
781 all-local:: $(LibName.LA)
782
783 ifdef LINK_LIBS_IN_SHARED
784 ifdef LOADABLE_MODULE
785 SharedLibKindMessage := "Loadable Module"
786 else
787 SharedLibKindMessage := "Shared Library"
788 endif
789 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
790         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
791           $(LIBRARYNAME)$(SHLIBEXT)
792         $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
793           $(LLVMLibsOptions)
794         $(Verb) $(LTInstall) $@ $(LibDir)
795 else
796 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
797         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
798         $(Verb) $(LTLink) -o $@ $(ObjectsLO)
799         $(Verb) $(LTInstall) $@ $(LibDir)
800 endif
801
802 clean-local::
803 ifneq ($(strip $(LibName.LA)),)
804         -$(Verb) $(RM) -f $(LibName.LA)
805 endif
806
807 ifdef NO_INSTALL
808 install-local::
809         $(Echo) Install circumvented with NO_INSTALL
810 uninstall-local::
811         $(Echo) Uninstall circumvented with NO_INSTALL
812 else
813 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
814
815 install-local:: $(DestSharedLib)
816
817 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
818         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
819         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
820         $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
821
822 uninstall-local:: 
823         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
824         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
825 endif
826 endif
827
828 #---------------------------------------------------------
829 # Bytecode Library Targets:
830 #   If the user asked for a bytecode library to be built
831 #   with the BYTECODE_LIBRARY variable, then we provide 
832 #   targets for building them.
833 #---------------------------------------------------------
834 ifdef BYTECODE_LIBRARY
835 ifeq ($(strip $(LLVMGCC)),)
836 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
837 else
838
839 all-local:: $(LibName.BCA)
840
841 ifdef EXPORTED_SYMBOL_FILE
842 BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
843                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
844
845 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
846                 $(LLVMToolDir)/llvm-ar
847         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
848           "(internalize)"
849         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
850         $(Verb) $(RM) -f $@
851         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
852 else
853 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
854                 $(LLVMToolDir)/llvm-ar
855         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
856         $(Verb) $(RM) -f $@
857         $(Verb) $(LArchive) $@ $(ObjectsBC)
858
859 endif
860
861 clean-local::
862 ifneq ($(strip $(LibName.BCA)),)
863         -$(Verb) $(RM) -f $(LibName.BCA)
864 endif
865
866 ifdef BYTECODE_DESTINATION
867 BytecodeDestDir := $(BYTECODE_DESTINATION)
868 else
869 BytecodeDestDir := $(PROJ_libdir)
870 endif
871
872 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
873
874 install-bytecode-local:: $(DestBytecodeLib)
875
876 ifdef NO_INSTALL
877 install-local::
878         $(Echo) Install circumvented with NO_INSTALL
879 uninstall-local::
880         $(Echo) Uninstall circumvented with NO_INSTALL
881 else
882 install-local:: $(DestBytecodeLib)
883
884 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
885         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
886         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
887
888 uninstall-local::
889         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
890         -$(Verb) $(RM) -f $(DestBytecodeLib)
891 endif
892 endif
893 endif
894
895 #---------------------------------------------------------
896 # ReLinked Library Targets:
897 #   If the user explicitly requests a relinked library with
898 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
899 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
900 #   them one.
901 #---------------------------------------------------------
902 ifndef BUILD_ARCHIVE
903 ifndef DONT_BUILD_RELINKED
904 BUILD_RELINKED = 1
905 endif
906 endif
907
908 ifdef BUILD_RELINKED
909
910 all-local:: $(LibName.O)
911
912 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
913         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
914         $(Verb) $(LTRelink) -o $@ $(ObjectsO)
915
916 clean-local::
917 ifneq ($(strip $(LibName.O)),)
918         -$(Verb) $(RM) -f $(LibName.O)
919 endif
920
921 ifdef NO_INSTALL
922 install-local::
923         $(Echo) Install circumvented with NO_INSTALL
924 uninstall-local::
925         $(Echo) Uninstall circumvented with NO_INSTALL
926 else
927 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
928
929 install-local:: $(DestRelinkedLib)
930
931 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
932         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
933         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
934
935 uninstall-local::
936         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
937         -$(Verb) $(RM) -f $(DestRelinkedLib)
938 endif
939 endif
940
941 #---------------------------------------------------------
942 # Archive Library Targets:
943 #   If the user wanted a regular archive library built, 
944 #   then we provide targets for building them.
945 #---------------------------------------------------------
946 ifdef BUILD_ARCHIVE
947
948 all-local:: $(LibName.A)
949
950 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
951         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
952         -$(Verb) $(RM) -f $@
953         $(Verb) $(Archive) $@ $(ObjectsO)
954         $(Verb) $(Ranlib) $@
955
956 clean-local::
957 ifneq ($(strip $(LibName.A)),)
958         -$(Verb) $(RM) -f $(LibName.A)
959 endif
960
961 ifdef NO_INSTALL
962 install-local::
963         $(Echo) Install circumvented with NO_INSTALL
964 uninstall-local::
965         $(Echo) Uninstall circumvented with NO_INSTALL
966 else
967 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
968
969 install-local:: $(DestArchiveLib)
970
971 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
972         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
973         $(Verb) $(MKDIR) $(PROJ_libdir)
974         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
975
976 uninstall-local::
977         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
978         -$(Verb) $(RM) -f $(DestArchiveLib)
979 endif
980 endif
981
982 # endif LIBRARYNAME
983 endif 
984
985 ###############################################################################
986 # Tool Build Rules: Build executable tool based on TOOLNAME option
987 ###############################################################################
988
989 ifdef TOOLNAME
990
991 #---------------------------------------------------------
992 # Set up variables for building a tool.
993 #---------------------------------------------------------
994 ifdef EXAMPLE_TOOL
995 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
996 else
997 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
998 endif
999
1000 #---------------------------------------------------------
1001 # Provide targets for building the tools
1002 #---------------------------------------------------------
1003 all-local:: $(ToolBuildPath)
1004
1005 clean-local::
1006 ifneq ($(strip $(ToolBuildPath)),)
1007         -$(Verb) $(RM) -f $(ToolBuildPath)
1008 endif
1009
1010 ifdef EXAMPLE_TOOL
1011 $(ToolBuildPath): $(ExmplDir)/.dir
1012 else
1013 $(ToolBuildPath): $(ToolDir)/.dir
1014 endif
1015
1016 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1017         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1018         $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1019         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1020         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1021           $(StripWarnMsg) 
1022
1023 ifdef NO_INSTALL
1024 install-local::
1025         $(Echo) Install circumvented with NO_INSTALL
1026 uninstall-local::
1027         $(Echo) Uninstall circumvented with NO_INSTALL
1028 else
1029 DestTool = $(PROJ_bindir)/$(TOOLNAME)
1030
1031 install-local:: $(DestTool)
1032
1033 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
1034         $(Echo) Installing $(BuildMode) $(DestTool)
1035         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1036
1037 uninstall-local::
1038         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1039         -$(Verb) $(RM) -f $(DestTool)
1040 endif
1041 endif
1042
1043 ###############################################################################
1044 # Object Build Rules: Build object files based on sources 
1045 ###############################################################################
1046
1047 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1048 ifeq ($(OS),HP-UX)
1049   DISABLE_AUTO_DEPENDENCIES=1
1050 endif
1051
1052 ifdef SHARED_LIBRARY
1053 PIC_FLAG = "(PIC)"
1054 MAYBE_PIC_Compile.CXX = $(LTCompile.CXX)
1055 MAYBE_PIC_Compile.C = $(LTCompile.C)
1056 else
1057 MAYBE_PIC_Compile.CXX = $(Compile.CXX)
1058 MAYBE_PIC_Compile.C = $(Compile.C)
1059 endif
1060
1061 # Provide rule sets for when dependency generation is enabled
1062 ifndef DISABLE_AUTO_DEPENDENCIES
1063
1064 #---------------------------------------------------------
1065 # Create .lo files in the ObjDir directory from the .cpp and .c files...
1066 #---------------------------------------------------------
1067
1068 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1069         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1070         $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
1071           then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
1072           else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
1073
1074 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1075         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1076         $(Verb) if $(MAYBE_PIC_Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
1077         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
1078         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
1079
1080 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1081         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1082         $(Verb) if $(MAYBE_PIC_Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
1083         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
1084         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
1085
1086 #---------------------------------------------------------
1087 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1088 #---------------------------------------------------------
1089
1090 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1091         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1092         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1093                               $< -o $@ -S -emit-llvm ; \
1094         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1095         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1096         $(call UPGRADE_MSG,$@) 
1097         $(call UPGRADE_LL,$@)
1098
1099 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1100         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1101         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1102                               $< -o $@ -S -emit-llvm ; \
1103         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1104         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1105         $(call UPGRADE_MSG,$@) 
1106         $(call UPGRADE_LL,$@)
1107
1108 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1109         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1110         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1111                             $< -o $@ -S -emit-llvm ; \
1112         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1113         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1114         $(call UPGRADE_MSG,$@) 
1115         $(call UPGRADE_LL,$@)
1116
1117 # Provide alternate rule sets if dependencies are disabled
1118 else
1119
1120 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1121         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1122         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1123
1124 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1125         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1126         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1127
1128 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1129         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1130         $(MAYBE_PIC_Compile.C) $< -o $@ 
1131
1132 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1133         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1134         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1135         $(call UPGRADE_MSG,$@) 
1136         $(call UPGRADE_LL,$@)
1137
1138 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1139         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1140         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1141         $(call UPGRADE_MSG,$@) 
1142         $(call UPGRADE_LL,$@)
1143
1144 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1145         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1146         $(BCCompile.C) $< -o $@ -S -emit-llvm
1147         $(call UPGRADE_MSG,@) 
1148         $(call UPGRADE_LL,@)
1149
1150 endif
1151
1152
1153 ## Rules for building preprocessed (.i/.ii) outputs.
1154 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1155         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1156         $(Verb) $(Preprocess.CXX) $< -o $@
1157
1158 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1159         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1160         $(Verb) $(Preprocess.CXX) $< -o $@
1161
1162 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1163         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1164         $(Verb) $(Preprocess.C) $< -o $@
1165
1166
1167 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1168         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1169         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1170
1171 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1172         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1173         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1174
1175 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1176         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1177         $(MAYBE_PIC_Compile.C) $< -o $@ -S
1178
1179
1180 # make the C and C++ compilers strip debug info out of bytecode libraries.
1181 ifdef DEBUG_RUNTIME
1182 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1183         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1184         $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts $< -o $@
1185 else
1186 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1187         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1188         $(Verb) $(LLVMAS) $< -o - | \
1189           $(LOPT) -std-compile-opts -strip-debug $< -o $@
1190 endif
1191
1192
1193 #---------------------------------------------------------
1194 # Provide rule to build .bc files from .ll sources,
1195 # regardless of dependencies
1196 #---------------------------------------------------------
1197 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1198         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1199         $(Verb) $(LLVMAS) $< -f -o $@
1200
1201 ###############################################################################
1202 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1203 ###############################################################################
1204
1205 ifdef TARGET
1206
1207 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1208            $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1209            $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td \
1210            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1211            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1212 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1213 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1214 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1215
1216 # All of these files depend on tblgen and the .td files.
1217 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1218
1219 # INCFiles rule: All of the tblgen generated files are emitted to 
1220 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1221 # us to only "touch" the real file if the contents of it change.  IOW, if
1222 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1223 # dependencies of the .inc files are, unless the contents of the .inc file
1224 # changes.
1225 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1226         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1227
1228 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1229 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1230         $(Echo) "Building $(<F) register names with tblgen"
1231         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1232
1233 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1234 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1235         $(Echo) "Building $(<F) register information header with tblgen"
1236         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1237
1238 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1239 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1240         $(Echo) "Building $(<F) register info implementation with tblgen"
1241         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1242
1243 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1244 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1245         $(Echo) "Building $(<F) instruction names with tblgen"
1246         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1247
1248 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1249 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1250         $(Echo) "Building $(<F) instruction information with tblgen"
1251         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1252
1253 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1254 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1255         $(Echo) "Building $(<F) assembly writer with tblgen"
1256         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1257
1258 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1259 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1260         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1261         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
1262
1263 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1264 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1265         $(Echo) "Building $(<F) code emitter with tblgen"
1266         $(Verb) $(TableGen) -gen-emitter -o $@ $<
1267
1268 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1269 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1270         $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1271         $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1272
1273 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1274 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1275         $(Echo) "Building $(<F) subtarget information with tblgen"
1276         $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1277
1278 clean-local::
1279         -$(Verb) $(RM) -f $(INCFiles)
1280
1281 endif
1282
1283 ###############################################################################
1284 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1285 ###############################################################################
1286
1287 #---------------------------------------------------------
1288 # Provide rules for generating a .cpp source file from 
1289 # (f)lex input sources. 
1290 #---------------------------------------------------------
1291
1292 LexFiles  := $(filter %.l,$(Sources))
1293
1294 ifneq ($(LexFiles),)
1295
1296 # Cancel built-in rules for lex
1297 %.c: %.l
1298 %.cpp: %.l
1299
1300 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1301
1302 # Note the extra sed filtering here, used to cut down on the warnings emited 
1303 # by GCC.  The last line is a gross hack to work around flex aparently not 
1304 # being able to resize the buffer on a large token input.  Currently, for 
1305 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1306 # this is a hack around it.
1307 # FIXME.  (f.e. char Buffer[10000] )
1308 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1309         $(Echo) Flexing $*.l
1310         $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1311         $(SED) 's/void yyunput/inline void yyunput/' | \
1312         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1313         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1314           > $(PROJ_SRC_DIR)/$*.cpp
1315     
1316 # IFF the .l file has changed since it was last checked into CVS, copy the .l
1317 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
1318 # so that people without flex can build LLVM by copying the .cvs files to the 
1319 # source location and building them.
1320 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1321 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1322         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs || \
1323       ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1324
1325 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1326 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1327
1328 clean-local::
1329         -$(Verb) $(RM) -f $(LexOutput)
1330
1331 endif
1332
1333 #---------------------------------------------------------
1334 # Provide rules for generating a .cpp and .h source files 
1335 # from yacc (bison) input sources.
1336 #---------------------------------------------------------
1337
1338 YaccFiles  := $(filter %.y,$(Sources))
1339 ifneq ($(YaccFiles),)
1340
1341 .PRECIOUS: $(YaccOutput)
1342
1343 all:: $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs)
1344
1345 # Cancel built-in rules for yacc
1346 %.c: %.y 
1347 %.cpp: %.y
1348 %.h: %.y
1349
1350 # Rule for building the bison based parsers...
1351 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1352 ifneq ($(BISON),)
1353         $(Echo) "Bisoning $*.y"
1354         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1355         $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1356         $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1357 else
1358         $(Echo) "Bison of $*.y SKIPPED -- bison not found"
1359 endif
1360
1361 # IFF the .y file has changed since it was last checked into CVS, copy the .y
1362 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
1363 # mechanism so that people without flex can build LLVM by copying the .cvs files
1364 # to the source location and building them.
1365 $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1366 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1367         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs || \
1368       ($(CP) $< $@; \
1369        $(CP) $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs; \
1370        $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)
1371
1372
1373 $(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1374
1375 YaccOutput := $(YaccFiles:%.y=%.output)
1376
1377 clean-local::
1378         -$(Verb) $(RM) -f $(YaccOutput)
1379 endif
1380
1381 ###############################################################################
1382 # OTHER RULES: Other rules needed
1383 ###############################################################################
1384
1385 # To create postscript files from dot files...
1386 ifneq ($(DOT),false)
1387 %.ps: %.dot
1388         $(DOT) -Tps < $< > $@
1389 else
1390 %.ps: %.dot
1391         $(Echo) "Cannot build $@: The program dot is not installed"
1392 endif
1393
1394 # This rules ensures that header files that are removed still have a rule for
1395 # which they can be "generated."  This allows make to ignore them and
1396 # reproduce the dependency lists.
1397 %.h:: ;
1398 %.hpp:: ;
1399
1400 # Define clean-local to clean the current directory. Note that this uses a
1401 # very conservative approach ensuring that empty variables do not cause 
1402 # errors or disastrous removal.
1403 clean-local::
1404 ifneq ($(strip $(ObjDir)),)
1405         -$(Verb) $(RM) -rf $(ObjDir)
1406 endif
1407         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1408 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1409         -$(Verb) $(RM) -f *$(SHLIBEXT)
1410 endif
1411
1412 clean-all-local::
1413         -$(Verb) $(RM) -rf Debug Release Profile
1414
1415 # Build tags database for Emacs/Xemacs:
1416 tags:: TAGS CTAGS
1417
1418 TAGS: 
1419         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1420           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1421           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1422           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1423         -name '*.cpp' -o -name '*.h' | \
1424         $(ETAGS) $(ETAGSFLAGS) -
1425
1426 CTAGS:
1427         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1428           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1429           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1430           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1431           \( -name '*.cpp' -o -name '*.h' \) -print | \
1432           ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1433
1434
1435 ###############################################################################
1436 # DEPENDENCIES: Include the dependency files if we should
1437 ###############################################################################
1438 ifndef DISABLE_AUTO_DEPENDENCIES
1439
1440 # If its not one of the cleaning targets
1441 ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS)))),)
1442
1443 # Get the list of dependency files
1444 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1445 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1446
1447 -include /dev/null $(DependFiles)
1448
1449 endif
1450
1451 endif 
1452
1453 ###############################################################################
1454 # CHECK: Running the test suite
1455 ###############################################################################
1456
1457 check::
1458         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1459           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1460             $(EchoCmd) Running test suite ; \
1461             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1462               TESTSUITE=$(TESTSUITE) ; \
1463           else \
1464             $(EchoCmd) No Makefile in test directory ; \
1465           fi ; \
1466         else \
1467           $(EchoCmd) No test directory ; \
1468         fi
1469
1470 ###############################################################################
1471 # DISTRIBUTION: Handle construction of a distribution tarball
1472 ###############################################################################
1473
1474 #------------------------------------------------------------------------
1475 # Define distribution related variables
1476 #------------------------------------------------------------------------
1477 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1478 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1479 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1480 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1481 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1482 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1483 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1484                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1485                Makefile.config.in configure autoconf
1486 DistOther   := $(notdir $(wildcard \
1487                $(PROJ_SRC_DIR)/*.h \
1488                $(PROJ_SRC_DIR)/*.td \
1489                $(PROJ_SRC_DIR)/*.def \
1490                $(PROJ_SRC_DIR)/*.ll \
1491                $(PROJ_SRC_DIR)/*.in))
1492 DistSubDirs := $(SubDirs)
1493 DistSources  = $(Sources) $(EXTRA_DIST)
1494 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1495
1496 #------------------------------------------------------------------------
1497 # We MUST build distribution with OBJ_DIR != SRC_DIR
1498 #------------------------------------------------------------------------
1499 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1500 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1501         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1502
1503 else
1504
1505 #------------------------------------------------------------------------
1506 # Prevent attempt to run dist targets from anywhere but the top level
1507 #------------------------------------------------------------------------
1508 ifneq ($(LEVEL),.)
1509 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1510         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1511 else
1512
1513 #------------------------------------------------------------------------
1514 # Provide the top level targets
1515 #------------------------------------------------------------------------
1516
1517 dist-gzip:: $(DistTarGZip)
1518
1519 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1520         $(Echo) Packing gzipped distribution tar file.
1521         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1522           $(GZIP) -c > "$(DistTarGZip)"
1523
1524 dist-bzip2:: $(DistTarBZ2)
1525
1526 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1527         $(Echo) Packing bzipped distribution tar file.
1528         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1529           $(BZIP2) -c >$(DistTarBZ2)
1530
1531 dist-zip:: $(DistZip)
1532
1533 $(DistZip) : $(TopDistDir)/.makedistdir
1534         $(Echo) Packing zipped distribution file.
1535         $(Verb) rm -f $(DistZip)
1536         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1537
1538 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1539         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1540
1541 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1542
1543 dist-check:: $(DistTarGZip)
1544         $(Echo) Checking distribution tar file.
1545         $(Verb) if test -d $(DistCheckDir) ; then \
1546           $(RM) -rf $(DistCheckDir) ; \
1547         fi
1548         $(Verb) $(MKDIR) $(DistCheckDir)
1549         $(Verb) cd $(DistCheckDir) && \
1550           $(MKDIR) $(DistCheckDir)/build && \
1551           $(MKDIR) $(DistCheckDir)/install && \
1552           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1553           cd build && \
1554           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1555             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1556           $(MAKE) all && \
1557           $(MAKE) check && \
1558           $(MAKE) install && \
1559           $(MAKE) uninstall && \
1560           $(MAKE) dist-clean && \
1561           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1562
1563 dist-clean::
1564         $(Echo) Cleaning distribution files
1565         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1566           $(DistCheckDir)
1567
1568 endif
1569
1570 #------------------------------------------------------------------------
1571 # Provide the recursive distdir target for building the distribution directory
1572 #------------------------------------------------------------------------
1573 distdir: $(DistDir)/.makedistdir
1574 $(DistDir)/.makedistdir: $(DistSources)
1575         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1576           if test -d "$(DistDir)" ; then \
1577             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1578               exit 1 ; \
1579           fi ; \
1580           $(EchoCmd) Removing old $(DistDir) ; \
1581           $(RM) -rf $(DistDir); \
1582           $(EchoCmd) Making 'all' to verify build ; \
1583           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1584         fi
1585         $(Echo) Building Distribution Directory $(DistDir)
1586         $(Verb) $(MKDIR) $(DistDir) 
1587         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1588         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1589         for file in $(DistFiles) ; do \
1590           case "$$file" in \
1591             $(PROJ_SRC_DIR)/*) \
1592               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1593               ;; \
1594             $(PROJ_SRC_ROOT)/*) \
1595               file=`echo "$$file" | \
1596                 sed "s#^$$srcrootstrip/##"` \
1597               ;; \
1598           esac; \
1599           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1600              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1601             from_dir="$(PROJ_SRC_DIR)" ; \
1602           elif test -f "$$file" || test -d "$$file" ; then \
1603             from_dir=. ; \
1604           fi ; \
1605           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1606           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1607             to_dir="$(DistDir)/$$dir"; \
1608             $(MKDIR) "$$to_dir" ; \
1609           else \
1610             to_dir="$(DistDir)"; \
1611           fi; \
1612           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1613           if test -n "$$mid_dir" ; then \
1614             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1615           fi ; \
1616           if test -d "$$from_dir/$$file"; then \
1617             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1618                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1619                cd $(PROJ_SRC_DIR) ; \
1620                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1621                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1622                cd $(PROJ_OBJ_DIR) ; \
1623             else \
1624                cd $$from_dir ; \
1625                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1626                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1627                cd $(PROJ_OBJ_DIR) ; \
1628             fi; \
1629           elif test -f "$$from_dir/$$file" ; then \
1630             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1631           elif test -L "$$from_dir/$$file" ; then \
1632             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1633           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1634             $(EchoCmd) "===== WARNING: Distribution Source " \
1635               "$$from_dir/$$file Not Found!" ; \
1636           elif test "$(Verb)" != '@' ; then \
1637             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1638           fi; \
1639         done
1640         $(Verb) for subdir in $(DistSubDirs) ; do \
1641           if test "$$subdir" \!= "." ; then \
1642             new_distdir="$(DistDir)/$$subdir" ; \
1643             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1644             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1645               DistDir="$$new_distdir" distdir ) || exit 1; \
1646           fi; \
1647         done
1648         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1649           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1650           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1651                                   -name .svn \) -print` ;\
1652           $(MAKE) dist-hook ; \
1653           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1654             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1655             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1656             -o ! -type d ! -perm -444 -exec \
1657               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1658             || chmod -R a+r $(DistDir) ; \
1659         fi
1660
1661 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1662 # defined by user.
1663 dist-hook::
1664
1665 endif
1666
1667 ###############################################################################
1668 # TOP LEVEL - targets only to apply at the top level directory
1669 ###############################################################################
1670
1671 ifeq ($(LEVEL),.)
1672
1673 #------------------------------------------------------------------------
1674 # Install support for the project's include files:
1675 #------------------------------------------------------------------------
1676 ifdef NO_INSTALL
1677 install-local::
1678         $(Echo) Install circumvented with NO_INSTALL
1679 uninstall-local::
1680         $(Echo) Uninstall circumvented with NO_INSTALL
1681 else
1682 install-local::
1683         $(Echo) Installing include files
1684         $(Verb) $(MKDIR) $(PROJ_includedir)
1685         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1686           cd $(PROJ_SRC_ROOT)/include && \
1687           for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1688               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1689             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1690             if test \! -d "$$instdir" ; then \
1691               $(EchoCmd) Making install directory $$instdir ; \
1692               $(MKDIR) $$instdir ;\
1693             fi ; \
1694             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1695           done ; \
1696         fi
1697 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1698         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1699           cd $(PROJ_OBJ_ROOT)/include && \
1700           for hdr in `find . -type f -print | grep -v CVS` ; do \
1701             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1702           done ; \
1703         fi
1704 endif
1705
1706 uninstall-local::
1707         $(Echo) Uninstalling include files
1708         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1709           cd $(PROJ_SRC_ROOT)/include && \
1710             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1711               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1712         -o -name '*.in' ')' -print ')' | \
1713         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1714           cd $(PROJ_SRC_ROOT)/include && \
1715             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1716       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1717         fi
1718 endif
1719 endif
1720
1721 #------------------------------------------------------------------------
1722 # Print out the directories used for building
1723 #------------------------------------------------------------------------
1724 printvars::
1725         $(Echo) "BuildMode    : " '$(BuildMode)'
1726         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1727         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1728         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1729         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1730         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1731         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1732         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1733         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1734         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1735         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1736         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1737         $(Echo) "UserTargets  : " '$(UserTargets)'
1738         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1739         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1740         $(Echo) "ObjDir       : " '$(ObjDir)'
1741         $(Echo) "LibDir       : " '$(LibDir)'
1742         $(Echo) "ToolDir      : " '$(ToolDir)'
1743         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1744         $(Echo) "Sources      : " '$(Sources)'
1745         $(Echo) "TDFiles      : " '$(TDFiles)'
1746         $(Echo) "INCFiles     : " '$(INCFiles)'
1747         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1748         $(Echo) "PreConditions: " '$(PreConditions)'
1749         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1750         $(Echo) "Compile.C    : " '$(Compile.C)'
1751         $(Echo) "Archive      : " '$(Archive)'
1752         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1753         $(Echo) "LexFiles     : " '$(LexFiles)'
1754         $(Echo) "Module       : " '$(Module)'
1755         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1756         $(Echo) "SubDirs      : " '$(SubDirs)'