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