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