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