| #---------------------------------------------------------------------- | |
| # Clients fill in the source files to build | |
| #---------------------------------------------------------------------- | |
| # C_SOURCES := main.c | |
| # CXX_SOURCES := | |
| # OBJC_SOURCES := | |
| # OBJCXX_SOURCES := | |
| # DYLIB_C_SOURCES := | |
| # DYLIB_OBJC_SOURCES := | |
| # DYLIB_CXX_SOURCES := | |
| # | |
| # Specifying DYLIB_ONLY has the effect of building dylib only, skipping | |
| # the building of the a.out executable program. For example, | |
| # DYLIB_ONLY := YES | |
| # | |
| # When specifying one of the DYLIB_*_SOURCES variables, DYLIB_NAME | |
| # controls the (platform-dependent) name of the produced dylib. E.g., | |
| # on Darwin, if "DYLIB_NAME := foo", the generated dylib will be called | |
| # "libfoo.dylib". | |
| # | |
| # DYLIB_NAME := foo | |
| # | |
| # Specifying FRAMEWORK and its variants has the effect of building a NeXT-style | |
| # framework. | |
| # FRAMEWORK := "Foo" | |
| # FRAMEWORK_HEADERS := "Foo.h" | |
| # FRAMEWORK_MODULES := "module.modulemap" | |
| # | |
| # Also might be of interest: | |
| # FRAMEWORK_INCLUDES (Darwin only) := | |
| # CFLAGS_EXTRAS := | |
| # LD_EXTRAS := | |
| # SPLIT_DEBUG_SYMBOLS := YES | |
| # CROSS_COMPILE := | |
| # USE_PRIVATE_MODULE_CACHE := YES | |
| # Uncomment line below for debugging shell commands | |
| # SHELL = /bin/sh -x | |
| # Cross platform shell commands | |
| ifeq "$(OS)" "Windows_NT" | |
| MKDIR_P = md $(subst /,\,$(1)) > nul 2>&1 || (exit 0) | |
| CP = copy $(subst /,\,$(1)) $(subst /,\,$(2)) | |
| CP_R = xcopy $(subst /,\,$(1)) $(subst /,\,$(2)) /s /e /y | |
| RM = del $(subst /,\,$(1)) > nul 2>&1 || (exit 0) | |
| RM_F = del /f /q $(subst /,\,$(1)) | |
| TOUCH = copy /b $(subst /,\,$(1)) +,, > nul | |
| RM_RF = $(if $(strip $(1)),(del /f /q $(subst /,\,$(1)) > nul 2>&1 & rd /s /q $(subst /,\,$(1)) > nul 2>&1) || (exit 0)) | |
| LN_SF = mklink /D "$(subst /,\,$(2))" "$(subst /,\,$(1))" | |
| ECHO = echo $(1); | |
| ECHO_TO_FILE = echo $(subst ',,$(1))> "$(subst /,\,$(2))" | |
| ECHO_APPEND_FILE = echo $(subst ',,$(1))>> "$(subst /,\,$(2))" | |
| else | |
| MKDIR_P = mkdir -p $(1) | |
| CP = cp $(1) $(2) | |
| CP_R = cp -r $(1) $(2) | |
| RM = rm $(1) > /dev/null 2>&1 || true | |
| RM_F = rm -f $(1) | |
| TOUCH = touch $(1) | |
| RM_RF = rm -rf $(1) | |
| # Use patsubst to strip the destination's directory from the source | |
| # path, turning absolute symlinks into relative ones when both paths | |
| # share the same parent directory (e.g. $(BUILDDIR)/Foo.framework/Foo | |
| # becomes Foo.framework/Foo). If the paths don't share a directory, | |
| # patsubst returns the source unchanged. This ensures symlinks remain | |
| # valid when transferred to a remote device. | |
| LN_SF = ln -sf $(patsubst $(dir $(2))%,%,$(1)) $(2) | |
| ECHO = echo $(1); | |
| ECHO_TO_FILE = printf '%s\n' $(1) > "$(2)" | |
| ECHO_APPEND_FILE = printf '%s\n' $(1) >> "$(2)" | |
| endif | |
| # Suppress built-in suffix rules. We explicitly define rules for %.o. | |
| .SUFFIXES: | |
| SRCDIR := $(shell dirname $(firstword $(MAKEFILE_LIST))) | |
| BUILDDIR := $(shell pwd) | |
| MAKEFILE_RULES := $(lastword $(MAKEFILE_LIST)) | |
| THIS_FILE_DIR := $(shell dirname $(MAKEFILE_RULES)) | |
| LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../ | |
| # The test harness invokes the test Makefiles with an explicit 'all' | |
| # target, but its handy to be able to recursively call this Makefile | |
| # without specifying a goal. You almost certainly want to build 'all', | |
| # and not only the first target defined in this file (which might vary | |
| # according to variable values). | |
| .DEFAULT_GOAL := all | |
| #---------------------------------------------------------------------- | |
| # If OS is Windows, force SHELL to be cmd | |
| # | |
| # Some versions of make on Windows will search for other shells such as | |
| # C:\cygwin\bin\sh.exe. This shell fails for numerous different reasons | |
| # so default to using cmd.exe. | |
| # Also reset BUILDDIR value because "pwd" returns cygwin or msys path | |
| # which needs to be converted to windows path. | |
| #---------------------------------------------------------------------- | |
| ifeq "$(HOST_OS)" "Windows_NT" | |
| # MinGW make gets $(windir) variable if launched from cmd.exe | |
| # and $(WINDIR) if launched from MSYS2. | |
| SHELL := $(or $(windir),$(WINDIR),C:\WINDOWS)\system32\cmd.exe | |
| BUILDDIR := $(shell echo %cd%) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # If the OS is Windows use double-quotes in commands | |
| # | |
| # For other operating systems, single-quotes work fine, but on Windows | |
| # we strictly required double-quotes | |
| #---------------------------------------------------------------------- | |
| ifeq "$(HOST_OS)" "Windows_NT" | |
| QUOTE = " | |
| FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = " | |
| else | |
| QUOTE = ' | |
| FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = ' | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Determine the target triple. The triple is the canonical way to | |
| # specify the target. When only ARCH is provided we query the compiler | |
| # for its default triple and replace the arch component. | |
| #---------------------------------------------------------------------- | |
| ARCH_CFLAGS := | |
| ifeq "$(OS)" "Android" | |
| include $(THIS_FILE_DIR)/Android.rules | |
| endif | |
| ifeq "$(OS)" "WASI" | |
| include $(THIS_FILE_DIR)/WASI.rules | |
| endif | |
| ifeq "$(TRIPLE)" "" | |
| ifeq "$(ARCH)" "" | |
| # No triple, no arch: query the compiler for its default triple. | |
| TRIPLE := $(shell $(CC) --print-target-triple) | |
| else | |
| # ARCH but no TRIPLE: replace the arch in the compiler's default triple. | |
| TRIPLE := $(shell $(CC) --print-target-triple | sed 's/^[^-]*/$(ARCH)/') | |
| endif | |
| endif | |
| # Derive ARCH from the first component of the triple if not already set. | |
| ifeq "$(ARCH)" "" | |
| ARCH := $(firstword $(subst -, ,$(TRIPLE))) | |
| endif | |
| # Use -target to pass the triple to the compiler. | |
| ARCH_CFLAGS := -target $(TRIPLE) | |
| #---------------------------------------------------------------------- | |
| # CC defaults to clang. | |
| # | |
| # If you change the defaults of CC, be sure to also change it in the file | |
| # test/builders/builder_base.py, which provides a Python way to return the | |
| # value of the make variable CC -- getCompiler(). | |
| #---------------------------------------------------------------------- | |
| ifeq "$(CC)" "" | |
| $(error "C compiler is not specified. Please run tests through lldb-dotest or lit") | |
| endif | |
| # Always override the linker. Assign already normalized CC. | |
| override LD := $(CC) | |
| # A kind of linker. It always gets retrieved from CC. | |
| override LDC := $(CC_TYPE) | |
| # The bare path to the C++ compiler before it is converted into a shell word on windows. | |
| CXX_PATH := $(CXX) | |
| ifeq "$(HOST_OS)" "Windows_NT" | |
| # This function enframes the full path with the platform specific quotes. This is necessary to run the c++ executable | |
| # properly under 'sh' on Windows host (prevent the path breakage because of Windows style path separators). | |
| override CXX := $(QUOTE)$(CXX)$(QUOTE) | |
| endif | |
| # Dependency tracking for build tools. For example, if a build rule | |
| # use uses $(CC) to compile a source file, add | |
| # | |
| # $(call tool_prereq $(CC)) | |
| # | |
| # as a dependency to the rule. | |
| tool_prereq = $(wildcard $(firstword $(1))) | |
| #---------------------------------------------------------------------- | |
| # Handle SDKROOT for the cross platform builds. | |
| #---------------------------------------------------------------------- | |
| ifeq "$(OS)" "Darwin" | |
| ifeq "$(SDKROOT)" "" | |
| $(error SDKROOT must be set on Darwin) | |
| endif | |
| SYSROOT_FLAGS := -isysroot "$(SDKROOT)" | |
| GCC_TOOLCHAIN_FLAGS := | |
| else | |
| ifneq "$(SDKROOT)" "" | |
| SYSROOT_FLAGS := --sysroot "$(SDKROOT)" | |
| ifeq "$(OS)" "WASI" | |
| GCC_TOOLCHAIN_FLAGS := | |
| else | |
| GCC_TOOLCHAIN_FLAGS := --gcc-toolchain="$(SDKROOT)/usr" | |
| endif | |
| else | |
| # Do not set up these options if SDKROOT was not specified. | |
| # This is a regular build in that case (or Android). | |
| SYSROOT_FLAGS := | |
| GCC_TOOLCHAIN_FLAGS := | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Use LLD when cross compiling on Darwin. | |
| #---------------------------------------------------------------------- | |
| ifeq "$(HOST_OS)" "Darwin" | |
| ifneq (,$(filter $(OS), Android FreeBSD Linux NetBSD Windows_NT)) | |
| LDFLAGS += -fuse-ld=lld | |
| endif | |
| endif | |
| # Detect x86 from ARCH. | |
| ifneq (,$(filter amd64 x86_64 x64 x86 i386 i686,$(ARCH))) | |
| IS_X86 := 1 | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Change any build/tool options needed | |
| #---------------------------------------------------------------------- | |
| ifeq "$(OS)" "Darwin" | |
| DS := $(DSYMUTIL) | |
| DSFLAGS := $(DSFLAGS_EXTRAS) | |
| DSYM = $(EXE).dSYM | |
| ARFLAGS := -static -o | |
| # The default UUID is a hash based on filename and __text section content. | |
| # Use a random UUID so that LLDB and Spotlight never confuse two test | |
| # binaries, where repeated test code can result in identical binaries. | |
| LDFLAGS += -Wl,-random_uuid | |
| else | |
| ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" | |
| DSYM = $(EXE).debug | |
| endif | |
| ifeq "$(MAKE_DWP)" "YES" | |
| MAKE_DWO := YES | |
| DWP_NAME = $(EXE).dwp | |
| DYLIB_DWP_NAME = $(DYLIB_NAME).dwp | |
| endif | |
| endif | |
| LIMIT_DEBUG_INFO_FLAGS = | |
| NO_LIMIT_DEBUG_INFO_FLAGS = | |
| MODULE_DEBUG_INFO_FLAGS = | |
| ifeq ($(CC_TYPE), clang) | |
| LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info | |
| NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info | |
| MODULE_DEBUG_INFO_FLAGS += -gmodules | |
| endif | |
| ifeq "$(MAKE_PDB)" "YES" | |
| DEBUG_INFO_FLAG ?= -g -gcodeview | |
| endif | |
| # If the OS is Windows, we need to pass -gdwarf to clang, otherwise it will build | |
| # with codeview by default but all the tests rely on dwarf. | |
| ifeq "$(OS)" "Windows_NT" | |
| DEBUG_INFO_FLAG ?= -gdwarf | |
| endif | |
| DEBUG_INFO_FLAG ?= -g | |
| CFLAGS ?= $(DEBUG_INFO_FLAG) -O0 | |
| # Some tests require no debug information. When lldb-dotest specifies a DWARF version, | |
| # it adds `-gdwarf-{version}` to the CFLAGS environment variable which causes those tests | |
| # to fail. Strip any existing debug flags from CFLAGS and force -g0 to prevent this. | |
| ifeq "$(MAKE_NO_DEBUG_INFO)" "YES" | |
| CFLAGS := $(filter-out -g%,$(CFLAGS)) -g0 | |
| endif | |
| CFLAGS += $(SYSROOT_FLAGS) | |
| ifeq "$(OS)" "Darwin" | |
| CFLAGS += $(FRAMEWORK_INCLUDES) | |
| endif | |
| CFLAGS += -I$(LLDB_BASE_DIR)/include -I$(LLDB_OBJ_ROOT)/include | |
| CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR) | |
| ifndef NO_TEST_COMMON_H | |
| CFLAGS += -include $(THIS_FILE_DIR)/test_common.h | |
| endif | |
| CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS) | |
| # Use this one if you want to build one part of the result without debug information: | |
| CFLAGS_NO_DEBUG = -O0 $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS) | |
| ifeq "$(MAKE_DWO)" "YES" | |
| CFLAGS += -gsplit-dwarf | |
| endif | |
| ifeq "$(MAKE_DEBUG_NAMES)" "YES" | |
| CFLAGS += -gpubnames | |
| endif | |
| # Enable GNU POSIX extensions (e.g. kill(), usleep(), getpgid(), ...) | |
| ifeq "$(OS)" "Linux" | |
| CFLAGS += -D_DEFAULT_SOURCE | |
| endif | |
| ifeq "$(USE_PRIVATE_MODULE_CACHE)" "YES" | |
| THE_CLANG_MODULE_CACHE_DIR := $(BUILDDIR)/private-module-cache | |
| else | |
| THE_CLANG_MODULE_CACHE_DIR := $(CLANG_MODULE_CACHE_DIR) | |
| endif | |
| MODULE_BASE_FLAGS := -fmodules -gmodules -fmodules-cache-path=$(THE_CLANG_MODULE_CACHE_DIR) | |
| MANDATORY_MODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -gmodules | |
| # Build flags for building with C++ modules. | |
| # -glldb is necessary for emitting information about what modules were imported. | |
| MANDATORY_CXXMODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -fcxx-modules -glldb | |
| ifeq "$(OS)" "Darwin" | |
| MANDATORY_MODULE_BUILD_CFLAGS += -fcxx-modules | |
| endif | |
| ifeq "$(MAKE_GMODULES)" "YES" | |
| CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS) | |
| CXXFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS) | |
| endif | |
| # Our files use x86 AT&T assembly throughout. | |
| # Enable it explicitly so any local Clang preference for Intel syntax gets overriden. | |
| ifeq ($(CC_TYPE), clang) | |
| ifeq ($(IS_X86), 1) | |
| CFLAGS += -mllvm -x86-asm-syntax=att | |
| CXXFLAGS += -mllvm -x86-asm-syntax=att | |
| endif | |
| endif | |
| CFLAGS += $(CFLAGS_EXTRAS) | |
| CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS) | |
| # Copy common options to the linker flags (dwarf, arch. & etc). | |
| # Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc). | |
| LDFLAGS += $(CFLAGS) | |
| LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS) | |
| ifeq (,$(filter $(OS), Windows_NT Android Darwin Wasm)) | |
| ifneq (,$(filter YES,$(ENABLE_THREADS))) | |
| LDFLAGS += -pthread | |
| endif | |
| endif | |
| # macOS forbids injecting the ASAN runtime into system processes when | |
| # SIP is enabled. That includes the just-built libLTO that the | |
| # just-built clang injects into the system linker. Since we don't | |
| # test the compiler here, just use the system (non-asanified) LTO | |
| # library to make ASAN tests work for most users, including the bots. | |
| ifeq "$(OS)" "Darwin" | |
| ifneq "$(ASAN_OPTIONS)" "" | |
| ASAN_LDFLAGS = -Wl,-lto_library -Wl,$(shell dirname $(shell xcrun -find clang))/../lib/libLTO.dylib | |
| endif | |
| endif | |
| LDFLAGS += $(ASAN_LDFLAGS) | |
| OBJECTS = | |
| EXE ?= a.out | |
| ifneq "$(FRAMEWORK)" "" | |
| DYLIB_NAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) | |
| DYLIB_FILENAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) | |
| endif | |
| ifneq "$(DYLIB_NAME)" "" | |
| ifeq "$(OS)" "Darwin" | |
| ifneq "$(FRAMEWORK)" "" | |
| DYLIB_INSTALL_NAME ?= @executable_path/$(FRAMEWORK).framework/Versions/A/$(FRAMEWORK) | |
| else | |
| DYLIB_FILENAME = lib$(DYLIB_NAME).dylib | |
| DYLIB_INSTALL_NAME ?= @executable_path/$(DYLIB_FILENAME) | |
| endif | |
| else ifeq "$(OS)" "Windows_NT" | |
| DYLIB_FILENAME = $(DYLIB_NAME).dll | |
| else | |
| DYLIB_FILENAME = lib$(DYLIB_NAME).so | |
| endif | |
| endif | |
| ifdef PIE | |
| LDFLAGS += -pie | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Windows specific options | |
| #---------------------------------------------------------------------- | |
| ifeq "$(OS)" "Windows_NT" | |
| ifeq ($(CC_TYPE), clang) | |
| # MSVC 2015 or higher is required, which depends on c++14, so | |
| # append these values unconditionally. | |
| CXXFLAGS += -fms-compatibility-version=19.0 | |
| CXXFLAGS += -std=c++14 | |
| # The MSVC linker doesn't understand long section names | |
| # generated by the clang compiler. | |
| LDFLAGS += -fuse-ld=lld | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # C++ standard library options | |
| #---------------------------------------------------------------------- | |
| ifneq ($(and $(USE_LIBSTDCPP), $(USE_LIBCPP)),) | |
| $(error Libcxx and Libstdc++ cannot be used together) | |
| endif | |
| ifeq (1, $(USE_SYSTEM_STDLIB)) | |
| ifneq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP)),) | |
| $(error Cannot use system's standard library and a custom standard library together) | |
| endif | |
| endif | |
| ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB))) | |
| ifeq "$(OS)" "Darwin" | |
| # If no explicit C++ library request was made, default to the system | |
| # libc++. Testing a custom libc++ correctly on apple platforms is difficult | |
| # and the apppropriate use cases are limited. | |
| USE_SYSTEM_STDLIB := 1 | |
| else | |
| # If no explicit C++ library request was made, but we have paths to a custom libcxx, use | |
| # them. Otherwise, use the system library by default. | |
| ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),) | |
| CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR) | |
| ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" "" | |
| CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR) | |
| endif | |
| # If `-nostdlib++` is not passed, clang will link to the system's stdlib. | |
| LDFLAGS += -nostdlib++ -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ | |
| else | |
| USE_SYSTEM_STDLIB := 1 | |
| endif | |
| endif | |
| endif | |
| ifeq (1,$(USE_LIBSTDCPP)) | |
| # Clang requires an extra flag: -stdlib=libstdc++ | |
| ifeq ($(CC_TYPE), clang) | |
| # Force clang looking for the gcc's headers at specific rootfs folder. | |
| CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) | |
| LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) | |
| endif | |
| endif | |
| ifeq (1,$(USE_LIBCPP)) | |
| ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),) | |
| CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR) | |
| ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" "" | |
| CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR) | |
| endif | |
| # If `-nostdlib++` is not passed, clang will link to the system's stdlib. | |
| LDFLAGS += -nostdlib++ -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ | |
| else | |
| ifeq "$(OS)" "Android" | |
| # Nothing to do, this is already handled in | |
| # Android.rules. | |
| else | |
| CXXFLAGS += -stdlib=libc++ | |
| LDFLAGS += -stdlib=libc++ | |
| endif | |
| ifneq (,$(filter $(OS), FreeBSD Linux NetBSD)) | |
| ifneq (,$(LLVM_LIBS_DIR)) | |
| LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR) | |
| endif | |
| endif | |
| endif | |
| endif | |
| ifeq (1, $(USE_SYSTEM_STDLIB)) | |
| ifeq "$(OS)" "Darwin" | |
| ifeq "$(SDKROOT)" "" | |
| $(error "SDKROOT must be set on Darwin to use the system libcxx") | |
| endif | |
| CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1 | |
| LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++ | |
| else | |
| ifeq ($(CC_TYPE),clang) | |
| # Force clang looking for the gcc's headers at specific rootfs folder. | |
| CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS) | |
| LDFLAGS += $(GCC_TOOLCHAIN_FLAGS) | |
| endif | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Additional system libraries | |
| #---------------------------------------------------------------------- | |
| ifeq (1,$(USE_LIBDL)) | |
| ifeq (,$(filter $(OS), NetBSD Windows_NT)) | |
| LDFLAGS += -ldl | |
| endif | |
| endif | |
| CXXFLAGS += $(CXXFLAGS_EXTRAS) | |
| #---------------------------------------------------------------------- | |
| # dylib settings | |
| #---------------------------------------------------------------------- | |
| DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o)) | |
| DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o)) | |
| ifneq "$(strip $(DYLIB_CXX_SOURCES))" "" | |
| DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o))) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Check if we have a precompiled header | |
| #---------------------------------------------------------------------- | |
| ifneq "$(strip $(PCH_CXX_SOURCE))" "" | |
| PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch) | |
| PCHFLAGS = -include $(PCH_CXX_SOURCE) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Check if we have any C source files | |
| #---------------------------------------------------------------------- | |
| ifneq "$(strip $(C_SOURCES))" "" | |
| OBJECTS +=$(strip $(C_SOURCES:.c=.o)) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Check if we have any C++ source files | |
| #---------------------------------------------------------------------- | |
| ifneq "$(strip $(CXX_SOURCES))" "" | |
| OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o)) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Check if we have any ObjC source files | |
| #---------------------------------------------------------------------- | |
| ifneq "$(strip $(OBJC_SOURCES))" "" | |
| OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o)) | |
| LDFLAGS +=-lobjc | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Check if we have any ObjC++ source files | |
| #---------------------------------------------------------------------- | |
| ifneq "$(strip $(OBJCXX_SOURCES))" "" | |
| OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o)) | |
| ifeq "$(findstring lobjc,$(LDFLAGS))" "" | |
| LDFLAGS +=-lobjc | |
| endif | |
| endif | |
| ifeq ($(CC_TYPE), clang) | |
| CXXFLAGS += --driver-mode=g++ | |
| endif | |
| ifneq "$(CXX)" "" | |
| # Specify the driver mode parameter if we use clang as the linker. | |
| ifeq ($(LDC), clang) | |
| LDFLAGS += --driver-mode=g++ | |
| endif | |
| endif | |
| ifeq "$(GEN_GNU_BUILD_ID)" "YES" | |
| LDFLAGS += -Wl,--build-id | |
| endif | |
| #---------------------------------------------------------------------- | |
| # DYLIB_ONLY variable can be used to skip the building of a.out. | |
| # See the sections below regarding dSYM file as well as the building of | |
| # EXE from all the objects. | |
| #---------------------------------------------------------------------- | |
| #---------------------------------------------------------------------- | |
| # Compile the executable from all the objects. | |
| #---------------------------------------------------------------------- | |
| ifneq "$(DYLIB_NAME)" "" | |
| ifeq "$(DYLIB_ONLY)" "" | |
| $(EXE) : $(OBJECTS) $(DYLIB_FILENAME) | |
| $(LD) $(OBJECTS) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)" | |
| ifneq "$(CODESIGN)" "" | |
| $(CODESIGN) -s - "$(EXE)" | |
| endif | |
| else | |
| EXE = $(DYLIB_FILENAME) | |
| endif | |
| else | |
| $(EXE) : $(OBJECTS) | |
| $(LD) $(OBJECTS) $(LDFLAGS) -o "$(EXE)" | |
| ifneq "$(CODESIGN)" "" | |
| $(CODESIGN) -s - "$(EXE)" | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Make the dSYM file from the executable if $(MAKE_DSYM) != "NO" | |
| # | |
| # On non-Darwin platforms with SPLIT_DEBUG_SYMBOLS, objcopy copies the debug | |
| # info of $(EXE) into $(DSYM) and then strips it from $(EXE), which leaves | |
| # $(EXE) newer than $(DSYM). Touch $(DSYM) last, or the next make would rerun | |
| # objcopy on the stripped $(EXE) and leave $(DSYM) without debug info. | |
| #---------------------------------------------------------------------- | |
| $(DSYM) : $(EXE) \ | |
| $(call tool_prereq,$(DS)) \ | |
| $(call tool_prereq,$(OBJCOPY)) \ | |
| $(call tool_prereq,$(DWP)) | |
| ifeq "$(OS)" "Darwin" | |
| ifneq "$(MAKE_DSYM)" "NO" | |
| "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)" | |
| else | |
| endif | |
| else | |
| ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" | |
| ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES" | |
| cp "$(EXE)" "$(EXE).unstripped" | |
| endif | |
| $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)" | |
| $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)" | |
| $(call TOUCH,$(DSYM)) | |
| endif | |
| ifeq "$(MAKE_DWP)" "YES" | |
| $(DWP) -o "$(DWP_NAME)" $(DWOS) | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Make the dylib | |
| #---------------------------------------------------------------------- | |
| $(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL | |
| ifneq "$(OS)" "Windows_NT" | |
| $(DYLIB_OBJECTS) : CFLAGS += -fPIC | |
| $(DYLIB_OBJECTS) : CXXFLAGS += -fPIC | |
| endif | |
| $(DYLIB_FILENAME) : $(DYLIB_OBJECTS) | |
| ifeq "$(OS)" "Darwin" | |
| ifneq "$(FRAMEWORK)" "" | |
| mkdir -p $(FRAMEWORK).framework/Versions/A/Headers | |
| mkdir -p $(FRAMEWORK).framework/Versions/A/Modules | |
| mkdir -p $(FRAMEWORK).framework/Versions/A/Resources | |
| ifneq "$(FRAMEWORK_MODULES)" "" | |
| cp -r $(FRAMEWORK_MODULES) $(FRAMEWORK).framework/Versions/A/Modules | |
| endif | |
| ifneq "$(FRAMEWORK_HEADERS)" "" | |
| cp -r $(FRAMEWORK_HEADERS) $(FRAMEWORK).framework/Versions/A/Headers | |
| endif | |
| (cd $(FRAMEWORK).framework/Versions; ln -sf A Current) | |
| (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Headers Headers) | |
| (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Modules Modules) | |
| (cd $(FRAMEWORK).framework/; ln -sf Versions/A/Resources Resources) | |
| (cd $(FRAMEWORK).framework/; ln -sf Versions/A/$(FRAMEWORK) $(FRAMEWORK)) | |
| endif | |
| $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_INSTALL_NAME)" -dynamiclib -o "$(DYLIB_FILENAME)" | |
| ifneq "$(CODESIGN)" "" | |
| $(CODESIGN) -s - "$(DYLIB_FILENAME)" | |
| endif | |
| ifneq "$(MAKE_DSYM)" "NO" | |
| ifneq "$(DS)" "" | |
| "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)" | |
| endif | |
| endif | |
| else | |
| $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)" | |
| ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" | |
| ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES" | |
| cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).unstripped" | |
| endif | |
| $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug" | |
| $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)" | |
| endif | |
| ifeq "$(MAKE_DWP)" "YES" | |
| $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS) | |
| endif | |
| endif | |
| #---------------------------------------------------------------------- | |
| # Make the precompiled header and compile C++ sources against it | |
| #---------------------------------------------------------------------- | |
| ifneq "$(PCH_OUTPUT)" "" | |
| $(PCH_OUTPUT) : $(PCH_CXX_SOURCE) $(call tool_prereq,$(CXX_PATH)) | |
| $(CXX) $(CXXFLAGS) -x c++-header -o $@ $< | |
| endif | |
| %.o: %.c %.d $(call tool_prereq,$(CC)) | |
| $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $< | |
| %.o: %.cpp %.d $(PCH_OUTPUT) $(call tool_prereq,$(CXX_PATH)) | |
| $(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $< | |
| %.o: %.m %.d $(call tool_prereq,$(CC)) | |
| $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $< | |
| %.o: %.mm %.d $(call tool_prereq,$(CXX_PATH)) | |
| $(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $< | |
| #---------------------------------------------------------------------- | |
| # Automatic variables based on items already entered. Below we create | |
| # an object's lists from the list of sources by replacing all entries | |
| # that end with .c with .o, and we also create a list of prerequisite | |
| # files by replacing all .c files with .d. | |
| #---------------------------------------------------------------------- | |
| PREREQS := $(OBJECTS:.o=.d) | |
| DWOS := $(OBJECTS:.o=.dwo) | |
| ifneq "$(DYLIB_NAME)" "" | |
| DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d) | |
| DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo) | |
| endif | |
| # Don't error if a .d file is deleted. | |
| $(PREREQS) $(DYLIB_PREREQS): ; | |
| #---------------------------------------------------------------------- | |
| # Include all of the makefiles for each source file so we don't have | |
| # to manually track all of the prerequisites for each source file. | |
| #---------------------------------------------------------------------- | |
| include $(wildcard $(PREREQS) $(DYLIB_PREREQS)) | |
| .PHONY: clean | |
| dsym: $(DSYM) | |
| all: $(EXE) $(DSYM) | |
| clean:: | |
| ifeq "$(findstring lldb-test-build, $(BUILDDIR))" "" | |
| $(error Trying to invoke the clean rule, but not using the default build tree layout) | |
| else | |
| $(call RM_RF,$(wildcard $(BUILDDIR)/*)) | |
| endif | |
| #---------------------------------------------------------------------- | |
| # From http://blog.melski.net/tag/debugging-makefiles/ | |
| # | |
| # Usage: make print-CC print-CXX print-LD | |
| #---------------------------------------------------------------------- | |
| print-%: | |
| @echo '$*=$($*)' | |
| @echo ' origin = $(origin $*)' | |
| @echo ' flavor = $(flavor $*)' | |
| @echo ' value = $(value $*)' | |
| ### Local Variables: ### | |
| ### mode:makefile ### | |
| ### End: ### |