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