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