@@ -47,7 +47,8 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
47
47
.DEFAULT_GOAL := all
48
48
49
49
#----------------------------------------------------------------------
50
- # If OS is not defined, use 'uname -s' to determine the OS name.
50
+ # If OS or/and HOST_OS are not defined, use 'uname -s' to determine
51
+ # the OS name.
51
52
#
52
53
# GNUWin32 uname gives "windows32" or "server version windows32" while
53
54
# some versions of MSYS uname return "MSYS_NT*", but most environments
@@ -56,15 +57,12 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
56
57
# inherited all the way down to the process spawned for make.
57
58
#----------------------------------------------------------------------
58
59
ifeq "$(HOST_OS)" ""
59
- HOST_OS := $(shell uname -s)
60
- endif
61
-
62
- ifneq (,$(findstring windows32,$(HOST_OS)))
63
- HOST_OS := Windows_NT
64
- endif
65
-
66
- ifneq (,$(findstring MSYS_NT,$(HOST_OS)))
67
- HOST_OS := Windows_NT
60
+ HOST_OS := $(shell uname -s)
61
+ ifneq (,$(or \
62
+ $(findstring windows32,$(HOST_OS)),\
63
+ $(findstring MSYS_NT,$(HOST_OS))))
64
+ HOST_OS := Windows_NT
65
+ endif
68
66
endif
69
67
70
68
ifeq "$(OS)" ""
80
78
# Also reset BUILDDIR value because "pwd" returns cygwin or msys path
81
79
# which needs to be converted to windows path.
82
80
#----------------------------------------------------------------------
83
- ifeq "$(OS)" "Windows_NT"
84
- SHELL = $(WINDIR)\system32\cmd.exe
81
+ path_wrapper = $(1)
82
+ ifeq "$(HOST_OS)" "Windows_NT"
83
+ # Windows 10 and later has the lower-case 'windir' env variable.
84
+ SHELL := $(or $(windir),$(WINDIR),C:\WINDOWS)\system32\cmd.exe
85
85
BUILDDIR := $(shell echo %cd%)
86
+
87
+ ifneq (,$(filter $(OS), Linux Android))
88
+ path_wrapper = $(subst \,/,$(1))
89
+ # Normalize base paths at the same time.
90
+ override SRCDIR := $(call path_wrapper,$(SRCDIR))
91
+ override BUILDDIR := $(call path_wrapper,$(BUILDDIR))
92
+ override MAKEFILE_RULES := $(call path_wrapper,$(MAKEFILE_RULES))
93
+ override THIS_FILE_DIR := $(call path_wrapper,$(THIS_FILE_DIR))
94
+ override LLDB_BASE_DIR := $(call path_wrapper,$(LLDB_BASE_DIR))
95
+ endif
86
96
endif
87
97
88
98
#----------------------------------------------------------------------
@@ -135,14 +145,26 @@ $(error "C compiler is not specified. Please run tests through lldb-dotest or li
135
145
endif
136
146
137
147
#----------------------------------------------------------------------
138
- # Handle SDKROOT on Darwin
148
+ # Handle SDKROOT for the cross platform builds.
139
149
#----------------------------------------------------------------------
140
150
141
151
ifeq "$(OS)" "Darwin"
142
152
ifeq "$(SDKROOT)" ""
143
153
# We haven't otherwise set the SDKROOT, so set it now to macosx
144
154
SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path)
145
155
endif
156
+ SYSROOT_FLAGS := -isysroot "$(SDKROOT)"
157
+ GCC_TOOLCHAIN_FLAGS :=
158
+ else
159
+ ifneq "$(SDKROOT)" ""
160
+ SYSROOT_FLAGS := --sysroot "$(call path_wrapper,$(SDKROOT))"
161
+ GCC_TOOLCHAIN_FLAGS := --gcc-toolchain="$(call path_wrapper,$(SDKROOT)/usr)"
162
+ else
163
+ # Do not set up these options if SDKROOT was not specified.
164
+ # This is a regular build in that case (or Android).
165
+ SYSROOT_FLAGS :=
166
+ GCC_TOOLCHAIN_FLAGS :=
167
+ endif
146
168
endif
147
169
148
170
#----------------------------------------------------------------------
@@ -239,20 +261,15 @@ endif
239
261
DEBUG_INFO_FLAG ?= -g
240
262
241
263
CFLAGS ?= $(DEBUG_INFO_FLAG) -O0
242
-
243
- ifeq "$(OS)" "Darwin"
244
- ifneq "$(SDKROOT)" ""
245
- CFLAGS += -isysroot "$(SDKROOT)"
246
- endif
247
- endif
264
+ CFLAGS += $(SYSROOT_FLAGS)
248
265
249
266
ifeq "$(OS)" "Darwin"
250
267
CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES)
251
268
else
252
269
CFLAGS += $(ARCHFLAG)$(ARCH)
253
270
endif
254
- CFLAGS += -I$(LLDB_BASE_DIR)include -I$(LLDB_OBJ_ROOT)/include
255
271
272
+ CFLAGS += -I$(LLDB_BASE_DIR)/include -I$(LLDB_OBJ_ROOT)/include
256
273
CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
257
274
258
275
ifndef NO_TEST_COMMON_H
@@ -263,9 +280,9 @@ CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS)
263
280
264
281
# Use this one if you want to build one part of the result without debug information:
265
282
ifeq "$(OS)" "Darwin"
266
- CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)"
283
+ CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
267
284
else
268
- CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
285
+ CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
269
286
endif
270
287
271
288
ifeq "$(MAKE_DWO)" "YES"
@@ -275,7 +292,7 @@ endif
275
292
ifeq "$(USE_PRIVATE_MODULE_CACHE)" "YES"
276
293
THE_CLANG_MODULE_CACHE_DIR := $(BUILDDIR)/private-module-cache
277
294
else
278
- THE_CLANG_MODULE_CACHE_DIR := $(CLANG_MODULE_CACHE_DIR)
295
+ THE_CLANG_MODULE_CACHE_DIR := $(call path_wrapper,$( CLANG_MODULE_CACHE_DIR) )
279
296
endif
280
297
281
298
MODULE_BASE_FLAGS := -fmodules -gmodules -fmodules-cache-path=$(THE_CLANG_MODULE_CACHE_DIR)
@@ -296,11 +313,13 @@ endif
296
313
CFLAGS += $(CFLAGS_EXTRAS)
297
314
CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
298
315
LD = $(CC)
299
- LDFLAGS ?= $(CFLAGS)
316
+ # Copy common options to the linker flags (dwarf, arch. & etc).
317
+ #Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc).
318
+ LDFLAGS += $(CFLAGS)
300
319
LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
301
320
ifeq (,$(filter $(OS), Windows_NT Android Darwin))
302
321
ifneq (,$(filter YES,$(ENABLE_THREADS)))
303
- LDFLAGS += -pthread
322
+ LDFLAGS += -lpthread
304
323
endif
305
324
endif
306
325
OBJECTS =
@@ -418,11 +437,28 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
418
437
endif
419
438
endif
420
439
440
+ # No C++ library has been specifieed. Use libstdc++ by default.
441
+ ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
442
+ # If no explicit request was made, but we have paths to a custom libcxx, use
443
+ # them.
444
+ ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
445
+ CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
446
+ ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
447
+ CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
448
+ endif
449
+ LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ -lc++abi
450
+ # Otherwise no C++ library has been specified. Use stdc++ by default.
451
+ else
452
+ USE_LIBSTDCPP := 1
453
+ endif
454
+ endif
455
+
421
456
ifeq (1,$(USE_LIBSTDCPP))
422
457
# Clang requires an extra flag: -stdlib=libstdc++
423
458
ifneq (,$(findstring clang,$(CC)))
424
- CXXFLAGS += -stdlib=libstdc++
425
- LDFLAGS += -stdlib=libstdc++
459
+ # Force clang looking for the gcc's headers at specific rootfs folder.
460
+ CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
461
+ LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
426
462
endif
427
463
endif
428
464
@@ -432,18 +468,18 @@ ifeq (1,$(USE_LIBCPP))
432
468
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
433
469
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
434
470
endif
435
- LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
471
+ LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ -lc++abi
436
472
else
437
473
ifeq "$(OS)" "Android"
438
474
# Nothing to do, this is already handled in
439
475
# Android.rules.
440
476
else
441
477
CXXFLAGS += -stdlib=libc++
442
- LDFLAGS += -stdlib=libc++
478
+ LDFLAGS += -stdlib=libc++ -lc++abi
443
479
endif
444
480
ifneq (,$(filter $(OS), FreeBSD Linux NetBSD))
445
481
ifneq (,$(LLVM_LIBS_DIR))
446
- LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
482
+ LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
447
483
endif
448
484
endif
449
485
endif
@@ -456,21 +492,15 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
456
492
endif
457
493
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
458
494
LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
495
+ else
496
+ ifneq (,$(findstring clang,$(CC)))
497
+ # Force clang looking for the gcc's headers at specific rootfs folder.
498
+ CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
499
+ LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
500
+ endif
459
501
endif
460
502
endif
461
503
462
- # If no explicit request was made, but we have paths to a custom libcxx, use
463
- # them.
464
- ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),)
465
- ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
466
- CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
467
- ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
468
- CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
469
- endif
470
- LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
471
- endif
472
- endif
473
-
474
504
#----------------------------------------------------------------------
475
505
# Additional system libraries
476
506
#----------------------------------------------------------------------
@@ -659,20 +689,20 @@ endif
659
689
660
690
ifneq "$(PCH_OUTPUT)" ""
661
691
$(PCH_OUTPUT) : $(PCH_CXX_SOURCE)
662
- $(CXX) $(CXXFLAGS) -x c++-header -o $@ $<
692
+ $(CXX) $(CXXFLAGS) -x c++-header -o $@ $(call path_wrapper,$<)
663
693
endif
664
694
665
695
%.o: %.c %.d
666
- $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
696
+ $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $(call path_wrapper,$<)
667
697
668
698
%.o: %.cpp %.d $(PCH_OUTPUT)
669
- $(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
699
+ $(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $(call path_wrapper,$<)
670
700
671
701
%.o: %.m %.d
672
- $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
702
+ $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $(call path_wrapper,$<)
673
703
674
704
%.o: %.mm %.d
675
- $(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
705
+ $(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $(call path_wrapper,$<)
676
706
677
707
#----------------------------------------------------------------------
678
708
# Automatic variables based on items already entered. Below we create
0 commit comments