1#---------------------------------------------------------------------- 2# Clients fill in the source files to build 3#---------------------------------------------------------------------- 4# C_SOURCES := main.c 5# CXX_SOURCES := 6# OBJC_SOURCES := 7# OBJCXX_SOURCES := 8# DYLIB_C_SOURCES := 9# DYLIB_OBJC_SOURCES := 10# DYLIB_CXX_SOURCES := 11# 12# Specifying DYLIB_ONLY has the effect of building dylib only, skipping 13# the building of the a.out executable program. For example, 14# DYLIB_ONLY := YES 15# 16# Specifying FRAMEWORK and its variants has the effect of building a NeXT-style 17# framework. 18# FRAMEWORK := "Foo" 19# FRAMEWORK_HEADERS := "Foo.h" 20# FRAMEWORK_MODULES := "module.modulemap" 21# 22# Also might be of interest: 23# FRAMEWORK_INCLUDES (Darwin only) := 24# CFLAGS_EXTRAS := 25# LD_EXTRAS := 26# SPLIT_DEBUG_SYMBOLS := YES 27# CROSS_COMPILE := 28# USE_PRIVATE_MODULE_CACHE := YES 29# 30# And test/functionalities/archives/Makefile: 31# MAKE_DSYM := NO 32# ARCHIVE_NAME := libfoo.a 33# ARCHIVE_C_SOURCES := a.c b.c 34 35# Uncomment line below for debugging shell commands 36# SHELL = /bin/sh -x 37 38SRCDIR := $(shell dirname $(firstword $(MAKEFILE_LIST))) 39BUILDDIR := $(shell pwd) 40MAKEFILE_RULES := $(lastword $(MAKEFILE_LIST)) 41THIS_FILE_DIR := $(shell dirname $(MAKEFILE_RULES)) 42LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../ 43 44# The test harness invokes the test Makefiles with an explicit 'all' 45# target, but its handy to be able to recursively call this Makefile 46# without specifying a goal. You almost certainly want to build 'all', 47# and not only the first target defined in this file (which might vary 48# according to variable values). 49.DEFAULT_GOAL := all 50 51#---------------------------------------------------------------------- 52# If OS is not defined, use 'uname -s' to determine the OS name. 53# 54# uname on Windows gives "windows32" or "server version windows32", but most 55# environments standardize on "Windows_NT", so we'll make it consistent here. 56# When running tests from Visual Studio, the environment variable isn't 57# inherited all the way down to the process spawned for make. 58#---------------------------------------------------------------------- 59HOST_OS = $(shell uname -s) 60ifneq (,$(findstring windows32,$(HOST_OS))) 61 HOST_OS = Windows_NT 62endif 63ifeq "$(OS)" "" 64 OS = $(HOST_OS) 65endif 66 67#---------------------------------------------------------------------- 68# If OS is Windows, force SHELL to be cmd 69# 70# Some versions of make on Windows will search for other shells such as 71# C:\cygwin\bin\sh.exe. This shell fails for numerous different reasons 72# so default to using cmd.exe. 73#---------------------------------------------------------------------- 74ifeq "$(OS)" "Windows_NT" 75 SHELL = $(WINDIR)\system32\cmd.exe 76endif 77 78#---------------------------------------------------------------------- 79# If the OS is Windows use double-quotes in commands 80# 81# For other operating systems, single-quotes work fine, but on Windows 82# we strictly required double-quotes 83#---------------------------------------------------------------------- 84ifeq "$(HOST_OS)" "Windows_NT" 85 JOIN_CMD = & 86 QUOTE = " 87 FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = " 88else 89 JOIN_CMD = ; 90 QUOTE = ' 91 FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = ' 92endif 93 94#---------------------------------------------------------------------- 95# If TRIPLE is not defined try to set the ARCH, CC, CFLAGS, and more 96# from the triple alone 97#---------------------------------------------------------------------- 98ARCH_CFLAGS := 99ifneq "$(TRIPLE)" "" 100 triple_space = $(subst -, ,$(TRIPLE)) 101 ARCH =$(word 1, $(triple_space)) 102 TRIPLE_VENDOR =$(word 2, $(triple_space)) 103 triple_os_and_version =$(shell echo $(word 3, $(triple_space)) | sed 's/\([a-z]*\)\(.*\)/\1 \2/') 104 TRIPLE_OS =$(word 1, $(triple_os_and_version)) 105 TRIPLE_VERSION =$(word 2, $(triple_os_and_version)) 106 TRIPLE_ENV =$(word 4, $(triple_space)) 107 ifeq "$(TRIPLE_VENDOR)" "apple" 108 ifeq "$(TRIPLE_OS)" "ios" 109 ifeq "$(TRIPLE_ENV)" "simulator" 110 SDK_NAME := iphonesimulator 111 else 112 ifeq "$(TRIPLE_ENV)" "macabi" 113 SDK_NAME := macosx 114 else 115 SDK_NAME := iphoneos 116 endif 117 endif 118 endif 119 ifeq "$(TRIPLE_OS)" "tvos" 120 ifeq "$(TRIPLE_ENV)" "simulator" 121 SDK_NAME := appletvsimulator 122 else 123 SDK_NAME := appletvos 124 endif 125 endif 126 ifeq "$(TRIPLE_OS)" "watchos" 127 ifeq "$(TRIPLE_ENV)" "simulator" 128 SDK_NAME := watchsimulator 129 else 130 SDK_NAME := watchos 131 endif 132 endif 133 ifneq "$(TRIPLE_OS)" "macosx" 134 ifeq "$(TRIPLE_ENV)" "" 135 CODESIGN := codesign 136 endif 137 endif 138 139 ifeq "$(SDKROOT)" "" 140 SDKROOT := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path) 141 endif 142 ifeq "$(TRIPLE_VERSION)" "" 143 ifeq "$(SDK_NAME)" "" 144 $(error "SDK_NAME is empty") 145 endif 146 TRIPLE_VERSION := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-version) 147 endif 148 ifeq "$(TRIPLE_ENV)" "simulator" 149 ARCH_CFLAGS := -m$(TRIPLE_OS)-simulator-version-min=$(TRIPLE_VERSION) 150 else 151 ifneq "$(TRIPLE_OS)" "macosx" 152 ARCH_CFLAGS := -m$(TRIPLE_OS)-version-min=$(TRIPLE_VERSION) 153 endif 154 endif 155 endif 156 ARCH_CFLAGS += -target $(TRIPLE) 157endif 158ifeq "$(OS)" "Android" 159 include $(THIS_FILE_DIR)/Android.rules 160endif 161 162#---------------------------------------------------------------------- 163# If ARCH is not defined, default to x86_64. 164#---------------------------------------------------------------------- 165ifeq "$(ARCH)" "" 166ifeq "$(OS)" "Windows_NT" 167 ARCH = x86 168else 169 ARCH = x86_64 170endif 171endif 172 173#---------------------------------------------------------------------- 174# CC defaults to clang. 175# 176# If you change the defaults of CC, be sure to also change it in the file 177# test/plugins/builder_base.py, which provides a Python way to return the 178# value of the make variable CC -- getCompiler(). 179# 180# See also these functions: 181# o cxx_compiler 182# o cxx_linker 183#---------------------------------------------------------------------- 184ifeq "$(CC)" "" 185$(error "C compiler is not specified. Please run tests through lldb-dotest or lit") 186endif 187 188#---------------------------------------------------------------------- 189# Handle SDKROOT on Darwin 190#---------------------------------------------------------------------- 191 192ifeq "$(OS)" "Darwin" 193 ifeq "$(SDKROOT)" "" 194 # We haven't otherwise set the SDKROOT, so set it now to macosx 195 SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path) 196 endif 197endif 198 199#---------------------------------------------------------------------- 200# ARCHFLAG is the flag used to tell the compiler which architecture 201# to compile for. The default is the flag that clang accepts. 202#---------------------------------------------------------------------- 203ARCHFLAG ?= -arch 204 205#---------------------------------------------------------------------- 206# Change any build/tool options needed 207#---------------------------------------------------------------------- 208ifeq "$(OS)" "Darwin" 209 DS := $(DSYMUTIL) 210 DSFLAGS = 211 DSYM = $(EXE).dSYM 212 AR := $(CROSS_COMPILE)libtool 213 ARFLAGS := -static -o 214else 215 AR := $(CROSS_COMPILE)ar 216 # On non-Apple platforms, -arch becomes -m 217 ARCHFLAG := -m 218 219 # i386, i686, x86 -> 32 220 # amd64, x86_64, x64 -> 64 221 ifeq "$(ARCH)" "amd64" 222 override ARCH := $(subst amd64,64,$(ARCH)) 223 endif 224 ifeq "$(ARCH)" "x86_64" 225 override ARCH := $(subst x86_64,64,$(ARCH)) 226 endif 227 ifeq "$(ARCH)" "x64" 228 override ARCH := $(subst x64,64,$(ARCH)) 229 endif 230 ifeq "$(ARCH)" "x86" 231 override ARCH := $(subst x86,32,$(ARCH)) 232 endif 233 ifeq "$(ARCH)" "i386" 234 override ARCH := $(subst i386,32,$(ARCH)) 235 endif 236 ifeq "$(ARCH)" "i686" 237 override ARCH := $(subst i686,32,$(ARCH)) 238 endif 239 ifeq "$(ARCH)" "powerpc" 240 override ARCH := $(subst powerpc,32,$(ARCH)) 241 endif 242 ifeq "$(ARCH)" "powerpc64" 243 override ARCH := $(subst powerpc64,64,$(ARCH)) 244 endif 245 ifeq "$(ARCH)" "powerpc64le" 246 override ARCH := $(subst powerpc64le,64,$(ARCH)) 247 endif 248 ifeq "$(ARCH)" "aarch64" 249 override ARCH := 250 override ARCHFLAG := 251 endif 252 ifeq "$(findstring arm,$(ARCH))" "arm" 253 override ARCH := 254 override ARCHFLAG := 255 endif 256 ifeq "$(ARCH)" "s390x" 257 override ARCH := 258 override ARCHFLAG := 259 endif 260 ifeq "$(findstring mips,$(ARCH))" "mips" 261 override ARCHFLAG := - 262 endif 263 264 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" 265 DSYM = $(EXE).debug 266 endif 267endif 268 269LIMIT_DEBUG_INFO_FLAGS = 270NO_LIMIT_DEBUG_INFO_FLAGS = 271MODULE_DEBUG_INFO_FLAGS = 272ifneq (,$(findstring clang,$(CC))) 273 LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info 274 NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info 275 MODULE_DEBUG_INFO_FLAGS += -gmodules 276endif 277 278DEBUG_INFO_FLAG ?= -g 279 280CFLAGS ?= $(DEBUG_INFO_FLAG) -O0 -fno-builtin 281 282ifeq "$(OS)" "Darwin" 283 ifneq "$(SDKROOT)" "" 284 CFLAGS += -isysroot "$(SDKROOT)" 285 endif 286endif 287 288ifeq "$(OS)" "Darwin" 289 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include 290else 291 CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include 292endif 293 294CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR) 295 296ifndef NO_TEST_COMMON_H 297 CFLAGS += -include $(THIS_FILE_DIR)/test_common.h 298endif 299 300CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS) 301 302# If the OS is Windows, we need to pass -gdwarf to clang, otherwise it will build 303# with codeview by default but all the tests rely on dwarf. 304ifeq "$(OS)" "Windows_NT" 305 CFLAGS += -gdwarf 306endif 307 308# Use this one if you want to build one part of the result without debug information: 309ifeq "$(OS)" "Darwin" 310 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)" 311else 312 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) 313endif 314 315ifeq "$(MAKE_DWO)" "YES" 316 CFLAGS += -gsplit-dwarf 317endif 318 319ifeq "$(USE_PRIVATE_MODULE_CACHE)" "YES" 320THE_CLANG_MODULE_CACHE_DIR := $(BUILDDIR)/private-module-cache 321else 322THE_CLANG_MODULE_CACHE_DIR := $(CLANG_MODULE_CACHE_DIR) 323endif 324 325MODULE_BASE_FLAGS := -fmodules -gmodules -fmodules-cache-path=$(THE_CLANG_MODULE_CACHE_DIR) 326MANDATORY_MODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -gmodules 327# Build flags for building with C++ modules. 328# -glldb is necessary for emitting information about what modules were imported. 329MANDATORY_CXXMODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -fcxx-modules -glldb 330 331ifeq "$(OS)" "Darwin" 332 MANDATORY_MODULE_BUILD_CFLAGS += -fcxx-modules 333endif 334 335ifeq "$(MAKE_GMODULES)" "YES" 336 CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS) 337 CXXFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS) 338endif 339 340CFLAGS += $(CFLAGS_EXTRAS) 341CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS) $(CXXFLAGS_EXTRAS) 342LD = $(CC) 343LDFLAGS ?= $(CFLAGS) 344LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS) 345ifneq (,$(LLVM_LIBS_DIR)) 346 ifeq ($(OS),NetBSD) 347 LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LLVM_LIBS_DIR) 348 endif 349endif 350ifeq (,$(filter $(OS), Windows_NT Android Darwin)) 351 ifneq (,$(filter YES,$(ENABLE_THREADS))) 352 LDFLAGS += -pthread 353 endif 354endif 355OBJECTS = 356EXE ?= a.out 357 358ifneq "$(FRAMEWORK)" "" 359 DYLIB_NAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) 360 DYLIB_FILENAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) 361endif 362 363ifneq "$(DYLIB_NAME)" "" 364 ifeq "$(OS)" "Darwin" 365 ifneq "$(FRAMEWORK)" "" 366 DYLIB_INSTALL_NAME ?= @executable_path/$(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) 367 else 368 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib 369 DYLIB_INSTALL_NAME ?= @executable_path/$(DYLIB_FILENAME) 370 endif 371 else ifeq "$(OS)" "Windows_NT" 372 DYLIB_FILENAME = $(DYLIB_NAME).dll 373 else 374 DYLIB_FILENAME = lib$(DYLIB_NAME).so 375 endif 376endif 377 378# Function that returns the counterpart C++ compiler, given $(CC) as arg. 379cxx_compiler_notdir = $(if $(findstring icc,$(1)), \ 380 $(subst icc,icpc,$(1)), \ 381 $(if $(findstring llvm-gcc,$(1)), \ 382 $(subst llvm-gcc,llvm-g++,$(1)), \ 383 $(if $(findstring gcc,$(1)), \ 384 $(subst gcc,g++,$(1)), \ 385 $(subst cc,c++,$(1))))) 386cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1))) 387 388# Function that returns the C++ linker, given $(CC) as arg. 389cxx_linker_notdir = $(if $(findstring icc,$(1)), \ 390 $(subst icc,icpc,$(1)), \ 391 $(if $(findstring llvm-gcc,$(1)), \ 392 $(subst llvm-gcc,llvm-g++,$(1)), \ 393 $(if $(findstring gcc,$(1)), \ 394 $(subst gcc,g++,$(1)), \ 395 $(subst cc,c++,$(1))))) 396cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1))) 397 398ifneq "$(OS)" "Darwin" 399 CLANG_OR_GCC := $(strip $(if $(findstring clang,$(CC)), \ 400 $(findstring clang,$(CC)), \ 401 $(if $(findstring gcc,$(CC)), \ 402 $(findstring gcc,$(CC)), \ 403 cc))) 404 405 CC_LASTWORD := $(strip $(lastword $(subst -, ,$(CC)))) 406 407 replace_with = $(strip $(if $(findstring $(3),$(CC_LASTWORD)), \ 408 $(subst $(3),$(1),$(2)), \ 409 $(subst $(3),$(1),$(subst -$(CC_LASTWORD),,$(2))))) 410 411 ifeq "$(notdir $(CC))" "$(CC)" 412 replace_cc_with = $(call replace_with,$(1),$(CC),$(CLANG_OR_GCC)) 413 else 414 replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(1),$(notdir $(CC)),$(CLANG_OR_GCC))) 415 endif 416 417 OBJCOPY ?= $(call replace_cc_with,objcopy) 418 ARCHIVER ?= $(call replace_cc_with,ar) 419 override AR = $(ARCHIVER) 420endif 421 422ifdef PIE 423 LDFLAGS += -pie 424endif 425 426#---------------------------------------------------------------------- 427# Windows specific options 428#---------------------------------------------------------------------- 429ifeq "$(OS)" "Windows_NT" 430 ifneq (,$(findstring clang,$(CC))) 431 # Clang for Windows doesn't support C++ Exceptions 432 CXXFLAGS += -fno-exceptions 433 CXXFLAGS += -D_HAS_EXCEPTIONS=0 434 435 # MSVC 2015 or higher is required, which depends on c++14, so 436 # append these values unconditionally. 437 CXXFLAGS += -fms-compatibility-version=19.0 438 override CXXFLAGS := $(subst -std=c++11,-std=c++14,$(CXXFLAGS)) 439 440 # The MSVC linker doesn't understand long section names 441 # generated by the clang compiler. 442 LDFLAGS += -fuse-ld=lld 443 endif 444endif 445 446#---------------------------------------------------------------------- 447# C++ standard library options 448#---------------------------------------------------------------------- 449ifeq (1,$(USE_LIBSTDCPP)) 450 # Clang requires an extra flag: -stdlib=libstdc++ 451 ifneq (,$(findstring clang,$(CC))) 452 CXXFLAGS += -stdlib=libstdc++ -DLLDB_USING_LIBSTDCPP 453 LDFLAGS += -stdlib=libstdc++ 454 endif 455endif 456 457ifeq (1,$(USE_LIBCPP)) 458 CXXFLAGS += -DLLDB_USING_LIBCPP 459 ifeq "$(OS)" "Linux" 460 ifneq (,$(findstring clang,$(CC))) 461 CXXFLAGS += -stdlib=libc++ 462 LDFLAGS += -stdlib=libc++ 463 else 464 CXXFLAGS += -isystem /usr/include/c++/v1 465 LDFLAGS += -lc++ 466 endif 467 else ifeq "$(OS)" "Android" 468 # Nothing to do, this is already handled in 469 # Android.rules. 470 else 471 CXXFLAGS += -stdlib=libc++ 472 LDFLAGS += -stdlib=libc++ 473 endif 474endif 475 476#---------------------------------------------------------------------- 477# Additional system libraries 478#---------------------------------------------------------------------- 479ifeq (1,$(USE_LIBDL)) 480 ifeq (,$(filter $(OS), NetBSD Windows_NT)) 481 LDFLAGS += -ldl 482 endif 483endif 484 485#---------------------------------------------------------------------- 486# dylib settings 487#---------------------------------------------------------------------- 488 489DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o)) 490DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o)) 491ifneq "$(strip $(DYLIB_CXX_SOURCES))" "" 492 DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o))) 493 CXX = $(call cxx_compiler,$(CC)) 494 LD = $(call cxx_linker,$(CC)) 495endif 496 497#---------------------------------------------------------------------- 498# Check if we have a precompiled header 499#---------------------------------------------------------------------- 500ifneq "$(strip $(PCH_CXX_SOURCE))" "" 501 PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch) 502 PCHFLAGS = -include $(PCH_CXX_SOURCE) 503endif 504 505#---------------------------------------------------------------------- 506# Check if we have any C source files 507#---------------------------------------------------------------------- 508ifneq "$(strip $(C_SOURCES))" "" 509 OBJECTS +=$(strip $(C_SOURCES:.c=.o)) 510endif 511 512#---------------------------------------------------------------------- 513# Check if we have any C++ source files 514#---------------------------------------------------------------------- 515ifneq "$(strip $(CXX_SOURCES))" "" 516 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o)) 517 CXX = $(call cxx_compiler,$(CC)) 518 LD = $(call cxx_linker,$(CC)) 519endif 520 521#---------------------------------------------------------------------- 522# Check if we have any ObjC source files 523#---------------------------------------------------------------------- 524ifneq "$(strip $(OBJC_SOURCES))" "" 525 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o)) 526 LDFLAGS +=-lobjc 527endif 528 529#---------------------------------------------------------------------- 530# Check if we have any ObjC++ source files 531#---------------------------------------------------------------------- 532ifneq "$(strip $(OBJCXX_SOURCES))" "" 533 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o)) 534 CXX = $(call cxx_compiler,$(CC)) 535 LD = $(call cxx_linker,$(CC)) 536 ifeq "$(findstring lobjc,$(LDFLAGS))" "" 537 LDFLAGS +=-lobjc 538 endif 539endif 540 541#---------------------------------------------------------------------- 542# Check if we have any C source files for archive 543#---------------------------------------------------------------------- 544ifneq "$(strip $(ARCHIVE_C_SOURCES))" "" 545 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o)) 546endif 547 548#---------------------------------------------------------------------- 549# Check if we have any C++ source files for archive 550#---------------------------------------------------------------------- 551ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" "" 552 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o)) 553 CXX = $(call cxx_compiler,$(CC)) 554 LD = $(call cxx_linker,$(CC)) 555endif 556 557#---------------------------------------------------------------------- 558# Check if we have any ObjC source files for archive 559#---------------------------------------------------------------------- 560ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" "" 561 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o)) 562 LDFLAGS +=-lobjc 563endif 564 565#---------------------------------------------------------------------- 566# Check if we have any ObjC++ source files for archive 567#---------------------------------------------------------------------- 568ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" "" 569 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o)) 570 CXX = $(call cxx_compiler,$(CC)) 571 LD = $(call cxx_linker,$(CC)) 572 ifeq "$(findstring lobjc,$(LDFLAGS))" "" 573 LDFLAGS +=-lobjc 574 endif 575endif 576 577#---------------------------------------------------------------------- 578# Check if we are compiling with gcc 4.6 579#---------------------------------------------------------------------- 580ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" "" 581ifneq "$(filter g++,$(CXX))" "" 582 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3) 583 ifeq "$(CXXVERSION)" "4.6" 584 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x 585 # instead. FIXME: remove once GCC version is upgraded. 586 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS)) 587 endif 588endif 589endif 590 591ifeq ($(findstring clang, $(CXX)), clang) 592 CXXFLAGS += --driver-mode=g++ 593endif 594 595ifneq "$(CXX)" "" 596 ifeq ($(findstring clang, $(LD)), clang) 597 LDFLAGS += --driver-mode=g++ 598 endif 599endif 600 601#---------------------------------------------------------------------- 602# DYLIB_ONLY variable can be used to skip the building of a.out. 603# See the sections below regarding dSYM file as well as the building of 604# EXE from all the objects. 605#---------------------------------------------------------------------- 606 607#---------------------------------------------------------------------- 608# Compile the executable from all the objects. 609#---------------------------------------------------------------------- 610ifneq "$(DYLIB_NAME)" "" 611ifeq "$(DYLIB_ONLY)" "" 612$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME) 613 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)" 614ifneq "$(CODESIGN)" "" 615 $(CODESIGN) -s - "$(EXE)" 616endif 617else 618EXE = $(DYLIB_FILENAME) 619endif 620else 621$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) 622 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)" 623ifneq "$(CODESIGN)" "" 624 $(CODESIGN) -s - "$(EXE)" 625endif 626endif 627 628#---------------------------------------------------------------------- 629# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO" 630#---------------------------------------------------------------------- 631$(DSYM) : $(EXE) 632ifeq "$(OS)" "Darwin" 633ifneq "$(MAKE_DSYM)" "NO" 634 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)" 635else 636endif 637else 638ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" 639 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)" 640 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)" 641endif 642endif 643 644#---------------------------------------------------------------------- 645# Make the archive 646#---------------------------------------------------------------------- 647ifneq "$(ARCHIVE_NAME)" "" 648ifeq "$(OS)" "Darwin" 649$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS) 650 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) 651 $(RM) $(ARCHIVE_OBJECTS) 652else 653$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj))) 654endif 655endif 656 657#---------------------------------------------------------------------- 658# Make the dylib 659#---------------------------------------------------------------------- 660$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL 661 662ifneq "$(OS)" "Windows_NT" 663$(DYLIB_OBJECTS) : CFLAGS += -fPIC 664$(DYLIB_OBJECTS) : CXXFLAGS += -fPIC 665endif 666 667$(DYLIB_FILENAME) : $(DYLIB_OBJECTS) 668ifeq "$(OS)" "Darwin" 669ifneq "$(FRAMEWORK)" "" 670 mkdir -p $(FRAMEWORK).framework/Versions/A/Headers 671 mkdir -p $(FRAMEWORK).framework/Versions/A/Modules 672 mkdir -p $(FRAMEWORK).framework/Versions/A/Resources 673ifneq "$(FRAMEWORK_MODULES)" "" 674 cp -r $(FRAMEWORK_MODULES) $(FRAMEWORK).framework/Versions/A/Modules 675endif 676ifneq "$(FRAMEWORK_HEADERS)" "" 677 cp -r $(FRAMEWORK_HEADERS) $(FRAMEWORK).framework/Versions/A/Headers 678endif 679 (cd $(FRAMEWORK).framework/Versions; ln -sf A Current) 680 (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Headers Headers) 681 (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Modules Modules) 682 (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Resources Resources) 683 (cd $(FRAMEWORK).framework/; ln -sf Versions/A/$(FRAMEWORK) $(FRAMEWORK)) 684endif 685 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_INSTALL_NAME)" -dynamiclib -o "$(DYLIB_FILENAME)" 686ifneq "$(CODESIGN)" "" 687 $(CODESIGN) -s - "$(DYLIB_FILENAME)" 688endif 689ifneq "$(MAKE_DSYM)" "NO" 690ifneq "$(DS)" "" 691 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)" 692endif 693endif 694else 695 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)" 696ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" 697 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug" 698 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)" 699endif 700endif 701 702#---------------------------------------------------------------------- 703# Make the precompiled header and compile C++ sources against it 704#---------------------------------------------------------------------- 705 706#ifneq "$(PCH_OUTPUT)" "" 707$(PCH_OUTPUT) : $(PCH_CXX_SOURCE) 708 $(CXX) $(CXXFLAGS) -x c++-header -o $@ $< 709%.o : %.cpp $(PCH_OUTPUT) 710 $(CXX) $(PCHFLAGS) $(CXXFLAGS) -c -o $@ $< 711#endif 712 713#---------------------------------------------------------------------- 714# Automatic variables based on items already entered. Below we create 715# an object's lists from the list of sources by replacing all entries 716# that end with .c with .o, and we also create a list of prerequisite 717# files by replacing all .c files with .d. 718#---------------------------------------------------------------------- 719PREREQS := $(OBJECTS:.o=.d) 720DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo) 721ifneq "$(DYLIB_NAME)" "" 722 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d) 723 DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo) 724endif 725 726#---------------------------------------------------------------------- 727# Rule for Generating Prerequisites Automatically using .d files and 728# the compiler -MM option. The -M option will list all system headers, 729# and the -MM option will list all non-system dependencies. 730#---------------------------------------------------------------------- 731%.d: %.c 732 @rm -f $@ $(JOIN_CMD) \ 733 $(CC) -M $(CFLAGS) $< > $@.tmp && \ 734 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \ 735 rm -f $@.tmp 736 737%.d: %.cpp 738 @rm -f $@ $(JOIN_CMD) \ 739 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \ 740 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \ 741 rm -f $@.tmp 742 743%.d: %.m 744 @rm -f $@ $(JOIN_CMD) \ 745 $(CC) -M $(CFLAGS) $< > $@.tmp && \ 746 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \ 747 rm -f $@.tmp 748 749%.d: %.mm 750 @rm -f $@ $(JOIN_CMD) \ 751 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \ 752 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \ 753 rm -f $@.tmp 754 755#---------------------------------------------------------------------- 756# Include all of the makefiles for each source file so we don't have 757# to manually track all of the prerequisites for each source file. 758#---------------------------------------------------------------------- 759sinclude $(PREREQS) 760ifneq "$(DYLIB_NAME)" "" 761 sinclude $(DYLIB_PREREQS) 762endif 763 764# Define a suffix rule for .mm -> .o 765.SUFFIXES: .mm .o 766.mm.o: 767 $(CXX) $(CXXFLAGS) -c $< 768 769.PHONY: clean 770dsym: $(DSYM) 771all: $(EXE) $(DSYM) 772clean:: 773ifeq "$(findstring lldb-test-build.noindex, $(BUILDDIR))" "" 774 $(error Trying to invoke the clean rule, but not using the default build tree layout) 775else 776 $(RM) -r $(wildcard $(BUILDDIR)/*) 777endif 778 779#---------------------------------------------------------------------- 780# From http://blog.melski.net/tag/debugging-makefiles/ 781# 782# Usage: make print-CC print-CXX print-LD 783#---------------------------------------------------------------------- 784print-%: 785 @echo '$*=$($*)' 786 @echo ' origin = $(origin $*)' 787 @echo ' flavor = $(flavor $*)' 788 @echo ' value = $(value $*)' 789 790### Local Variables: ### 791### mode:makefile ### 792### End: ### 793