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