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