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