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