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