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