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