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