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