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