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