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 endif 82endif 83ifeq "$(OS)" "Android" 84 include $(THIS_FILE_DIR)/Android.rules 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 -I$(THIS_FILE_DIR) $(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 304 # MSVC 2015 or higher is required, which depends on c++14, so 305 # append these values unconditionally. 306 CXXFLAGS += -fms-compatibility-version=19.0 307 override CXXFLAGS := $(subst -std=c++11,-std=c++14,$(CXXFLAGS)) 308 309 # The MSVC linker doesn't understand long section names 310 # generated by the clang compiler. 311 LDFLAGS += -fuse-ld=lld 312 endif 313endif 314 315#---------------------------------------------------------------------- 316# C++ standard library options 317#---------------------------------------------------------------------- 318ifeq (1,$(USE_LIBSTDCPP)) 319 # Clang requires an extra flag: -stdlib=libstdc++ 320 ifneq (,$(findstring clang,$(CC))) 321 CXXFLAGS += -stdlib=libstdc++ -DLLDB_USING_LIBSTDCPP 322 LDFLAGS += -stdlib=libstdc++ 323 endif 324endif 325 326ifeq (1,$(USE_LIBCPP)) 327 CXXFLAGS += -DLLDB_USING_LIBCPP 328 ifeq "$(OS)" "Linux" 329 ifneq (,$(findstring clang,$(CC))) 330 CXXFLAGS += -stdlib=libc++ 331 LDFLAGS += -stdlib=libc++ 332 else 333 CXXFLAGS += -isystem /usr/include/c++/v1 334 LDFLAGS += -lc++ 335 endif 336 else ifeq "$(OS)" "Android" 337 # Nothing to do, this is already handled in 338 # Android.rules. 339 else 340 CXXFLAGS += -stdlib=libc++ 341 LDFLAGS += -stdlib=libc++ 342 endif 343endif 344 345#---------------------------------------------------------------------- 346# dylib settings 347#---------------------------------------------------------------------- 348ifneq "$(strip $(DYLIB_C_SOURCES))" "" 349 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o)) 350endif 351 352ifneq "$(strip $(DYLIB_OBJC_SOURCES))" "" 353 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o)) 354endif 355 356ifneq "$(strip $(DYLIB_CXX_SOURCES))" "" 357 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o)) 358 CXX = $(call cxx_compiler,$(CC)) 359 LD = $(call cxx_linker,$(CC)) 360endif 361 362#---------------------------------------------------------------------- 363# Check if we have a precompiled header 364#---------------------------------------------------------------------- 365ifneq "$(strip $(PCH_CXX_SOURCE))" "" 366 PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch) 367 PCHFLAGS = -include $(PCH_CXX_SOURCE) 368endif 369 370#---------------------------------------------------------------------- 371# Check if we have any C source files 372#---------------------------------------------------------------------- 373ifneq "$(strip $(C_SOURCES))" "" 374 OBJECTS +=$(strip $(C_SOURCES:.c=.o)) 375endif 376 377#---------------------------------------------------------------------- 378# Check if we have any C++ source files 379#---------------------------------------------------------------------- 380ifneq "$(strip $(CXX_SOURCES))" "" 381 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o)) 382 CXX = $(call cxx_compiler,$(CC)) 383 LD = $(call cxx_linker,$(CC)) 384endif 385 386#---------------------------------------------------------------------- 387# Check if we have any ObjC source files 388#---------------------------------------------------------------------- 389ifneq "$(strip $(OBJC_SOURCES))" "" 390 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o)) 391 LDFLAGS +=-lobjc 392endif 393 394#---------------------------------------------------------------------- 395# Check if we have any ObjC++ source files 396#---------------------------------------------------------------------- 397ifneq "$(strip $(OBJCXX_SOURCES))" "" 398 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o)) 399 CXX = $(call cxx_compiler,$(CC)) 400 LD = $(call cxx_linker,$(CC)) 401 ifeq "$(findstring lobjc,$(LDFLAGS))" "" 402 LDFLAGS +=-lobjc 403 endif 404endif 405 406#---------------------------------------------------------------------- 407# Check if we have any C source files for archive 408#---------------------------------------------------------------------- 409ifneq "$(strip $(ARCHIVE_C_SOURCES))" "" 410 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o)) 411endif 412 413#---------------------------------------------------------------------- 414# Check if we have any C++ source files for archive 415#---------------------------------------------------------------------- 416ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" "" 417 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o)) 418 CXX = $(call cxx_compiler,$(CC)) 419 LD = $(call cxx_linker,$(CC)) 420endif 421 422#---------------------------------------------------------------------- 423# Check if we have any ObjC source files for archive 424#---------------------------------------------------------------------- 425ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" "" 426 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o)) 427 LDFLAGS +=-lobjc 428endif 429 430#---------------------------------------------------------------------- 431# Check if we have any ObjC++ source files for archive 432#---------------------------------------------------------------------- 433ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" "" 434 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o)) 435 CXX = $(call cxx_compiler,$(CC)) 436 LD = $(call cxx_linker,$(CC)) 437 ifeq "$(findstring lobjc,$(LDFLAGS))" "" 438 LDFLAGS +=-lobjc 439 endif 440endif 441 442#---------------------------------------------------------------------- 443# Check if we are compiling with gcc 4.6 444#---------------------------------------------------------------------- 445ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" "" 446ifneq "$(filter g++,$(CXX))" "" 447 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3) 448 ifeq "$(CXXVERSION)" "4.6" 449 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x 450 # instead. FIXME: remove once GCC version is upgraded. 451 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS)) 452 endif 453endif 454endif 455 456ifeq ($(findstring clang, $(CXX)), clang) 457 CXXFLAGS += --driver-mode=g++ 458endif 459 460ifneq "$(CXX)" "" 461 ifeq ($(findstring clang, $(LD)), clang) 462 LDFLAGS += --driver-mode=g++ 463 endif 464endif 465 466#---------------------------------------------------------------------- 467# DYLIB_ONLY variable can be used to skip the building of a.out. 468# See the sections below regarding dSYM file as well as the building of 469# EXE from all the objects. 470#---------------------------------------------------------------------- 471 472#---------------------------------------------------------------------- 473# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO" 474#---------------------------------------------------------------------- 475ifneq "$(DYLIB_ONLY)" "YES" 476$(DSYM) : $(EXE) 477ifeq "$(OS)" "Darwin" 478ifneq "$(MAKE_DSYM)" "NO" 479 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)" 480endif 481else 482ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" 483 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)" 484 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)" 485endif 486endif 487endif 488 489#---------------------------------------------------------------------- 490# Compile the executable from all the objects. 491#---------------------------------------------------------------------- 492ifneq "$(DYLIB_NAME)" "" 493ifeq "$(DYLIB_ONLY)" "" 494$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME) 495 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)" 496else 497EXE = $(DYLIB_FILENAME) 498endif 499else 500$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) 501 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)" 502endif 503 504#---------------------------------------------------------------------- 505# Make the archive 506#---------------------------------------------------------------------- 507ifneq "$(ARCHIVE_NAME)" "" 508ifeq "$(OS)" "Darwin" 509$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS) 510 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) 511 $(RM) $(ARCHIVE_OBJECTS) 512else 513$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj))) 514endif 515endif 516 517#---------------------------------------------------------------------- 518# Make the dylib 519#---------------------------------------------------------------------- 520$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL 521 522$(DYLIB_FILENAME) : $(DYLIB_OBJECTS) 523ifeq "$(OS)" "Darwin" 524 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)" 525ifneq "$(MAKE_DSYM)" "NO" 526ifneq "$(DS)" "" 527 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)" 528endif 529endif 530else 531 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)" 532ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" 533 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug" 534 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)" 535endif 536endif 537 538#---------------------------------------------------------------------- 539# Make the precompiled header and compile C++ sources against it 540#---------------------------------------------------------------------- 541 542#ifneq "$(PCH_OUTPUT)" "" 543$(PCH_OUTPUT) : $(PCH_CXX_SOURCE) 544 $(CXX) $(CXXFLAGS) -x c++-header -o $(PCH_OUTPUT) $(PCH_CXX_SOURCE) 545%.o : %.cpp $(PCH_OUTPUT) 546 $(CXX) $(PCHFLAGS) $(CXXFLAGS) -c -o $@ $< 547#endif 548 549#---------------------------------------------------------------------- 550# Automatic variables based on items already entered. Below we create 551# an object's lists from the list of sources by replacing all entries 552# that end with .c with .o, and we also create a list of prerequisite 553# files by replacing all .c files with .d. 554#---------------------------------------------------------------------- 555PREREQS := $(OBJECTS:.o=.d) 556DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo) 557ifneq "$(DYLIB_NAME)" "" 558 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d) 559 DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo) 560endif 561 562#---------------------------------------------------------------------- 563# Rule for Generating Prerequisites Automatically using .d files and 564# the compiler -MM option. The -M option will list all system headers, 565# and the -MM option will list all non-system dependencies. 566#---------------------------------------------------------------------- 567ifeq "$(HOST_OS)" "Windows_NT" 568 JOIN_CMD = & 569 QUOTE = " 570else 571 JOIN_CMD = ; 572 QUOTE = ' 573endif 574 575%.d: %.c 576 @rm -f $@ $(JOIN_CMD) \ 577 $(CC) -M $(CFLAGS) $< > [email protected] && \ 578 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \ 579 rm -f [email protected] 580 581%.d: %.cpp 582 @rm -f $@ $(JOIN_CMD) \ 583 $(CXX) -M $(CXXFLAGS) $< > [email protected] && \ 584 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \ 585 rm -f [email protected] 586 587%.d: %.m 588 @rm -f $@ $(JOIN_CMD) \ 589 $(CC) -M $(CFLAGS) $< > [email protected] && \ 590 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \ 591 rm -f [email protected] 592 593%.d: %.mm 594 @rm -f $@ $(JOIN_CMD) \ 595 $(CXX) -M $(CXXFLAGS) $< > [email protected] && \ 596 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \ 597 rm -f [email protected] 598 599#---------------------------------------------------------------------- 600# Include all of the makefiles for each source file so we don't have 601# to manually track all of the prerequisites for each source file. 602#---------------------------------------------------------------------- 603sinclude $(PREREQS) 604ifneq "$(DYLIB_NAME)" "" 605 sinclude $(DYLIB_PREREQS) 606endif 607 608# Define a suffix rule for .mm -> .o 609.SUFFIXES: .mm .o 610.mm.o: 611 $(CXX) $(CXXFLAGS) -c $< 612 613.PHONY: clean 614dsym: $(DSYM) 615all: $(EXE) $(DSYM) 616clean:: 617 $(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) 618ifneq "$(DYLIB_NAME)" "" 619 $(RM) -r $(DYLIB_FILENAME).dSYM 620 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug 621endif 622ifneq "$(PCH_OUTPUT)" "" 623 $(RM) $(PCH_OUTPUT) 624endif 625ifneq "$(DSYM)" "" 626 $(RM) -r "$(DSYM)" 627endif 628ifeq "$(OS)" "Windows_NT" 629# http://llvm.org/pr24589 630 IF EXIST "$(EXE)" del "$(EXE)" 631 $(RM) $(wildcard *.manifest *.pdb *.ilk) 632ifneq "$(DYLIB_NAME)" "" 633 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp 634endif 635else 636 $(RM) "$(EXE)" 637endif 638 639#---------------------------------------------------------------------- 640# From http://blog.melski.net/tag/debugging-makefiles/ 641# 642# Usage: make print-CC print-CXX print-LD 643#---------------------------------------------------------------------- 644print-%: 645 @echo '$*=$($*)' 646 @echo ' origin = $(origin $*)' 647 @echo ' flavor = $(flavor $*)' 648 @echo ' value = $(value $*)' 649 650### Local Variables: ### 651### mode:makefile ### 652### End: ### 653