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