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