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