[PR2886] Ignore stderr from ocamlc since it prints unresolvable warnings on some...
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # 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 dist-gzip dist-bzip2 \
27                     dist-zip
28 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29 InternalTargets  := preconditions distdir dist-hook
30
31 ################################################################################
32 # INITIALIZATION: Basic things the makefile needs
33 ################################################################################
34
35 #--------------------------------------------------------------------
36 # Set the VPATH so that we can find source files.
37 #--------------------------------------------------------------------
38 VPATH=$(PROJ_SRC_DIR)
39
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build.
42 #--------------------------------------------------------------------
43 .SUFFIXES:
44 .SUFFIXES: .c .cpp .cc .h .hpp .y .l .lo .o .a .bc .td .ps .dot .ll
45 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46
47 #--------------------------------------------------------------------
48 # Mark all of these targets as phony to avoid implicit rule search
49 #--------------------------------------------------------------------
50 .PHONY: $(UserTargets) $(InternalTargets)
51
52 #--------------------------------------------------------------------
53 # Make sure all the user-target rules are double colon rules and 
54 # they are defined first.
55 #--------------------------------------------------------------------
56
57 $(UserTargets)::
58
59 ################################################################################
60 # PRECONDITIONS: that which must be built/checked first
61 ################################################################################
62
63 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
64                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
67 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
71 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
72 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
73 ifneq ($(MakefileCommonIn),)
74 PreConditions      += $(MakefileCommon)
75 endif
76
77 ifneq ($(MakefileConfigIn),)
78 PreConditions      += $(MakefileConfig)
79 endif
80
81 preconditions: $(PreConditions)
82
83 #------------------------------------------------------------------------
84 # Make sure the BUILT_SOURCES are built first
85 #------------------------------------------------------------------------
86 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
87
88 clean-all-local::
89 ifneq ($(strip $(BUILT_SOURCES)),)
90         -$(Verb) $(RM) -f $(BUILT_SOURCES)
91 endif
92
93 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94 spotless:
95         $(Verb) if test -x config.status ; then \
96           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
97           $(MKDIR) .spotless.save ; \
98           $(MV) config.status .spotless.save ; \
99           $(MV) mklib  .spotless.save ; \
100           $(MV) projects  .spotless.save ; \
101           $(RM) -rf * ; \
102           $(MV) .spotless.save/config.status . ; \
103           $(MV) .spotless.save/mklib . ; \
104           $(MV) .spotless.save/projects . ; \
105           $(RM) -rf .spotless.save ; \
106           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
107           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108           $(ConfigStatusScript) ; \
109         else \
110           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
111         fi
112 else
113 spotless:
114         $(EchoCmd) "spotless target not supported for objdir == srcdir"
115 endif
116
117 $(BUILT_SOURCES) : $(ObjMakefiles)
118
119 #------------------------------------------------------------------------
120 # Make sure we're not using a stale configuration
121 #------------------------------------------------------------------------
122 reconfigure:
123         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124         $(Verb) cd $(PROJ_OBJ_ROOT) && \
125           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127           fi ; \
128           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129           $(ConfigStatusScript)
130
131 .PRECIOUS: $(ConfigStatusScript)
132 $(ConfigStatusScript): $(ConfigureScript)
133         $(Echo) Reconfiguring with $<
134         $(Verb) cd $(PROJ_OBJ_ROOT) && \
135           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
136             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137           fi ; \
138           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
139           $(ConfigStatusScript)
140
141 #------------------------------------------------------------------------
142 # Make sure the configuration makefile is up to date
143 #------------------------------------------------------------------------
144 ifneq ($(MakefileConfigIn),)
145 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
146         $(Echo) Regenerating $@
147         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
148 endif
149
150 ifneq ($(MakefileCommonIn),)
151 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
152         $(Echo) Regenerating $@
153         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
154 endif
155
156 #------------------------------------------------------------------------
157 # If the Makefile in the source tree has been updated, copy it over into the
158 # build tree. But, only do this if the source and object makefiles differ
159 #------------------------------------------------------------------------
160 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161
162 Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
163         $(Echo) "Updating Makefile"
164         $(Verb) $(MKDIR) $(@D)
165         $(Verb) $(CP) -f $< $@
166
167 # Copy the Makefile.* files unless we're in the root directory which avoids
168 # the copying of Makefile.config.in or other things that should be explicitly
169 # taken care of.
170 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171         @case '$?' in \
172           *Makefile.rules) ;; \
173           *.in) ;; \
174           *) $(EchoCmd) "Updating $(@F)" ; \
175              $(MKDIR) $(@D) ; \
176              $(CP) -f $< $@ ;; \
177         esac
178
179 endif
180
181 #------------------------------------------------------------------------
182 # Set up the basic dependencies
183 #------------------------------------------------------------------------
184 $(UserTargets):: $(PreConditions)
185
186 all:: all-local
187 clean:: clean-local 
188 clean-all:: clean-local clean-all-local
189 install:: install-local
190 uninstall:: uninstall-local
191 install-local:: all-local 
192 install-bytecode:: install-bytecode-local
193
194 ###############################################################################
195 # VARIABLES: Set up various variables based on configuration data
196 ###############################################################################
197
198 # Variable for if this make is for a "cleaning" target
199 ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
200   IS_CLEANING_TARGET=1
201 endif
202
203 #--------------------------------------------------------------------
204 # Variables derived from configuration we are building
205 #--------------------------------------------------------------------
206
207 CPP.Defines :=
208 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
209 # this can be overridden on the make command line.
210 ifneq ($(OS),MingW)
211   OPTIMIZE_OPTION := -O3
212 else
213   OPTIMIZE_OPTION := -O2
214 endif
215
216 ifdef ENABLE_PROFILING
217   BuildMode := Profile
218   CXX.Flags += $(OPTIMIZE_OPTION) -pg -g
219   C.Flags   += $(OPTIMIZE_OPTION) -pg -g
220   LD.Flags  += $(OPTIMIZE_OPTION) -pg -g
221   KEEP_SYMBOLS := 1
222 else
223   ifeq ($(ENABLE_OPTIMIZED),1)
224     BuildMode := Release
225     # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
226     ifneq ($(OS),FreeBSD)
227     ifneq ($(OS),Darwin)
228       OmitFramePointer := -fomit-frame-pointer
229     endif
230     endif
231
232     # Darwin requires -fstrict-aliasing to be explicitly enabled.
233     ifeq ($(OS),Darwin)
234       EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
235     endif
236
237     CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
238     C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
239     LD.Flags  += $(OPTIMIZE_OPTION)
240   else
241     BuildMode := Debug
242     CXX.Flags += -g
243     C.Flags   += -g
244     LD.Flags  += -g
245     KEEP_SYMBOLS := 1
246   endif
247 endif
248
249 #ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
250 #    CXX.Flags += -fvisibility-inlines-hidden
251 #endif
252
253 # IF REQUIRES_EH=1 is specified then don't disable exceptions
254 ifndef REQUIRES_EH
255   CXX.Flags += -fno-exceptions
256 endif
257
258 # IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
259 ifndef REQUIRES_RTTI
260 #  CXX.Flags += -fno-rtti
261 endif
262
263 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
264 # then disable assertions by defining the appropriate preprocessor symbols.
265 ifdef DISABLE_ASSERTIONS
266   BuildMode := $(BuildMode)-Asserts
267   CPP.Defines += -DNDEBUG
268 else
269   CPP.Defines += -D_DEBUG
270 endif
271
272 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or 
273 # configured), then enable expensive checks by defining the 
274 # appropriate preprocessor symbols.
275 ifdef ENABLE_EXPENSIVE_CHECKS
276   BuildMode := $(BuildMode)+Checks
277   CPP.Defines += -D_GLIBCXX_DEBUG
278 endif
279
280 ifeq ($(ENABLE_PIC),1)
281   CXX.Flags += -fPIC
282   C.Flags   += -fPIC
283 endif
284
285 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
286 C.Flags       += $(CFLAGS)
287 CPP.Defines   += $(CPPFLAGS)
288 CPP.BaseFlags += $(CPP.Defines)
289 LD.Flags      += $(LDFLAGS)
290 AR.Flags      := cru
291 LibTool.Flags := --tag=CXX
292
293 # Make Floating point IEEE compliant on Alpha.
294 ifeq ($(ARCH),Alpha)
295   CXX.Flags     += -mieee
296   CPP.BaseFlags += -mieee
297 ifeq ($(ENABLE_PIC),0)
298   CXX.Flags     += -fPIC
299   CPP.BaseFlags += -fPIC
300 endif
301 endif
302
303 ifeq ($(ARCH),Alpha)
304   LD.Flags += -Wl,--no-relax
305 endif
306
307 #--------------------------------------------------------------------
308 # Directory locations
309 #--------------------------------------------------------------------
310 TargetMode :=
311 ifeq ($(LLVM_CROSS_COMPILING),1)
312   ifeq ($(BUILD_COMPONENT),1)
313     TargetMode := Build
314   else
315     TargetMode := Host
316   endif
317   BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/Build/bin
318 endif
319
320 ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
321 # It is very important that ObjDir not have an extra trailing
322 # slash. This ends up changing the rules so that dependency file (.d)
323 # information is not used at all!
324 ifeq ($(TargetMode),)
325   ObjDir      := $(ObjRootDir)
326 else
327   ObjDir      := $(ObjRootDir)/$(TargetMode)
328 endif
329 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/lib
330 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/bin
331 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/examples
332 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/lib
333 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/bin
334 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/$(TargetMode)/examples
335 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
336
337 #--------------------------------------------------------------------
338 # Full Paths To Compiled Tools and Utilities
339 #--------------------------------------------------------------------
340 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
341 Echo     = @$(EchoCmd)
342 ifndef LIBTOOL
343 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
344 endif
345 ifndef LLVMAS
346 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
347 endif
348 ifndef TBLGEN
349   ifeq ($(LLVM_CROSS_COMPILING),1)
350     TBLGEN   := $(BuildLLVMToolDir)/tblgen$(EXEEXT)
351   else
352     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
353   endif
354 endif
355 LLVM_CONFIG := $(LLVMToolDir)/llvm-config 
356 ifndef LLVMLD
357 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
358 endif
359 ifndef LLVMDIS
360 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
361 endif
362 ifndef LLI
363 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
364 endif
365 ifndef LLC
366 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
367 endif
368 ifndef LOPT
369 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
370 endif
371 ifndef LBUGPOINT
372 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
373 endif
374 ifndef LUPGRADE
375 LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
376 endif
377 ifeq ($(LLVMGCC_MAJVERS),3)
378 UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
379 UPGRADE_LL  = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
380 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
381 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
382 else
383 UPGRADE_MSG =
384 UPGRADE_LL  =
385 LLVMGCCWITHPATH  := $(LLVMGCC)
386 LLVMGXXWITHPATH  := $(LLVMGXX)
387 endif
388
389 #--------------------------------------------------------------------
390 # Adjust to user's request
391 #--------------------------------------------------------------------
392
393 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
394 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
395 # shared library can be opened with dlopen. Also, LOADABLE_MODULE implies 
396 # several other things so we force them to be defined/on.
397 ifdef LOADABLE_MODULE
398   SHARED_LIBRARY := 1
399   DONT_BUILD_RELINKED := 1
400   LINK_LIBS_IN_SHARED := 1
401   LD.Flags += -module
402 endif
403
404 ifdef SHARED_LIBRARY
405   LD.Flags += -rpath $(LibDir)
406 else
407   LibTool.Flags += --tag=disable-shared
408 endif
409
410 ifdef TOOL_VERBOSE
411   C.Flags += -v
412   CXX.Flags += -v
413   LD.Flags += -v
414   VERBOSE := 1
415 endif
416
417 # Adjust settings for verbose mode
418 ifndef VERBOSE
419   Verb := @
420   LibTool.Flags += --silent
421   AR.Flags += >/dev/null 2>/dev/null
422   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
423 else
424   ConfigureScriptFLAGS := 
425 endif
426
427 # By default, strip symbol information from executable
428 ifndef KEEP_SYMBOLS
429   Strip := $(PLATFORMSTRIPOPTS)
430   StripWarnMsg := "(without symbols)"
431   Install.StripFlag += -s
432 endif
433
434 # Adjust linker flags for building an executable
435 ifdef TOOLNAME
436 ifdef EXAMPLE_TOOL
437   LD.Flags += -rpath $(ExmplDir) -export-dynamic
438 else
439   LD.Flags += -rpath $(ToolDir) -export-dynamic
440 endif
441 endif
442
443 #----------------------------------------------------------
444 # Options To Invoke Tools
445 #----------------------------------------------------------
446
447 CompileCommonOpts := -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
448                      -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
449
450 ifeq ($(OS),HP-UX)
451   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
452 endif
453
454 # If we are building a universal binary on Mac OS/X, pass extra options.  This
455 # is useful to people that want to link the LLVM libraries into their universal
456 # apps.
457 #
458 # The following can be optionally specified:
459 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
460 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
461 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
462 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
463 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
464 #      i386/ppc only.
465 ifdef UNIVERSAL
466   ifndef UNIVERSAL_ARCH
467     UNIVERSAL_ARCH := i386 ppc
468   endif
469   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
470   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
471   Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS:%=-XCClinker %)
472   ifdef UNIVERSAL_SDK_PATH
473     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
474     Relink.Flags      += -XCClinker -isysroot -XCClinker $(UNIVERSAL_SDK_PATH)
475   endif
476
477   # Building universal cannot compute dependencies automatically.
478   DISABLE_AUTO_DEPENDENCIES=1
479 endif
480
481 ifeq ($(OS),SunOS)
482 CPP.BaseFlags += -include llvm/System/Solaris.h
483 endif
484
485 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir) 
486 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
487 # All -I flags should go here, so that they don't confuse llvm-config.
488 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
489                  $(patsubst %,-I%/include,\
490                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
491                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
492                  $(CPP.BaseFlags)
493
494  ifeq ($(BUILD_COMPONENT), 1)
495   Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
496   Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
497   Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
498   Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
499                   $(LD.Flags) $(Strip)
500   Relink        = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
501                   $(Relink.Flags)
502 else
503   Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
504   Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
505   Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
506   Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
507                   $(LD.Flags) $(Strip)
508   Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
509                   $(Relink.Flags)
510 endif
511
512 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
513 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
514 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
515
516 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
517 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
518                 $(CompileCommonOpts)
519
520 LTLink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Link)
521 LTRelink      = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Relink)
522 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
523                 $(Install.Flags)
524 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
525 ScriptInstall = $(INSTALL) -m 0755 
526 DataInstall   = $(INSTALL) -m 0644
527
528 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
529 # paths. In this case, the SYSPATH function (defined in
530 # Makefile.config) transforms Unix paths into Windows paths.
531 TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
532                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
533                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
534
535 Archive       = $(AR) $(AR.Flags)
536 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
537 ifdef RANLIB
538 Ranlib        = $(RANLIB)
539 else
540 Ranlib        = ranlib
541 endif
542
543 #----------------------------------------------------------
544 # Get the list of source files and compute object file 
545 # names from them. 
546 #----------------------------------------------------------
547
548 ifndef SOURCES
549   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
550              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
551              $(PROJ_SRC_DIR)/*.l))
552 else
553   Sources := $(SOURCES)
554 endif 
555
556 ifdef BUILT_SOURCES
557 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
558 endif
559
560 BaseNameSources := $(sort $(basename $(Sources)))
561
562 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
563 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
564 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
565
566 ###############################################################################
567 # DIRECTORIES: Handle recursive descent of directory structure
568 ###############################################################################
569
570 #---------------------------------------------------------
571 # Provide rules to make install dirs. This must be early
572 # in the file so they get built before dependencies
573 #---------------------------------------------------------
574
575 $(PROJ_bindir): $(PROJ_bindir)/.dir
576 $(PROJ_libdir): $(PROJ_libdir)/.dir
577 $(PROJ_includedir): $(PROJ_includedir)/.dir
578 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
579
580 # To create other directories, as needed, and timestamp their creation
581 %/.dir:
582         $(Verb) $(MKDIR) $* > /dev/null
583         $(Verb) $(DATE) > $@
584
585 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
586 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
587
588 #---------------------------------------------------------
589 # Handle the DIRS options for sequential construction
590 #---------------------------------------------------------
591
592 SubDirs := 
593 ifdef DIRS
594 SubDirs += $(DIRS)
595
596 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
597 ifdef BUILD_TARGET_DIRS
598 $(RecursiveTargets)::
599         $(Verb) for dir in $(BUILD_TARGET_DIRS); do \
600             if [ ! -f $$dir/Makefile ]; then \
601             $(MKDIR) $$dir; \
602               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
603             fi; \
604             ($(MAKE) -C $$dir $@ BUILD_COMPONENT=1 NO_INSTALL=1 ) || exit 1; \
605           done
606 endif
607 $(RecursiveTargets)::
608         $(Verb) for dir in $(DIRS); do \
609           if [ ! -f $$dir/Makefile ]; then \
610             $(MKDIR) $$dir; \
611             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
612           fi; \
613           ($(MAKE) -C $$dir $@ ) || exit 1; \
614         done
615 else
616 ifdef BUILD_TARGET_DIRS
617 $(RecursiveTargets)::
618         $(Verb) for dir in $(BUILD_TARGET_DIRS); do \
619             ($(MAKE) -C $$dir $@ BUILD_COMPONENT=1 NO_INSTALL=1 ) || exit 1; \
620           done
621 endif
622 $(RecursiveTargets)::
623         $(Verb) for dir in $(DIRS); do \
624           ($(MAKE) -C $$dir $@ ) || exit 1; \
625         done
626 endif
627
628 endif
629
630 #---------------------------------------------------------
631 # Handle the EXPERIMENTAL_DIRS options ensuring success
632 # after each directory is built.
633 #---------------------------------------------------------
634 ifdef EXPERIMENTAL_DIRS
635 $(RecursiveTargets)::
636         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
637           if [ ! -f $$dir/Makefile ]; then \
638             $(MKDIR) $$dir; \
639             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
640           fi; \
641           ($(MAKE) -C $$dir $@ ) || exit 0; \
642         done
643 endif
644
645 #-----------------------------------------------------------
646 # Handle the PARALLEL_DIRS options for parallel construction
647 #-----------------------------------------------------------
648 ifdef PARALLEL_DIRS
649
650 SubDirs += $(PARALLEL_DIRS)
651
652 # Unfortunately, this list must be maintained if new recursive targets are added
653 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
654 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
655 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
656 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
657 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
658 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
659
660 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
661
662 $(ParallelTargets) :
663         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
664           $(MKDIR) $(@D); \
665           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
666         fi; \
667         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
668 endif
669
670 #---------------------------------------------------------
671 # Handle the OPTIONAL_DIRS options for directores that may
672 # or may not exist.
673 #---------------------------------------------------------
674 ifdef OPTIONAL_DIRS
675
676 SubDirs += $(OPTIONAL_DIRS)
677
678 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
679 $(RecursiveTargets)::
680         $(Verb) for dir in $(OPTIONAL_DIRS); do \
681           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
682             if [ ! -f $$dir/Makefile ]; then \
683               $(MKDIR) $$dir; \
684               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
685             fi; \
686             ($(MAKE) -C$$dir $@ ) || exit 1; \
687           fi \
688         done
689 else
690 $(RecursiveTargets)::
691         $(Verb) for dir in $(OPTIONAL_DIRS); do \
692           ($(MAKE) -C$$dir $@ ) || exit 1; \
693         done
694 endif
695 endif
696
697 #---------------------------------------------------------
698 # Handle the CONFIG_FILES options
699 #---------------------------------------------------------
700 ifdef CONFIG_FILES
701
702 ifdef NO_INSTALL
703 install-local::
704         $(Echo) Install circumvented with NO_INSTALL
705 uninstall-local::
706         $(Echo) UnInstall circumvented with NO_INSTALL
707 else
708 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
709         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
710         $(Verb)for file in $(CONFIG_FILES); do \
711           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
712             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
713           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
714             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
715           else \
716             $(ECHO) Error: cannot find config file $${file}. ; \
717           fi \
718         done
719
720 uninstall-local::
721         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
722         $(Verb)for file in $(CONFIG_FILES); do \
723           $(RM) -f $(PROJ_etcdir)/$${file} ; \
724         done
725 endif
726
727 endif
728
729 ###############################################################################
730 # Set up variables for building libararies
731 ###############################################################################
732
733 #---------------------------------------------------------
734 # Define various command line options pertaining to the
735 # libraries needed when linking. There are "Proj" libs 
736 # (defined by the user's project) and "LLVM" libs (defined 
737 # by the LLVM project).
738 #---------------------------------------------------------
739
740 ifdef USEDLIBS
741 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
742 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
743 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
744 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
745 endif
746
747 ifdef LLVMLIBS
748 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
749 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
750 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
751 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
752 endif
753
754 ifndef IS_CLEANING_TARGET
755 ifdef LINK_COMPONENTS
756
757 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
758 # clean in tools, then do a make in tools (instead of at the top level).
759 $(LLVM_CONFIG):
760         @echo "*** llvm-config doesn't exist - rebuilding it."
761         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
762
763 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
764
765 ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
766 ProjLibsPaths   += $(LLVM_CONFIG) \
767                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
768 endif
769 endif
770
771 ###############################################################################
772 # Library Build Rules: Four ways to build a library
773 ###############################################################################
774
775 #---------------------------------------------------------
776 # Bytecode Module Targets:
777 #   If the user set MODULE_NAME then they want to build a
778 #   bytecode module from the sources. We compile all the
779 #   sources and link it together into a single bytecode
780 #   module.
781 #---------------------------------------------------------
782
783 ifdef MODULE_NAME
784 ifeq ($(strip $(LLVMGCC)),)
785 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
786 else
787
788 Module     := $(LibDir)/$(MODULE_NAME).bc
789 LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
790
791
792 ifdef EXPORTED_SYMBOL_FILE
793 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
794 endif
795
796 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
797         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
798         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
799
800 all-local:: $(Module)
801
802 clean-local::
803 ifneq ($(strip $(Module)),)
804         -$(Verb) $(RM) -f $(Module)
805 endif
806
807 ifdef BYTECODE_DESTINATION
808 ModuleDestDir := $(BYTECODE_DESTINATION)
809 else
810 ModuleDestDir := $(PROJ_libdir)
811 endif
812
813 ifdef NO_INSTALL
814 install-local::
815         $(Echo) Install circumvented with NO_INSTALL
816 uninstall-local::
817         $(Echo) Uninstall circumvented with NO_INSTALL
818 else
819 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
820
821 install-module:: $(DestModule)
822 install-local:: $(DestModule)
823
824 $(DestModule): $(ModuleDestDir) $(Module) 
825         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
826         $(Verb) $(DataInstall) $(Module) $(DestModule)
827
828 uninstall-local::
829         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
830         -$(Verb) $(RM) -f $(DestModule)
831 endif
832
833 endif
834 endif
835
836 # if we're building a library ...
837 ifdef LIBRARYNAME
838
839 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
840 LIBRARYNAME := $(strip $(LIBRARYNAME))
841 ifdef LOADABLE_MODULE
842 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
843 else
844 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
845 endif
846 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
847 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
848 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
849
850 #---------------------------------------------------------
851 # Shared Library Targets:
852 #   If the user asked for a shared library to be built
853 #   with the SHARED_LIBRARY variable, then we provide
854 #   targets for building them.
855 #---------------------------------------------------------
856 ifdef SHARED_LIBRARY
857
858 all-local:: $(LibName.LA)
859
860 ifdef LINK_LIBS_IN_SHARED
861 ifdef LOADABLE_MODULE
862 SharedLibKindMessage := "Loadable Module"
863 else
864 SharedLibKindMessage := "Shared Library"
865 endif
866 $(LibName.LA): $(ObjectsLO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
867         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
868           $(LIBRARYNAME)$(SHLIBEXT)
869         $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
870           $(LLVMLibsOptions)
871         $(Verb) $(LTInstall) $@ $(LibDir)
872 else
873 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
874         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
875         $(Verb) $(LTLink) -o $@ $(ObjectsLO)
876         $(Verb) $(LTInstall) $@ $(LibDir)
877 endif
878
879 clean-local::
880 ifneq ($(strip $(LibName.LA)),)
881         -$(Verb) $(RM) -f $(LibName.LA)
882 endif
883
884 ifdef NO_INSTALL
885 install-local::
886         $(Echo) Install circumvented with NO_INSTALL
887 uninstall-local::
888         $(Echo) Uninstall circumvented with NO_INSTALL
889 else
890 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
891
892 install-local:: $(DestSharedLib)
893
894 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
895         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
896         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
897         $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
898
899 uninstall-local:: 
900         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
901         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
902 endif
903 endif
904
905 #---------------------------------------------------------
906 # Bytecode Library Targets:
907 #   If the user asked for a bytecode library to be built
908 #   with the BYTECODE_LIBRARY variable, then we provide 
909 #   targets for building them.
910 #---------------------------------------------------------
911 ifdef BYTECODE_LIBRARY
912 ifeq ($(strip $(LLVMGCC)),)
913 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
914 else
915
916 all-local:: $(LibName.BCA)
917
918 ifdef EXPORTED_SYMBOL_FILE
919 BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
920                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
921
922 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
923                 $(LLVMToolDir)/llvm-ar
924         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
925           "(internalize)"
926         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
927         $(Verb) $(RM) -f $@
928         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
929 else
930 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
931                 $(LLVMToolDir)/llvm-ar
932         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
933         $(Verb) $(RM) -f $@
934         $(Verb) $(LArchive) $@ $(ObjectsBC)
935
936 endif
937
938 clean-local::
939 ifneq ($(strip $(LibName.BCA)),)
940         -$(Verb) $(RM) -f $(LibName.BCA)
941 endif
942
943 ifdef BYTECODE_DESTINATION
944 BytecodeDestDir := $(BYTECODE_DESTINATION)
945 else
946 BytecodeDestDir := $(PROJ_libdir)
947 endif
948
949 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
950
951 install-bytecode-local:: $(DestBytecodeLib)
952
953 ifdef NO_INSTALL
954 install-local::
955         $(Echo) Install circumvented with NO_INSTALL
956 uninstall-local::
957         $(Echo) Uninstall circumvented with NO_INSTALL
958 else
959 install-local:: $(DestBytecodeLib)
960
961 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
962         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
963         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
964
965 uninstall-local::
966         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
967         -$(Verb) $(RM) -f $(DestBytecodeLib)
968 endif
969 endif
970 endif
971
972 #---------------------------------------------------------
973 # ReLinked Library Targets:
974 #   If the user explicitly requests a relinked library with
975 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
976 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
977 #   them one.
978 #---------------------------------------------------------
979 ifndef BUILD_ARCHIVE
980 ifndef DONT_BUILD_RELINKED
981 BUILD_RELINKED = 1
982 endif
983 endif
984
985 ifdef BUILD_RELINKED
986
987 all-local:: $(LibName.O)
988
989 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
990         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
991         $(Verb) $(LTRelink) -o $@ $(ObjectsO)
992
993 clean-local::
994 ifneq ($(strip $(LibName.O)),)
995         -$(Verb) $(RM) -f $(LibName.O)
996 endif
997
998 ifdef NO_INSTALL
999 install-local::
1000         $(Echo) Install circumvented with NO_INSTALL
1001 uninstall-local::
1002         $(Echo) Uninstall circumvented with NO_INSTALL
1003 else
1004 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
1005
1006 install-local:: $(DestRelinkedLib)
1007
1008 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
1009         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
1010         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
1011
1012 uninstall-local::
1013         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
1014         -$(Verb) $(RM) -f $(DestRelinkedLib)
1015 endif
1016 endif
1017
1018 #---------------------------------------------------------
1019 # Archive Library Targets:
1020 #   If the user wanted a regular archive library built, 
1021 #   then we provide targets for building them.
1022 #---------------------------------------------------------
1023 ifdef BUILD_ARCHIVE
1024
1025 all-local:: $(LibName.A)
1026
1027 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
1028         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1029         -$(Verb) $(RM) -f $@
1030         $(Verb) $(Archive) $@ $(ObjectsO)
1031         $(Verb) $(Ranlib) $@
1032
1033 clean-local::
1034 ifneq ($(strip $(LibName.A)),)
1035         -$(Verb) $(RM) -f $(LibName.A)
1036 endif
1037
1038 ifdef NO_INSTALL
1039 install-local::
1040         $(Echo) Install circumvented with NO_INSTALL
1041 uninstall-local::
1042         $(Echo) Uninstall circumvented with NO_INSTALL
1043 else
1044 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
1045
1046 install-local:: $(DestArchiveLib)
1047
1048 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
1049         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1050         $(Verb) $(MKDIR) $(PROJ_libdir)
1051         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
1052
1053 uninstall-local::
1054         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1055         -$(Verb) $(RM) -f $(DestArchiveLib)
1056 endif
1057 endif
1058
1059 # endif LIBRARYNAME
1060 endif 
1061
1062 ###############################################################################
1063 # Tool Build Rules: Build executable tool based on TOOLNAME option
1064 ###############################################################################
1065
1066 ifdef TOOLNAME
1067
1068 #---------------------------------------------------------
1069 # Set up variables for building a tool.
1070 #---------------------------------------------------------
1071 ifdef EXAMPLE_TOOL
1072 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1073 else
1074 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1075 endif
1076
1077 #---------------------------------------------------------
1078 # Provide targets for building the tools
1079 #---------------------------------------------------------
1080 all-local:: $(ToolBuildPath)
1081
1082 clean-local::
1083 ifneq ($(strip $(ToolBuildPath)),)
1084         -$(Verb) $(RM) -f $(ToolBuildPath)
1085 endif
1086
1087 ifdef EXAMPLE_TOOL
1088 $(ToolBuildPath): $(ExmplDir)/.dir
1089 else
1090 $(ToolBuildPath): $(ToolDir)/.dir
1091 endif
1092
1093 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1094         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1095         $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1096         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1097         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1098           $(StripWarnMsg) 
1099
1100 ifdef NO_INSTALL
1101 install-local::
1102         $(Echo) Install circumvented with NO_INSTALL
1103 uninstall-local::
1104         $(Echo) Uninstall circumvented with NO_INSTALL
1105 else
1106 DestTool = $(PROJ_bindir)/$(TOOLNAME)
1107
1108 install-local:: $(DestTool)
1109
1110 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
1111         $(Echo) Installing $(BuildMode) $(DestTool)
1112         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1113
1114 uninstall-local::
1115         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1116         -$(Verb) $(RM) -f $(DestTool)
1117 endif
1118 endif
1119
1120 ###############################################################################
1121 # Object Build Rules: Build object files based on sources 
1122 ###############################################################################
1123
1124 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1125 ifeq ($(OS),HP-UX)
1126   DISABLE_AUTO_DEPENDENCIES=1
1127 endif
1128
1129 ifdef SHARED_LIBRARY
1130 PIC_FLAG = "(PIC)"
1131 MAYBE_PIC_Compile.CXX = $(LTCompile.CXX)
1132 MAYBE_PIC_Compile.C = $(LTCompile.C)
1133 else
1134 MAYBE_PIC_Compile.CXX = $(Compile.CXX)
1135 MAYBE_PIC_Compile.C = $(Compile.C)
1136 endif
1137
1138 # Provide rule sets for when dependency generation is enabled
1139 ifndef DISABLE_AUTO_DEPENDENCIES
1140
1141 #---------------------------------------------------------
1142 # Create .lo files in the ObjDir directory from the .cpp and .c files...
1143 #---------------------------------------------------------
1144
1145 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1146          -MT "$(ObjDir)/$*.lo" -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1147
1148 # If the build succeeded, move the dependency file over.  If it failed, put an
1149 # empty file there.
1150 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1151                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1152
1153 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1154         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1155         $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1156                 $(DEPEND_MOVEFILE)
1157
1158 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1159         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1160         $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1161                 $(DEPEND_MOVEFILE)
1162
1163 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1164         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1165         $(Verb) if $(MAYBE_PIC_Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1166                 $(DEPEND_MOVEFILE)
1167
1168 #---------------------------------------------------------
1169 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1170 #---------------------------------------------------------
1171
1172 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1173         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1174         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1175                               $< -o $@ -S -emit-llvm ; \
1176         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1177         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1178         $(call UPGRADE_MSG,$@) 
1179         $(call UPGRADE_LL,$@)
1180
1181 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1182         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1183         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1184                               $< -o $@ -S -emit-llvm ; \
1185         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1186         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1187         $(call UPGRADE_MSG,$@) 
1188         $(call UPGRADE_LL,$@)
1189
1190 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1191         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1192         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1193                             $< -o $@ -S -emit-llvm ; \
1194         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1195         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1196         $(call UPGRADE_MSG,$@) 
1197         $(call UPGRADE_LL,$@)
1198
1199 # Provide alternate rule sets if dependencies are disabled
1200 else
1201
1202 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1203         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1204         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1205
1206 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1207         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1208         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1209
1210 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1211         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1212         $(MAYBE_PIC_Compile.C) $< -o $@ 
1213
1214 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1215         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1216         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1217         $(call UPGRADE_MSG,$@) 
1218         $(call UPGRADE_LL,$@)
1219
1220 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1221         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1222         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1223         $(call UPGRADE_MSG,$@) 
1224         $(call UPGRADE_LL,$@)
1225
1226 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1227         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1228         $(BCCompile.C) $< -o $@ -S -emit-llvm
1229         $(call UPGRADE_MSG,@) 
1230         $(call UPGRADE_LL,@)
1231
1232 endif
1233
1234
1235 ## Rules for building preprocessed (.i/.ii) outputs.
1236 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1237         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1238         $(Verb) $(Preprocess.CXX) $< -o $@
1239
1240 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1241         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1242         $(Verb) $(Preprocess.CXX) $< -o $@
1243
1244 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1245         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1246         $(Verb) $(Preprocess.C) $< -o $@
1247
1248
1249 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1250         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1251         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1252
1253 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1254         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1255         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1256
1257 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1258         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1259         $(MAYBE_PIC_Compile.C) $< -o $@ -S
1260
1261
1262 # make the C and C++ compilers strip debug info out of bytecode libraries.
1263 ifdef DEBUG_RUNTIME
1264 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1265         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1266         $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1267 else
1268 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1269         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1270         $(Verb) $(LLVMAS) $< -o - | \
1271            $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1272 endif
1273
1274
1275 #---------------------------------------------------------
1276 # Provide rule to build .bc files from .ll sources,
1277 # regardless of dependencies
1278 #---------------------------------------------------------
1279 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1280         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1281         $(Verb) $(LLVMAS) $< -f -o $@
1282
1283 ###############################################################################
1284 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1285 ###############################################################################
1286
1287 ifdef TARGET
1288
1289 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1290            $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1291            $(LLVM_SRC_ROOT)/lib/Target/TargetCallingConv.td \
1292            $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td \
1293            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1294            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1295 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1296 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1297 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1298
1299 # All of these files depend on tblgen and the .td files.
1300 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1301
1302 # INCFiles rule: All of the tblgen generated files are emitted to 
1303 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1304 # us to only "touch" the real file if the contents of it change.  IOW, if
1305 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1306 # dependencies of the .inc files are, unless the contents of the .inc file
1307 # changes.
1308 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1309         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1310
1311 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1312 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1313         $(Echo) "Building $(<F) register names with tblgen"
1314         $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
1315
1316 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1317 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1318         $(Echo) "Building $(<F) register information header with tblgen"
1319         $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
1320
1321 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1322 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1323         $(Echo) "Building $(<F) register info implementation with tblgen"
1324         $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
1325
1326 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1327 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1328         $(Echo) "Building $(<F) instruction names with tblgen"
1329         $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
1330
1331 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1332 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1333         $(Echo) "Building $(<F) instruction information with tblgen"
1334         $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
1335
1336 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1337 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1338         $(Echo) "Building $(<F) assembly writer with tblgen"
1339         $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1340
1341 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1342 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1343         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1344         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $< 
1345
1346 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1347 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1348         $(Echo) "Building $(<F) code emitter with tblgen"
1349         $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1350
1351 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1352 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1353         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1354         $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1355
1356 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1357 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1358         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1359         $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1360
1361 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1362 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1363         $(Echo) "Building $(<F) subtarget information with tblgen"
1364         $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1365
1366 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1367 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1368         $(Echo) "Building $(<F) calling convention information with tblgen"
1369         $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1370
1371 clean-local::
1372         -$(Verb) $(RM) -f $(INCFiles)
1373
1374 endif
1375
1376 ###############################################################################
1377 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1378 ###############################################################################
1379
1380 #---------------------------------------------------------
1381 # Provide rules for generating a .cpp source file from 
1382 # (f)lex input sources. 
1383 #---------------------------------------------------------
1384
1385 LexFiles  := $(filter %.l,$(Sources))
1386
1387 ifneq ($(LexFiles),)
1388
1389 # Cancel built-in rules for lex
1390 %.c: %.l
1391 %.cpp: %.l
1392
1393 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1394
1395 # Note the extra sed filtering here, used to cut down on the warnings emited 
1396 # by GCC.  The last line is a gross hack to work around flex aparently not 
1397 # being able to resize the buffer on a large token input.  Currently, for 
1398 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1399 # this is a hack around it.
1400 # FIXME.  (f.e. char Buffer[10000] )
1401 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1402         $(Echo) Flexing $*.l
1403         $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1404         $(SED) 's/void yyunput/inline void yyunput/' | \
1405         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1406         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1407           > $(PROJ_SRC_DIR)/$*.cpp
1408
1409 # IFF the .l file has changed since it was last checked into SVN, copy the .l
1410 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
1411 # so that people without flex can build LLVM by copying the .cvs files to the 
1412 # source location and building them.
1413 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1414 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1415         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs || \
1416       ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1417
1418 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1419 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1420
1421 clean-local::
1422         -$(Verb) $(RM) -f $(LexOutput)
1423
1424 endif
1425
1426 #---------------------------------------------------------
1427 # Provide rules for generating a .cpp and .h source files 
1428 # from yacc (bison) input sources.
1429 #---------------------------------------------------------
1430
1431 YaccFiles  := $(filter %.y,$(Sources))
1432 ifneq ($(YaccFiles),)
1433
1434 .PRECIOUS: $(YaccOutput)
1435
1436 all:: $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs)
1437
1438 # Cancel built-in rules for yacc
1439 %.c: %.y 
1440 %.cpp: %.y
1441 %.h: %.y
1442
1443 # Rule for building the bison based parsers...
1444 ifneq ($(BISON),)
1445 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1446         $(Echo) "Bisoning $*.y"
1447         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1448         $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1449         $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1450
1451 # IFF the .y file has changed since it was last checked into SVN, copy the .y
1452 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
1453 # mechanism so that people without flex can build LLVM by copying the .cvs files
1454 # to the source location and building them.
1455 $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1456 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1457         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs || \
1458       ($(CP) $< $@; \
1459        $(CP) $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs; \
1460        $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)
1461
1462 else
1463 $(PROJ_SRC_DIR)/%.cpp : $(PROJ_SRC_DIR)/%.cpp.cvs
1464         $(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .cpp.cvs"
1465         $(Verb)$(CP) $(PROJ_SRC_DIR)/$*.cpp.cvs $(PROJ_SRC_DIR)/$*.cpp
1466
1467 $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.h.cvs
1468         $(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .h.cvs"
1469         $(Verb)$(CP) $(PROJ_SRC_DIR)/$*.h.cvs $(PROJ_SRC_DIR)/$*.h
1470 endif
1471
1472
1473 $(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1474
1475 YaccOutput := $(YaccFiles:%.y=%.output)
1476
1477 clean-local::
1478         -$(Verb) $(RM) -f $(YaccOutput)
1479 endif
1480
1481 ###############################################################################
1482 # OTHER RULES: Other rules needed
1483 ###############################################################################
1484
1485 # To create postscript files from dot files...
1486 ifneq ($(DOT),false)
1487 %.ps: %.dot
1488         $(DOT) -Tps < $< > $@
1489 else
1490 %.ps: %.dot
1491         $(Echo) "Cannot build $@: The program dot is not installed"
1492 endif
1493
1494 # This rules ensures that header files that are removed still have a rule for
1495 # which they can be "generated."  This allows make to ignore them and
1496 # reproduce the dependency lists.
1497 %.h:: ;
1498 %.hpp:: ;
1499
1500 # Define clean-local to clean the current directory. Note that this uses a
1501 # very conservative approach ensuring that empty variables do not cause 
1502 # errors or disastrous removal.
1503 clean-local::
1504 ifneq ($(strip $(ObjRootDir)),)
1505         -$(Verb) $(RM) -rf $(ObjRootDir)
1506 endif
1507         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1508 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1509         -$(Verb) $(RM) -f *$(SHLIBEXT)
1510 endif
1511
1512 clean-all-local::
1513         -$(Verb) $(RM) -rf Debug Release Profile
1514
1515
1516 ###############################################################################
1517 # DEPENDENCIES: Include the dependency files if we should
1518 ###############################################################################
1519 ifndef DISABLE_AUTO_DEPENDENCIES
1520
1521 # If its not one of the cleaning targets
1522 ifndef IS_CLEANING_TARGET
1523
1524 # Get the list of dependency files
1525 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1526 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1527
1528 -include $(DependFiles) ""
1529
1530 endif
1531
1532 endif 
1533
1534 ###############################################################################
1535 # CHECK: Running the test suite
1536 ###############################################################################
1537
1538 check::
1539         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1540           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1541             $(EchoCmd) Running test suite ; \
1542             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1543               TESTSUITE=$(TESTSUITE) ; \
1544           else \
1545             $(EchoCmd) No Makefile in test directory ; \
1546           fi ; \
1547         else \
1548           $(EchoCmd) No test directory ; \
1549         fi
1550
1551 ###############################################################################
1552 # DISTRIBUTION: Handle construction of a distribution tarball
1553 ###############################################################################
1554
1555 #------------------------------------------------------------------------
1556 # Define distribution related variables
1557 #------------------------------------------------------------------------
1558 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1559 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1560 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1561 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1562 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1563 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1564 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1565                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1566                Makefile.config.in configure autoconf
1567 DistOther   := $(notdir $(wildcard \
1568                $(PROJ_SRC_DIR)/*.h \
1569                $(PROJ_SRC_DIR)/*.td \
1570                $(PROJ_SRC_DIR)/*.def \
1571                $(PROJ_SRC_DIR)/*.ll \
1572                $(PROJ_SRC_DIR)/*.in))
1573 DistSubDirs := $(SubDirs)
1574 DistSources  = $(Sources) $(EXTRA_DIST)
1575 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1576
1577 #------------------------------------------------------------------------
1578 # We MUST build distribution with OBJ_DIR != SRC_DIR
1579 #------------------------------------------------------------------------
1580 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1581 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1582         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1583
1584 else
1585
1586 #------------------------------------------------------------------------
1587 # Prevent attempt to run dist targets from anywhere but the top level
1588 #------------------------------------------------------------------------
1589 ifneq ($(LEVEL),.)
1590 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1591         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1592 else
1593
1594 #------------------------------------------------------------------------
1595 # Provide the top level targets
1596 #------------------------------------------------------------------------
1597
1598 dist-gzip:: $(DistTarGZip)
1599
1600 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1601         $(Echo) Packing gzipped distribution tar file.
1602         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1603           $(GZIP) -c > "$(DistTarGZip)"
1604
1605 dist-bzip2:: $(DistTarBZ2)
1606
1607 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1608         $(Echo) Packing bzipped distribution tar file.
1609         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1610           $(BZIP2) -c >$(DistTarBZ2)
1611
1612 dist-zip:: $(DistZip)
1613
1614 $(DistZip) : $(TopDistDir)/.makedistdir
1615         $(Echo) Packing zipped distribution file.
1616         $(Verb) rm -f $(DistZip)
1617         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1618
1619 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1620         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1621
1622 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1623
1624 dist-check:: $(DistTarGZip)
1625         $(Echo) Checking distribution tar file.
1626         $(Verb) if test -d $(DistCheckDir) ; then \
1627           $(RM) -rf $(DistCheckDir) ; \
1628         fi
1629         $(Verb) $(MKDIR) $(DistCheckDir)
1630         $(Verb) cd $(DistCheckDir) && \
1631           $(MKDIR) $(DistCheckDir)/build && \
1632           $(MKDIR) $(DistCheckDir)/install && \
1633           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1634           cd build && \
1635           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1636             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1637           $(MAKE) all && \
1638           $(MAKE) check && \
1639           $(MAKE) install && \
1640           $(MAKE) uninstall && \
1641           $(MAKE) dist-clean && \
1642           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1643
1644 dist-clean::
1645         $(Echo) Cleaning distribution files
1646         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1647           $(DistCheckDir)
1648
1649 endif
1650
1651 #------------------------------------------------------------------------
1652 # Provide the recursive distdir target for building the distribution directory
1653 #------------------------------------------------------------------------
1654 distdir: $(DistDir)/.makedistdir
1655 $(DistDir)/.makedistdir: $(DistSources)
1656         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1657           if test -d "$(DistDir)" ; then \
1658             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1659               exit 1 ; \
1660           fi ; \
1661           $(EchoCmd) Removing old $(DistDir) ; \
1662           $(RM) -rf $(DistDir); \
1663           $(EchoCmd) Making 'all' to verify build ; \
1664           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1665         fi
1666         $(Echo) Building Distribution Directory $(DistDir)
1667         $(Verb) $(MKDIR) $(DistDir) 
1668         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1669         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1670         for file in $(DistFiles) ; do \
1671           case "$$file" in \
1672             $(PROJ_SRC_DIR)/*) \
1673               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1674               ;; \
1675             $(PROJ_SRC_ROOT)/*) \
1676               file=`echo "$$file" | \
1677                 sed "s#^$$srcrootstrip/##"` \
1678               ;; \
1679           esac; \
1680           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1681              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1682             from_dir="$(PROJ_SRC_DIR)" ; \
1683           elif test -f "$$file" || test -d "$$file" ; then \
1684             from_dir=. ; \
1685           fi ; \
1686           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1687           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1688             to_dir="$(DistDir)/$$dir"; \
1689             $(MKDIR) "$$to_dir" ; \
1690           else \
1691             to_dir="$(DistDir)"; \
1692           fi; \
1693           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1694           if test -n "$$mid_dir" ; then \
1695             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1696           fi ; \
1697           if test -d "$$from_dir/$$file"; then \
1698             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1699                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1700                cd $(PROJ_SRC_DIR) ; \
1701                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1702                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1703                cd $(PROJ_OBJ_DIR) ; \
1704             else \
1705                cd $$from_dir ; \
1706                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1707                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1708                cd $(PROJ_OBJ_DIR) ; \
1709             fi; \
1710           elif test -f "$$from_dir/$$file" ; then \
1711             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1712           elif test -L "$$from_dir/$$file" ; then \
1713             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1714           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1715             $(EchoCmd) "===== WARNING: Distribution Source " \
1716               "$$from_dir/$$file Not Found!" ; \
1717           elif test "$(Verb)" != '@' ; then \
1718             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1719           fi; \
1720         done
1721         $(Verb) for subdir in $(DistSubDirs) ; do \
1722           if test "$$subdir" \!= "." ; then \
1723             new_distdir="$(DistDir)/$$subdir" ; \
1724             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1725             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1726               DistDir="$$new_distdir" distdir ) || exit 1; \
1727           fi; \
1728         done
1729         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1730           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1731           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1732                                   -name .svn \) -print` ;\
1733           $(MAKE) dist-hook ; \
1734           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1735             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1736             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1737             -o ! -type d ! -perm -444 -exec \
1738               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1739             || chmod -R a+r $(DistDir) ; \
1740         fi
1741
1742 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1743 # defined by user.
1744 dist-hook::
1745
1746 endif
1747
1748 ###############################################################################
1749 # TOP LEVEL - targets only to apply at the top level directory
1750 ###############################################################################
1751
1752 ifeq ($(LEVEL),.)
1753
1754 #------------------------------------------------------------------------
1755 # Install support for the project's include files:
1756 #------------------------------------------------------------------------
1757 ifdef NO_INSTALL
1758 install-local::
1759         $(Echo) Install circumvented with NO_INSTALL
1760 uninstall-local::
1761         $(Echo) Uninstall circumvented with NO_INSTALL
1762 else
1763 install-local::
1764         $(Echo) Installing include files
1765         $(Verb) $(MKDIR) $(PROJ_includedir)
1766         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1767           cd $(PROJ_SRC_ROOT)/include && \
1768           for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1769               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1770               grep -v .svn` ; do \
1771             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1772             if test \! -d "$$instdir" ; then \
1773               $(EchoCmd) Making install directory $$instdir ; \
1774               $(MKDIR) $$instdir ;\
1775             fi ; \
1776             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1777           done ; \
1778         fi
1779 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1780         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1781           cd $(PROJ_OBJ_ROOT)/include && \
1782           for hdr in `find . -type f -print | grep -v CVS` ; do \
1783             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1784           done ; \
1785         fi
1786 endif
1787
1788 uninstall-local::
1789         $(Echo) Uninstalling include files
1790         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1791           cd $(PROJ_SRC_ROOT)/include && \
1792             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1793               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1794         -o -name '*.in' ')' -print ')' | \
1795         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1796           cd $(PROJ_SRC_ROOT)/include && \
1797             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1798       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1799         fi
1800 endif
1801 endif
1802
1803 check-line-length:
1804         @echo searching for overlength lines in files: $(Sources)
1805         @echo
1806         @echo
1807         egrep -n '.{81}' $(Sources) /dev/null
1808
1809 check-for-tabs:
1810         @echo searching for tabs in files: $(Sources)
1811         @echo
1812         @echo
1813         egrep -n '      ' $(Sources) /dev/null
1814
1815 check-footprint:
1816         @ls -l $(LibDir) | awk '\
1817           BEGIN { sum = 0; } \
1818                 { sum += $$5; } \
1819           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1820         @ls -l $(ToolDir) | awk '\
1821           BEGIN { sum = 0; } \
1822                 { sum += $$5; } \
1823           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1824 #------------------------------------------------------------------------
1825 # Print out the directories used for building
1826 #------------------------------------------------------------------------
1827 printvars::
1828         $(Echo) "BuildMode    : " '$(BuildMode)'
1829         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1830         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1831         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1832         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1833         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1834         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1835         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1836         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1837         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1838         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1839         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1840         $(Echo) "UserTargets  : " '$(UserTargets)'
1841         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1842         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1843         $(Echo) "ObjDir       : " '$(ObjDir)'
1844         $(Echo) "LibDir       : " '$(LibDir)'
1845         $(Echo) "ToolDir      : " '$(ToolDir)'
1846         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1847         $(Echo) "Sources      : " '$(Sources)'
1848         $(Echo) "TDFiles      : " '$(TDFiles)'
1849         $(Echo) "INCFiles     : " '$(INCFiles)'
1850         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1851         $(Echo) "PreConditions: " '$(PreConditions)'
1852         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1853         $(Echo) "Compile.C    : " '$(Compile.C)'
1854         $(Echo) "Archive      : " '$(Archive)'
1855         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1856         $(Echo) "LexFiles     : " '$(LexFiles)'
1857         $(Echo) "Module       : " '$(Module)'
1858         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1859         $(Echo) "SubDirs      : " '$(SubDirs)'
1860         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1861         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'