Skip to content

Commit 880660a

Browse files
committed
depends: Fully determine path for darwin_{CC,CXX}
Instead of doing the awkward /bin path prepending at config.site creation time, set darwin_{CC,CXX} in a way that fully determines the program's path (clang/clang++) similar to how AC_PATH_{TOOL,PROG} would do. Also see the added comment block in depends/Makefile for more context on determining $PATH for our config.site.
1 parent 8033110 commit 880660a

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

depends/Makefile

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,7 @@ $(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain)
167167
include funcs.mk
168168

169169
binutils_path=$($($(host_arch)_$(host_os)_native_binutils)_prefixbin)
170-
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
171-
toolchain_path=$($($(host_arch)_$(host_os)_native_toolchain)_prefixbin)
172-
else
173-
toolchain_path=
174-
endif
170+
175171
final_build_id_long+=$(shell $(build_SHA256SUM) config.site.in)
176172
final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH))
177173
$(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages)
@@ -182,11 +178,35 @@ $(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages)
182178
$(AT)cd $(@D); $(foreach package,$^, tar xf $($(package)_cached); )
183179
$(AT)touch $@
184180

181+
# $PATH is not preserved between ./configure and make by convention. Its
182+
# modification and overriding at ./configure time is (as I understand it)
183+
# supposed to be captured by the AC_{PROG_{,OBJ}CXX,PATH_{PROG,TOOL}} macros,
184+
# which will expand the program names to their full absolute paths. The notable
185+
# exception is command line overriding: ./configure CC=clang, which skips the
186+
# program name expansion step, and works because the user implicitly indicates
187+
# with CC=clang that clang will be available in $PATH at all times, and is most
188+
# likely part of the user's system.
189+
#
190+
# Therefore, when we "seed the autoconf cache"/"override well-known program
191+
# vars" by setting AR=<blah> in our config.site, either one of two things needs
192+
# to be true for the build system to work correctly:
193+
#
194+
# 1. If we refer to the program by name (e.g. AR=riscv64-gnu-linux-ar), the
195+
# tool needs to be available in $PATH at all times.
196+
#
197+
# 2. If the tool is _**not**_ expected to be available in $PATH at all times
198+
# (such as is the case for our native_cctools binutils tools), it needs to
199+
# be referred to by its absolute path, such as would be output by the
200+
# AC_PATH_{PROG,TOOL} macros.
201+
#
202+
# Minor note: it is also okay to refer to tools by their absolute path even if
203+
# we expect them to be available in $PATH at all times, more specificity does
204+
# not hurt.
185205
$(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_build_id)
186206
$(AT)@mkdir -p $(@D)
187207
$(AT)sed -e 's|@HOST@|$(host)|' \
188-
-e 's|@CC@|$(toolchain_path)$(host_CC)|' \
189-
-e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \
208+
-e 's|@CC@|$(host_CC)|' \
209+
-e 's|@CXX@|$(host_CXX)|' \
190210
-e 's|@AR@|$(binutils_path)$(host_AR)|' \
191211
-e 's|@RANLIB@|$(binutils_path)$(host_RANLIB)|' \
192212
-e 's|@NM@|$(binutils_path)$(host_NM)|' \

depends/hosts/darwin.mk

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,33 @@ LD64_VERSION=530
77
OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-libcxx-headers
88

99
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
10+
# FORCE_USE_SYSTEM_CLANG is empty, so we use our depends-managed, pinned clang
11+
# from llvm.org
12+
13+
# The native_cctools package is what provides clang when FORCE_USE_SYSTEM_CLANG
14+
# is empty
15+
darwin_native_toolchain=native_cctools
16+
17+
clang_prog=$(build_prefix)/bin/clang
18+
clangxx_prog=$(clang_prog)++
19+
1020
clang_resource_dir=$(build_prefix)/lib/clang/$(native_cctools_clang_version)
1121
else
22+
# FORCE_USE_SYSTEM_CLANG is non-empty, so we use the clang from the user's
23+
# system
24+
25+
darwin_native_toolchain=
26+
27+
# We can't just use $(shell command -v clang) because GNU Make handles builtins
28+
# in a special way and doesn't know that `command` is a POSIX-standard builtin
29+
# prior to 1af314465e5dfe3e8baa839a32a72e83c04f26ef, first released in v4.2.90.
30+
# At the time of writing, GNU Make v4.2.1 is still being used in supported
31+
# distro releases.
32+
#
33+
# Source: https://lists.gnu.org/archive/html/bug-make/2017-11/msg00017.html
34+
clang_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang")
35+
clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")
36+
1237
clang_resource_dir=$(shell clang -print-resource-dir)
1338
endif
1439

@@ -62,15 +87,15 @@ endif
6287
darwin_CC=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
6388
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
6489
-u LIBRARY_PATH \
65-
clang --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
90+
$(clang_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
6691
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
6792
--sysroot=$(OSX_SDK) \
6893
-Xclang -internal-externc-isystem$(clang_resource_dir)/include \
6994
-Xclang -internal-externc-isystem$(OSX_SDK)/usr/include
7095
darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
7196
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
7297
-u LIBRARY_PATH \
73-
clang++ --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
98+
$(clangxx_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
7499
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
75100
--sysroot=$(OSX_SDK) \
76101
-stdlib=libc++ -nostdinc++ \
@@ -88,10 +113,4 @@ darwin_debug_CFLAGS=-O1
88113
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)
89114

90115
darwin_native_binutils=native_cctools
91-
ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),)
92-
darwin_native_toolchain=native_cctools
93-
else
94-
darwin_native_toolchain=
95-
endif
96-
97116
darwin_cmake_system=Darwin

0 commit comments

Comments
 (0)