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