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