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