@@ -6,6 +6,12 @@ LD64_VERSION=530
6
6
7
7
OSX_SDK =$(SDK_PATH ) /Xcode-$(XCODE_VERSION ) -$(XCODE_BUILD_ID ) -extracted-SDK-with-libcxx-headers
8
8
9
+ ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG ) ) ,)
10
+ clang_resource_dir =$(build_prefix ) /lib/clang/$(native_cctools_clang_version )
11
+ else
12
+ clang_resource_dir =$(shell clang -print-resource-dir)
13
+ endif
14
+
9
15
# Flag explanations:
10
16
#
11
17
# -mlinker-version
@@ -18,7 +24,7 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
18
24
# Explicitly point to our binaries (e.g. cctools) so that they are
19
25
# ensured to be found and preferred over other possibilities.
20
26
#
21
- # -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
27
+ # -stdlib=libc++ - nostdinc++ -Xclang -cxx-isystem $(OSX_SDK)/usr/include/c++/v1
22
28
#
23
29
# Forces clang to use the libc++ headers from our SDK and completely
24
30
# forget about the libc++ headers from the standard directories
@@ -28,8 +34,51 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
28
34
# https://reviews.llvm.org/D64089, we should use that instead. Read the
29
35
# differential summary there for more details.
30
36
#
31
- darwin_CC =clang -target $(host ) -mmacosx-version-min=$(OSX_MIN_VERSION ) --sysroot $(OSX_SDK ) -mlinker-version=$(LD64_VERSION ) -B$(build_prefix ) /bin
32
- darwin_CXX =clang++ -target $(host ) -mmacosx-version-min=$(OSX_MIN_VERSION ) --sysroot $(OSX_SDK ) -stdlib=libc++ -mlinker-version=$(LD64_VERSION ) -B$(build_prefix ) /bin -nostdinc++ -isystem $(OSX_SDK ) /usr/include/c++/v1
37
+ # -Xclang -*system<path_a> \
38
+ # -Xclang -*system<path_b> \
39
+ # -Xclang -*system<path_c> ...
40
+ #
41
+ # Adds path_a, path_b, and path_c to the bottom of clang's list of
42
+ # include search paths. This is used to explicitly specify the list of
43
+ # system include search paths and its ordering, rather than rely on
44
+ # clang's autodetection routine. This routine has been shown to:
45
+ # 1. Fail to pickup libc++ headers in $SYSROOT/usr/include/c++/v1
46
+ # when clang was built manually (see: https://github.com/bitcoin/bitcoin/pull/17919#issuecomment-656785034)
47
+ # 2. Fail to pickup C headers in $SYSROOT/usr/include when
48
+ # C_INCLUDE_DIRS was specified at configure time (see: https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9)
49
+ #
50
+ # Talking directly to cc1 with -Xclang here grants us access to specify
51
+ # more granular categories for these system include search paths, and we
52
+ # can use the correct categories that these search paths would have been
53
+ # placed in if the autodetection routine had worked correctly. (see:
54
+ # https://gist.github.com/dongcarl/5cdc6990b7599e8a5bf6d2a9c70e82f9#the-treatment)
55
+ #
56
+ # Furthermore, it places these search paths after any "non-Xclang"
57
+ # specified search paths. This prevents any additional clang options or
58
+ # environment variables from coming after or in between these system
59
+ # include search paths, as that would be wrong in general but would also
60
+ # break #include_next's.
61
+ #
62
+ darwin_CC =env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
63
+ -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
64
+ -u LIBRARY_PATH \
65
+ clang --target=$(host ) -mmacosx-version-min=$(OSX_MIN_VERSION ) \
66
+ -B$(build_prefix ) /bin -mlinker-version=$(LD64_VERSION ) \
67
+ -fuse-ld=$(build_prefix ) /bin/x86_64-apple-darwin16-ld \
68
+ --sysroot=$(OSX_SDK ) \
69
+ -Xclang -internal-externc-isystem$(clang_resource_dir ) /include \
70
+ -Xclang -internal-externc-isystem$(OSX_SDK ) /usr/include
71
+ darwin_CXX =env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
72
+ -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
73
+ -u LIBRARY_PATH \
74
+ clang++ --target=$(host ) -mmacosx-version-min=$(OSX_MIN_VERSION ) \
75
+ -B$(build_prefix ) /bin -mlinker-version=$(LD64_VERSION ) \
76
+ -fuse-ld=$(build_prefix ) /bin/x86_64-apple-darwin16-ld \
77
+ --sysroot=$(OSX_SDK ) \
78
+ -stdlib=libc++ -nostdinc++ \
79
+ -Xclang -cxx-isystem$(OSX_SDK ) /usr/include/c++/v1 \
80
+ -Xclang -internal-externc-isystem$(clang_resource_dir ) /include \
81
+ -Xclang -internal-externc-isystem$(OSX_SDK ) /usr/include
33
82
34
83
darwin_CFLAGS =-pipe
35
84
darwin_CXXFLAGS =$(darwin_CFLAGS )
0 commit comments