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