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