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