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