Add ENABLE_COVERAGE, for building a +Coverage (gcov) configuration.
[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   CompileCommonOpts += -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       CompileCommonOpts += -m64
540     else
541       ifeq ($(ARCH),x86)
542         CompileCommonOpts += -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                   $(CompileCommonOpts) -c
564   Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
565                   $(CompileCommonOpts) -c
566   Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) \
567                   $(CXX.Flags.NoRelink) -E
568   Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
569                   $(CompileCommonOpts) $(LD.Flags) $(Strip)
570   Relink        = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
571                   $(Relink.Flags)
572 else
573   Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(C.Flags.NoRelink) \
574                   $(CompileCommonOpts) -c
575   Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
576                   $(CompileCommonOpts) -c
577   Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) \
578                   $(CXX.Flags.NoRelink) -E
579   Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXX.Flags.NoRelink) \
580                   $(CompileCommonOpts) $(LD.Flags) $(Strip)
581   Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
582                   $(Relink.Flags)
583 endif
584
585 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
586 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
587
588 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
589                 $(CompileCommonOpts)
590
591 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
592 ScriptInstall = $(INSTALL) -m 0755
593 DataInstall   = $(INSTALL) -m 0644
594
595 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
596 # paths. In this case, the SYSPATH function (defined in
597 # Makefile.config) transforms Unix paths into Windows paths.
598 TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
599                 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
600                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
601                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
602
603 Archive       = $(AR) $(AR.Flags)
604 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
605 ifdef RANLIB
606 Ranlib        = $(RANLIB)
607 else
608 Ranlib        = ranlib
609 endif
610
611 #----------------------------------------------------------
612 # Get the list of source files and compute object file
613 # names from them.
614 #----------------------------------------------------------
615
616 ifndef SOURCES
617   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
618              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
619 else
620   Sources := $(SOURCES)
621 endif
622
623 ifdef BUILT_SOURCES
624 Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
625 endif
626
627 BaseNameSources := $(sort $(basename $(Sources)))
628
629 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
630 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
631
632 ###############################################################################
633 # DIRECTORIES: Handle recursive descent of directory structure
634 ###############################################################################
635
636 #---------------------------------------------------------
637 # Provide rules to make install dirs. This must be early
638 # in the file so they get built before dependencies
639 #---------------------------------------------------------
640
641 $(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
642         $(Verb) $(MKDIR) $@
643
644 # To create other directories, as needed, and timestamp their creation
645 %/.dir:
646         $(Verb) $(MKDIR) $* > /dev/null
647         $(Verb) $(DATE) > $@
648
649 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
650 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
651
652 #---------------------------------------------------------
653 # Handle the DIRS options for sequential construction
654 #---------------------------------------------------------
655
656 SubDirs :=
657 ifdef DIRS
658 SubDirs += $(DIRS)
659
660 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
661 $(RecursiveTargets)::
662         $(Verb) for dir in $(DIRS); do \
663           if [ ! -f $$dir/Makefile ]; then \
664             $(MKDIR) $$dir; \
665             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
666           fi; \
667           ($(MAKE) -C $$dir $@ ) || exit 1; \
668         done
669 else
670 $(RecursiveTargets)::
671         $(Verb) for dir in $(DIRS); do \
672           ($(MAKE) -C $$dir $@ ) || exit 1; \
673         done
674 endif
675
676 endif
677
678 #---------------------------------------------------------
679 # Handle the EXPERIMENTAL_DIRS options ensuring success
680 # after each directory is built.
681 #---------------------------------------------------------
682 ifdef EXPERIMENTAL_DIRS
683 $(RecursiveTargets)::
684         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
685           if [ ! -f $$dir/Makefile ]; then \
686             $(MKDIR) $$dir; \
687             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
688           fi; \
689           ($(MAKE) -C $$dir $@ ) || exit 0; \
690         done
691 endif
692
693 #-----------------------------------------------------------
694 # Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
695 #-----------------------------------------------------------
696 ifdef OPTIONAL_PARALLEL_DIRS
697   PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
698 endif
699
700 #-----------------------------------------------------------
701 # Handle the PARALLEL_DIRS options for parallel construction
702 #-----------------------------------------------------------
703 ifdef PARALLEL_DIRS
704
705 SubDirs += $(PARALLEL_DIRS)
706
707 # Unfortunately, this list must be maintained if new recursive targets are added
708 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
709 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
710 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
711 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
712 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
713 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
714
715 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
716
717 $(ParallelTargets) :
718         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
719           $(MKDIR) $(@D); \
720           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
721         fi; \
722         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
723 endif
724
725 #---------------------------------------------------------
726 # Handle the OPTIONAL_DIRS options for directores that may
727 # or may not exist.
728 #---------------------------------------------------------
729 ifdef OPTIONAL_DIRS
730
731 SubDirs += $(OPTIONAL_DIRS)
732
733 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
734 $(RecursiveTargets)::
735         $(Verb) for dir in $(OPTIONAL_DIRS); do \
736           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
737             if [ ! -f $$dir/Makefile ]; then \
738               $(MKDIR) $$dir; \
739               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
740             fi; \
741             ($(MAKE) -C$$dir $@ ) || exit 1; \
742           fi \
743         done
744 else
745 $(RecursiveTargets)::
746         $(Verb) for dir in $(OPTIONAL_DIRS); do \
747           ($(MAKE) -C$$dir $@ ) || exit 1; \
748         done
749 endif
750 endif
751
752 #---------------------------------------------------------
753 # Handle the CONFIG_FILES options
754 #---------------------------------------------------------
755 ifdef CONFIG_FILES
756
757 ifdef NO_INSTALL
758 install-local::
759         $(Echo) Install circumvented with NO_INSTALL
760 uninstall-local::
761         $(Echo) UnInstall circumvented with NO_INSTALL
762 else
763 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
764         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
765         $(Verb)for file in $(CONFIG_FILES); do \
766           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
767             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
768           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
769             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
770           else \
771             $(ECHO) Error: cannot find config file $${file}. ; \
772           fi \
773         done
774
775 uninstall-local::
776         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
777         $(Verb)for file in $(CONFIG_FILES); do \
778           $(RM) -f $(PROJ_etcdir)/$${file} ; \
779         done
780 endif
781
782 endif
783
784 ###############################################################################
785 # Set up variables for building libararies
786 ###############################################################################
787
788 #---------------------------------------------------------
789 # Define various command line options pertaining to the
790 # libraries needed when linking. There are "Proj" libs
791 # (defined by the user's project) and "LLVM" libs (defined
792 # by the LLVM project).
793 #---------------------------------------------------------
794
795 ifdef USEDLIBS
796 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
797 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
798 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
799 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
800 endif
801
802 ifdef LLVMLIBS
803 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
804 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
805 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
806 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
807 endif
808
809 ifndef IS_CLEANING_TARGET
810 ifdef LINK_COMPONENTS
811
812 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
813 # clean in tools, then do a make in tools (instead of at the top level).
814 $(LLVM_CONFIG):
815         @echo "*** llvm-config doesn't exist - rebuilding it."
816         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
817
818 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
819
820 LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
821 LLVMLibsPaths   += $(LLVM_CONFIG) \
822                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
823 endif
824 endif
825
826 ###############################################################################
827 # Library Build Rules: Four ways to build a library
828 ###############################################################################
829
830 #---------------------------------------------------------
831 # Bytecode Module Targets:
832 #   If the user set MODULE_NAME then they want to build a
833 #   bytecode module from the sources. We compile all the
834 #   sources and link it together into a single bytecode
835 #   module.
836 #---------------------------------------------------------
837
838 ifdef MODULE_NAME
839 ifeq ($(strip $(LLVMGCC)),)
840 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
841 else
842
843 Module     := $(LibDir)/$(MODULE_NAME).bc
844 LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
845
846
847 ifdef EXPORTED_SYMBOL_FILE
848 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
849 endif
850
851 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
852         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
853         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
854
855 all-local:: $(Module)
856
857 clean-local::
858 ifneq ($(strip $(Module)),)
859         -$(Verb) $(RM) -f $(Module)
860 endif
861
862 ifdef BYTECODE_DESTINATION
863 ModuleDestDir := $(BYTECODE_DESTINATION)
864 else
865 ModuleDestDir := $(PROJ_libdir)
866 endif
867
868 ifdef NO_INSTALL
869 install-local::
870         $(Echo) Install circumvented with NO_INSTALL
871 uninstall-local::
872         $(Echo) Uninstall circumvented with NO_INSTALL
873 else
874 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
875
876 install-module:: $(DestModule)
877 install-local:: $(DestModule)
878
879 $(DestModule): $(ModuleDestDir) $(Module)
880         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
881         $(Verb) $(DataInstall) $(Module) $(DestModule)
882
883 uninstall-local::
884         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
885         -$(Verb) $(RM) -f $(DestModule)
886 endif
887
888 endif
889 endif
890
891 # if we're building a library ...
892 ifdef LIBRARYNAME
893
894 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
895 LIBRARYNAME := $(strip $(LIBRARYNAME))
896 ifdef LOADABLE_MODULE
897 LibName.A  := $(LibDir)/$(LIBRARYNAME).a
898 LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
899 else
900 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
901 LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
902 endif
903 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
904 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
905
906 #---------------------------------------------------------
907 # Shared Library Targets:
908 #   If the user asked for a shared library to be built
909 #   with the SHARED_LIBRARY variable, then we provide
910 #   targets for building them.
911 #---------------------------------------------------------
912 ifdef SHARED_LIBRARY
913
914 all-local:: $(LibName.SO)
915
916 ifdef LINK_LIBS_IN_SHARED
917 ifdef LOADABLE_MODULE
918 SharedLibKindMessage := "Loadable Module"
919 else
920 SharedLibKindMessage := "Shared Library"
921 endif
922 $(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
923         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
924           $(LIBRARYNAME)$(SHLIBEXT)
925         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
926           $(ProjLibsOptions) $(LLVMLibsOptions)
927 else
928 $(LibName.SO): $(ObjectsO) $(LibDir)/.dir
929         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
930         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
931 endif
932
933 clean-local::
934 ifneq ($(strip $(LibName.SO)),)
935         -$(Verb) $(RM) -f $(LibName.SO)
936 endif
937
938 ifdef NO_INSTALL
939 install-local::
940         $(Echo) Install circumvented with NO_INSTALL
941 uninstall-local::
942         $(Echo) Uninstall circumvented with NO_INSTALL
943 else
944 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
945
946 install-local:: $(DestSharedLib)
947
948 $(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
949         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
950         $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
951
952 uninstall-local::
953         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
954         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
955 endif
956 endif
957
958 #---------------------------------------------------------
959 # Bytecode Library Targets:
960 #   If the user asked for a bytecode library to be built
961 #   with the BYTECODE_LIBRARY variable, then we provide
962 #   targets for building them.
963 #---------------------------------------------------------
964 ifdef BYTECODE_LIBRARY
965 ifeq ($(strip $(LLVMGCC)),)
966 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
967 else
968
969 all-local:: $(LibName.BCA)
970
971 ifdef EXPORTED_SYMBOL_FILE
972 BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
973                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
974
975 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
976                 $(LLVMToolDir)/llvm-ar
977         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
978           "(internalize)"
979         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
980         $(Verb) $(RM) -f $@
981         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
982 else
983 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
984                 $(LLVMToolDir)/llvm-ar
985         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
986         $(Verb) $(RM) -f $@
987         $(Verb) $(LArchive) $@ $(ObjectsBC)
988
989 endif
990
991 clean-local::
992 ifneq ($(strip $(LibName.BCA)),)
993         -$(Verb) $(RM) -f $(LibName.BCA)
994 endif
995
996 ifdef BYTECODE_DESTINATION
997 BytecodeDestDir := $(BYTECODE_DESTINATION)
998 else
999 BytecodeDestDir := $(PROJ_libdir)
1000 endif
1001
1002 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
1003
1004 install-bytecode-local:: $(DestBytecodeLib)
1005
1006 ifdef NO_INSTALL
1007 install-local::
1008         $(Echo) Install circumvented with NO_INSTALL
1009 uninstall-local::
1010         $(Echo) Uninstall circumvented with NO_INSTALL
1011 else
1012 install-local:: $(DestBytecodeLib)
1013
1014 $(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
1015         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1016         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1017
1018 uninstall-local::
1019         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1020         -$(Verb) $(RM) -f $(DestBytecodeLib)
1021 endif
1022 endif
1023 endif
1024
1025 #---------------------------------------------------------
1026 # ReLinked Library Targets:
1027 #   If the user explicitly requests a relinked library with
1028 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
1029 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
1030 #   them one.
1031 #---------------------------------------------------------
1032 ifndef BUILD_ARCHIVE
1033 ifndef DONT_BUILD_RELINKED
1034 BUILD_RELINKED = 1
1035 endif
1036 endif
1037
1038 ifdef BUILD_RELINKED
1039
1040 all-local:: $(LibName.O)
1041
1042 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
1043         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
1044         $(Verb) $(Relink) -Wl,-r -nodefaultlibs -nostdlib -nostartfiles -o $@ $(ObjectsO)
1045
1046 clean-local::
1047 ifneq ($(strip $(LibName.O)),)
1048         -$(Verb) $(RM) -f $(LibName.O)
1049 endif
1050
1051 ifdef NO_INSTALL
1052 install-local::
1053         $(Echo) Install circumvented with NO_INSTALL
1054 uninstall-local::
1055         $(Echo) Uninstall circumvented with NO_INSTALL
1056 else
1057 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
1058
1059 install-local:: $(DestRelinkedLib)
1060
1061 $(DestRelinkedLib): $(LibName.O) $(PROJ_libdir)
1062         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
1063         $(Verb) $(INSTALL) $(LibName.O) $(DestRelinkedLib)
1064
1065 uninstall-local::
1066         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
1067         -$(Verb) $(RM) -f $(DestRelinkedLib)
1068 endif
1069 endif
1070
1071 #---------------------------------------------------------
1072 # Archive Library Targets:
1073 #   If the user wanted a regular archive library built,
1074 #   then we provide targets for building them.
1075 #---------------------------------------------------------
1076 ifdef BUILD_ARCHIVE
1077
1078 all-local:: $(LibName.A)
1079
1080 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
1081         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1082         -$(Verb) $(RM) -f $@
1083         $(Verb) $(Archive) $@ $(ObjectsO)
1084         $(Verb) $(Ranlib) $@
1085
1086 clean-local::
1087 ifneq ($(strip $(LibName.A)),)
1088         -$(Verb) $(RM) -f $(LibName.A)
1089 endif
1090
1091 ifdef NO_INSTALL
1092 install-local::
1093         $(Echo) Install circumvented with NO_INSTALL
1094 uninstall-local::
1095         $(Echo) Uninstall circumvented with NO_INSTALL
1096 else
1097 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
1098
1099 install-local:: $(DestArchiveLib)
1100
1101 $(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
1102         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1103         $(Verb) $(MKDIR) $(PROJ_libdir)
1104         $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1105
1106 uninstall-local::
1107         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1108         -$(Verb) $(RM) -f $(DestArchiveLib)
1109 endif
1110 endif
1111
1112 # endif LIBRARYNAME
1113 endif
1114
1115 ###############################################################################
1116 # Tool Build Rules: Build executable tool based on TOOLNAME option
1117 ###############################################################################
1118
1119 ifdef TOOLNAME
1120
1121 #---------------------------------------------------------
1122 # Set up variables for building a tool.
1123 #---------------------------------------------------------
1124 ifdef EXAMPLE_TOOL
1125 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1126 else
1127 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1128 endif
1129
1130 #---------------------------------------------------------
1131 # Prune Exports
1132 #---------------------------------------------------------
1133
1134 # If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1135 # not exporting all of the weak symbols from the binary.  This reduces dyld
1136 # startup time by 4x on darwin in some cases.
1137 ifdef TOOL_NO_EXPORTS
1138 ifeq ($(OS),Darwin)
1139
1140 # Tiger tools don't support this.
1141 ifneq ($(DARWIN_MAJVERS),4)
1142 LD.Flags += -Wl,-exported_symbol -Wl,_main
1143 endif
1144 endif
1145
1146 ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
1147 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
1148 endif
1149 endif
1150
1151
1152 #---------------------------------------------------------
1153 # Provide targets for building the tools
1154 #---------------------------------------------------------
1155 all-local:: $(ToolBuildPath)
1156
1157 clean-local::
1158 ifneq ($(strip $(ToolBuildPath)),)
1159         -$(Verb) $(RM) -f $(ToolBuildPath)
1160 endif
1161
1162 ifdef EXAMPLE_TOOL
1163 $(ToolBuildPath): $(ExmplDir)/.dir
1164 else
1165 $(ToolBuildPath): $(ToolDir)/.dir
1166 endif
1167
1168 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1169         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1170         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1171         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1172         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1173           $(StripWarnMsg)
1174
1175 ifdef NO_INSTALL
1176 install-local::
1177         $(Echo) Install circumvented with NO_INSTALL
1178 uninstall-local::
1179         $(Echo) Uninstall circumvented with NO_INSTALL
1180 else
1181 DestTool = $(PROJ_bindir)/$(TOOLNAME)
1182
1183 install-local:: $(DestTool)
1184
1185 $(DestTool): $(ToolBuildPath) $(PROJ_bindir)
1186         $(Echo) Installing $(BuildMode) $(DestTool)
1187         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1188
1189 uninstall-local::
1190         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1191         -$(Verb) $(RM) -f $(DestTool)
1192 endif
1193 endif
1194
1195 ###############################################################################
1196 # Object Build Rules: Build object files based on sources
1197 ###############################################################################
1198
1199 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1200 ifeq ($(OS),HP-UX)
1201   DISABLE_AUTO_DEPENDENCIES=1
1202 endif
1203
1204 # Provide rule sets for when dependency generation is enabled
1205 ifndef DISABLE_AUTO_DEPENDENCIES
1206
1207 #---------------------------------------------------------
1208 # Create .o files in the ObjDir directory from the .cpp and .c files...
1209 #---------------------------------------------------------
1210
1211 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1212          -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1213
1214 # If the build succeeded, move the dependency file over.  If it failed, put an
1215 # empty file there.
1216 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1217                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1218
1219 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1220         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1221         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1222                 $(DEPEND_MOVEFILE)
1223
1224 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1225         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1226         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1227                 $(DEPEND_MOVEFILE)
1228
1229 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1230         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1231         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1232                 $(DEPEND_MOVEFILE)
1233
1234 #---------------------------------------------------------
1235 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1236 #---------------------------------------------------------
1237
1238 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1239         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1240         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1241                               $< -o $@ -S -emit-llvm ; \
1242         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1243         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1244         $(call UPGRADE_MSG,$@)
1245         $(call UPGRADE_LL,$@)
1246
1247 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1248         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1249         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1250                               $< -o $@ -S -emit-llvm ; \
1251         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1252         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1253         $(call UPGRADE_MSG,$@)
1254         $(call UPGRADE_LL,$@)
1255
1256 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1257         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1258         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1259                             $< -o $@ -S -emit-llvm ; \
1260         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1261         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1262         $(call UPGRADE_MSG,$@)
1263         $(call UPGRADE_LL,$@)
1264
1265 # Provide alternate rule sets if dependencies are disabled
1266 else
1267
1268 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1269         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1270         $(Compile.CXX) $< -o $@
1271
1272 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1273         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1274         $(Compile.CXX) $< -o $@
1275
1276 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1277         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1278         $(Compile.C) $< -o $@
1279
1280 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1281         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1282         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1283         $(call UPGRADE_MSG,$@)
1284         $(call UPGRADE_LL,$@)
1285
1286 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1287         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1288         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1289         $(call UPGRADE_MSG,$@)
1290         $(call UPGRADE_LL,$@)
1291
1292 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1293         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1294         $(BCCompile.C) $< -o $@ -S -emit-llvm
1295         $(call UPGRADE_MSG,@)
1296         $(call UPGRADE_LL,@)
1297
1298 endif
1299
1300
1301 ## Rules for building preprocessed (.i/.ii) outputs.
1302 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1303         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1304         $(Verb) $(Preprocess.CXX) $< -o $@
1305
1306 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1307         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1308         $(Verb) $(Preprocess.CXX) $< -o $@
1309
1310 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1311         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1312         $(Verb) $(Preprocess.C) $< -o $@
1313
1314
1315 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1316         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1317         $(Compile.CXX) $< -o $@ -S
1318
1319 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1320         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1321         $(Compile.CXX) $< -o $@ -S
1322
1323 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1324         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1325         $(Compile.C) $< -o $@ -S
1326
1327
1328 # make the C and C++ compilers strip debug info out of bytecode libraries.
1329 ifdef DEBUG_RUNTIME
1330 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1331         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1332         $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1333 else
1334 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1335         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1336         $(Verb) $(LLVMAS) $< -o - | \
1337            $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1338 endif
1339
1340
1341 #---------------------------------------------------------
1342 # Provide rule to build .bc files from .ll sources,
1343 # regardless of dependencies
1344 #---------------------------------------------------------
1345 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1346         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1347         $(Verb) $(LLVMAS) $< -f -o $@
1348
1349 ###############################################################################
1350 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1351 ###############################################################################
1352
1353 ifdef TARGET
1354 TABLEGEN_INC_FILES_COMMON = 1
1355 endif
1356
1357 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1358 TABLEGEN_INC_FILES_COMMON = 1
1359 endif
1360
1361 ifdef TABLEGEN_INC_FILES_COMMON
1362
1363 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1364 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1365 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1366
1367 # INCFiles rule: All of the tblgen generated files are emitted to
1368 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1369 # us to only "touch" the real file if the contents of it change.  IOW, if
1370 # tblgen is modified, all of the .inc.tmp files are regenerated, but no
1371 # dependencies of the .inc files are, unless the contents of the .inc file
1372 # changes.
1373 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1374         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1375
1376 endif # TABLEGEN_INC_FILES_COMMON
1377
1378 ifdef TARGET
1379
1380 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1381            $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1382            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1383            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1384            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1385            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1386            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1387
1388 # All of these files depend on tblgen and the .td files.
1389 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1390
1391 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1392 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1393         $(Echo) "Building $(<F) register names with tblgen"
1394         $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
1395
1396 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1397 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1398         $(Echo) "Building $(<F) register information header with tblgen"
1399         $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
1400
1401 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1402 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1403         $(Echo) "Building $(<F) register info implementation with tblgen"
1404         $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
1405
1406 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1407 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1408         $(Echo) "Building $(<F) instruction names with tblgen"
1409         $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
1410
1411 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1412 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1413         $(Echo) "Building $(<F) instruction information with tblgen"
1414         $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
1415
1416 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1417 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1418         $(Echo) "Building $(<F) assembly writer with tblgen"
1419         $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1420
1421 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1422 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1423         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1424         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1425
1426 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1427 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1428         $(Echo) "Building $(<F) code emitter with tblgen"
1429         $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1430
1431 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1432 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1433         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1434         $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1435
1436 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1437 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1438         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1439         $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1440
1441 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1442 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1443         $(Echo) "Building $(<F) subtarget information with tblgen"
1444         $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1445
1446 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1447 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1448         $(Echo) "Building $(<F) calling convention information with tblgen"
1449         $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1450
1451 $(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1452 $(ObjDir)/%GenIntrinsics.inc.tmp : Intrinsics%.td $(ObjDir)/.dir
1453         $(Echo) "Building $(<F) calling convention information with tblgen"
1454         $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1455
1456 clean-local::
1457         -$(Verb) $(RM) -f $(INCFiles)
1458
1459 endif # TARGET
1460
1461 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1462
1463 LLVMCPluginSrc := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td))
1464
1465 TDFiles := $(LLVMCPluginSrc) \
1466         $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1467
1468 $(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1469                                 $(TBLGEN) $(TD_COMMON)
1470         $(Echo) "Building LLVMC configuration library with tblgen"
1471         $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1472
1473 endif # LLVMC_BUILD_AUTOGENERATED_INC
1474
1475
1476 ###############################################################################
1477 # OTHER RULES: Other rules needed
1478 ###############################################################################
1479
1480 # To create postscript files from dot files...
1481 ifneq ($(DOT),false)
1482 %.ps: %.dot
1483         $(DOT) -Tps < $< > $@
1484 else
1485 %.ps: %.dot
1486         $(Echo) "Cannot build $@: The program dot is not installed"
1487 endif
1488
1489 # This rules ensures that header files that are removed still have a rule for
1490 # which they can be "generated."  This allows make to ignore them and
1491 # reproduce the dependency lists.
1492 %.h:: ;
1493 %.hpp:: ;
1494
1495 # Define clean-local to clean the current directory. Note that this uses a
1496 # very conservative approach ensuring that empty variables do not cause
1497 # errors or disastrous removal.
1498 clean-local::
1499 ifneq ($(strip $(ObjRootDir)),)
1500         -$(Verb) $(RM) -rf $(ObjRootDir)
1501 endif
1502         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1503 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1504         -$(Verb) $(RM) -f *$(SHLIBEXT)
1505 endif
1506
1507 clean-all-local::
1508         -$(Verb) $(RM) -rf Debug Release Profile
1509
1510
1511 ###############################################################################
1512 # DEPENDENCIES: Include the dependency files if we should
1513 ###############################################################################
1514 ifndef DISABLE_AUTO_DEPENDENCIES
1515
1516 # If its not one of the cleaning targets
1517 ifndef IS_CLEANING_TARGET
1518
1519 # Get the list of dependency files
1520 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1521 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1522
1523 -include $(DependFiles) ""
1524
1525 endif
1526
1527 endif
1528
1529 ###############################################################################
1530 # CHECK: Running the test suite
1531 ###############################################################################
1532
1533 check::
1534         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1535           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1536             $(EchoCmd) Running test suite ; \
1537             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1538               TESTSUITE=$(TESTSUITE) ; \
1539           else \
1540             $(EchoCmd) No Makefile in test directory ; \
1541           fi ; \
1542         else \
1543           $(EchoCmd) No test directory ; \
1544         fi
1545
1546 ###############################################################################
1547 # UNITTESTS: Running the unittests test suite
1548 ###############################################################################
1549
1550 unittests::
1551         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1552           if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1553             $(EchoCmd) Running unittests test suite ; \
1554             $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests ; \
1555           else \
1556             $(EchoCmd) No Makefile in unittests directory ; \
1557           fi ; \
1558         else \
1559           $(EchoCmd) No unittests directory ; \
1560         fi
1561
1562 ###############################################################################
1563 # DISTRIBUTION: Handle construction of a distribution tarball
1564 ###############################################################################
1565
1566 #------------------------------------------------------------------------
1567 # Define distribution related variables
1568 #------------------------------------------------------------------------
1569 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1570 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1571 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1572 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1573 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1574 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1575 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1576                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1577                Makefile.config.in configure autoconf
1578 DistOther   := $(notdir $(wildcard \
1579                $(PROJ_SRC_DIR)/*.h \
1580                $(PROJ_SRC_DIR)/*.td \
1581                $(PROJ_SRC_DIR)/*.def \
1582                $(PROJ_SRC_DIR)/*.ll \
1583                $(PROJ_SRC_DIR)/*.in))
1584 DistSubDirs := $(SubDirs)
1585 DistSources  = $(Sources) $(EXTRA_DIST)
1586 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1587
1588 #------------------------------------------------------------------------
1589 # We MUST build distribution with OBJ_DIR != SRC_DIR
1590 #------------------------------------------------------------------------
1591 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1592 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1593         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1594
1595 else
1596
1597 #------------------------------------------------------------------------
1598 # Prevent attempt to run dist targets from anywhere but the top level
1599 #------------------------------------------------------------------------
1600 ifneq ($(LEVEL),.)
1601 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1602         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1603 else
1604
1605 #------------------------------------------------------------------------
1606 # Provide the top level targets
1607 #------------------------------------------------------------------------
1608
1609 dist-gzip:: $(DistTarGZip)
1610
1611 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1612         $(Echo) Packing gzipped distribution tar file.
1613         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1614           $(GZIP) -c > "$(DistTarGZip)"
1615
1616 dist-bzip2:: $(DistTarBZ2)
1617
1618 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1619         $(Echo) Packing bzipped distribution tar file.
1620         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1621           $(BZIP2) -c >$(DistTarBZ2)
1622
1623 dist-zip:: $(DistZip)
1624
1625 $(DistZip) : $(TopDistDir)/.makedistdir
1626         $(Echo) Packing zipped distribution file.
1627         $(Verb) rm -f $(DistZip)
1628         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1629
1630 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1631         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1632
1633 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1634
1635 dist-check:: $(DistTarGZip)
1636         $(Echo) Checking distribution tar file.
1637         $(Verb) if test -d $(DistCheckDir) ; then \
1638           $(RM) -rf $(DistCheckDir) ; \
1639         fi
1640         $(Verb) $(MKDIR) $(DistCheckDir)
1641         $(Verb) cd $(DistCheckDir) && \
1642           $(MKDIR) $(DistCheckDir)/build && \
1643           $(MKDIR) $(DistCheckDir)/install && \
1644           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1645           cd build && \
1646           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1647             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1648           $(MAKE) all && \
1649           $(MAKE) check && \
1650           $(MAKE) unittests && \
1651           $(MAKE) install && \
1652           $(MAKE) uninstall && \
1653           $(MAKE) dist-clean && \
1654           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1655
1656 dist-clean::
1657         $(Echo) Cleaning distribution files
1658         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1659           $(DistCheckDir)
1660
1661 endif
1662
1663 #------------------------------------------------------------------------
1664 # Provide the recursive distdir target for building the distribution directory
1665 #------------------------------------------------------------------------
1666 distdir: $(DistDir)/.makedistdir
1667 $(DistDir)/.makedistdir: $(DistSources)
1668         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1669           if test -d "$(DistDir)" ; then \
1670             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1671               exit 1 ; \
1672           fi ; \
1673           $(EchoCmd) Removing old $(DistDir) ; \
1674           $(RM) -rf $(DistDir); \
1675           $(EchoCmd) Making 'all' to verify build ; \
1676           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1677         fi
1678         $(Echo) Building Distribution Directory $(DistDir)
1679         $(Verb) $(MKDIR) $(DistDir)
1680         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1681         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1682         for file in $(DistFiles) ; do \
1683           case "$$file" in \
1684             $(PROJ_SRC_DIR)/*) \
1685               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1686               ;; \
1687             $(PROJ_SRC_ROOT)/*) \
1688               file=`echo "$$file" | \
1689                 sed "s#^$$srcrootstrip/##"` \
1690               ;; \
1691           esac; \
1692           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1693              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1694             from_dir="$(PROJ_SRC_DIR)" ; \
1695           elif test -f "$$file" || test -d "$$file" ; then \
1696             from_dir=. ; \
1697           fi ; \
1698           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1699           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1700             to_dir="$(DistDir)/$$dir"; \
1701             $(MKDIR) "$$to_dir" ; \
1702           else \
1703             to_dir="$(DistDir)"; \
1704           fi; \
1705           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1706           if test -n "$$mid_dir" ; then \
1707             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1708           fi ; \
1709           if test -d "$$from_dir/$$file"; then \
1710             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1711                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1712                cd $(PROJ_SRC_DIR) ; \
1713                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1714                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1715                cd $(PROJ_OBJ_DIR) ; \
1716             else \
1717                cd $$from_dir ; \
1718                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1719                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1720                cd $(PROJ_OBJ_DIR) ; \
1721             fi; \
1722           elif test -f "$$from_dir/$$file" ; then \
1723             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1724           elif test -L "$$from_dir/$$file" ; then \
1725             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1726           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1727             $(EchoCmd) "===== WARNING: Distribution Source " \
1728               "$$from_dir/$$file Not Found!" ; \
1729           elif test "$(Verb)" != '@' ; then \
1730             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1731           fi; \
1732         done
1733         $(Verb) for subdir in $(DistSubDirs) ; do \
1734           if test "$$subdir" \!= "." ; then \
1735             new_distdir="$(DistDir)/$$subdir" ; \
1736             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1737             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1738               DistDir="$$new_distdir" distdir ) || exit 1; \
1739           fi; \
1740         done
1741         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1742           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1743           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1744                                   -name .svn \) -print` ;\
1745           $(MAKE) dist-hook ; \
1746           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1747             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1748             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1749             -o ! -type d ! -perm -444 -exec \
1750               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1751             || chmod -R a+r $(DistDir) ; \
1752         fi
1753
1754 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1755 # defined by user.
1756 dist-hook::
1757
1758 endif
1759
1760 ###############################################################################
1761 # TOP LEVEL - targets only to apply at the top level directory
1762 ###############################################################################
1763
1764 ifeq ($(LEVEL),.)
1765
1766 #------------------------------------------------------------------------
1767 # Install support for the project's include files:
1768 #------------------------------------------------------------------------
1769 ifdef NO_INSTALL
1770 install-local::
1771         $(Echo) Install circumvented with NO_INSTALL
1772 uninstall-local::
1773         $(Echo) Uninstall circumvented with NO_INSTALL
1774 else
1775 install-local::
1776         $(Echo) Installing include files
1777         $(Verb) $(MKDIR) $(PROJ_includedir)
1778         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1779           cd $(PROJ_SRC_ROOT)/include && \
1780           for  hdr in `find . -type f '!' '(' -name '*~' \
1781               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1782               grep -v .svn` ; do \
1783             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1784             if test \! -d "$$instdir" ; then \
1785               $(EchoCmd) Making install directory $$instdir ; \
1786               $(MKDIR) $$instdir ;\
1787             fi ; \
1788             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1789           done ; \
1790         fi
1791 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1792         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1793           cd $(PROJ_OBJ_ROOT)/include && \
1794           for hdr in `find . -type f -print | grep -v CVS` ; do \
1795             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1796           done ; \
1797         fi
1798 endif
1799
1800 uninstall-local::
1801         $(Echo) Uninstalling include files
1802         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1803           cd $(PROJ_SRC_ROOT)/include && \
1804             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1805               '!' '(' -name '*~' -o -name '.#*' \
1806         -o -name '*.in' ')' -print ')' | \
1807         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1808           cd $(PROJ_SRC_ROOT)/include && \
1809             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1810       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1811         fi
1812 endif
1813 endif
1814
1815 check-line-length:
1816         @echo searching for overlength lines in files: $(Sources)
1817         @echo
1818         @echo
1819         egrep -n '.{81}' $(Sources) /dev/null
1820
1821 check-for-tabs:
1822         @echo searching for tabs in files: $(Sources)
1823         @echo
1824         @echo
1825         egrep -n '      ' $(Sources) /dev/null
1826
1827 check-footprint:
1828         @ls -l $(LibDir) | awk '\
1829           BEGIN { sum = 0; } \
1830                 { sum += $$5; } \
1831           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1832         @ls -l $(ToolDir) | awk '\
1833           BEGIN { sum = 0; } \
1834                 { sum += $$5; } \
1835           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1836 #------------------------------------------------------------------------
1837 # Print out the directories used for building
1838 #------------------------------------------------------------------------
1839 printvars::
1840         $(Echo) "BuildMode    : " '$(BuildMode)'
1841         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1842         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1843         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1844         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1845         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1846         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1847         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1848         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1849         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1850         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1851         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1852         $(Echo) "UserTargets  : " '$(UserTargets)'
1853         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1854         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1855         $(Echo) "ObjDir       : " '$(ObjDir)'
1856         $(Echo) "LibDir       : " '$(LibDir)'
1857         $(Echo) "ToolDir      : " '$(ToolDir)'
1858         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1859         $(Echo) "Sources      : " '$(Sources)'
1860         $(Echo) "TDFiles      : " '$(TDFiles)'
1861         $(Echo) "INCFiles     : " '$(INCFiles)'
1862         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1863         $(Echo) "PreConditions: " '$(PreConditions)'
1864         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1865         $(Echo) "Compile.C    : " '$(Compile.C)'
1866         $(Echo) "Archive      : " '$(Archive)'
1867         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1868         $(Echo) "LexFiles     : " '$(LexFiles)'
1869         $(Echo) "Module       : " '$(Module)'
1870         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1871         $(Echo) "SubDirs      : " '$(SubDirs)'
1872         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1873         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
1874
1875 ###
1876 # Debugging
1877
1878 # General debugging rule, use 'make dbg-print-XXX' to print the
1879 # definition, value and origin of XXX.
1880 make-print-%:
1881         $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))