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