@@ -112,14 +112,26 @@ $(error "C compiler is not specified. Please run tests through lldb-dotest or li
112112endif
113113
114114#----------------------------------------------------------------------
115- # Handle SDKROOT on Darwin
115+ # Handle SDKROOT for the cross platform builds.
116116#----------------------------------------------------------------------
117117
118118ifeq "$(OS)" "Darwin"
119119 ifeq "$(SDKROOT)" ""
120120 # We haven't otherwise set the SDKROOT, so set it now to macosx
121121 SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path)
122122 endif
123+ SYSROOT_FLAGS := -isysroot "$(SDKROOT)"
124+ GCC_TOOLCHAIN_FLAGS :=
125+ else
126+ ifneq "$(SDKROOT)" ""
127+ SYSROOT_FLAGS := --sysroot "$(SDKROOT)"
128+ GCC_TOOLCHAIN_FLAGS := --gcc-toolchain="$(SDKROOT)/usr"
129+ else
130+ # Do not set up these options if SDKROOT was not specified.
131+ # This is a regular build in that case (or Android).
132+ SYSROOT_FLAGS :=
133+ GCC_TOOLCHAIN_FLAGS :=
134+ endif
123135endif
124136
125137#----------------------------------------------------------------------
@@ -210,20 +222,15 @@ endif
210222DEBUG_INFO_FLAG ?= -g
211223
212224CFLAGS ?= $(DEBUG_INFO_FLAG) -O0
213-
214- ifeq "$(OS)" "Darwin"
215- ifneq "$(SDKROOT)" ""
216- CFLAGS += -isysroot "$(SDKROOT)"
217- endif
218- endif
225+ CFLAGS += $(SYSROOT_FLAGS)
219226
220227ifeq "$(OS)" "Darwin"
221228 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES)
222229else
223230 CFLAGS += $(ARCHFLAG)$(ARCH)
224231endif
225- CFLAGS += -I$(LLDB_BASE_DIR)include -I$(LLDB_OBJ_ROOT)/include
226232
233+ CFLAGS += -I$(LLDB_BASE_DIR)/include -I$(LLDB_OBJ_ROOT)/include
227234CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
228235
229236ifndef NO_TEST_COMMON_H
@@ -234,9 +241,9 @@ CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS)
234241
235242# Use this one if you want to build one part of the result without debug information:
236243ifeq "$(OS)" "Darwin"
237- CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)"
244+ CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
238245else
239- CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
246+ CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
240247endif
241248
242249ifeq "$(MAKE_DWO)" "YES"
@@ -267,7 +274,9 @@ endif
267274CFLAGS += $(CFLAGS_EXTRAS)
268275CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
269276LD = $(CC)
270- LDFLAGS ?= $(CFLAGS)
277+ # Copy common options to the linker flags (dwarf, arch. & etc).
278+ # Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc).
279+ LDFLAGS += $(CFLAGS)
271280LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
272281ifeq (,$(filter $(OS), Windows_NT Android Darwin))
273282 ifneq (,$(filter YES,$(ENABLE_THREADS)))
@@ -378,11 +387,26 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
378387 endif
379388endif
380389
390+ ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
391+ # If no explicit C++ library request was made, but we have paths to a custom libcxx, use
392+ # them. Otherwise, use the system library by default.
393+ ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
394+ CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
395+ ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
396+ CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
397+ endif
398+ LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
399+ else
400+ USE_SYSTEM_STDLIB := 1
401+ endif
402+ endif
403+
381404ifeq (1,$(USE_LIBSTDCPP))
382405 # Clang requires an extra flag: -stdlib=libstdc++
383406 ifneq (,$(findstring clang,$(CC)))
384- CXXFLAGS += -stdlib=libstdc++
385- LDFLAGS += -stdlib=libstdc++
407+ # Force clang looking for the gcc's headers at specific rootfs folder.
408+ CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
409+ LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
386410 endif
387411endif
388412
@@ -416,21 +440,15 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
416440 endif
417441 CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
418442 LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
443+ else
444+ ifneq (,$(findstring clang,$(CC)))
445+ # Force clang looking for the gcc's headers at specific rootfs folder.
446+ CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS)
447+ LDFLAGS += $(GCC_TOOLCHAIN_FLAGS)
448+ endif
419449 endif
420450endif
421451
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-
434452#----------------------------------------------------------------------
435453# Additional system libraries
436454#----------------------------------------------------------------------
0 commit comments