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