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