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