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