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