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