Rules for win32 ld shouldn't fire when cross-compiling.
[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                     unitcheck
24 LocalTargets     := all-local clean-local clean-all-local check-local \
25                     install-local printvars uninstall-local \
26                     install-bytecode-local
27 TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
28                     dist-zip unittests
29 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
30 InternalTargets  := preconditions distdir dist-hook
31
32 ################################################################################
33 # INITIALIZATION: Basic things the makefile needs
34 ################################################################################
35
36 #--------------------------------------------------------------------
37 # Set the VPATH so that we can find source files.
38 #--------------------------------------------------------------------
39 VPATH=$(PROJ_SRC_DIR)
40
41 #--------------------------------------------------------------------
42 # Reset the list of suffixes we know how to build.
43 #--------------------------------------------------------------------
44 .SUFFIXES:
45 .SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
46 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
47
48 #--------------------------------------------------------------------
49 # Mark all of these targets as phony to avoid implicit rule search
50 #--------------------------------------------------------------------
51 .PHONY: $(UserTargets) $(InternalTargets)
52
53 #--------------------------------------------------------------------
54 # Make sure all the user-target rules are double colon rules and
55 # they are defined first.
56 #--------------------------------------------------------------------
57
58 $(UserTargets)::
59
60 ################################################################################
61 # PRECONDITIONS: that which must be built/checked first
62 ################################################################################
63
64 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
65                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
66 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
67 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
68 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
69 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
70 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
71 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
72 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
73 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
74 ifneq ($(MakefileCommonIn),)
75 PreConditions      += $(MakefileCommon)
76 endif
77
78 ifneq ($(MakefileConfigIn),)
79 PreConditions      += $(MakefileConfig)
80 endif
81
82 preconditions: $(PreConditions)
83
84 #------------------------------------------------------------------------
85 # Make sure the BUILT_SOURCES are built first
86 #------------------------------------------------------------------------
87 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
88
89 clean-all-local::
90 ifneq ($(strip $(BUILT_SOURCES)),)
91         -$(Verb) $(RM) -f $(BUILT_SOURCES)
92 endif
93
94 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
95 spotless:
96         $(Verb) if test -x config.status ; then \
97           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
98           $(MKDIR) .spotless.save ; \
99           $(MV) config.status .spotless.save ; \
100           $(MV) mklib  .spotless.save ; \
101           $(MV) projects  .spotless.save ; \
102           $(RM) -rf * ; \
103           $(MV) .spotless.save/config.status . ; \
104           $(MV) .spotless.save/mklib . ; \
105           $(MV) .spotless.save/projects . ; \
106           $(RM) -rf .spotless.save ; \
107           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
108           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
109           $(ConfigStatusScript) ; \
110         else \
111           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
112         fi
113 else
114 spotless:
115         $(EchoCmd) "spotless target not supported for objdir == srcdir"
116 endif
117
118 $(BUILT_SOURCES) : $(ObjMakefiles)
119
120 #------------------------------------------------------------------------
121 # Make sure we're not using a stale configuration
122 #------------------------------------------------------------------------
123 reconfigure:
124         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
125         $(Verb) cd $(PROJ_OBJ_ROOT) && \
126           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
127             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
128           fi ; \
129           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
130           $(ConfigStatusScript)
131
132 # FIXME: The {PIC16,MSP430}/AsmPrinter line here is a hack to force a reconfigure to pick
133 # up AsmPrinter changes. Remove it after a reasonable delay from 2009-08-13.
134
135 .PRECIOUS: $(ConfigStatusScript)
136 $(ConfigStatusScript): $(ConfigureScript) $(LLVM_SRC_ROOT)/lib/Target/PIC16/AsmPrinter/Makefile $(LLVM_SRC_ROOT)/lib/Target/MSP430/AsmPrinter/Makefile
137         $(Echo) Reconfiguring with $<
138         $(Verb) cd $(PROJ_OBJ_ROOT) && \
139           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
140             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
141           fi ; \
142           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
143           $(ConfigStatusScript)
144
145 #------------------------------------------------------------------------
146 # Make sure the configuration makefile is up to date
147 #------------------------------------------------------------------------
148 ifneq ($(MakefileConfigIn),)
149 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
150         $(Echo) Regenerating $@
151         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
152 endif
153
154 ifneq ($(MakefileCommonIn),)
155 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
156         $(Echo) Regenerating $@
157         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
158 endif
159
160 #------------------------------------------------------------------------
161 # If the Makefile in the source tree has been updated, copy it over into the
162 # build tree. But, only do this if the source and object makefiles differ
163 #------------------------------------------------------------------------
164 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
165
166 Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
167         $(Echo) "Updating Makefile"
168         $(Verb) $(MKDIR) $(@D)
169         $(Verb) $(CP) -f $< $@
170
171 # Copy the Makefile.* files unless we're in the root directory which avoids
172 # the copying of Makefile.config.in or other things that should be explicitly
173 # taken care of.
174 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
175         @case '$?' in \
176           *Makefile.rules) ;; \
177           *.in) ;; \
178           *) $(EchoCmd) "Updating $(@F)" ; \
179              $(MKDIR) $(@D) ; \
180              $(CP) -f $< $@ ;; \
181         esac
182
183 endif
184
185 #------------------------------------------------------------------------
186 # Set up the basic dependencies
187 #------------------------------------------------------------------------
188 $(UserTargets):: $(PreConditions)
189
190 all:: all-local
191 clean:: clean-local
192 clean-all:: clean-local clean-all-local
193 install:: install-local
194 uninstall:: uninstall-local
195 install-local:: all-local
196 install-bytecode:: install-bytecode-local
197
198 ###############################################################################
199 # LLVMC: Provide rules for compiling llvmc-based driver
200 ###############################################################################
201
202 ifdef LLVMC_BASED_DRIVER
203
204 TOOLNAME = $(LLVMC_BASED_DRIVER)
205
206 LLVMLIBS = CompilerDriver.a
207 LINK_COMPONENTS = support system
208
209 endif # LLVMC_BASED_DRIVER
210
211 ###############################################################################
212 # VARIABLES: Set up various variables based on configuration data
213 ###############################################################################
214
215 # Variable for if this make is for a "cleaning" target
216 ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
217   IS_CLEANING_TARGET=1
218 endif
219
220 #--------------------------------------------------------------------
221 # Variables derived from configuration we are building
222 #--------------------------------------------------------------------
223
224 CPP.Defines :=
225 ifeq ($(ENABLE_OPTIMIZED),1)
226   BuildMode := Release
227   # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
228   ifneq ($(HOST_OS),FreeBSD)
229   ifneq ($(HOST_OS),Darwin)
230     OmitFramePointer := -fomit-frame-pointer
231   endif
232   endif
233
234   # Darwin requires -fstrict-aliasing to be explicitly enabled.
235   # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
236   # with -fstrict-aliasing and ipa-type-escape radr://6756684
237   #ifeq ($(HOST_OS),Darwin)
238   #  EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
239   #endif
240   CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
241   C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
242   LD.Flags  += $(OPTIMIZE_OPTION)
243   ifdef DEBUG_SYMBOLS
244     BuildMode := $(BuildMode)+Debug
245     CXX.Flags += -g
246     C.Flags   += -g
247     LD.Flags  += -g
248     KEEP_SYMBOLS := 1
249   endif
250 else
251   ifdef NO_DEBUG_SYMBOLS
252     BuildMode := Unoptimized
253     CXX.Flags +=
254     C.Flags   +=
255     LD.Flags  +=
256     KEEP_SYMBOLS := 1
257   else
258     BuildMode := Debug
259     CXX.Flags += -g
260     C.Flags   += -g
261     LD.Flags  += -g
262     KEEP_SYMBOLS := 1
263   endif
264 endif
265
266 ifeq ($(ENABLE_PROFILING),1)
267   BuildMode := $(BuildMode)+Profile
268   CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
269   C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
270   LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
271   KEEP_SYMBOLS := 1
272 endif
273
274 #ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
275 #    CXX.Flags += -fvisibility-inlines-hidden
276 #endif
277
278 ifdef ENABLE_EXPENSIVE_CHECKS
279   # GNU libstdc++ uses RTTI if you define _GLIBCXX_DEBUG, which we did above.
280   # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40160
281   REQUIRES_RTTI := 1
282 endif
283
284 # IF REQUIRES_EH=1 is specified then don't disable exceptions
285 ifndef REQUIRES_EH
286   CXX.Flags += -fno-exceptions
287 else
288   # If the library requires EH, it also requires RTTI.
289   REQUIRES_RTTI := 1
290 endif
291
292 ifdef REQUIRES_FRAME_POINTER
293   CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags))
294   C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags))
295   LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags))
296 endif
297
298 # If REQUIRES_RTTI=1 is specified then don't disable run-time type id.
299 ifneq ($(REQUIRES_RTTI), 1)
300   CXX.Flags += -fno-rtti
301 endif
302
303 ifdef ENABLE_COVERAGE
304   BuildMode := $(BuildMode)+Coverage
305   CXX.Flags += -ftest-coverage -fprofile-arcs
306   C.Flags   += -ftest-coverage -fprofile-arcs
307 endif
308
309 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
310 # then disable assertions by defining the appropriate preprocessor symbols.
311 ifndef DISABLE_ASSERTIONS
312   BuildMode := $(BuildMode)+Asserts
313   CPP.Defines += -D_DEBUG
314 else
315   CPP.Defines += -DNDEBUG
316 endif
317
318 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
319 # configured), then enable expensive checks by defining the
320 # appropriate preprocessor symbols.
321 ifdef ENABLE_EXPENSIVE_CHECKS
322   BuildMode := $(BuildMode)+Checks
323   CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
324 endif
325
326 # LOADABLE_MODULE implies several other things so we force them to be
327 # defined/on.
328 ifdef LOADABLE_MODULE
329   SHARED_LIBRARY := 1
330   LINK_LIBS_IN_SHARED := 1
331 endif
332
333 ifdef SHARED_LIBRARY
334   ENABLE_PIC := 1
335   PIC_FLAG = "(PIC)"
336 endif
337
338 ifeq ($(ENABLE_PIC),1)
339   ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
340     # Nothing. Win32 defaults to PIC and warns when given -fPIC
341   else
342     ifeq ($(HOST_OS),Darwin)
343       # Common symbols not allowed in dylib files
344       CXX.Flags += -fno-common
345       C.Flags   += -fno-common
346     else
347       # Linux and others; pass -fPIC
348       CXX.Flags += -fPIC
349       C.Flags   += -fPIC
350     endif
351   endif
352 else
353   ifeq ($(HOST_OS),Darwin)
354       CXX.Flags += -mdynamic-no-pic
355       C.Flags   += -mdynamic-no-pic
356   endif
357 endif
358
359 # Support makefile variable to disable any kind of timestamp/non-deterministic
360 # info from being used in the build.
361 ifeq ($(ENABLE_TIMESTAMPS),1)
362   DOTDIR_TIMESTAMP_COMMAND := $(DATE)
363 else
364   DOTDIR_TIMESTAMP_COMMAND := echo 'Created.'
365 endif
366
367 ifeq ($(HOST_OS),MingW)
368   # Work around PR4957
369   CPP.Defines += -D__NO_CTYPE_INLINE
370   ifeq ($(LLVM_CROSS_COMPILING),1)
371     # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
372     ifdef TOOLNAME
373       LD.Flags += -Wl,--allow-multiple-definition
374     endif
375   endif
376 endif
377
378 CXX.Flags     += -Woverloaded-virtual
379 CPP.BaseFlags += $(CPP.Defines)
380 AR.Flags      := cru
381
382 # Make Floating point IEEE compliant on Alpha.
383 ifeq ($(ARCH),Alpha)
384   CXX.Flags     += -mieee
385   CPP.BaseFlags += -mieee
386 ifeq ($(ENABLE_PIC),0)
387   CXX.Flags     += -fPIC
388   CPP.BaseFlags += -fPIC
389 endif
390 endif
391
392 ifeq ($(ARCH),Alpha)
393   LD.Flags += -Wl,--no-relax
394 endif
395
396 #--------------------------------------------------------------------
397 # Directory locations
398 #--------------------------------------------------------------------
399 TargetMode :=
400 ifeq ($(LLVM_CROSS_COMPILING),1)
401   BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
402 endif
403
404 ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
405 ObjDir      := $(ObjRootDir)
406 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
407 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
408 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
409 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
410 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
411 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
412
413 #--------------------------------------------------------------------
414 # Locations of shared libraries
415 #--------------------------------------------------------------------
416
417 SharedPrefix     := lib
418 SharedLibDir     := $(LibDir)
419 LLVMSharedLibDir := $(LLVMLibDir)
420
421 # Win32.DLL prefers to be located on the "PATH" of binaries.
422 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
423   SharedLibDir     := $(ToolDir)
424   LLVMSharedLibDir := $(LLVMToolDir)
425
426   ifeq ($(HOST_OS),Cygwin)
427     SharedPrefix  := cyg
428   else
429     SharedPrefix  :=
430   endif
431 endif
432
433 #--------------------------------------------------------------------
434 # LLVM Capable Compiler
435 #--------------------------------------------------------------------
436
437 ifeq ($(LLVMCC_OPTION),llvm-gcc)
438   LLVMCC := $(LLVMGCC)
439   LLVMCXX := $(LLVMGXX)
440 else
441   ifeq ($(LLVMCC_OPTION),clang)
442     ifneq ($(CLANGPATH),)
443       LLVMCC := $(CLANGPATH)
444       LLVMCXX := $(CLANGXXPATH)
445     else
446       ifeq ($(ENABLE_BUILT_CLANG),1)
447         LLVMCC := $(LLVMToolDir)/clang
448         LLVMCXX := $(LLVMToolDir)/clang++
449       endif
450     endif
451   endif
452 endif
453
454 #--------------------------------------------------------------------
455 # Full Paths To Compiled Tools and Utilities
456 #--------------------------------------------------------------------
457 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
458 Echo     = @$(EchoCmd)
459 ifndef LLVMAS
460 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
461 endif
462 ifndef TBLGEN
463   ifeq ($(LLVM_CROSS_COMPILING),1)
464     TBLGEN   := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
465   else
466     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
467   endif
468 endif
469 LLVM_CONFIG := $(LLVMToolDir)/llvm-config
470 ifndef LLVMLD
471 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
472 endif
473 ifndef LLVMDIS
474 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
475 endif
476 ifndef LLI
477 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
478 endif
479 ifndef LLC
480 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
481 endif
482 ifndef LOPT
483 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
484 endif
485 ifndef LBUGPOINT
486 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
487 endif
488
489 #--------------------------------------------------------------------
490 # Adjust to user's request
491 #--------------------------------------------------------------------
492
493 ifeq ($(HOST_OS),Darwin)
494   DARWIN_VERSION := `sw_vers -productVersion`
495   # Strip a number like 10.4.7 to 10.4
496   DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
497   # Get "4" out of 10.4 for later pieces in the makefile.
498   DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
499
500   SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined,suppress \
501                     -dynamiclib
502   ifneq ($(ARCH),ARM)
503     SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
504   endif
505 else
506   SharedLinkOptions=-shared
507 endif
508
509 ifeq ($(TARGET_OS),Darwin)
510   ifneq ($(ARCH),ARM)
511     TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
512   endif
513 endif
514
515 ifdef SHARED_LIBRARY
516 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
517 ifneq ($(HOST_OS),Darwin)
518   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
519 else
520 ifneq ($(DARWIN_MAJVERS),4)
521   LD.Flags += $(RPATH) -Wl,$(SharedLibDir)
522 endif
523 endif
524 endif
525 endif
526
527 ifdef TOOL_VERBOSE
528   C.Flags += -v
529   CXX.Flags += -v
530   LD.Flags += -v
531   VERBOSE := 1
532 endif
533
534 # Adjust settings for verbose mode
535 ifndef VERBOSE
536   Verb := @
537   AR.Flags += >/dev/null 2>/dev/null
538   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
539 else
540   ConfigureScriptFLAGS :=
541 endif
542
543 # By default, strip symbol information from executable
544 ifndef KEEP_SYMBOLS
545   Strip := $(PLATFORMSTRIPOPTS)
546   StripWarnMsg := "(without symbols)"
547   Install.StripFlag += -s
548 endif
549
550 # Adjust linker flags for building an executable
551 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
552 ifneq ($(HOST_OS), Darwin)
553 ifdef TOOLNAME
554   LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
555   ifdef EXAMPLE_TOOL
556     LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
557   else
558     LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
559   endif
560 endif
561 else
562 ifneq ($(DARWIN_MAJVERS),4)
563   LD.Flags += $(RPATH) -Wl,@executable_path/../lib
564 endif
565 endif
566 endif
567
568
569 #----------------------------------------------------------
570 # Options To Invoke Tools
571 #----------------------------------------------------------
572
573 ifndef NO_PEDANTIC
574 CompileCommonOpts += -pedantic -Wno-long-long
575 endif
576 CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
577                      $(EXTRA_OPTIONS)
578 # Enable cast-qual for C++; the workaround is to use const_cast.
579 CXX.Flags += -Wcast-qual
580
581 ifeq ($(HOST_OS),HP-UX)
582   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
583 endif
584
585 # If we are building a universal binary on Mac OS/X, pass extra options.  This
586 # is useful to people that want to link the LLVM libraries into their universal
587 # apps.
588 #
589 # The following can be optionally specified:
590 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
591 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
592 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
593 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
594 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
595 #      i386/ppc only.
596 ifdef UNIVERSAL
597   ifndef UNIVERSAL_ARCH
598     UNIVERSAL_ARCH := i386 ppc
599   endif
600   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
601   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
602   ifdef UNIVERSAL_SDK_PATH
603     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
604   endif
605
606   # Building universal cannot compute dependencies automatically.
607   DISABLE_AUTO_DEPENDENCIES=1
608 else
609   ifeq ($(TARGET_OS),Darwin)
610     ifeq ($(ARCH),x86_64)
611       TargetCommonOpts = -m64
612     else
613       ifeq ($(ARCH),x86)
614         TargetCommonOpts = -m32
615       endif
616     endif
617   endif
618 endif
619
620 ifeq ($(HOST_OS),SunOS)
621 CPP.BaseFlags += -include llvm/System/Solaris.h
622 endif
623
624 ifeq ($(HOST_OS),AuroraUX)
625 CPP.BaseFlags += -include llvm/System/Solaris.h
626 endif # !HOST_OS - AuroraUX.
627
628 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
629 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
630 # All -I flags should go here, so that they don't confuse llvm-config.
631 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
632                  $(patsubst %,-I%/include,\
633                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
634                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
635                  $(CPP.BaseFlags)
636
637 ifeq ($(BUILD_COMPONENT), 1)
638   Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
639                   $(TargetCommonOpts) $(CompileCommonOpts) -c
640   Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
641                   $(CPPFLAGS) \
642                   $(TargetCommonOpts) $(CompileCommonOpts) -c
643   Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CPPFLAGS) $(TargetCommonOpts) \
644                   $(CompileCommonOpts) $(CXX.Flags) -E
645   Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) \
646                   $(LDFLAGS) \
647                   $(TargetCommonOpts) $(CompileCommonOpts) $(LD.Flags) $(Strip)
648 else
649   Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
650                   $(TargetCommonOpts) $(CompileCommonOpts) -c
651   Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
652                   $(TargetCommonOpts) $(CompileCommonOpts) -c
653   Preprocess.CXX= $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
654                   $(CompileCommonOpts) $(CXX.Flags) -E
655   Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LDFLAGS) \
656                   $(TargetCommonOpts)  $(CompileCommonOpts) $(LD.Flags) $(Strip)
657 endif
658
659 BCCompile.C   = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
660                 $(TargetCommonOpts) $(CompileCommonOpts)
661 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
662                 $(TargetCommonOpts) $(CompileCommonOpts) -E
663
664 BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
665                 $(TargetCommonOpts) $(CompileCommonOpts)
666
667 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
668 ScriptInstall = $(INSTALL) -m 0755
669 DataInstall   = $(INSTALL) -m 0644
670
671 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
672 # paths. In this case, the SYSPATH function (defined in
673 # Makefile.config) transforms Unix paths into Windows paths.
674 TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
675                 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
676                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
677                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
678
679 Archive       = $(AR) $(AR.Flags)
680 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
681 ifdef RANLIB
682 Ranlib        = $(RANLIB)
683 else
684 Ranlib        = ranlib
685 endif
686
687 AliasTool     = ln -s
688
689 #----------------------------------------------------------
690 # Get the list of source files and compute object file
691 # names from them.
692 #----------------------------------------------------------
693
694 ifndef SOURCES
695   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
696              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
697 else
698   Sources := $(SOURCES)
699 endif
700
701 ifdef BUILT_SOURCES
702 Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
703 endif
704
705 BaseNameSources := $(sort $(basename $(Sources)))
706
707 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
708 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
709
710 ###############################################################################
711 # DIRECTORIES: Handle recursive descent of directory structure
712 ###############################################################################
713
714 #---------------------------------------------------------
715 # Provide rules to make install dirs. This must be early
716 # in the file so they get built before dependencies
717 #---------------------------------------------------------
718
719 $(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $(DESTDIR)$(PROJ_etcdir)::
720         $(Verb) $(MKDIR) $@
721
722 # To create other directories, as needed, and timestamp their creation
723 %/.dir:
724         $(Verb) $(MKDIR) $* > /dev/null
725         $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
726
727 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
728 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
729
730 #---------------------------------------------------------
731 # Handle the DIRS options for sequential construction
732 #---------------------------------------------------------
733
734 SubDirs :=
735 ifdef DIRS
736 SubDirs += $(DIRS)
737
738 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
739 $(RecursiveTargets)::
740         $(Verb) for dir in $(DIRS); do \
741           if ([ ! -f $$dir/Makefile ] || \
742               command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
743             $(MKDIR) $$dir; \
744             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
745           fi; \
746           ($(MAKE) -C $$dir $@ ) || exit 1; \
747         done
748 else
749 $(RecursiveTargets)::
750         $(Verb) for dir in $(DIRS); do \
751           ($(MAKE) -C $$dir $@ ) || exit 1; \
752         done
753 endif
754
755 endif
756
757 #---------------------------------------------------------
758 # Handle the EXPERIMENTAL_DIRS options ensuring success
759 # after each directory is built.
760 #---------------------------------------------------------
761 ifdef EXPERIMENTAL_DIRS
762 $(RecursiveTargets)::
763         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
764           if ([ ! -f $$dir/Makefile ] || \
765               command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
766             $(MKDIR) $$dir; \
767             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
768           fi; \
769           ($(MAKE) -C $$dir $@ ) || exit 0; \
770         done
771 endif
772
773 #-----------------------------------------------------------
774 # Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
775 #-----------------------------------------------------------
776 ifdef OPTIONAL_PARALLEL_DIRS
777   PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
778 endif
779
780 #-----------------------------------------------------------
781 # Handle the PARALLEL_DIRS options for parallel construction
782 #-----------------------------------------------------------
783 ifdef PARALLEL_DIRS
784
785 SubDirs += $(PARALLEL_DIRS)
786
787 # Unfortunately, this list must be maintained if new recursive targets are added
788 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
789 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
790 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
791 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
792 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
793 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
794 unitcheck:: $(addsuffix /.makeunitcheck,$(PARALLEL_DIRS))
795
796 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
797
798 $(ParallelTargets) :
799         $(Verb) if ([ ! -f $(@D)/Makefile ] || \
800                     command test $(@D)/Makefile -ot \
801                       $(PROJ_SRC_DIR)/$(@D)/Makefile ); then \
802           $(MKDIR) $(@D); \
803           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
804         fi; \
805         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
806 endif
807
808 #---------------------------------------------------------
809 # Handle the OPTIONAL_DIRS options for directores that may
810 # or may not exist.
811 #---------------------------------------------------------
812 ifdef OPTIONAL_DIRS
813
814 SubDirs += $(OPTIONAL_DIRS)
815
816 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
817 $(RecursiveTargets)::
818         $(Verb) for dir in $(OPTIONAL_DIRS); do \
819           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
820             if ([ ! -f $$dir/Makefile ] || \
821                 command test $$dir/Makefile -ot $(PROJ_SRC_DIR)/$$dir/Makefile ); then \
822               $(MKDIR) $$dir; \
823               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
824             fi; \
825             ($(MAKE) -C$$dir $@ ) || exit 1; \
826           fi \
827         done
828 else
829 $(RecursiveTargets)::
830         $(Verb) for dir in $(OPTIONAL_DIRS); do \
831           ($(MAKE) -C$$dir $@ ) || exit 1; \
832         done
833 endif
834 endif
835
836 #---------------------------------------------------------
837 # Handle the CONFIG_FILES options
838 #---------------------------------------------------------
839 ifdef CONFIG_FILES
840
841 ifdef NO_INSTALL
842 install-local::
843         $(Echo) Install circumvented with NO_INSTALL
844 uninstall-local::
845         $(Echo) UnInstall circumvented with NO_INSTALL
846 else
847 install-local:: $(DESTDIR)$(PROJ_etcdir) $(CONFIG_FILES)
848         $(Echo) Installing Configuration Files To $(DESTDIR)$(PROJ_etcdir)
849         $(Verb)for file in $(CONFIG_FILES); do \
850           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
851             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
852           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
853             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(DESTDIR)$(PROJ_etcdir) ; \
854           else \
855             $(ECHO) Error: cannot find config file $${file}. ; \
856           fi \
857         done
858
859 uninstall-local::
860         $(Echo) Uninstalling Configuration Files From $(DESTDIR)$(PROJ_etcdir)
861         $(Verb)for file in $(CONFIG_FILES); do \
862           $(RM) -f $(DESTDIR)$(PROJ_etcdir)/$${file} ; \
863         done
864 endif
865
866 endif
867
868 ###############################################################################
869 # Set up variables for building libraries
870 ###############################################################################
871
872 #---------------------------------------------------------
873 # Define various command line options pertaining to the
874 # libraries needed when linking. There are "Proj" libs
875 # (defined by the user's project) and "LLVM" libs (defined
876 # by the LLVM project).
877 #---------------------------------------------------------
878
879 ifdef USEDLIBS
880 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
881 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
882 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
883 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
884 endif
885
886 ifdef LLVMLIBS
887 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
888 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
889 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
890 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
891 endif
892
893 # Win32.DLL may refer to other components.
894 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
895   ifdef LOADABLE_MODULE
896     LINK_COMPONENTS := all
897   endif
898 endif
899
900 ifndef IS_CLEANING_TARGET
901 ifdef LINK_COMPONENTS
902
903 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
904 # clean in tools, then do a make in tools (instead of at the top level).
905 $(LLVM_CONFIG):
906         @echo "*** llvm-config doesn't exist - rebuilding it."
907         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
908
909 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
910
911 ifeq ($(ENABLE_SHARED), 1)
912 # We can take the "auto-import" feature to get rid of using dllimport.
913 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
914 LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
915                    -L $(SharedLibDir)
916 endif
917 LLVMLibsOptions += -lLLVM-$(LLVMVersion)
918 LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
919 else
920
921 ifndef NO_LLVM_CONFIG
922 LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
923 ifeq ($(LLVMConfigLibs),Error)
924 $(error llvm-config --libs failed)
925 endif
926 LLVMLibsOptions += $(LLVMConfigLibs)
927 LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
928 ifeq ($(LLVMConfigLibfiles),Error)
929 $(error llvm-config --libfiles failed)
930 endif
931 LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
932 endif
933
934 endif
935 endif
936 endif
937
938 # Set up the library exports file.
939 ifdef EXPORTED_SYMBOL_FILE
940
941 # First, set up the native export file, which may differ from the source
942 # export file.
943
944 ifeq ($(HOST_OS),Darwin)
945 # Darwin convention prefixes symbols with underscores.
946 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).sed
947 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
948         $(Verb) sed -e 's/^/_/' < $< > $@
949 clean-local::
950         -$(Verb) $(RM) -f $(NativeExportsFile)
951 else
952 ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
953 # Gold and BFD ld require a version script rather than a plain list.
954 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
955 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
956         $(Verb) echo "{" > $@
957         $(Verb) grep -q "\<" $< && echo "  global:" >> $@ || :
958         $(Verb) sed -e 's/$$/;/' -e 's/^/    /' < $< >> $@
959         $(Verb) echo "  local: *;" >> $@
960         $(Verb) echo "};" >> $@
961 clean-local::
962         -$(Verb) $(RM) -f $(NativeExportsFile)
963 else
964 NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
965 endif
966 endif
967
968 # Now add the linker command-line options to use the native export file.
969
970 ifeq ($(HOST_OS),Darwin)
971 LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
972 endif
973
974 # GNU ld Win32 accepts .DEF files that contain "DATA" entries.
975 # This doesn't work when cross-compiling, though.
976 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
977 ifneq ($(LLVM_CROSS_COMPILING),1)
978 HAVE_WIN32_GNU_LD=1
979 endif
980 endif
981
982 ifeq ($(HAVE_WIN32_GNU_LD),1)
983 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
984
985 # LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
986 SharedLinkOptions += $(NativeExportsFile)
987
988 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
989         $(Echo) Generating $(notdir $@)
990         $(Verb) $(ECHO) "EXPORTS" > $@
991         $(Verb) $(CAT) $< >> $@
992 clean-local::
993         -$(Verb) $(RM) -f $(NativeExportsFile)
994 else
995
996 # gold, bfd ld, etc.
997 ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
998 LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
999 endif
1000
1001 endif
1002
1003 endif
1004
1005 ###############################################################################
1006 # Library Build Rules: Four ways to build a library
1007 ###############################################################################
1008
1009 #---------------------------------------------------------
1010 # Bytecode Module Targets:
1011 #   If the user set MODULE_NAME then they want to build a
1012 #   bytecode module from the sources. We compile all the
1013 #   sources and link it together into a single bytecode
1014 #   module.
1015 #---------------------------------------------------------
1016
1017 ifdef MODULE_NAME
1018 ifeq ($(strip $(LLVMCC)),)
1019 $(warning Modules require LLVM capable compiler but none is available ****)
1020 else
1021
1022 Module     := $(LibDir)/$(MODULE_NAME).bc
1023 LinkModule := $(LLVMLD) -r
1024
1025
1026 ifdef EXPORTED_SYMBOL_FILE
1027 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1028 endif
1029
1030 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
1031         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
1032         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
1033
1034 all-local:: $(Module)
1035
1036 clean-local::
1037 ifneq ($(strip $(Module)),)
1038         -$(Verb) $(RM) -f $(Module)
1039 endif
1040
1041 ifdef BYTECODE_DESTINATION
1042 ModuleDestDir := $(BYTECODE_DESTINATION)
1043 else
1044 ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
1045 endif
1046
1047 ifdef NO_INSTALL
1048 install-local::
1049         $(Echo) Install circumvented with NO_INSTALL
1050 uninstall-local::
1051         $(Echo) Uninstall circumvented with NO_INSTALL
1052 else
1053 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
1054
1055 install-module:: $(DestModule)
1056 install-local:: $(DestModule)
1057
1058 $(DestModule): $(ModuleDestDir) $(Module)
1059         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
1060         $(Verb) $(DataInstall) $(Module) $(DestModule)
1061
1062 uninstall-local::
1063         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
1064         -$(Verb) $(RM) -f $(DestModule)
1065 endif
1066
1067 endif
1068 endif
1069
1070 # if we're building a library ...
1071 ifdef LIBRARYNAME
1072
1073 # Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
1074 LIBRARYNAME := $(strip $(LIBRARYNAME))
1075 ifdef LOADABLE_MODULE
1076 LibName.A  := $(LibDir)/$(LIBRARYNAME).a
1077 LibName.SO := $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT)
1078 else
1079 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
1080 LibName.SO := $(SharedLibDir)/$(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
1081 endif
1082 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
1083 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
1084
1085 #---------------------------------------------------------
1086 # Shared Library Targets:
1087 #   If the user asked for a shared library to be built
1088 #   with the SHARED_LIBRARY variable, then we provide
1089 #   targets for building them.
1090 #---------------------------------------------------------
1091 ifdef SHARED_LIBRARY
1092
1093 all-local:: $(LibName.SO)
1094
1095 ifdef EXPORTED_SYMBOL_FILE
1096 $(LibName.SO): $(NativeExportsFile)
1097 endif
1098
1099 ifdef LINK_LIBS_IN_SHARED
1100 ifdef LOADABLE_MODULE
1101 SharedLibKindMessage := "Loadable Module"
1102 else
1103 SharedLibKindMessage := "Shared Library"
1104 endif
1105 $(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
1106         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
1107           $(notdir $@)
1108         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
1109           $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
1110 else
1111 $(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
1112         $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
1113         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
1114 endif
1115
1116 clean-local::
1117 ifneq ($(strip $(LibName.SO)),)
1118         -$(Verb) $(RM) -f $(LibName.SO)
1119 endif
1120
1121 ifdef NO_INSTALL
1122 install-local::
1123         $(Echo) Install circumvented with NO_INSTALL
1124 uninstall-local::
1125         $(Echo) Uninstall circumvented with NO_INSTALL
1126 else
1127
1128 # Win32.DLL prefers to be located on the "PATH" of binaries.
1129 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
1130 DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
1131 else
1132 DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
1133 endif
1134 DestSharedLib := $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
1135
1136 install-local:: $(DestSharedLib)
1137
1138 $(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
1139         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
1140         $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
1141
1142 uninstall-local::
1143         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
1144         -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
1145 endif
1146 endif
1147
1148 #---------------------------------------------------------
1149 # Bytecode Library Targets:
1150 #   If the user asked for a bytecode library to be built
1151 #   with the BYTECODE_LIBRARY variable, then we provide
1152 #   targets for building them.
1153 #---------------------------------------------------------
1154 ifdef BYTECODE_LIBRARY
1155 ifeq ($(strip $(LLVMCC)),)
1156 $(warning Bytecode libraries require LLVM capable compiler but none is available ****)
1157 else
1158
1159 all-local:: $(LibName.BCA)
1160
1161 ifdef EXPORTED_SYMBOL_FILE
1162 BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
1163
1164 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
1165                 $(LLVMToolDir)/llvm-ar
1166         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
1167           "(internalize)"
1168         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
1169         $(Verb) $(RM) -f $@
1170         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
1171 else
1172 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
1173                 $(LLVMToolDir)/llvm-ar
1174         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
1175         $(Verb) $(RM) -f $@
1176         $(Verb) $(LArchive) $@ $(ObjectsBC)
1177
1178 endif
1179
1180 clean-local::
1181 ifneq ($(strip $(LibName.BCA)),)
1182         -$(Verb) $(RM) -f $(LibName.BCA)
1183 endif
1184
1185 ifdef BYTECODE_DESTINATION
1186 BytecodeDestDir := $(BYTECODE_DESTINATION)
1187 else
1188 BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
1189 endif
1190
1191 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
1192
1193 install-bytecode-local:: $(DestBytecodeLib)
1194
1195 ifdef NO_INSTALL
1196 install-local::
1197         $(Echo) Install circumvented with NO_INSTALL
1198 uninstall-local::
1199         $(Echo) Uninstall circumvented with NO_INSTALL
1200 else
1201 install-local:: $(DestBytecodeLib)
1202
1203 $(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
1204         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1205         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
1206
1207 uninstall-local::
1208         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
1209         -$(Verb) $(RM) -f $(DestBytecodeLib)
1210 endif
1211 endif
1212 endif
1213
1214 #---------------------------------------------------------
1215 # Library Targets:
1216 #   If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
1217 #   building an archive.
1218 #---------------------------------------------------------
1219 ifndef NO_BUILD_ARCHIVE
1220 ifndef BUILD_ARCHIVE
1221 ifndef LOADABLE_MODULE
1222 BUILD_ARCHIVE = 1
1223 endif
1224 endif
1225 endif
1226
1227 #---------------------------------------------------------
1228 # Archive Library Targets:
1229 #   If the user wanted a regular archive library built,
1230 #   then we provide targets for building them.
1231 #---------------------------------------------------------
1232 ifdef BUILD_ARCHIVE
1233
1234 all-local:: $(LibName.A)
1235
1236 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
1237         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1238         -$(Verb) $(RM) -f $@
1239         $(Verb) $(Archive) $@ $(ObjectsO)
1240         $(Verb) $(Ranlib) $@
1241
1242 clean-local::
1243 ifneq ($(strip $(LibName.A)),)
1244         -$(Verb) $(RM) -f $(LibName.A)
1245 endif
1246
1247 ifdef NO_INSTALL
1248 install-local::
1249         $(Echo) Install circumvented with NO_INSTALL
1250 uninstall-local::
1251         $(Echo) Uninstall circumvented with NO_INSTALL
1252 else
1253 ifdef NO_INSTALL_ARCHIVES
1254 install-local::
1255         $(Echo) Install circumvented with NO_INSTALL
1256 uninstall-local::
1257         $(Echo) Uninstall circumvented with NO_INSTALL
1258 else
1259 DestArchiveLib := $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).a
1260
1261 install-local:: $(DestArchiveLib)
1262
1263 $(DestArchiveLib): $(LibName.A) $(DESTDIR)$(PROJ_libdir)
1264         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1265         $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_libdir)
1266         $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1267
1268 uninstall-local::
1269         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1270         -$(Verb) $(RM) -f $(DestArchiveLib)
1271 endif
1272 endif
1273 endif
1274
1275 # endif LIBRARYNAME
1276 endif
1277
1278 ###############################################################################
1279 # Tool Build Rules: Build executable tool based on TOOLNAME option
1280 ###############################################################################
1281
1282 ifdef TOOLNAME
1283
1284 #---------------------------------------------------------
1285 # Set up variables for building a tool.
1286 #---------------------------------------------------------
1287 TOOLEXENAME := $(strip $(TOOLNAME))$(EXEEXT)
1288 ifdef EXAMPLE_TOOL
1289 ToolBuildPath   := $(ExmplDir)/$(TOOLEXENAME)
1290 else
1291 ToolBuildPath   := $(ToolDir)/$(TOOLEXENAME)
1292 endif
1293
1294 # TOOLALIAS is a name to symlink (or copy) the tool to.
1295 ifdef TOOLALIAS
1296 ifdef EXAMPLE_TOOL
1297 ToolAliasBuildPath   := $(ExmplDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1298 else
1299 ToolAliasBuildPath   := $(ToolDir)/$(strip $(TOOLALIAS))$(EXEEXT)
1300 endif
1301 endif
1302
1303 #---------------------------------------------------------
1304 # Prune Exports
1305 #---------------------------------------------------------
1306
1307 # If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1308 # not exporting all of the weak symbols from the binary.  This reduces dyld
1309 # startup time by 4x on darwin in some cases.
1310 ifdef TOOL_NO_EXPORTS
1311 ifeq ($(HOST_OS),Darwin)
1312
1313 # Tiger tools don't support this.
1314 ifneq ($(DARWIN_MAJVERS),4)
1315 LD.Flags += -Wl,-exported_symbol,_main
1316 endif
1317 endif
1318
1319 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
1320 ifneq ($(ARCH), Mips)
1321   LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
1322 endif
1323 endif
1324 endif
1325
1326 #---------------------------------------------------------
1327 # Tool Version Info Support
1328 #---------------------------------------------------------
1329
1330 ifeq ($(HOST_OS),Darwin)
1331 ifdef TOOL_INFO_PLIST
1332
1333 LD.Flags += -Wl,-sectcreate,__TEXT,__info_plist,$(ObjDir)/$(TOOL_INFO_PLIST)
1334
1335 $(ToolBuildPath): $(ObjDir)/$(TOOL_INFO_PLIST)
1336
1337 $(ObjDir)/$(TOOL_INFO_PLIST): $(PROJ_SRC_DIR)/$(TOOL_INFO_PLIST).in $(ObjDir)/.dir
1338         $(Echo) "Creating $(TOOLNAME) '$(TOOL_INFO_PLIST)' file..."
1339         $(Verb)sed -e "s#@TOOL_INFO_UTI@#$(TOOL_INFO_UTI)#g" \
1340                    -e "s#@TOOL_INFO_NAME@#$(TOOL_INFO_NAME)#g" \
1341                    -e "s#@TOOL_INFO_VERSION@#$(TOOL_INFO_VERSION)#g" \
1342                  -e "s#@TOOL_INFO_BUILD_VERSION@#$(TOOL_INFO_BUILD_VERSION)#g" \
1343                    $< > $@
1344
1345 endif
1346 endif
1347
1348 #---------------------------------------------------------
1349 # Provide targets for building the tools
1350 #---------------------------------------------------------
1351 all-local:: $(ToolBuildPath) $(ToolAliasBuildPath)
1352
1353 clean-local::
1354 ifneq ($(strip $(ToolBuildPath)),)
1355         -$(Verb) $(RM) -f $(ToolBuildPath)
1356 endif
1357 ifneq ($(strip $(ToolAliasBuildPath)),)
1358         -$(Verb) $(RM) -f $(ToolAliasBuildPath)
1359 endif
1360
1361 ifdef EXAMPLE_TOOL
1362 $(ToolBuildPath): $(ExmplDir)/.dir
1363 else
1364 $(ToolBuildPath): $(ToolDir)/.dir
1365 endif
1366
1367 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1368         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1369         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1370         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1371         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1372           $(StripWarnMsg)
1373
1374 ifneq ($(strip $(ToolAliasBuildPath)),)
1375 $(ToolAliasBuildPath): $(ToolBuildPath)
1376         $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
1377         $(Verb) $(RM) -f $(ToolAliasBuildPath)
1378         $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
1379         $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
1380           $(StripWarnMsg)
1381 endif
1382
1383 ifdef NO_INSTALL
1384 install-local::
1385         $(Echo) Install circumvented with NO_INSTALL
1386 uninstall-local::
1387         $(Echo) Uninstall circumvented with NO_INSTALL
1388 else
1389 DestTool = $(DESTDIR)$(PROJ_bindir)/$(TOOLEXENAME)
1390
1391 install-local:: $(DestTool)
1392
1393 $(DestTool): $(ToolBuildPath) $(DESTDIR)$(PROJ_bindir)
1394         $(Echo) Installing $(BuildMode) $(DestTool)
1395         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1396
1397 uninstall-local::
1398         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1399         -$(Verb) $(RM) -f $(DestTool)
1400
1401 # TOOLALIAS install.
1402 ifdef TOOLALIAS
1403 DestToolAlias = $(DESTDIR)$(PROJ_bindir)/$(TOOLALIAS)$(EXEEXT)
1404
1405 install-local:: $(DestToolAlias)
1406
1407 $(DestToolAlias): $(DestTool)
1408         $(Echo) Installing $(BuildMode) $(DestToolAlias)
1409         $(Verb) $(RM) -f $(DestToolAlias)
1410         $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
1411
1412 uninstall-local::
1413         $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
1414         -$(Verb) $(RM) -f $(DestToolAlias)
1415 endif
1416
1417 endif
1418 endif
1419
1420 ###############################################################################
1421 # Object Build Rules: Build object files based on sources
1422 ###############################################################################
1423
1424 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1425 ifeq ($(HOST_OS),HP-UX)
1426   DISABLE_AUTO_DEPENDENCIES=1
1427 endif
1428
1429 # Provide rule sets for when dependency generation is enabled
1430 ifndef DISABLE_AUTO_DEPENDENCIES
1431
1432 #---------------------------------------------------------
1433 # Create .o files in the ObjDir directory from the .cpp and .c files...
1434 #---------------------------------------------------------
1435
1436 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1437          -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1438
1439 # If the build succeeded, move the dependency file over, otherwise
1440 # remove it.
1441 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1442                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1443
1444 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
1445         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1446         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1447                 $(DEPEND_MOVEFILE)
1448
1449 $(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
1450         $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1451         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1452                 $(DEPEND_MOVEFILE)
1453
1454 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
1455         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1456         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1457                 $(DEPEND_MOVEFILE)
1458
1459 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
1460         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1461         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1462                 $(DEPEND_MOVEFILE)
1463
1464 $(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_SRC_DIR)/Makefile
1465         $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1466         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1467                 $(DEPEND_MOVEFILE)
1468
1469 #---------------------------------------------------------
1470 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1471 #---------------------------------------------------------
1472
1473 BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
1474         -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
1475
1476 # If the build succeeded, move the dependency file over, otherwise
1477 # remove it.
1478 BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
1479                      else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
1480
1481 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1482         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1483         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1484                               $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1485                 $(BC_DEPEND_MOVEFILE)
1486
1487 $(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1488         $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1489         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1490                               $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1491                 $(BC_DEPEND_MOVEFILE)
1492
1493 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1494         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1495         $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
1496                               $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1497                 $(BC_DEPEND_MOVEFILE)
1498
1499 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1500         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1501         $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1502                               $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1503                 $(BC_DEPEND_MOVEFILE)
1504
1505 $(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1506         $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1507         $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
1508                               $< -o $(ObjDir)/$*.ll -S -emit-llvm ; \
1509                 $(BC_DEPEND_MOVEFILE)
1510
1511 # Provide alternate rule sets if dependencies are disabled
1512 else
1513
1514 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1515         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1516         $(Compile.CXX) $< -o $@
1517
1518 $(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1519         $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
1520         $(Compile.CXX) $< -o $@
1521
1522 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1523         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1524         $(Compile.CXX) $< -o $@
1525
1526 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1527         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1528         $(Compile.C) $< -o $@
1529
1530 $(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1531         $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
1532         $(Compile.C) $< -o $@
1533
1534 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1535         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1536         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1537
1538 $(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1539         $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
1540         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1541
1542 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
1543         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1544         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1545
1546 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1547         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1548         $(BCCompile.C) $< -o $@ -S -emit-llvm
1549
1550 $(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
1551         $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
1552         $(BCCompile.C) $< -o $@ -S -emit-llvm
1553
1554 endif
1555
1556
1557 ## Rules for building preprocessed (.i/.ii) outputs.
1558 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1559         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1560         $(Verb) $(Preprocess.CXX) $< -o $@
1561
1562 $(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1563         $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
1564         $(Verb) $(Preprocess.CXX) $< -o $@
1565
1566 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1567         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1568         $(Verb) $(Preprocess.CXX) $< -o $@
1569
1570 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1571         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1572         $(Verb) $(Preprocess.C) $< -o $@
1573
1574 $(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1575         $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
1576         $(Verb) $(Preprocess.C) $< -o $@
1577
1578
1579 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1580         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1581         $(Compile.CXX) $< -o $@ -S
1582
1583 $(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
1584         $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
1585         $(Compile.CXX) $< -o $@ -S
1586
1587 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1588         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1589         $(Compile.CXX) $< -o $@ -S
1590
1591 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1592         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1593         $(Compile.C) $< -o $@ -S
1594
1595 $(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
1596         $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
1597         $(Compile.C) $< -o $@ -S
1598
1599
1600 # make the C and C++ compilers strip debug info out of bytecode libraries.
1601 ifdef DEBUG_RUNTIME
1602 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1603         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1604         $(Verb) $(LOPT) $< -std-compile-opts -o $@
1605 else
1606 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
1607         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1608         $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
1609 endif
1610
1611
1612 #---------------------------------------------------------
1613 # Provide rule to build .bc files from .ll sources,
1614 # regardless of dependencies
1615 #---------------------------------------------------------
1616 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1617         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1618         $(Verb) $(LLVMAS) $< -f -o $@
1619
1620 ###############################################################################
1621 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1622 ###############################################################################
1623
1624 ifdef TARGET
1625 TABLEGEN_INC_FILES_COMMON = 1
1626 endif
1627
1628 ifdef LLVMC_BASED_DRIVER
1629 TABLEGEN_INC_FILES_COMMON = 1
1630 endif
1631
1632 ifdef TABLEGEN_INC_FILES_COMMON
1633
1634 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1635 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1636 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1637
1638 # INCFiles rule: All of the tblgen generated files are emitted to
1639 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1640 # us to only "touch" the real file if the contents of it change.  IOW, if
1641 # tblgen is modified, all of the .inc.tmp files are regenerated, but no
1642 # dependencies of the .inc files are, unless the contents of the .inc file
1643 # changes.
1644 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1645         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1646
1647 endif # TABLEGEN_INC_FILES_COMMON
1648
1649 ifdef TARGET
1650
1651 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1652            $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1653            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1654            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1655            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1656            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1657            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1658
1659 # All of these files depend on tblgen and the .td files.
1660 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1661
1662 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1663 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1664         $(Echo) "Building $(<F) register names with tblgen"
1665         $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
1666
1667 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1668 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1669         $(Echo) "Building $(<F) register information header with tblgen"
1670         $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
1671
1672 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1673 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1674         $(Echo) "Building $(<F) register info implementation with tblgen"
1675         $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
1676
1677 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1678 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1679         $(Echo) "Building $(<F) instruction names with tblgen"
1680         $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
1681
1682 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1683 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1684         $(Echo) "Building $(<F) instruction information with tblgen"
1685         $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
1686
1687 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1688 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1689         $(Echo) "Building $(<F) assembly writer with tblgen"
1690         $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1691
1692 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1693 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1694         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1695         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1696
1697 $(TARGET:%=$(ObjDir)/%GenAsmMatcher.inc.tmp): \
1698 $(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
1699         $(Echo) "Building $(<F) assembly matcher with tblgen"
1700         $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
1701
1702 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1703 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1704         $(Echo) "Building $(<F) code emitter with tblgen"
1705         $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1706
1707 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1708 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1709         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1710         $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1711
1712 $(TARGET:%=$(ObjDir)/%GenDisassemblerTables.inc.tmp): \
1713 $(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir
1714         $(Echo) "Building $(<F) disassembly tables with tblgen"
1715         $(Verb) $(TableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
1716
1717 $(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
1718 $(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir
1719         $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
1720         $(Verb) $(TableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
1721
1722 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1723 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1724         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1725         $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1726
1727 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1728 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1729         $(Echo) "Building $(<F) subtarget information with tblgen"
1730         $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1731
1732 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1733 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1734         $(Echo) "Building $(<F) calling convention information with tblgen"
1735         $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1736
1737 $(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1738 $(ObjDir)/%GenIntrinsics.inc.tmp : %.td $(ObjDir)/.dir
1739         $(Echo) "Building $(<F) intrinsics information with tblgen"
1740         $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1741
1742 $(ObjDir)/ARMGenDecoderTables.inc.tmp : ARM.td $(ObjDir)/.dir
1743         $(Echo) "Building $(<F) decoder tables with tblgen"
1744         $(Verb) $(TableGen) -gen-arm-decoder -o $(call SYSPATH, $@) $<
1745
1746
1747 clean-local::
1748         -$(Verb) $(RM) -f $(INCFiles)
1749
1750 endif # TARGET
1751
1752 ifdef LLVMC_BASED_DRIVER
1753
1754 TDSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1755                 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
1756
1757 TDCommon := $(strip $(wildcard \
1758                 $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1759
1760 TDFiles := $(TDSrc) $(TDCommon)
1761
1762 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1763
1764 $(ObjDir)/%.inc.tmp: %.td $(ObjDir)/.dir
1765         $(Echo) "Building LLVMC compilation graph description with tblgen"
1766         $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1767
1768 clean-local::
1769         -$(Verb) $(RM) -f $(INCFiles)
1770
1771 endif # LLVMC_BASED_DRIVER
1772
1773 ###############################################################################
1774 # OTHER RULES: Other rules needed
1775 ###############################################################################
1776
1777 # To create postscript files from dot files...
1778 ifneq ($(DOT),false)
1779 %.ps: %.dot
1780         $(DOT) -Tps < $< > $@
1781 else
1782 %.ps: %.dot
1783         $(Echo) "Cannot build $@: The program dot is not installed"
1784 endif
1785
1786 # This rules ensures that header files that are removed still have a rule for
1787 # which they can be "generated."  This allows make to ignore them and
1788 # reproduce the dependency lists.
1789 %.h:: ;
1790 %.hpp:: ;
1791
1792 # Define clean-local to clean the current directory. Note that this uses a
1793 # very conservative approach ensuring that empty variables do not cause
1794 # errors or disastrous removal.
1795 clean-local::
1796 ifneq ($(strip $(ObjRootDir)),)
1797         -$(Verb) $(RM) -rf $(ObjRootDir)
1798 endif
1799         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1800 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1801         -$(Verb) $(RM) -f *$(SHLIBEXT)
1802 endif
1803
1804 clean-all-local::
1805         -$(Verb) $(RM) -rf Debug Release Profile
1806
1807
1808 ###############################################################################
1809 # DEPENDENCIES: Include the dependency files if we should
1810 ###############################################################################
1811 ifndef DISABLE_AUTO_DEPENDENCIES
1812
1813 # If its not one of the cleaning targets
1814 ifndef IS_CLEANING_TARGET
1815
1816 # Get the list of dependency files
1817 DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
1818 DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1819
1820 # Include bitcode dependency files if using bitcode libraries
1821 ifdef BYTECODE_LIBRARY
1822 DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
1823 endif
1824
1825 -include $(DependFiles) ""
1826
1827 endif
1828
1829 endif
1830
1831 ###############################################################################
1832 # CHECK: Running the test suite
1833 ###############################################################################
1834
1835 check::
1836         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1837           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1838             $(EchoCmd) Running test suite ; \
1839             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1840               TESTSUITE=$(TESTSUITE) ; \
1841           else \
1842             $(EchoCmd) No Makefile in test directory ; \
1843           fi ; \
1844         else \
1845           $(EchoCmd) No test directory ; \
1846         fi
1847
1848 check-lit:: check
1849
1850 check-dg::
1851         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1852           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1853             $(EchoCmd) Running test suite ; \
1854             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
1855           else \
1856             $(EchoCmd) No Makefile in test directory ; \
1857           fi ; \
1858         else \
1859           $(EchoCmd) No test directory ; \
1860         fi
1861
1862 check-all::
1863         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1864           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1865             $(EchoCmd) Running test suite ; \
1866             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-all ; \
1867           else \
1868             $(EchoCmd) No Makefile in test directory ; \
1869           fi ; \
1870         else \
1871           $(EchoCmd) No test directory ; \
1872         fi
1873
1874 ###############################################################################
1875 # UNITTESTS: Running the unittests test suite
1876 ###############################################################################
1877
1878 unittests::
1879         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1880           if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1881             $(EchoCmd) Running unittests test suite ; \
1882             $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests unitcheck; \
1883           else \
1884             $(EchoCmd) No Makefile in unittests directory ; \
1885           fi ; \
1886         else \
1887           $(EchoCmd) No unittests directory ; \
1888         fi
1889
1890 ###############################################################################
1891 # DISTRIBUTION: Handle construction of a distribution tarball
1892 ###############################################################################
1893
1894 #------------------------------------------------------------------------
1895 # Define distribution related variables
1896 #------------------------------------------------------------------------
1897 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1898 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1899 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1900 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1901 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1902 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1903 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1904                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1905                Makefile.config.in configure autoconf
1906 DistOther   := $(notdir $(wildcard \
1907                $(PROJ_SRC_DIR)/*.h \
1908                $(PROJ_SRC_DIR)/*.td \
1909                $(PROJ_SRC_DIR)/*.def \
1910                $(PROJ_SRC_DIR)/*.ll \
1911                $(PROJ_SRC_DIR)/*.in))
1912 DistSubDirs := $(SubDirs)
1913 DistSources  = $(Sources) $(EXTRA_DIST)
1914 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1915
1916 #------------------------------------------------------------------------
1917 # We MUST build distribution with OBJ_DIR != SRC_DIR
1918 #------------------------------------------------------------------------
1919 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1920 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1921         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1922
1923 else
1924
1925 #------------------------------------------------------------------------
1926 # Prevent attempt to run dist targets from anywhere but the top level
1927 #------------------------------------------------------------------------
1928 ifneq ($(LEVEL),.)
1929 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1930         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1931 else
1932
1933 #------------------------------------------------------------------------
1934 # Provide the top level targets
1935 #------------------------------------------------------------------------
1936
1937 dist-gzip:: $(DistTarGZip)
1938
1939 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1940         $(Echo) Packing gzipped distribution tar file.
1941         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1942           $(GZIP) -c > "$(DistTarGZip)"
1943
1944 dist-bzip2:: $(DistTarBZ2)
1945
1946 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1947         $(Echo) Packing bzipped distribution tar file.
1948         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1949           $(BZIP2) -c >$(DistTarBZ2)
1950
1951 dist-zip:: $(DistZip)
1952
1953 $(DistZip) : $(TopDistDir)/.makedistdir
1954         $(Echo) Packing zipped distribution file.
1955         $(Verb) rm -f $(DistZip)
1956         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1957
1958 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1959         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1960
1961 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1962
1963 dist-check:: $(DistTarGZip)
1964         $(Echo) Checking distribution tar file.
1965         $(Verb) if test -d $(DistCheckDir) ; then \
1966           $(RM) -rf $(DistCheckDir) ; \
1967         fi
1968         $(Verb) $(MKDIR) $(DistCheckDir)
1969         $(Verb) cd $(DistCheckDir) && \
1970           $(MKDIR) $(DistCheckDir)/build && \
1971           $(MKDIR) $(DistCheckDir)/install && \
1972           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1973           cd build && \
1974           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1975             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1976           $(MAKE) all && \
1977           $(MAKE) check && \
1978           $(MAKE) unittests && \
1979           $(MAKE) install && \
1980           $(MAKE) uninstall && \
1981           $(MAKE) dist-clean && \
1982           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1983
1984 dist-clean::
1985         $(Echo) Cleaning distribution files
1986         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1987           $(DistCheckDir)
1988
1989 endif
1990
1991 #------------------------------------------------------------------------
1992 # Provide the recursive distdir target for building the distribution directory
1993 #------------------------------------------------------------------------
1994 distdir: $(DistDir)/.makedistdir
1995 $(DistDir)/.makedistdir: $(DistSources)
1996         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1997           if test -d "$(DistDir)" ; then \
1998             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1999               exit 1 ; \
2000           fi ; \
2001           $(EchoCmd) Removing old $(DistDir) ; \
2002           $(RM) -rf $(DistDir); \
2003           $(EchoCmd) Making 'all' to verify build ; \
2004           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
2005         fi
2006         $(Echo) Building Distribution Directory $(DistDir)
2007         $(Verb) $(MKDIR) $(DistDir)
2008         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
2009         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
2010         for file in $(DistFiles) ; do \
2011           case "$$file" in \
2012             $(PROJ_SRC_DIR)/*) \
2013               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
2014               ;; \
2015             $(PROJ_SRC_ROOT)/*) \
2016               file=`echo "$$file" | \
2017                 sed "s#^$$srcrootstrip/##"` \
2018               ;; \
2019           esac; \
2020           if test -f "$(PROJ_SRC_DIR)/$$file" || \
2021              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
2022             from_dir="$(PROJ_SRC_DIR)" ; \
2023           elif test -f "$$file" || test -d "$$file" ; then \
2024             from_dir=. ; \
2025           fi ; \
2026           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
2027           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
2028             to_dir="$(DistDir)/$$dir"; \
2029             $(MKDIR) "$$to_dir" ; \
2030           else \
2031             to_dir="$(DistDir)"; \
2032           fi; \
2033           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
2034           if test -n "$$mid_dir" ; then \
2035             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
2036           fi ; \
2037           if test -d "$$from_dir/$$file"; then \
2038             if test -d "$(PROJ_SRC_DIR)/$$file" && \
2039                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
2040                cd $(PROJ_SRC_DIR) ; \
2041                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2042                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2043                cd $(PROJ_OBJ_DIR) ; \
2044             else \
2045                cd $$from_dir ; \
2046                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
2047                  ( cd $$to_dir ; $(TAR) xf - ) ; \
2048                cd $(PROJ_OBJ_DIR) ; \
2049             fi; \
2050           elif test -f "$$from_dir/$$file" ; then \
2051             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
2052           elif test -L "$$from_dir/$$file" ; then \
2053             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
2054           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
2055             $(EchoCmd) "===== WARNING: Distribution Source " \
2056               "$$from_dir/$$file Not Found!" ; \
2057           elif test "$(Verb)" != '@' ; then \
2058             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
2059           fi; \
2060         done
2061         $(Verb) for subdir in $(DistSubDirs) ; do \
2062           if test "$$subdir" \!= "." ; then \
2063             new_distdir="$(DistDir)/$$subdir" ; \
2064             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
2065             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
2066               DistDir="$$new_distdir" distdir ) || exit 1; \
2067           fi; \
2068         done
2069         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
2070           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
2071           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
2072                                   -name .svn \) -print` ;\
2073           $(MAKE) dist-hook ; \
2074           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
2075             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
2076             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
2077             -o ! -type d ! -perm -444 -exec \
2078               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
2079             || chmod -R a+r $(DistDir) ; \
2080         fi
2081
2082 # This is invoked by distdir target, define it as a no-op to avoid errors if not
2083 # defined by user.
2084 dist-hook::
2085
2086 endif
2087
2088 ###############################################################################
2089 # TOP LEVEL - targets only to apply at the top level directory
2090 ###############################################################################
2091
2092 ifeq ($(LEVEL),.)
2093
2094 #------------------------------------------------------------------------
2095 # Install support for the project's include files:
2096 #------------------------------------------------------------------------
2097 ifdef NO_INSTALL
2098 install-local::
2099         $(Echo) Install circumvented with NO_INSTALL
2100 uninstall-local::
2101         $(Echo) Uninstall circumvented with NO_INSTALL
2102 else
2103 install-local::
2104         $(Echo) Installing include files
2105         $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_includedir)
2106         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
2107           cd $(PROJ_SRC_ROOT)/include && \
2108           for  hdr in `find . -type f '!' '(' -name '*~' \
2109               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
2110               grep -v .svn` ; do \
2111             instdir=`dirname "$(DESTDIR)$(PROJ_includedir)/$$hdr"` ; \
2112             if test \! -d "$$instdir" ; then \
2113               $(EchoCmd) Making install directory $$instdir ; \
2114               $(MKDIR) $$instdir ;\
2115             fi ; \
2116             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2117           done ; \
2118         fi
2119 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
2120         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
2121           cd $(PROJ_OBJ_ROOT)/include && \
2122           for hdr in `find . -type f -print | grep -v CVS` ; do \
2123             $(DataInstall) $$hdr $(DESTDIR)$(PROJ_includedir)/$$hdr ; \
2124           done ; \
2125         fi
2126 endif
2127
2128 uninstall-local::
2129         $(Echo) Uninstalling include files
2130         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
2131           cd $(PROJ_SRC_ROOT)/include && \
2132             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
2133               '!' '(' -name '*~' -o -name '.#*' \
2134         -o -name '*.in' ')' -print ')' | \
2135         grep -v CVS | sed 's#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2136           cd $(PROJ_SRC_ROOT)/include && \
2137             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
2138       -print ')' | sed 's#\.in$$##;s#^#$(DESTDIR)$(PROJ_includedir)/#'` ; \
2139         fi
2140 endif
2141 endif
2142
2143 check-line-length:
2144         @echo searching for overlength lines in files: $(Sources)
2145         @echo
2146         @echo
2147         egrep -n '.{81}' $(Sources) /dev/null
2148
2149 check-for-tabs:
2150         @echo searching for tabs in files: $(Sources)
2151         @echo
2152         @echo
2153         egrep -n '      ' $(Sources) /dev/null
2154
2155 check-footprint:
2156         @ls -l $(LibDir) | awk '\
2157           BEGIN { sum = 0; } \
2158                 { sum += $$5; } \
2159           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2160         @ls -l $(ToolDir) | awk '\
2161           BEGIN { sum = 0; } \
2162                 { sum += $$5; } \
2163           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
2164 #------------------------------------------------------------------------
2165 # Print out the directories used for building
2166 #------------------------------------------------------------------------
2167 printvars::
2168         $(Echo) "BuildMode    : " '$(BuildMode)'
2169         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
2170         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
2171         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
2172         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
2173         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
2174         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
2175         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
2176         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
2177         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
2178         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
2179         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
2180         $(Echo) "UserTargets  : " '$(UserTargets)'
2181         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
2182         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
2183         $(Echo) "ObjDir       : " '$(ObjDir)'
2184         $(Echo) "LibDir       : " '$(LibDir)'
2185         $(Echo) "ToolDir      : " '$(ToolDir)'
2186         $(Echo) "ExmplDir     : " '$(ExmplDir)'
2187         $(Echo) "Sources      : " '$(Sources)'
2188         $(Echo) "TDFiles      : " '$(TDFiles)'
2189         $(Echo) "INCFiles     : " '$(INCFiles)'
2190         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
2191         $(Echo) "PreConditions: " '$(PreConditions)'
2192         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
2193         $(Echo) "Compile.C    : " '$(Compile.C)'
2194         $(Echo) "Archive      : " '$(Archive)'
2195         $(Echo) "YaccFiles    : " '$(YaccFiles)'
2196         $(Echo) "LexFiles     : " '$(LexFiles)'
2197         $(Echo) "Module       : " '$(Module)'
2198         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
2199         $(Echo) "SubDirs      : " '$(SubDirs)'
2200         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
2201         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
2202
2203 ###
2204 # Debugging
2205
2206 # General debugging rule, use 'make dbg-print-XXX' to print the
2207 # definition, value and origin of XXX.
2208 make-print-%:
2209         $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))