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