Makefile: reorganize tool detection

There are now a large number of paths that need to be searched, and this started to get a little bit unwieldy.
Additionally, brew paths were searched unconditionally, resulting in warnings every time the Makefile was run.
This reorganizes the detection paths into a parameterized list of search paths by version, which is appended to on Mac.
This list is then expanded across all versions.
The loop and filtering has been moved into the detect function.

Additionally, a helpful error message is displayed upon use of a missing tool:
Makefile:204: *** failed to locate llvm-blah at any of: llvm-build/bin/llvm-blah llvm-blah-13 llvm-blah-12 llvm-blah-11 llvm-blah.  Stop.
Этот коммит содержится в:
Nia Waldvogel 2022-01-18 13:45:55 -05:00 коммит произвёл Ron Evans
родитель 7c3a22d289
коммит ecf7014f7e

Просмотреть файл

@ -7,13 +7,23 @@ LLVM_BUILDDIR ?= llvm-build
LLVM_PROJECTDIR ?= llvm-project LLVM_PROJECTDIR ?= llvm-project
CLANG_SRC ?= $(LLVM_PROJECTDIR)/clang CLANG_SRC ?= $(LLVM_PROJECTDIR)/clang
LLD_SRC ?= $(LLVM_PROJECTDIR)/lld LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
BREW_PREFIX := $(shell brew --prefix)
# Try to autodetect LLVM build tools. # Try to autodetect LLVM build tools.
detect = $(shell command -v $(1) 2> /dev/null && echo $(1)) # Versions are listed here in descending priority order.
CLANG ?= $(word 1,$(abspath $(call detect,llvm-build/bin/clang))$(call detect,$(BREW_PREFIX)/opt/llvm@13/bin/clang-13)$(call detect,clang-13)$(call detect,$(BREW_PREFIX)/opt/llvm@12/bin/clang-12)$(call detect,clang-12)$(call detect,$(BREW_PREFIX)/opt/llvm@11/bin/clang-11)$(call detect,clang-11)$(call detect,$(BREW_PREFIX)/opt/llvm/bin/clang)$(call detect,clang)) LLVM_VERSIONS = 13 12 11
LLVM_AR ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-ar))$(call detect,$(BREW_PREFIX)/opt/llvm@13/bin/llvm-ar-13)$(call detect,llvm-ar-13)$(call detect,$(BREW_PREFIX)/opt/llvm@12/bin/llvm-ar-12)$(call detect,llvm-ar-12)$(call detect,$(BREW_PREFIX)/opt/llvm@11/bin/llvm-ar-11)$(call detect,llvm-ar-11)$(call detect,$(BREW_PREFIX)/opt/llvm/bin/llvm-ar)$(call detect,llvm-ar)) errifempty = $(if $(1),$(1),$(error $(2)))
LLVM_NM ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-nm))$(call detect,$(BREW_PREFIX)/opt/llvm@13/bin/llvm-nm-13)$(call detect,llvm-nm-13)$(call detect,$(BREW_PREFIX)/opt/llvm@12/bin/llvm-nm-12)$(call detect,llvm-nm-12)$(call detect,$(BREW_PREFIX)/opt/llvm@11/bin/llvm-nm-11)$(call detect,llvm-nm-11)$(call detect,$(BREW_PREFIX)/opt/llvm/bin/llvm-nm)$(call detect,llvm-nm)) detect = $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(abspath $(p))))),failed to locate $(1) at any of: $(2))
toolSearchPathsVersion = $(1)-$(2)
ifeq ($(shell uname -s),Darwin)
# Also explicitly search Brew's copy, which is not in PATH by default.
BREW_PREFIX := $(shell brew --prefix)
toolSearchPathsVersion += $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)-$(2) $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)
endif
# First search for a custom built copy, then move on to explicitly version-tagged binaries, then just see if the tool is in path with its normal name.
findLLVMTool = $(call detect,$(1),llvm-build/bin/$(1) $(foreach ver,$(LLVM_VERSIONS),$(call toolSearchPathsVersion,$(1),$(ver))) $(1))
CLANG ?= $(call findLLVMTool,clang)
LLVM_AR ?= $(call findLLVMTool,llvm-ar)
LLVM_NM ?= $(call findLLVMTool,llvm-nm)
# Go binary and GOROOT to select # Go binary and GOROOT to select
GO ?= go GO ?= go
@ -26,7 +36,7 @@ GOTESTFLAGS ?= -v
MD5SUM = md5sum MD5SUM = md5sum
# tinygo binary for tests # tinygo binary for tests
TINYGO ?= $(word 1,$(call detect,tinygo)$(call detect,build/tinygo)) TINYGO ?= $(call detect,tinygo,tinygo build/tinygo)
# Use CCACHE for LLVM if possible # Use CCACHE for LLVM if possible
ifneq (, $(shell command -v ccache 2> /dev/null)) ifneq (, $(shell command -v ccache 2> /dev/null))