a6cb6bb30eca670a0d7c8022e3054afcbdbd9b14
[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 # Set the VPATH so that we can find source files.
17 #
18 VPATH=$(BUILD_SRC_DIR)
19
20 ###############################################################################
21 # TARGETS: Define standard targets that can be invoked
22 ###############################################################################
23
24 #--------------------------------------------------------------------
25 # Define the various target sets
26 #--------------------------------------------------------------------
27 RECURSIVE_TARGETS := all clean check install uninstall
28 LOCAL_TARGETS     := all-local clean-local check-local install-local \
29                      printvars uninstall-local
30 TOPLEV_TARGETS    := dist dist-check dist-clean tags
31 USER_TARGETS      := $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOPLEV_TARGETS)
32 INTERNAL_TARGETS  := preconditions \
33   install-config-dir install-shared-library install-bytecode-library \
34   install-archive-library install-relinked-library install-tool \
35   uninstall-config-dir uninstall-shared-library uninstall-bytecode-library \
36   uninstall-archive-library uninstall-relinked-library uninstall-tool
37
38 ###############################################################################
39 # INITIALIZATION: Basic things the makefile needs
40 ###############################################################################
41
42 #--------------------------------------------------------------------
43 # Reset the list of suffixes we know how to build
44 #--------------------------------------------------------------------
45 .SUFFIXES:
46 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
47
48 #--------------------------------------------------------------------
49 # Mark all of these targets as phony to avoid implicit rule search
50 #--------------------------------------------------------------------
51 .PHONY: $(USER_TARGETS) $(INTERNAL_TARGETS)
52
53 #--------------------------------------------------------------------
54 # Make sure all the user-target rules are double colon rules and 
55 # they are defined first.
56 #--------------------------------------------------------------------
57
58 $(USER_TARGETS)::
59
60 ################################################################################
61 # PRECONDITIONS: that which must be built/checked first
62 ################################################################################
63
64 SRCMKFILES    := $(filter-out Makefile.rules %.in,\
65                  $(wildcard $(BUILD_SRC_DIR)/Makefile.*))
66 OBJMKFILES    := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SRCMKFILES))
67 CONFIGURE     := $(LLVM_SRC_ROOT)/configure
68 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
69 MAKE_CONFIG_IN:= $(LLVM_SRC_ROOT)/Makefile.config.in
70 MAKE_CONFIG   := $(LLVM_OBJ_ROOT)/Makefile.config
71 PRECONDITIONS := $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILES)
72
73 preconditions : $(PRECONDITIONS)
74
75 #------------------------------------------------------------------------
76 # Make sure the BUILT_SOURCES are built first
77 #------------------------------------------------------------------------
78 $(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)
79
80 clean-local::
81 ifneq ($(strip $(BUILT_SOURCES)),)
82         $(VERB) $(RM) -f $(BUILT_SOURCES)
83 endif
84
85 #------------------------------------------------------------------------
86 # Make sure we're not using a stale configuration
87 #------------------------------------------------------------------------
88 .PRECIOUS: $(CONFIG_STATUS)
89 $(CONFIG_STATUS): $(CONFIGURE)
90         @$(ECHO) Reconfiguring with $<
91         $(VERB) $(CONFIG_STATUS) --recheck $(CONFIGUREFLAGS)
92         $(VERB) $(CONFIG_STATUS)
93
94 #------------------------------------------------------------------------
95 # Make sure the configuration makefile is up to date
96 #------------------------------------------------------------------------
97 $(MAKE_CONFIG): $(MAKE_CONFIG_IN) $(CONFIG_STATUS)
98         @$(ECHO) Regenerating $@
99         $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
100
101 #------------------------------------------------------------------------
102 # If the Makefile in the source tree has been updated, copy it over into the
103 # build tree. But, only do this if the source and object makefiles differ
104 #------------------------------------------------------------------------
105 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
106
107 $(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
108         @$(ECHO) "Updating Makefile"
109         $(VERB) $(MKDIR) $(@D)
110         $(VERB) cp -f $< $@
111
112 # Copy the Makefile.* files unless we're in the root directory which avoids
113 # the copying of Makefile.config.in or other things that should be explicitly
114 # taken care of.
115 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
116         @case '$?' in \
117           *Makefile.rules) ;; \
118           *.in) ;; \
119           *) $(ECHO) "Updating $(@F)" ; \
120              $(MKDIR) $(@D) ; \
121              cp -f $< $@ ;; \
122         esac
123          
124 endif
125
126 #------------------------------------------------------------------------
127 # Set up the basic dependencies
128 #------------------------------------------------------------------------
129 $(USER_TARGETS):: $(PRECONDITIONS)
130
131 all:: all-local
132 check:: check-local
133 clean:: clean-local 
134 install:: install-local
135 uninstall:: uninstall-local
136 check-local:: all-local
137 install-local:: all-local 
138
139 ###############################################################################
140 # VARIABLES: Set up various variables based on configuration data
141 ###############################################################################
142
143 #--------------------------------------------------------------------
144 # Variables derived from configuration we are building
145 #--------------------------------------------------------------------
146
147 ifdef ENABLE_PROFILING
148   CONFIGURATION := Profile
149   CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
150   CFLAGS   += -O3 -DNDEBUG -pg
151   LDFLAGS  += -O3 -DNDEBUG -pg 
152 else
153   ifdef ENABLE_OPTIMIZED
154     CONFIGURATION := Release
155     CXXFLAGS  += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
156     CFLAGS    += -O3 -DNDEBUG -fomit-frame-pointer
157     LDFLAGS   += -O3 -DNDEBUG 
158   else
159     CONFIGURATION := Debug
160     CXXFLAGS += -g -D_DEBUG 
161     CFLAGS   += -g -D_DEBUG
162     LDFLAGS  += -g -D_DEBUG 
163     KEEP_SYMBOLS := 1
164   endif
165 endif
166
167 ARFLAGS := cru
168
169 #--------------------------------------------------------------------
170 # Directory locations
171 #--------------------------------------------------------------------
172 OBJDIR      := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
173 LIBDIR      := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
174 TOOLDIR     := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
175 LLVMLIBDIR  := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
176 LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
177
178 #--------------------------------------------------------------------
179 # Full Paths To Compiled Tools and Utilities
180 #--------------------------------------------------------------------
181 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
182 LLVMAS   := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
183 BURG     := $(LLVMTOOLDIR)/burg$(EXEEXT)
184 TBLGEN   := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
185 GCCLD    := $(LLVMTOOLDIR)/gccld$(EXEEXT)
186 LLVMGCC  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
187 LLVMGXX  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
188
189 # Need a better way to compute this.
190 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
191
192 #--------------------------------------------------------------------
193 # Adjust to user's request
194 #--------------------------------------------------------------------
195
196 # Adjust LIBTOOL options for shared libraries, or not.
197 ifndef SHARED_LIBRARY
198   LIBTOOL += --tag=disable-shared
199 else
200   LDFLAGS += -rpath $(LIBDIR)
201 endif
202
203 # Adjust settings for verbose mode
204 ifndef VERBOSE
205   VERB := @
206   LIBTOOL += --silent
207   AR += >/dev/null 2>/dev/null
208   CONFIGUREFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
209 else
210   CONFIGUREFLAGS := 
211 endif
212
213 # By default, strip symbol information from executable
214 ifndef KEEP_SYMBOLS
215   STRIP = $(PLATFORMSTRIPOPTS)
216   STRIP_WARN_MSG = "(without symbols)"
217 endif
218
219 # Adjust linker flags for building an executable
220 ifdef TOOLNAME
221   LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
222 endif
223
224 # Use TOOLLINKOPTSB to pass options to the linker like library search 
225 # path etc.
226 # Note that this is different from TOOLLINKOPTS, these options
227 # are passed to the linker *before* the USEDLIBS options are passed.
228 # e.g. usage TOOLLINKOPTSB =  -L/home/xxx/lib
229 ifdef TOOLLINKOPTSB
230 LDFLAGS += $(TOOLLINKOPTSB)
231 endif
232
233 #----------------------------------------------------------
234 # Options To Invoke Tools
235 #----------------------------------------------------------
236
237 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
238
239 LDFLAGS  += -L$(LIBDIR) -L$(LLVMLIBDIR)
240 CPPFLAGS += -I$(BUILD_OBJ_DIR) \
241             -I$(BUILD_SRC_DIR) \
242             -I$(BUILD_SRC_ROOT)/include \
243             -I$(BUILD_OBJ_ROOT)/include \
244             -I$(LLVM_OBJ_ROOT)/include \
245             -I$(LLVM_SRC_ROOT)/include \
246             -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
247
248 Compile.C     = $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
249 Compile.CXX   = $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
250 LTCompile.C   = $(LIBTOOL) --mode=compile $(Compile.C)
251 LTCompile.CXX = $(LIBTOOL) --tag=CXX --mode=compile $(Compile.CXX)
252 BCCompile.CXX = $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
253 BCCompile.C   = $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
254 Link          = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) \
255                 $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
256 Relink        = $(LIBTOOL) --tag=CXX --mode=link $(CXX)
257 BCLinkLib     = $(LLVMGCC) -shared -nostdlib
258 Burg          = $(BURG) -I $(BUILD_SRC_DIR)
259 TableGen      = $(TBLGEN) -I $(BUILD_SRC_DIR)
260 Archive       = $(AR) $(ARFLAGS)
261 ifdef RANLIB
262 Ranlib        = $(RANLIB)
263 else
264 Ranlib        = ranlib
265 endif
266
267 #----------------------------------------------------------
268 # Get the list of source files
269 #----------------------------------------------------------
270 ifndef SOURCES
271 SOURCES  := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
272             $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
273             $(BUILD_SRC_DIR)/*.l))
274 endif
275
276 ifdef BUILT_SOURCES
277 SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
278 endif
279
280 #----------------------------------------------------------
281 # Types of objects that can be built from sources
282 #----------------------------------------------------------
283 BASENAME_SOURCES := $(sort $(basename $(SOURCES)))
284 ObjectsO  := $(BASENAME_SOURCES:%=$(OBJDIR)/%.o)
285 ObjectsLO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.lo)
286 ObjectsBC := $(BASENAME_SOURCES:%=$(OBJDIR)/%.bc)
287
288
289 ###############################################################################
290 # DIRECTORIES: Handle recursive descent of directory structure
291 ###############################################################################
292
293 #---------------------------------------------------------
294 # Handle the DIRS options for sequential construction
295 #---------------------------------------------------------
296
297 SUBDIRS := 
298 ifdef DIRS
299 SUBDIRS += $(DIRS)
300 $(RECURSIVE_TARGETS)::
301         $(VERB) for dir in $(DIRS); do \
302           if [ ! -f $$dir/Makefile ]; then \
303             $(MKDIR) $$dir; \
304             cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
305           fi; \
306           ($(MAKE) -C $$dir $@ ) || exit 1; \
307         done
308 endif
309
310 #---------------------------------------------------------
311 # Handle the EXPERIMENTAL_DIRS options ensuring success
312 # after each directory is built.
313 #---------------------------------------------------------
314 ifdef EXPERIMENTAL_DIRS
315 $(RECURSIVE_TARGETS)::
316         $(VERB) for dir in $(EXPERIMENTAL_DIRS); do \
317           if [ ! -f $$dir/Makefile ]; then \
318             $(MKDIR) $$dir; \
319             cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
320           fi; \
321           ($(MAKE) -C $$dir $@ ) || exit 0; \
322         done
323 endif
324
325 #---------------------------------------------------------
326 # Handle the PARALLEL_DIRS options for parallel construction
327 #---------------------------------------------------------
328 ifdef PARALLEL_DIRS
329
330 SUBDIRS += $(PARALLEL_DIRS)
331 # Unfortunately, this list must be maintained if new 
332 # recursive targets are added.
333 all      :: $(addsuffix /.makeall     , $(PARALLEL_DIRS))
334 clean    :: $(addsuffix /.makeclean   , $(PARALLEL_DIRS))
335 check    :: $(addsuffix /.makecheck   , $(PARALLEL_DIRS))
336 install  :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
337 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
338
339 Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
340
341 $(Parallel_Targets) :
342         $(VERB) if [ ! -f $(@D)/Makefile ]; then \
343           $(MKDIR) $(@D); \
344           cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
345         fi; \
346         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
347 endif
348
349 #---------------------------------------------------------
350 # Handle the OPTIONAL_DIRS options for directores that may
351 # or may not exist.
352 #---------------------------------------------------------
353 ifdef OPTIONAL_DIRS
354
355 SUBDIRS += $(OPTIONAL_DIRS)
356
357 $(RECURSIVE_TARGETS)::
358         $(VERB) for dir in $(OPTIONAL_DIRS); do \
359           if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
360             if [ ! -f $$dir/Makefile ]; then \
361               $(MKDIR) $$dir; \
362               cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
363             fi; \
364             ($(MAKE) -C$$dir $@ ) || exit 1; \
365           fi \
366         done
367 endif
368
369 #---------------------------------------------------------
370 # Handle the CONFIG_FILES options
371 #---------------------------------------------------------
372 ifdef CONFIG_FILES
373
374 install-local:: install-config-dir 
375
376 install-config-dir: $(sysconfdir) $(CONFIG_FILES)
377         $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
378         $(VERB)for file in $(CONFIG_FILES); do \
379                 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
380         done
381
382 uninstall-local:: uninstall-config-dir
383
384 uninstall-config-dir:
385         $(VERB)$(ECHO) Uninstalling Configuration Files From $(sysconfdir)
386         $(VERB)for file in $(CONFIG_FILES); do \
387           $(RM) -f $(sysconfdir)/$${file} ; \
388         done
389
390 $(sysconfdir):
391         $(VERB) $(MKDIR) $(sysconfdir)
392
393 endif
394
395 ###############################################################################
396 # Library Build Rules: Four ways to build a library
397 ###############################################################################
398
399 $(libdir):
400         $(VERB) $(MKDIR) $(libdir)
401
402 $(bytecode_libdir):
403         $(VERB) $(MKDIR) $(bytecode_libdir)
404
405
406
407 # if we're building a library ...
408 ifdef LIBRARYNAME
409
410 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
411 LIBRARYNAME := $(strip $(LIBRARYNAME))
412 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
413 LIBNAME_A  := $(LIBDIR)/lib$(LIBRARYNAME).a
414 LIBNAME_O  := $(LIBDIR)/$(LIBRARYNAME).o
415 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
416
417 #---------------------------------------------------------
418 # Shared Library Targets:
419 #   If the user asked for a shared library to be built
420 #   with the SHARED_LIBRARY variable, then we provide
421 #   targets for building them.
422 #---------------------------------------------------------
423 ifdef SHARED_LIBRARY
424
425 all-local:: $(LIBNAME_LA)
426
427 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
428         @$(ECHO) Linking $(CONFIGURATION) Shared Library $(notdir $@)
429         $(VERB) $(Link) -o $@ $(ObjectsLO)
430         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
431
432 clean-local::
433 ifneq ($(strip $(LIBNAME_LA)),)
434         $(VERB) $(RM) -f $(LIBNAME_LA)
435 endif
436
437 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
438 install-local:: install-shared-library
439
440 install-shared-library: $(libdir) $(DestSharedLib)
441
442 $(DestSharedLib): $(LIBNAME_LA)
443         @$(ECHO) Installing $(CONFIGURATION) Shared Library $(DestSharedLib)
444         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
445         $(VERB) $(LIBTOOL) --finish $(libdir)
446
447 uninstall-local:: uninstall-shared-library
448
449 uninstall-shared-library:
450         @$(ECHO) Uninstalling $(CONFIGURATION) Shared Library $(DestSharedLib)
451         $(VERB) $(RM) -f $(DestSharedLib)
452
453 endif
454
455 #---------------------------------------------------------
456 # Bytecode Library Targets:
457 #   If the user asked for a bytecode library to be built
458 #   with the BYTECODE_LIBRARY variable, then we provide 
459 #   targets for building them.
460 #---------------------------------------------------------
461 ifdef BYTECODE_LIBRARY
462
463 ifdef EXPORTED_SYMBOL_LIST
464   BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
465 else
466   ifdef EXPORTED_SYMBOL_FILE
467     BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
468   else
469     BCLinkLib += -Xlinker -disable-internalize
470   endif
471 endif
472
473 all-local:: $(LIBNAME_BC)
474
475 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
476         @$(ECHO) Linking $(CONFIGURATION) Bytecode Library $(notdir $@)
477         $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
478
479 clean-local::
480 ifneq ($(strip $(LIBNAME_BC)),)
481         $(VERB) $(RM) -f $(LIBNAME_BC)
482 endif
483
484 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
485
486 install-local:: install-bytecode-library
487
488 install-bytecode-library: $(bytecode_libdir) $(DestBytecodeLib)
489
490 $(DestBytecodeLib): $(LIBNAME_BC) $(bytecode_libdir)
491         @$(ECHO) Installing $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
492         $(VERB) $(INSTALL) $< $@
493
494 uninstall-local:: uninstall-bytecode-library
495
496 uninstall-bytecode-library: 
497         @$(ECHO) Uninstalling $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
498         $(VERB) $(RM) -f $(DestBytecodeLib)
499
500 endif
501
502 # Does the library want a .o version built?
503 ifndef DONT_BUILD_RELINKED
504 all-local:: $(LIBNAME_O)
505
506 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
507         @$(ECHO) Linking $(CONFIGURATION) Object Library $(notdir $@)
508         $(VERB) $(Relink) -o $@ $(ObjectsO)
509
510 clean-local::
511 ifneq ($(strip $(LIBNAME_O)),)
512         $(VERB) $(RM) -f $(LIBNAME_O)
513 endif
514
515 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
516
517 install-local:: install-relinked-library 
518
519 install-relinked-library: $(libdir) $(DestRelinkedLib)
520
521 $(DestRelinkedLib): $(LIBNAME_O)
522         @$(ECHO) Installing $(CONFIGURATION) Object Library $(DestRelinkedLib)
523         $(VERB) $(MKDIR) $(libdir)
524         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
525
526 uninstall-local:: uninstall-relinked-library 
527
528 uninstall-relinked-library: 
529         @$(ECHO) Uninstalling $(CONFIGURATION) Object Library $(DestRelinkedLib)
530         $(VERB) $(RM) -f $(DestRelinkedLib)
531
532 endif
533
534 # Does the library want an archive version built?
535 ifdef BUILD_ARCHIVE
536 all-local:: $(LIBNAME_A)
537
538 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
539         @$(ECHO) Building $(CONFIGURATION) Archive Library $(notdir $@)
540         $(VERB)$(RM) -f $@
541         $(VERB) $(Archive) $@ $(ObjectsO)
542         $(VERB) $(Ranlib) $@
543
544 clean-local::
545 ifneq ($(strip $(LIBNAME_A)),)
546         $(VERB) $(RM) -f $(LIBNAME_A)
547 endif
548
549 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
550
551 install-local:: install-archive-library
552
553 install-archive-library: $(libdir) $(DestArchiveLib)
554
555 $(DestArchiveLib): $(LIBNAME_A)
556         @$(ECHO) Installing $(CONFIGURATION) Archive Library $(DestArchiveLib)
557         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
558
559 uninstall-local:: uninstall-archive-library
560
561 uninstall-archive-library: 
562         @$(ECHO) Uninstalling $(CONFIGURATION) Archive Library $(DestArchiveLib)
563         $(VERB) $(RM) -f $(DestArchiveLib)
564
565 endif
566
567 # endif LIBRARYNAME
568 endif 
569
570 ###############################################################################
571 # Tool Build Rules: Build executable tool based on TOOLNAME option
572 ###############################################################################
573
574 ifdef TOOLNAME
575
576 #---------------------------------------------------------
577 # TOOLLINKOPTSB to pass options to the linker like library search path etc
578 # Note that this is different from TOOLLINKOPTS, these options
579 # are passed to the linker *before* the USEDLIBS options are passed.
580 # e.g. usage TOOLLINKOPTSB =  -L/home/xxx/lib
581 #---------------------------------------------------------
582 ifdef TOOLLINKOPTSB
583 Link    += $(TOOLLINKOPTSB) 
584 endif
585
586 # TOOLEXENAME - This is the output filenames to generate
587 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
588
589 # LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
590 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
591 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o,  $(PROJ_LIBS_OPTIONS))
592 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
593 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
594
595 # USED_LIBS/LIBS_PATHS - Compute dependent library file paths
596 PROJ_USED_LIBS    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
597 LLVM_USED_LIBS    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
598 PROJ_LIBS_PATHS   := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
599 LLVM_LIBS_PATHS   := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
600
601 # Concatenate all the optoins
602 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
603
604 # Handle compression libraries automatically
605 ifeq ($(HAVE_BZIP2),1)
606 LIBS += -lbz2
607 endif
608 ifeq ($(HAVE_ZLIB),1)
609 LIBS += -lz
610 endif
611
612 # Tell make that we need to rebuild subdirectories before we can link the tool.
613 # This affects things like LLI which has library subdirectories.
614 $(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
615
616 all-local:: $(TOOLEXENAME)
617
618 clean-local::
619 ifneq ($(strip $(TOOLEXENAME)),)
620         $(VERB) $(RM) -f $(TOOLEXENAME)
621 endif
622
623 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
624         @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
625         $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
626         @$(ECHO) ======= Finished Linking $(CONFIGURATION) Executable $(TOOLNAME) $(STRIP_WARN_MSG) 
627
628 DestTool = $(bindir)/$(TOOLNAME)
629
630 install-local:: install-tool
631
632 install-tool: $(bindir) $(DestTool)
633
634 $(DestTool): $(TOOLEXENAME)
635         @$(ECHO) Installing $(CONFIGURATION) $(DestTool)
636         $(VERB) $(INSTALL) $(TOOLEXENAME) $(DestTool)
637
638 $(bindir):
639         $(VERB) $(MKDIR) $(bindir)
640         
641 uninstall-local:: uninstall-tool
642
643 uninstall-tool:
644         @$(ECHO) Uninstalling $(CONFIGURATION) $(DestTool)
645         $(VERB) $(RM) -f $(DestTool)
646
647 endif
648
649 ifndef DISABLE_AUTO_DEPENDENCIES
650
651 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
652 ifdef SHARED_LIBRARY
653
654 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
655         @$(ECHO) "Compiling $*.cpp (PIC)"
656         $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
657         then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
658         else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
659
660 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir 
661         @$(ECHO) "Compiling $*.c (PIC)"
662         $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
663         then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
664         else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
665
666 else
667
668 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
669         @$(ECHO) "Compiling $*.cpp"
670         $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
671         then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
672         else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
673
674 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
675         @$(ECHO) "Compiling $*.c"
676         $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
677         then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
678         else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
679
680 endif
681
682 # Create .bc files in the OBJDIR directory from .cpp and .c files...
683 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
684         @$(ECHO) "Compiling $*.cpp (bytecode)"
685         $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
686         then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
687         else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
688
689 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
690         @$(ECHO) "Compiling $*.c (bytecode)"
691         $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
692         then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
693         else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
694
695 else
696
697 ifdef SHARED_LIBRARY
698
699 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir 
700         @$(ECHO) "Compiling $*.cpp (PIC)"
701         $(LTCompile.CXX) $< -o $@ 
702
703 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir 
704         @$(ECHO) "Compiling $*.cpp (PIC)"
705         $(LTCompile.C) $< -o $@ 
706
707 else
708
709 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
710         @$(ECHO) "Compiling $*.cpp"
711         $(Compile.CXX) $< -o $@ 
712
713 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
714         @$(ECHO) "Compiling $*.cpp"
715         $(Compile.C) $< -o $@ 
716 endif
717
718 # Create .bc files in the OBJDIR directory from .cpp and .c files...
719 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
720         @$(ECHO) "Compiling $*.cpp (bytecode)"
721         $(BCCompileCPP) $< -o $@ 
722
723 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
724         @$(ECHO) "Compiling $*.c (bytecode)"
725         $(BCCompileC) $< -o $@
726
727 endif
728
729 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
730         @$(ECHO) "Compiling $*.ll"
731         $(VERB) $(LLVMAS) $< -f -o $@
732
733 ifdef TARGET
734
735 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
736 INCFILES := $(filter %.inc,$(BUILT_SOURCES))
737
738 $(INCFILES) : $(TBLGEN) $(TDFILES)
739
740 %GenRegisterNames.inc : %.td 
741         @echo "Building $(<F) register names with tblgen"
742         $(VERB) $(TableGen) -gen-register-enums -o $@ $<
743
744 %GenRegisterInfo.h.inc : %.td 
745         @echo "Building $(<F) register information header with tblgen"
746         $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
747
748 %GenRegisterInfo.inc : %.td
749         @echo "Building $(<F) register info implementation with tblgen"
750         $(VERB) $(TableGen) -gen-register-desc -o $@ $<
751
752 %GenInstrNames.inc : %.td
753         @echo "Building $(<F) instruction names with tblgen"
754         $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
755
756 %GenInstrInfo.inc : %.td
757         @echo "Building $(<F) instruction information with tblgen"
758         $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
759
760 %GenAsmWriter.inc : %.td
761         @echo "Building $(<F) assembly writer with tblgen"
762         $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
763
764 %GenATTAsmWriter.inc : %.td
765         @echo "Building $(<F) AT&T assembly writer with tblgen"
766         $(VERB) $(TableGen) -gen-asm-writer -o $@ $< 
767
768 %GenIntelAsmWriter.inc : %.td
769         @echo "Building $(<F) Intel assembly writer with tblgen"
770         $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
771
772 %GenInstrSelector.inc: %.td
773         @echo "Building $(<F) instruction selector with tblgen"
774         $(VERB) $(TableGen) -gen-instr-selector -o $@ $< 
775
776 %GenCodeEmitter.inc:: %.td
777         @echo "Building $(<F) code emitter with tblgen"
778         $(VERB) $(TableGen) -gen-emitter -o $@ $<
779
780 clean-local::
781         $(VERB) rm -f *.inc
782
783 endif
784
785 #
786 # Rules for building lex/yacc files
787 #
788 LEX_FILES   = $(filter %.l, $(SOURCES))
789 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
790 YACC_FILES  = $(filter %.y, $(SOURCES))
791 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
792 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
793
794 # Create a .cpp source file from a flex input file... this uses sed to cut down
795 # on the warnings emited by GCC...
796 #
797 # The last line is a gross hack to work around flex aparently not being able to
798 # resize the buffer on a large token input.  Currently, for uninitialized string
799 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
800 # FIXME.  (f.e. char Buffer[10000] )
801 #
802 %.cpp: %.l
803         @$(ECHO) Flexing $<
804         $(VERB) $(FLEX) -t $< | \
805         $(SED) '/^find_rule/d' | \
806         $(SED) 's/void yyunput/inline void yyunput/' | \
807         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
808         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
809           > $@.tmp
810         $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
811         @# remove the output of flex if it didn't get moved over...
812         @rm -f $@.tmp
813
814 # Rule for building the bison parsers...
815 %.c: %.y     # Cancel built-in rules for yacc
816 %.h: %.y     # Cancel built-in rules for yacc
817 %.cpp %.h : %.y
818         @$(ECHO) "Bisoning $*.y"
819         $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
820         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
821         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || $(MV) -f $*.tab.h $*.h
822         @# If the files were not updated, don't leave them lying around...
823         @rm -f $*.tab.c $*.tab.h
824
825 # To create the directories...
826 %/.dir:
827         $(VERB) $(MKDIR) $* > /dev/null
828         @$(DATE) > $@
829
830 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
831 .PRECIOUS: $(LLVMTOOLDIR)/.dir
832
833 # To create postscript files from dot files...
834 ifneq ($(DOT),false)
835 %.ps: %.dot
836         $(DOT) -Tps < $< > $@
837 else
838 %.ps: %.dot
839         $(ECHO) "Cannot build $@: The program dot is not installed"
840 endif
841
842 #
843 # This rules ensures that header files that are removed still have a rule for
844 # which they can be "generated."  This allows make to ignore them and
845 # reproduce the dependency lists.
846 #
847 %.h:: ;
848
849 # 'make clean' nukes the tree
850 clean-local::
851 ifneq ($(strip $(OBJDIR)),)
852         $(VERB) $(RM) -rf $(OBJDIR)
853 endif
854         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
855 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
856         $(VERB) $(RM) -f *$(SHLIBEXT)
857 endif
858 ifneq ($(strip $(LEX_OUTPUT)),)
859         $(VERB) $(RM) -f $(LEX_OUTPUT) 
860 endif
861 ifneq ($(strip $(YACC_OUTPUT)),)
862         $(VERB) $(RM) -f $(YACC_OUTPUT)
863 endif
864
865 ###############################################################################
866 # DEPENDENCIES: Include the dependency files if we should
867 ###############################################################################
868 ifndef DISABLE_AUTO_DEPENDENCIES
869
870 # If its not one of the cleaning targets
871 ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
872
873 # Get the list of dependency files
874 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
875 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
876
877 -include /dev/null $(DependFiles)
878
879 endif
880
881 endif  # ifndef DISABLE_AUTO_DEPENDENCIES
882
883 ###############################################################################
884 # Handle construction of a distribution tarball
885 ###############################################################################
886
887 .PHONY: dist dist-chck dist-clean distdir dist-gzip dist-bzip2 dist-zip
888
889 #------------------------------------------------------------------------
890 # Define distribution related variables
891 #------------------------------------------------------------------------
892 DistName    := $(LLVM_TARBALL_NAME)
893 DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
894 TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
895 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
896 DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
897 DistTarBZ2  := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
898 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
899                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
900                Makefile.config.in configure autoconf
901 DistOther   := $(notdir $(wildcard \
902                $(BUILD_SRC_DIR)/*.h \
903                $(BUILD_SRC_DIR)/*.td \
904                $(BUILD_SRC_DIR)/*.def \
905                $(BUILD_SRC_DIR)/*.ll \
906                $(BUILD_SRC_DIR)/*.in))
907 DistSources := $(SOURCES) $(EXTRA_DIST)
908 DistSubDirs := $(SUBDIRS)
909 DistFiles   := $(DistAlways) $(DistSources) $(DistOther)
910
911
912 #------------------------------------------------------------------------
913 # We MUST build distribution with OBJ_DIR != SRC_DIR
914 #------------------------------------------------------------------------
915 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
916 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
917         @$(ECHO) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
918
919 DistCheckTop := 
920 else
921
922 DistCheckTop := check
923 #------------------------------------------------------------------------
924 # Prevent catastrophic remove
925 #------------------------------------------------------------------------
926 ifeq ($(LLVM_TARBALL_NAME),)
927 $(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
928 endif
929
930 #------------------------------------------------------------------------
931 # Prevent attempt to run dist targets from anywhere but the top level
932 #------------------------------------------------------------------------
933 ifneq ($(LEVEL),.)
934
935 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
936         @$(ECHO) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
937
938 else
939
940 #------------------------------------------------------------------------
941 # Provide the top level targets
942 #------------------------------------------------------------------------
943
944 dist-gzip: $(DistTarGZip)
945
946 $(DistTarGZip) : distdir
947         @$(ECHO) Packing gzipped distribution tar file.
948         $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
949
950 dist-bzip2: $(DistTarBZ2)
951
952 $(DistTarBZ2) : distdir
953         @$(ECHO) Packing bzipped distribution tar file.
954         $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
955
956 dist-zip: $(DistZip)
957
958 $(DistZip) : distdir
959         @$(ECHO) Packing zipped distribution file.
960         $(VERB) rm -f $(DistZip)
961         $(VERB) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
962
963 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
964         @$(ECHO) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
965
966 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
967
968 dist-check:: $(DistCheckTop) $(DistTarGZip)
969         @$(ECHO) Checking distribution tar file.
970         $(VERB) if test -d $(DistCheckDir) ; then \
971           $(RM) -rf $(DistCheckDir) ; \
972         fi
973         $(VERB) $(MKDIR) $(DistCheckDir)
974         $(VERB) cd $(DistCheckDir) && \
975           $(MKDIR) $(DistCheckDir)/build && \
976           $(MKDIR) $(DistCheckDir)/install && \
977           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
978           cd build && \
979           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
980             --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
981           $(MAKE) check && \
982           $(MAKE) install && \
983           $(MAKE) uninstall && \
984           $(MAKE) dist && \
985           $(MAKE) clean && \
986           $(MAKE) dist-clean && \
987           $(ECHO) ===== $(DistTarGZip) Ready For Distribution =====
988
989 dist-clean::
990         @$(ECHO) Cleaning distribution files
991         $(VERB) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
992
993 endif
994
995 #------------------------------------------------------------------------
996 # Provide the recursive distdir target for building the distribution directory
997 #------------------------------------------------------------------------
998 distdir : $(DistSources)
999         @$(ECHO) Building Distribution Directory $(DistDir)
1000         $(VERB) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1001           if test -d "$(DistDir)" ; then \
1002             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1003               exit 1 ; \
1004           fi ; \
1005           echo Removing $(DistDir) ; \
1006           $(RM) -rf $(DistDir); \
1007         fi
1008         $(VERB) $(MKDIR) $(DistDir) 
1009         $(VERB) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1010         srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1011         for file in $(DistFiles) ; do \
1012           case "$$file" in \
1013             $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
1014             $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
1015           esac; \
1016           if test -f "$$file" || test -d "$$file" ; then \
1017             from_dir=. ; \
1018           else \
1019             from_dir=$(BUILD_SRC_DIR); \
1020           fi; \
1021           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
1022           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1023             to_dir="$(DistDir)/$$dir"; \
1024             $(MKDIR) "$$to_dir" ; \
1025           else \
1026             to_dir="$(DistDir)"; \
1027           fi; \
1028           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1029           if test -n "$$mid_dir" ; then \
1030             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1031           fi ; \
1032           if test -d "$$from_dir/$$file"; then \
1033             if test -d "$(BUILD_SRC_DIR)/$$file" && \
1034                test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1035               cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1036             fi; \
1037             cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1038           elif test -f "$$from_dir/$$file" ; then \
1039             cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1040           elif test -L "$$from_dir/$$file" ; then \
1041             cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1042           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1043             $(ECHO) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1044           elif test "$(VERB)" != '@' ; then \
1045             $(ECHO) "Skipping non-existent $$from_dir/$$file" ; \
1046           fi; \
1047         done
1048         $(VERB) for subdir in $(DistSubDirs) ; do \
1049           if test "$$subdir" \!= "." ; then \
1050             new_distdir="$(DistDir)/$$subdir" ; \
1051             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1052             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1053           fi; \
1054         done
1055         $(VERB) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1056         -$(VERB) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1057           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1058           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1059           ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1060         || chmod -R a+r $(DistDir)
1061
1062 dist-hook::
1063
1064
1065 endif
1066
1067 ###############################################################################
1068 # TOP LEVEL - targets only to apply at the top level directory
1069 ###############################################################################
1070
1071 ifeq ($(LEVEL),.)
1072
1073 #------------------------------------------------------------------------
1074 # Install support for project's include files:
1075 #------------------------------------------------------------------------
1076 install-local::
1077         @$(ECHO) Installing include files
1078         $(VERB) $(MKDIR) $(includedir)
1079         $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1080           cd $(BUILD_SRC_ROOT)/include && \
1081             find . -path '*/Internal' -prune -o '(' -type f \
1082               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1083               -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1084         fi
1085
1086 uninstall-local::
1087         @$(ECHO) Uninstalling include files
1088         $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1089           cd $(BUILD_SRC_ROOT)/include && \
1090             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1091               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1092               -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1093         fi 
1094
1095 #------------------------------------------------------------------------
1096 # Build tags database for Emacs/Xemacs:
1097 #------------------------------------------------------------------------
1098 tags:: TAGS
1099
1100 TAGS: 
1101         find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
1102
1103 endif
1104
1105 ###############################################################################
1106 # MISCELLANEOUS - utility targets
1107 ###############################################################################
1108
1109 #------------------------------------------------------------------------
1110 # Print out the directories used for building
1111 printvars::
1112         @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
1113         @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
1114         @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
1115         @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
1116         @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
1117         @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
1118         @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
1119         @$(ECHO) "libdir : " $(libdir)
1120         @$(ECHO) "bindir : " $(bindir)
1121         @$(ECHO) "sysconfdir : " $(sysconfdir)
1122         @$(ECHO) "bytecode_libdir : " $(bytecode_libdir)
1123         @$(ECHO) "USER_TARGETS : " $(USER_TARGETS)
1124         @$(ECHO) "OBJMKFILES: $(OBJMKFILES)"
1125         @$(ECHO) "SRCMKFILES: $(SRCMKFILES)"
1126         @$(ECHO) "OBJDIR: " $(OBJDIR)
1127         @$(ECHO) "LIBDIR: " $(LIBDIR)
1128         @$(ECHO) "TOOLDIR: " $(TOOLDIR)
1129         @$(ECHO) "TDFILES:" '$(TDFILES)'
1130         @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
1131         @$(ECHO) "Compile.C: " '$(Compile.C)'
1132