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