Skip to content

Commit 1d074ba

Browse files
committed
[LLDB][test] Update Makefile.rules to support Windows host+Linux target
These changes are aimed to support cross compilation build on Windows host for Linux target for API tests execution. They're not final: changes will follow for refactoring and adjustments to make all tests passing. Chocolatey make is recommended to use, since it is maintained better than GnuWin32 recommended here https://lldb.llvm.org/resources/build.html#codesigning (it was updated last time in 2010) and helps to avoid problems with building tests (for example, GnuWin32 doesn't support long paths and there are some other failures with building for Linux with it).
1 parent 456c512 commit 1d074ba

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,26 @@ $(error "C compiler is not specified. Please run tests through lldb-dotest or li
112112
endif
113113

114114
#----------------------------------------------------------------------
115-
# Handle SDKROOT on Darwin
115+
# Handle SDKROOT for the cross platform builds.
116116
#----------------------------------------------------------------------
117117

118118
ifeq "$(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
123135
endif
124136

125137
#----------------------------------------------------------------------
@@ -210,20 +222,15 @@ endif
210222
DEBUG_INFO_FLAG ?= -g
211223

212224
CFLAGS ?= $(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

220227
ifeq "$(OS)" "Darwin"
221228
CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES)
222229
else
223230
CFLAGS += $(ARCHFLAG)$(ARCH)
224231
endif
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
227234
CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
228235

229236
ifndef 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:
236243
ifeq "$(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)
238245
else
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)
240247
endif
241248

242249
ifeq "$(MAKE_DWO)" "YES"
@@ -267,7 +274,9 @@ endif
267274
CFLAGS += $(CFLAGS_EXTRAS)
268275
CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
269276
LD = $(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)
271280
LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
272281
ifeq (,$(filter $(OS), Windows_NT Android Darwin))
273282
ifneq (,$(filter YES,$(ENABLE_THREADS)))
@@ -378,11 +387,28 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
378387
endif
379388
endif
380389

390+
# No C++ library has been specifieed. Use libstdc++ by default.
391+
ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
392+
# If no explicit request was made, but we have paths to a custom libcxx, use
393+
# them.
394+
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
395+
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
396+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
397+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
398+
endif
399+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
400+
# Otherwise no C++ library has been specified. Use stdc++ by default.
401+
else
402+
USE_SYSTEM_STDLIB := 1
403+
endif
404+
endif
405+
381406
ifeq (1,$(USE_LIBSTDCPP))
382407
# Clang requires an extra flag: -stdlib=libstdc++
383408
ifneq (,$(findstring clang,$(CC)))
384-
CXXFLAGS += -stdlib=libstdc++
385-
LDFLAGS += -stdlib=libstdc++
409+
# Force clang looking for the gcc's headers at specific rootfs folder.
410+
CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
411+
LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
386412
endif
387413
endif
388414

@@ -403,7 +429,7 @@ ifeq (1,$(USE_LIBCPP))
403429
endif
404430
ifneq (,$(filter $(OS), FreeBSD Linux NetBSD))
405431
ifneq (,$(LLVM_LIBS_DIR))
406-
LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
432+
LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
407433
endif
408434
endif
409435
endif
@@ -416,21 +442,15 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
416442
endif
417443
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
418444
LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
445+
else
446+
ifneq (,$(findstring clang,$(CC)))
447+
# Force clang looking for the gcc's headers at specific rootfs folder.
448+
CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
449+
LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
450+
endif
419451
endif
420452
endif
421453

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-
434454
#----------------------------------------------------------------------
435455
# Additional system libraries
436456
#----------------------------------------------------------------------

0 commit comments

Comments
 (0)