Fix the default install directory of modules from / to $(libdir) !
[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         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
596           "(internalize)"
597         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
598         $(Verb) $(RM) -f $@
599         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
600 else
601 $(LibName.BCA): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir
602         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
603         $(Verb) $(RM) -f $@
604         $(Verb) $(LArchive) $@ $(ObjectsBC)
605
606 endif
607
608 clean-local::
609 ifneq ($(strip $(LibName.BCA)),)
610         -$(Verb) $(RM) -f $(LibName.BCA)
611 endif
612
613 ifdef BYTECODE_DESTINATION
614 BytecodeDestDir := $(BYTECODE_DESTINATION)
615 else
616 BytecodeDestDir := $(libdir)
617 endif
618
619 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
620
621 install-bytecode-local:: $(DestBytecodeLib)
622
623 install-local:: $(DestBytecodeLib)
624
625 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
626         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
627         $(Verb) $(INSTALL) $(LibName.BCA) $@
628
629 uninstall-local::
630         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
631         -$(Verb) $(RM) -f $(DestBytecodeLib)
632
633 endif
634
635 #---------------------------------------------------------
636 # ReLinked Library Targets:
637 #   If the user didn't explicitly forbid building a 
638 #   relinked then we provide targets for building them.
639 #---------------------------------------------------------
640 ifndef DONT_BUILD_RELINKED
641
642 all-local:: $(LibName.O)
643
644 $(LibName.O): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
645         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
646         $(Verb) $(Relink) -o $@ $(ObjectsO)
647
648 clean-local::
649 ifneq ($(strip $(LibName.O)),)
650         -$(Verb) $(RM) -f $(LibName.O)
651 endif
652
653 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
654
655 install-local:: $(DestRelinkedLib)
656
657 $(DestRelinkedLib): $(libdir) $(LibName.O)
658         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
659         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
660
661 uninstall-local::
662         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
663         -$(Verb) $(RM) -f $(DestRelinkedLib)
664
665 endif
666
667 #---------------------------------------------------------
668 # Archive Library Targets:
669 #   If the user wanted a regular archive library built, 
670 #   then we provide targets for building them.
671 #---------------------------------------------------------
672 ifdef BUILD_ARCHIVE
673
674 all-local:: $(LibName.A)
675
676 $(LibName.A): $(BUILT_SOURCES) $(ObjectsO) $(LibDir)/.dir
677         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
678         -$(Verb) $(RM) -f $@
679         $(Verb) $(Archive) $@ $(ObjectsO)
680         $(Verb) $(Ranlib) $@
681
682 clean-local::
683 ifneq ($(strip $(LibName.A)),)
684         -$(Verb) $(RM) -f $(LibName.A)
685 endif
686
687 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
688
689 install-local:: $(DestArchiveLib)
690
691 $(DestArchiveLib): $(libdir) $(LibName.A)
692         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
693         $(Verb) $(MKDIR) $(libdir)
694         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
695
696 uninstall-local::
697         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
698         -$(Verb) $(RM) -f $(DestArchiveLib)
699
700 endif
701
702 # endif LIBRARYNAME
703 endif 
704
705 ###############################################################################
706 # Tool Build Rules: Build executable tool based on TOOLNAME option
707 ###############################################################################
708
709 ifdef TOOLNAME
710
711 #---------------------------------------------------------
712 # Handle the special "JIT" value for LLVM_LIBS which is a
713 # shorthand for a bunch of libraries that get the correct
714 # JIT support for a tool that runs JIT.
715 #---------------------------------------------------------
716 ifeq ($(LLVMLIBS),JIT)
717
718 # Make sure we can get our own symbols in the tool
719 Link += -dlopen self
720
721 # Generic JIT libraries
722 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
723
724 # You can enable the X86 JIT on a non-X86 host by setting the flag
725 # ENABLE_X86_JIT on the make command line. If not, it will still be
726 # enabled automagically on an X86 host.
727 ifeq ($(ARCH), x86)
728   ENABLE_X86_JIT = 1
729 endif
730
731 # What the X86 JIT requires
732 ifdef ENABLE_X86_JIT
733   JIT_LIBS  += LLVMX86 LLVMSelectionDAG
734 endif
735
736 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
737 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
738 # enabled automagically on an SparcV9 host.
739 ifeq ($(ARCH), Sparc)
740   ENABLE_SPARCV9_JIT = 1
741 endif
742
743 # What the Sparc JIT requires
744 ifdef ENABLE_SPARCV9_JIT
745   JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
746               LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
747               LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
748               LLVMDataStructure.a LLVMSparcV9RegAlloc
749 endif
750
751 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
752 # ENABLE_PPC_JIT on the make command line. If not, it will still be
753 # enabled automagically on an PowerPC host.
754 ifeq ($(ARCH), PowerPC)
755   ENABLE_PPC_JIT = 1
756 endif
757
758 # What the PowerPC JIT requires
759 ifdef ENABLE_PPC_JIT
760   JIT_LIBS  += LLVMPowerPC
761 endif
762
763 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
764              LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
765              LLVMSystem.a $(PLATFORMLIBDL)
766 endif
767
768 #---------------------------------------------------------
769 # Set up variables for building a tool.
770 #---------------------------------------------------------
771 ifdef EXAMPLE_TOOL
772 ToolBuildPath   := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
773 else
774 ToolBuildPath   := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
775 endif
776 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
777 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
778 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
779 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
780 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
781 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
782 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
783 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
784
785 #---------------------------------------------------------
786 # Tell make that we need to rebuild subdirectories before 
787 # we can link the tool. This affects things like LLI which 
788 # has library subdirectories.
789 #---------------------------------------------------------
790 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
791
792 #---------------------------------------------------------
793 # Provide targets for building the tools
794 #---------------------------------------------------------
795 all-local:: $(ToolBuildPath)
796
797 clean-local::
798 ifneq ($(strip $(ToolBuildPath)),)
799         -$(Verb) $(RM) -f $(ToolBuildPath)
800 endif
801
802 ifdef EXAMPLE_TOOL
803 $(ToolBuildPath): $(ExmplDir)/.dir
804 else
805 $(ToolBuildPath): $(ToolDir)/.dir
806 endif
807
808 $(ToolBuildPath): $(BUILT_SOURCES) $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
809         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
810         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
811           $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
812         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg) 
813
814 DestTool = $(bindir)/$(TOOLNAME)
815
816 install-local:: $(DestTool)
817
818 $(DestTool): $(bindir) $(ToolBuildPath)
819         $(Echo) Installing $(BuildMode) $(DestTool)
820         $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
821
822 uninstall-local::
823         $(Echo) Uninstalling $(BuildMode) $(DestTool)
824         -$(Verb) $(RM) -f $(DestTool)
825
826 endif
827
828 ###############################################################################
829 # Object Build Rules: Build object files based on sources 
830 ###############################################################################
831
832 # Provide rule sets for when dependency generation is enabled
833 ifndef DISABLE_AUTO_DEPENDENCIES
834
835 #---------------------------------------------------------
836 # Create .lo files in the ObjDir directory from the .cpp and .c files...
837 #---------------------------------------------------------
838 ifdef SHARED_LIBRARY
839
840 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
841         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
842         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
843         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
844         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
845
846 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
847         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
848         $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
849         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
850         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
851
852 #---------------------------------------------------------
853 # Create .o files in the ObjDir directory from the .cpp and .c files...
854 #---------------------------------------------------------
855 else
856
857 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
858         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
859         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
860         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
861         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
862
863 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
864         $(Echo) "Compiling $*.c for $(BuildMode) build"
865         $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
866         then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
867         else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
868
869 endif
870
871 #---------------------------------------------------------
872 # Create .bc files in the ObjDir directory from .cpp and .c files...
873 #---------------------------------------------------------
874 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS)
875         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
876         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
877         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
878         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
879
880 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS)
881         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
882         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
883         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
884         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
885
886 # Provide alternate rule sets if dependencies are disabled
887 else
888
889 ifdef SHARED_LIBRARY
890
891 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir 
892         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
893         $(LTCompile.CXX) $< -o $@ 
894
895 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir 
896         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
897         $(LTCompile.C) $< -o $@ 
898
899 else
900
901 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir
902         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
903         $(Compile.CXX) $< -o $@ 
904
905 $(ObjDir)/%.o: %.c $(ObjDir)/.dir
906         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
907         $(Compile.C) $< -o $@ 
908 endif
909
910 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS)
911         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
912         $(BCCompile.CXX) $< -o $@ 
913
914 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS)
915         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
916         $(BCCompile.C) $< -o $@
917
918 endif
919
920 #---------------------------------------------------------
921 # Provide rule to build .bc files from .ll sources,
922 # regardless of dependencies
923 #---------------------------------------------------------
924 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
925         $(Echo) "Compiling $*.ll for $(BuildMode) build"
926         $(Verb) $(LLVMAS) $< -f -o $@
927
928 ###############################################################################
929 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
930 ###############################################################################
931
932 ifdef TARGET
933
934 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
935 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
936
937 $(INCFiles) : $(TBLGEN) $(TDFiles)
938
939 %GenRegisterNames.inc : %.td 
940         $(Echo) "Building $(<F) register names with tblgen"
941         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
942
943 %GenRegisterInfo.h.inc : %.td 
944         $(Echo) "Building $(<F) register information header with tblgen"
945         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
946
947 %GenRegisterInfo.inc : %.td
948         $(Echo) "Building $(<F) register info implementation with tblgen"
949         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
950
951 %GenInstrNames.inc : %.td
952         $(Echo) "Building $(<F) instruction names with tblgen"
953         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
954
955 %GenInstrInfo.inc : %.td
956         $(Echo) "Building $(<F) instruction information with tblgen"
957         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
958
959 %GenAsmWriter.inc : %.td
960         $(Echo) "Building $(<F) assembly writer with tblgen"
961         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
962
963 %GenATTAsmWriter.inc : %.td
964         $(Echo) "Building $(<F) AT&T assembly writer with tblgen"
965         $(Verb) $(TableGen) -gen-asm-writer -o $@ $< 
966
967 %GenIntelAsmWriter.inc : %.td
968         $(Echo) "Building $(<F) Intel assembly writer with tblgen"
969         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
970
971 %GenInstrSelector.inc: %.td
972         $(Echo) "Building $(<F) instruction selector with tblgen"
973         $(Verb) $(TableGen) -gen-instr-selector -o $@ $< 
974
975 %GenCodeEmitter.inc:: %.td
976         $(Echo) "Building $(<F) code emitter with tblgen"
977         $(Verb) $(TableGen) -gen-emitter -o $@ $<
978
979 clean-local::
980         -$(Verb) $(RM) -f $(INCFiles)
981
982 endif
983
984 ###############################################################################
985 # LEX AND YACC: Provide rules for generating sources with lex and yacc
986 ###############################################################################
987
988 #---------------------------------------------------------
989 # Provide rules for generating a .cpp source file from 
990 # (f)lex input sources. 
991 #---------------------------------------------------------
992
993 LexFiles  := $(filter %.l,$(Sources))
994
995 ifneq ($(LexFiles),)
996
997 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
998
999 .PRECIOUS: $(LexOutput)
1000
1001 # Note the extra sed filtering here, used to cut down on the warnings emited 
1002 # by GCC.  The last line is a gross hack to work around flex aparently not 
1003 # being able to resize the buffer on a large token input.  Currently, for 
1004 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1005 # this is a hack around it.
1006 # FIXME.  (f.e. char Buffer[10000] )
1007 %.cpp: %.l
1008         $(Echo) Flexing $*.l
1009         $(Verb) $(FLEX) -t $< | \
1010         $(SED) 's/void yyunput/inline void yyunput/' | \
1011         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1012         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1013           > $@
1014
1015 clean-local::
1016         -$(Verb) $(RM) -f $(LexOutput)
1017         $(Verb) $(RM) -f $(LexOutput)
1018
1019 endif
1020
1021 #---------------------------------------------------------
1022 # Provide rules for generating a .cpp and .h source files 
1023 # from yacc (bison) input sources.
1024 #---------------------------------------------------------
1025
1026 YaccFiles  := $(filter %.y,$(Sources))
1027 ifneq ($(YaccFiles),)
1028 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
1029
1030 .PRECIOUS: $(YaccOutput)
1031
1032 # Cancel built-in rules for yacc
1033 %.c: %.y 
1034 %.cpp: %.y
1035 %.h: %.y
1036
1037 # Rule for building the bison parsers...
1038 %.cpp %.h : %.y
1039         $(Echo) "Bisoning $*.y"
1040         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
1041         $(Verb) $(MV) -f $*.tab.c $*.cpp
1042         $(Verb) $(MV) -f $*.tab.h $*.h
1043
1044 clean-local::
1045         -$(Verb) $(RM) -f $(YaccOutput)
1046         $(Verb) $(RM) -f $(YaccOutput)
1047 endif
1048
1049 ###############################################################################
1050 # OTHER RULES: Other rules needed
1051 ###############################################################################
1052
1053 # To create postscript files from dot files...
1054 ifneq ($(DOT),false)
1055 %.ps: %.dot
1056         $(DOT) -Tps < $< > $@
1057 else
1058 %.ps: %.dot
1059         $(Echo) "Cannot build $@: The program dot is not installed"
1060 endif
1061
1062 # This rules ensures that header files that are removed still have a rule for
1063 # which they can be "generated."  This allows make to ignore them and
1064 # reproduce the dependency lists.
1065 %.h:: ;
1066
1067 # Define clean-local to clean the current directory. Note that this uses a
1068 # very conservative approach ensuring that empty variables do not cause 
1069 # errors or disastrous removal.
1070 clean-local::
1071 ifneq ($(strip $(ObjDir)),)
1072         -$(Verb) $(RM) -rf $(ObjDir)
1073 endif
1074         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1075 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1076         -$(Verb) $(RM) -f *$(SHLIBEXT)
1077 endif
1078
1079 clean-all-local::
1080         -$(Verb) $(RM) -rf Debug Release Profile
1081
1082 # Build tags database for Emacs/Xemacs:
1083 tags:: TAGS CTAGS
1084
1085 TAGS: 
1086         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1087           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1088           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1089           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1090         -name '*.cpp' -o -name '*.h' | \
1091         $(ETAGS) $(ETAGSFLAGS) -
1092
1093 CTAGS:
1094         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1095           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1096           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1097           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1098           \( -name '*.cpp' -o -name '*.h' \) -print | \
1099           ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1100
1101
1102 ###############################################################################
1103 # DEPENDENCIES: Include the dependency files if we should
1104 ###############################################################################
1105 ifndef DISABLE_AUTO_DEPENDENCIES
1106
1107 # If its not one of the cleaning targets
1108 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1109
1110 # Get the list of dependency files
1111 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1112 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1113
1114 -include /dev/null $(DependFiles)
1115
1116 endif
1117
1118 endif 
1119
1120 ###############################################################################
1121 # CHECK: Running the test suite
1122 ###############################################################################
1123
1124 check::
1125         $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1126           if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1127             $(EchoCmd) Running test suite ; \
1128             $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1129               TESTSUITE=$(TESTSUITE) ; \
1130           else \
1131             $(EchoCmd) No Makefile in test directory ; \
1132           fi ; \
1133         else \
1134           $(EchoCmd) No test directory ; \
1135         fi
1136
1137 ###############################################################################
1138 # DISTRIBUTION: Handle construction of a distribution tarball
1139 ###############################################################################
1140
1141 #------------------------------------------------------------------------
1142 # Define distribution related variables
1143 #------------------------------------------------------------------------
1144 DistName    := $(LLVM_TARBALL_NAME)
1145 DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
1146 TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
1147 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1148 DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
1149 DistTarBZ2  := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1150 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1151                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1152                Makefile.config.in configure autoconf
1153 DistOther   := $(notdir $(wildcard \
1154                $(BUILD_SRC_DIR)/*.h \
1155                $(BUILD_SRC_DIR)/*.td \
1156                $(BUILD_SRC_DIR)/*.def \
1157                $(BUILD_SRC_DIR)/*.ll \
1158                $(BUILD_SRC_DIR)/*.in))
1159 DistSubDirs := $(SubDirs)
1160 DistSources  = $(Sources) $(EXTRA_DIST)
1161 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1162
1163 #------------------------------------------------------------------------
1164 # We MUST build distribution with OBJ_DIR != SRC_DIR
1165 #------------------------------------------------------------------------
1166 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1167 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1168         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1169
1170 else
1171
1172 #------------------------------------------------------------------------
1173 # Prevent catastrophic remove
1174 #------------------------------------------------------------------------
1175 ifeq ($(LLVM_TARBALL_NAME),)
1176 $(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
1177 endif
1178
1179 #------------------------------------------------------------------------
1180 # Prevent attempt to run dist targets from anywhere but the top level
1181 #------------------------------------------------------------------------
1182 ifneq ($(LEVEL),.)
1183
1184 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1185         $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
1186
1187 else
1188
1189 #------------------------------------------------------------------------
1190 # Provide the top level targets
1191 #------------------------------------------------------------------------
1192
1193 dist-gzip:: $(DistTarGZip)
1194
1195 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1196         $(Echo) Packing gzipped distribution tar file.
1197         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1198           $(GZIP) -c > "$(DistTarGZip)"
1199
1200 dist-bzip2:: $(DistTarBZ2)
1201
1202 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1203         $(Echo) Packing bzipped distribution tar file.
1204         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1205           $(BZIP2) -c >$(DistTarBZ2)
1206
1207 dist-zip:: $(DistZip)
1208
1209 $(DistZip) : $(TopDistDir)/.makedistdir
1210         $(Echo) Packing zipped distribution file.
1211         $(Verb) rm -f $(DistZip)
1212         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1213
1214 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1215         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1216
1217 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1218
1219 dist-check:: $(DistTarGZip)
1220         $(Echo) Checking distribution tar file.
1221         $(Verb) if test -d $(DistCheckDir) ; then \
1222           $(RM) -rf $(DistCheckDir) ; \
1223         fi
1224         $(Verb) $(MKDIR) $(DistCheckDir)
1225         $(Verb) cd $(DistCheckDir) && \
1226           $(MKDIR) $(DistCheckDir)/build && \
1227           $(MKDIR) $(DistCheckDir)/install && \
1228           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1229           cd build && \
1230           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1231             --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
1232           $(MAKE) all && \
1233           $(MAKE) check && \
1234           $(MAKE) install && \
1235           $(MAKE) uninstall && \
1236           $(MAKE) dist && \
1237           $(MAKE) clean && \
1238           $(MAKE) dist-clean && \
1239           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1240
1241 dist-clean::
1242         $(Echo) Cleaning distribution files
1243         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1244           $(DistCheckDir)
1245
1246 endif
1247
1248 #------------------------------------------------------------------------
1249 # Provide the recursive distdir target for building the distribution directory
1250 #------------------------------------------------------------------------
1251 distdir: $(DistDir)/.makedistdir
1252 $(DistDir)/.makedistdir: $(DistSources)
1253         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1254           if test -d "$(DistDir)" ; then \
1255             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1256               exit 1 ; \
1257           fi ; \
1258           $(EchoCmd) Removing old $(DistDir) ; \
1259           $(RM) -rf $(DistDir); \
1260           $(EchoCmd) Making 'all' to verify build ; \
1261           $(MAKE) all ; \
1262         fi
1263         $(Echo) Building Distribution Directory $(DistDir)
1264         $(Verb) $(MKDIR) $(DistDir) 
1265         $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1266         srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1267         for file in $(DistFiles) ; do \
1268           case "$$file" in \
1269             $(BUILD_SRC_DIR)/*) \
1270               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1271               ;; \
1272             $(BUILD_SRC_ROOT)/*) \
1273               file=`echo "$$file" | \
1274                 sed "s#^$$srcrootstrip/##"` \
1275               ;; \
1276           esac; \
1277           if test -f "$(BUILD_SRC_DIR)/$$file" || \
1278              test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1279             from_dir="$(BUILD_SRC_DIR)" ; \
1280           elif test -f "$$file" || test -d "$$file" ; then \
1281             from_dir=. ; \
1282           fi ; \
1283           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1284           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1285             to_dir="$(DistDir)/$$dir"; \
1286             $(MKDIR) "$$to_dir" ; \
1287           else \
1288             to_dir="$(DistDir)"; \
1289           fi; \
1290           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1291           if test -n "$$mid_dir" ; then \
1292             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1293           fi ; \
1294           if test -d "$$from_dir/$$file"; then \
1295             if test -d "$(BUILD_SRC_DIR)/$$file" && \
1296                test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1297               cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1298             fi; \
1299             cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1300           elif test -f "$$from_dir/$$file" ; then \
1301             cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1302           elif test -L "$$from_dir/$$file" ; then \
1303             cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1304           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1305             $(EchoCmd) "===== WARNING: Distribution Source " \
1306               "$$from_dir/$$file Not Found!" ; \
1307           elif test "$(Verb)" != '@' ; then \
1308             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1309           fi; \
1310         done
1311         $(Verb) for subdir in $(DistSubDirs) ; do \
1312           if test "$$subdir" \!= "." ; then \
1313             new_distdir="$(DistDir)/$$subdir" ; \
1314             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1315             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1316             exit 1; \
1317           fi; \
1318         done
1319         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1320           $(EchoCmd) Eliminating CVS directories from distribution ; \
1321           $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1322           $(MAKE) dist-hook ; \
1323           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1324             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1325             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1326             -o ! -type d ! -perm -444 -exec \
1327               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1328             || chmod -R a+r $(DistDir) ; \
1329         fi
1330
1331 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1332 # defined by user.
1333 dist-hook::
1334
1335 endif
1336
1337 ###############################################################################
1338 # TOP LEVEL - targets only to apply at the top level directory
1339 ###############################################################################
1340
1341 ifeq ($(LEVEL),.)
1342
1343 #------------------------------------------------------------------------
1344 # Install support for the project's include files:
1345 #------------------------------------------------------------------------
1346 install-local::
1347         $(Echo) Installing include files
1348         $(Verb) $(MKDIR) $(includedir)
1349         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1350           cd $(BUILD_SRC_ROOT)/include && \
1351             find . -path '*/Internal' -prune -o '(' -type f \
1352               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1353               -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1354         fi
1355
1356 uninstall-local::
1357         $(Echo) Uninstalling include files
1358         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1359           cd $(BUILD_SRC_ROOT)/include && \
1360             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1361               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1362               -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1363         fi 
1364
1365 endif
1366
1367 #------------------------------------------------------------------------
1368 # Print out the directories used for building
1369 #------------------------------------------------------------------------
1370 printvars::
1371         $(Echo) "BuildMode      : " '$(BuildMode)'
1372         $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1373         $(Echo) "BUILD_SRC_DIR  : " '$(BUILD_SRC_DIR)'
1374         $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1375         $(Echo) "BUILD_OBJ_DIR  : " '$(BUILD_OBJ_DIR)'
1376         $(Echo) "LLVM_SRC_ROOT  : " '$(LLVM_SRC_ROOT)'
1377         $(Echo) "LLVM_OBJ_ROOT  : " '$(LLVM_OBJ_ROOT)'
1378         $(Echo) "libdir         : " '$(libdir)'
1379         $(Echo) "bindir         : " '$(bindir)'
1380         $(Echo) "sysconfdir     : " '$(sysconfdir)'
1381         $(Echo) "UserTargets    : " '$(UserTargets)'
1382         $(Echo) "ObjMakefiles   : " '$(ObjMakefiles)'
1383         $(Echo) "SrcMakefiles   : " '$(SrcMakefiles)'
1384         $(Echo) "ObjDir         : " '$(ObjDir)'
1385         $(Echo) "LibDir         : " '$(LibDir)'
1386         $(Echo) "ToolDir        : " '$(ToolDir)'
1387         $(Echo) "ExmplDir       : " '$(ExmplDir)'
1388         $(Echo) "Sources        : " '$(Sources)'
1389         $(Echo) "TDFiles        : " '$(TDFiles)'
1390         $(Echo) "INCFiles       : " '$(INCFiles)'
1391         $(Echo) "Compile.CXX    : " '$(Compile.CXX)'
1392         $(Echo) "Compile.C      : " '$(Compile.C)'
1393         $(Echo) "Archive        : " '$(Archive)'
1394         $(Echo) "YaccFiles      : " '$(YaccFiles)'
1395         $(Echo) "LexFiles       : " '$(LexFiles)'
1396         $(Echo) "Module         : " '$(Module)'