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