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