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