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