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