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