Convert the bison-output-checked-into-cvs makefile handling stuff to work
[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 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
955 ifeq ($(OS),HP-UX)
956   DISABLE_AUTO_DEPENDENCIES=1
957 endif
958
959 # Provide rule sets for when dependency generation is enabled
960 ifndef DISABLE_AUTO_DEPENDENCIES
961
962 #---------------------------------------------------------
963 # Create .lo files in the ObjDir directory from the .cpp and .c files...
964 #---------------------------------------------------------
965 ifdef SHARED_LIBRARY
966
967 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
968         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
969         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
970         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
971         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
972
973 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
974         $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
975         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ;\
976         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
977         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
978
979 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
980         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
981         $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
982         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
983         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
984
985 #---------------------------------------------------------
986 # Create .o files in the ObjDir directory from the .cpp and .c files...
987 #---------------------------------------------------------
988 else
989
990 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
991         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
992         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
993         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
994         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
995
996 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
997         $(Echo) "Compiling $*.cc for $(BuildMode) build"
998         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
999         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
1000         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
1001
1002 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1003         $(Echo) "Compiling $*.c for $(BuildMode) build"
1004         $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
1005         then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
1006         else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
1007
1008 endif
1009
1010 ## Rules for building preprocessed (.i/.ii) outputs.
1011 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1012         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1013         $(Verb) $(Preprocess.CXX) $< -o $@
1014
1015 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1016         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1017         $(Verb) $(Preprocess.CXX) $< -o $@
1018
1019  $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1020         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1021         $(Verb) $(Preprocess.C) $< -o $@
1022
1023
1024 #---------------------------------------------------------
1025 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1026 #---------------------------------------------------------
1027
1028 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1029         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1030         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1031                               $< -o $@ -S -emit-llvm ; \
1032         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1033         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1034
1035 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1036         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1037         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1038                               $< -o $@ -S -emit-llvm ; \
1039         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1040         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1041
1042 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1043         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1044         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1045                             $< -o $@ -S -emit-llvm ; \
1046         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1047         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1048
1049 # Provide alternate rule sets if dependencies are disabled
1050 else
1051
1052 ifdef SHARED_LIBRARY
1053
1054 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1055         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
1056         $(LTCompile.CXX) $< -o $@ 
1057
1058 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1059         $(Echo) "Compiling $*.cc for $(BuildMode) build (PIC)"
1060         $(LTCompile.CXX) $< -o $@ 
1061
1062 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1063         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
1064         $(LTCompile.C) $< -o $@ 
1065
1066 else
1067
1068 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1069         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
1070         $(Compile.CXX) $< -o $@ 
1071
1072 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1073         $(Echo) "Compiling $*.cc for $(BuildMode) build"
1074         $(Compile.CXX) $< -o $@ 
1075
1076 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1077         $(Echo) "Compiling $*.c for $(BuildMode) build"
1078         $(Compile.C) $< -o $@ 
1079 endif
1080
1081 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1082         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1083         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1084
1085 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1086         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1087         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1088
1089 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1090         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1091         $(BCCompile.C) $< -o $@ -S -emit-llvm
1092
1093 endif
1094
1095 # make the C and C++ compilers strip debug info out of bytecode libraries.
1096 ifdef DEBUG_RUNTIME
1097 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1098         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1099         @$(GCCAS) $< -o $@
1100 else
1101 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(GCCAS)
1102         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1103         @$(GCCAS) -strip-debug $< -o $@
1104 endif
1105
1106
1107 #---------------------------------------------------------
1108 # Provide rule to build .bc files from .ll sources,
1109 # regardless of dependencies
1110 #---------------------------------------------------------
1111 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1112         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1113         $(Verb) $(LLVMAS) $< -f -o $@
1114
1115 ###############################################################################
1116 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1117 ###############################################################################
1118
1119 ifdef TARGET
1120
1121 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1122            $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1123            $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td)
1124 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1125 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1126 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1127
1128 # All of these files depend on tblgen and the .td files.
1129 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1130
1131 # INCFiles rule: All of the tblgen generated files are emitted to 
1132 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1133 # us to only "touch" the real file if the contents of it change.  IOW, if
1134 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1135 # dependencies of the .inc files are, unless the contents of the .inc file
1136 # changes.
1137 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1138         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1139
1140 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1141 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1142         $(Echo) "Building $(<F) register names with tblgen"
1143         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
1144
1145 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1146 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1147         $(Echo) "Building $(<F) register information header with tblgen"
1148         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1149
1150 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1151 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1152         $(Echo) "Building $(<F) register info implementation with tblgen"
1153         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1154
1155 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1156 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1157         $(Echo) "Building $(<F) instruction names with tblgen"
1158         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1159
1160 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1161 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1162         $(Echo) "Building $(<F) instruction information with tblgen"
1163         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1164
1165 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1166 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1167         $(Echo) "Building $(<F) assembly writer with tblgen"
1168         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1169
1170 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1171 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1172         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1173         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
1174
1175 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1176 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1177         $(Echo) "Building $(<F) code emitter with tblgen"
1178         $(Verb) $(TableGen) -gen-emitter -o $@ $<
1179
1180 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1181 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1182         $(Echo) "Building $(<F) instruction selector implementation with tblgen"
1183         $(Verb) $(TableGen) -gen-dag-isel -o $@ $<
1184
1185 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1186 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1187         $(Echo) "Building $(<F) subtarget information with tblgen"
1188         $(Verb) $(TableGen) -gen-subtarget -o $@ $<
1189
1190 clean-local::
1191         -$(Verb) $(RM) -f $(INCFiles)
1192
1193 endif
1194
1195 ###############################################################################
1196 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1197 ###############################################################################
1198
1199 #---------------------------------------------------------
1200 # Provide rules for generating a .cpp source file from 
1201 # (f)lex input sources. 
1202 #---------------------------------------------------------
1203
1204 LexFiles  := $(filter %.l,$(Sources))
1205
1206 ifneq ($(LexFiles),)
1207
1208 # Cancel built-in rules for lex
1209 %.c: %.l
1210 %.cpp: %.l
1211
1212 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1213
1214 # Note the extra sed filtering here, used to cut down on the warnings emited 
1215 # by GCC.  The last line is a gross hack to work around flex aparently not 
1216 # being able to resize the buffer on a large token input.  Currently, for 
1217 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1218 # this is a hack around it.
1219 # FIXME.  (f.e. char Buffer[10000] )
1220 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1221         $(Echo) Flexing $*.l
1222         $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1223         $(SED) 's/void yyunput/inline void yyunput/' | \
1224         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1225         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1226           > $(PROJ_SRC_DIR)/$*.cpp
1227     
1228 # IFF the .l file has changed since it was last checked into CVS, copy the .l
1229 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
1230 # so that people without flex can build LLVM by copying the .cvs files to the 
1231 # source location and building them.
1232 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1233 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1234         $(Verb) $(CMP) -s $@ $< || \
1235       ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1236
1237 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1238 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1239
1240 clean-local::
1241         -$(Verb) $(RM) -f $(LexOutput)
1242
1243 endif
1244
1245 #---------------------------------------------------------
1246 # Provide rules for generating a .cpp and .h source files 
1247 # from yacc (bison) input sources.
1248 #---------------------------------------------------------
1249
1250 YaccFiles  := $(filter %.y,$(Sources))
1251 ifneq ($(YaccFiles),)
1252
1253 .PRECIOUS: $(YaccOutput)
1254
1255 all:: $(YaccFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1256
1257 # Cancel built-in rules for yacc
1258 %.c: %.y 
1259 %.cpp: %.y
1260 %.h: %.y
1261
1262 # Rule for building the bison based parsers...
1263 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1264         $(Echo) "Bisoning $*.y"
1265         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1266         $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1267         $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1268         $(Echo) "*** DON'T FORGET TO CHECK IN $*.cpp and $*.h (generated files)"
1269
1270 # IFF the .y file has changed since it was last checked into CVS, copy the .y
1271 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
1272 # mechanism so that people without flex can build LLVM by copying the .cvs files
1273 # to the source location and building them.
1274 $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1275 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1276         $(Verb) $(CMP) -s $@ $< || \
1277       ($(CP) $< $@; \
1278        $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs; \
1279        $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)
1280
1281
1282 $(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1283
1284 YaccOutput := $(YaccFiles:%.y=%.output)
1285
1286 clean-local::
1287         -$(Verb) $(RM) -f $(YaccOutput)
1288 endif
1289
1290 ###############################################################################
1291 # OTHER RULES: Other rules needed
1292 ###############################################################################
1293
1294 # To create postscript files from dot files...
1295 ifneq ($(DOT),false)
1296 %.ps: %.dot
1297         $(DOT) -Tps < $< > $@
1298 else
1299 %.ps: %.dot
1300         $(Echo) "Cannot build $@: The program dot is not installed"
1301 endif
1302
1303 # This rules ensures that header files that are removed still have a rule for
1304 # which they can be "generated."  This allows make to ignore them and
1305 # reproduce the dependency lists.
1306 %.h:: ;
1307 %.hpp:: ;
1308
1309 # Define clean-local to clean the current directory. Note that this uses a
1310 # very conservative approach ensuring that empty variables do not cause 
1311 # errors or disastrous removal.
1312 clean-local::
1313 ifneq ($(strip $(ObjDir)),)
1314         -$(Verb) $(RM) -rf $(ObjDir)
1315 endif
1316         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1317 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1318         -$(Verb) $(RM) -f *$(SHLIBEXT)
1319 endif
1320
1321 clean-all-local::
1322         -$(Verb) $(RM) -rf Debug Release Profile
1323
1324 # Build tags database for Emacs/Xemacs:
1325 tags:: TAGS CTAGS
1326
1327 TAGS: 
1328         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1329           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1330           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1331           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1332         -name '*.cpp' -o -name '*.h' | \
1333         $(ETAGS) $(ETAGSFLAGS) -
1334
1335 CTAGS:
1336         find $(PROJ_SRC_ROOT)/include $(PROJ_SRC_ROOT)/lib \
1337           $(PROJ_SRC_ROOT)/tools $(PROJ_SRC_ROOT)/examples \
1338           $(PROJ_OBJ_ROOT)/include $(PROJ_OBJ_ROOT)/lib \
1339           $(PROJ_OBJ_ROOT)/tools $(PROJ_OBJ_ROOT)/examples \
1340           \( -name '*.cpp' -o -name '*.h' \) -print | \
1341           ctags -ImtT -o $(PROJ_OBJ_ROOT)/CTAGS -L -
1342
1343
1344 ###############################################################################
1345 # DEPENDENCIES: Include the dependency files if we should
1346 ###############################################################################
1347 ifndef DISABLE_AUTO_DEPENDENCIES
1348
1349 # If its not one of the cleaning targets
1350 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1351
1352 # Get the list of dependency files
1353 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1354 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1355
1356 -include /dev/null $(DependFiles)
1357
1358 endif
1359
1360 endif 
1361
1362 ###############################################################################
1363 # CHECK: Running the test suite
1364 ###############################################################################
1365
1366 check::
1367         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1368           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1369             $(EchoCmd) Running test suite ; \
1370             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1371               TESTSUITE=$(TESTSUITE) ; \
1372           else \
1373             $(EchoCmd) No Makefile in test directory ; \
1374           fi ; \
1375         else \
1376           $(EchoCmd) No test directory ; \
1377         fi
1378
1379 ###############################################################################
1380 # DISTRIBUTION: Handle construction of a distribution tarball
1381 ###############################################################################
1382
1383 #------------------------------------------------------------------------
1384 # Define distribution related variables
1385 #------------------------------------------------------------------------
1386 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1387 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1388 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1389 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1390 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1391 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1392 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1393                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1394                Makefile.config.in configure autoconf
1395 DistOther   := $(notdir $(wildcard \
1396                $(PROJ_SRC_DIR)/*.h \
1397                $(PROJ_SRC_DIR)/*.td \
1398                $(PROJ_SRC_DIR)/*.def \
1399                $(PROJ_SRC_DIR)/*.ll \
1400                $(PROJ_SRC_DIR)/*.in))
1401 DistSubDirs := $(SubDirs)
1402 DistSources  = $(Sources) $(EXTRA_DIST)
1403 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1404
1405 #------------------------------------------------------------------------
1406 # We MUST build distribution with OBJ_DIR != SRC_DIR
1407 #------------------------------------------------------------------------
1408 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1409 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1410         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1411
1412 else
1413
1414 #------------------------------------------------------------------------
1415 # Prevent attempt to run dist targets from anywhere but the top level
1416 #------------------------------------------------------------------------
1417 ifneq ($(LEVEL),.)
1418 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1419         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1420 else
1421
1422 #------------------------------------------------------------------------
1423 # Provide the top level targets
1424 #------------------------------------------------------------------------
1425
1426 dist-gzip:: $(DistTarGZip)
1427
1428 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1429         $(Echo) Packing gzipped distribution tar file.
1430         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1431           $(GZIP) -c > "$(DistTarGZip)"
1432
1433 dist-bzip2:: $(DistTarBZ2)
1434
1435 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1436         $(Echo) Packing bzipped distribution tar file.
1437         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1438           $(BZIP2) -c >$(DistTarBZ2)
1439
1440 dist-zip:: $(DistZip)
1441
1442 $(DistZip) : $(TopDistDir)/.makedistdir
1443         $(Echo) Packing zipped distribution file.
1444         $(Verb) rm -f $(DistZip)
1445         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1446
1447 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1448         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1449
1450 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1451
1452 dist-check:: $(DistTarGZip)
1453         $(Echo) Checking distribution tar file.
1454         $(Verb) if test -d $(DistCheckDir) ; then \
1455           $(RM) -rf $(DistCheckDir) ; \
1456         fi
1457         $(Verb) $(MKDIR) $(DistCheckDir)
1458         $(Verb) cd $(DistCheckDir) && \
1459           $(MKDIR) $(DistCheckDir)/build && \
1460           $(MKDIR) $(DistCheckDir)/install && \
1461           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1462           cd build && \
1463           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1464             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1465           $(MAKE) all && \
1466           $(MAKE) check && \
1467           $(MAKE) install && \
1468           $(MAKE) uninstall && \
1469           $(MAKE) dist && \
1470           $(MAKE) clean && \
1471           $(MAKE) dist-clean && \
1472           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1473
1474 dist-clean::
1475         $(Echo) Cleaning distribution files
1476         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1477           $(DistCheckDir)
1478
1479 endif
1480
1481 #------------------------------------------------------------------------
1482 # Provide the recursive distdir target for building the distribution directory
1483 #------------------------------------------------------------------------
1484 distdir: $(DistDir)/.makedistdir
1485 $(DistDir)/.makedistdir: $(DistSources)
1486         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1487           if test -d "$(DistDir)" ; then \
1488             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1489               exit 1 ; \
1490           fi ; \
1491           $(EchoCmd) Removing old $(DistDir) ; \
1492           $(RM) -rf $(DistDir); \
1493           $(EchoCmd) Making 'all' to verify build ; \
1494           $(MAKE) all ; \
1495         fi
1496         $(Echo) Building Distribution Directory $(DistDir)
1497         $(Verb) $(MKDIR) $(DistDir) 
1498         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1499         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1500         for file in $(DistFiles) ; do \
1501           case "$$file" in \
1502             $(PROJ_SRC_DIR)/*) \
1503               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1504               ;; \
1505             $(PROJ_SRC_ROOT)/*) \
1506               file=`echo "$$file" | \
1507                 sed "s#^$$srcrootstrip/##"` \
1508               ;; \
1509           esac; \
1510           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1511              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1512             from_dir="$(PROJ_SRC_DIR)" ; \
1513           elif test -f "$$file" || test -d "$$file" ; then \
1514             from_dir=. ; \
1515           fi ; \
1516           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1517           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1518             to_dir="$(DistDir)/$$dir"; \
1519             $(MKDIR) "$$to_dir" ; \
1520           else \
1521             to_dir="$(DistDir)"; \
1522           fi; \
1523           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1524           if test -n "$$mid_dir" ; then \
1525             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1526           fi ; \
1527           if test -d "$$from_dir/$$file"; then \
1528             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1529                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1530                cd $(PROJ_SRC_DIR) ; \
1531                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1532                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1533                cd $(PROJ_OBJ_DIR) ; \
1534             else \
1535                cd $$from_dir ; \
1536                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1537                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1538                cd $(PROJ_OBJ_DIR) ; \
1539             fi; \
1540           elif test -f "$$from_dir/$$file" ; then \
1541             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1542           elif test -L "$$from_dir/$$file" ; then \
1543             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1544           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1545             $(EchoCmd) "===== WARNING: Distribution Source " \
1546               "$$from_dir/$$file Not Found!" ; \
1547           elif test "$(Verb)" != '@' ; then \
1548             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1549           fi; \
1550         done
1551         $(Verb) for subdir in $(DistSubDirs) ; do \
1552           if test "$$subdir" \!= "." ; then \
1553             new_distdir="$(DistDir)/$$subdir" ; \
1554             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1555             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1556             exit 1; \
1557           fi; \
1558         done
1559         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1560           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1561           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1562                                   -name .svn \) -print` ;\
1563           $(MAKE) dist-hook ; \
1564           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1565             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1566             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1567             -o ! -type d ! -perm -444 -exec \
1568               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1569             || chmod -R a+r $(DistDir) ; \
1570         fi
1571
1572 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1573 # defined by user.
1574 dist-hook::
1575
1576 endif
1577
1578 ###############################################################################
1579 # TOP LEVEL - targets only to apply at the top level directory
1580 ###############################################################################
1581
1582 ifeq ($(LEVEL),.)
1583
1584 #------------------------------------------------------------------------
1585 # Install support for the project's include files:
1586 #------------------------------------------------------------------------
1587 install-local::
1588         $(Echo) Installing include files
1589         $(Verb) $(MKDIR) $(PROJ_includedir)
1590         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1591           cd $(PROJ_SRC_ROOT)/include && \
1592           for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1593               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS ` ; do \
1594             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1595             if test \! -d "$$instdir" ; then \
1596               $(EchoCmd) Making install directory $$instdir ; \
1597               $(MKDIR) $$instdir ;\
1598             fi ; \
1599             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1600           done ; \
1601         fi
1602 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1603         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1604           cd $(PROJ_OBJ_ROOT)/include && \
1605           for hdr in `find . -type f -print | grep -v CVS` ; do \
1606             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1607           done ; \
1608         fi
1609 endif
1610
1611 uninstall-local::
1612         $(Echo) Uninstalling include files
1613         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1614           cd $(PROJ_SRC_ROOT)/include && \
1615             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1616               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1617         -o -name '*.in' ')' -print ')' | \
1618         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1619           cd $(PROJ_SRC_ROOT)/include && \
1620             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1621       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1622         fi
1623
1624 endif
1625
1626 #------------------------------------------------------------------------
1627 # Print out the directories used for building
1628 #------------------------------------------------------------------------
1629 printvars::
1630         $(Echo) "BuildMode    : " '$(BuildMode)'
1631         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1632         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1633         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1634         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1635         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1636         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1637         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1638         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1639         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1640         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1641         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1642         $(Echo) "UserTargets  : " '$(UserTargets)'
1643         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1644         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1645         $(Echo) "ObjDir       : " '$(ObjDir)'
1646         $(Echo) "LibDir       : " '$(LibDir)'
1647         $(Echo) "ToolDir      : " '$(ToolDir)'
1648         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1649         $(Echo) "Sources      : " '$(Sources)'
1650         $(Echo) "TDFiles      : " '$(TDFiles)'
1651         $(Echo) "INCFiles     : " '$(INCFiles)'
1652         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1653         $(Echo) "PreConditions: " '$(PreConditions)'
1654         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1655         $(Echo) "Compile.C    : " '$(Compile.C)'
1656         $(Echo) "Archive      : " '$(Archive)'
1657         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1658         $(Echo) "LexFiles     : " '$(LexFiles)'
1659         $(Echo) "Module       : " '$(Module)'
1660         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'