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