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