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