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