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