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