Skip to content

Commit 682b3a9

Browse files
aykevldeadprogram
authored andcommitted
Makefile: call uname at most once
Instead of calling it 5 times, call it only once on Unix-like systems (Linux, MacOS) and avoid it entirely on Windows. The main benefit of this is that it avoids a ton of overhead doing subprocess calls, which are very slow on Windows (~0.2s on my system).
1 parent fdf075a commit 682b3a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

GNUmakefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ LLVM_PROJECTDIR ?= llvm-project
88
CLANG_SRC ?= $(LLVM_PROJECTDIR)/clang
99
LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
1010

11+
ifeq ($(OS),Windows_NT)
12+
# avoid calling uname on Windows
13+
uname := Windows_NT
14+
else
15+
uname := $(shell uname -s)
16+
endif
17+
1118
# Try to autodetect LLVM build tools.
1219
# Versions are listed here in descending priority order.
1320
LLVM_VERSIONS = 19 18 17 16 15
1421
errifempty = $(if $(1),$(1),$(error $(2)))
1522
detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
1623
toolSearchPathsVersion = $(1)-$(2)
17-
ifeq ($(shell uname -s),Darwin)
24+
ifeq ($(uname),Darwin)
1825
# Also explicitly search Brew's copy, which is not in PATH by default.
1926
BREW_PREFIX := $(shell brew --prefix)
2027
toolSearchPathsVersion += $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)-$(2) $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)
@@ -127,14 +134,14 @@ ifeq ($(OS),Windows_NT)
127134

128135
USE_SYSTEM_BINARYEN ?= 1
129136

130-
else ifeq ($(shell uname -s),Darwin)
137+
else ifeq ($(uname),Darwin)
131138
MD5SUM ?= md5
132139

133140
CGO_LDFLAGS += -lxar
134141

135142
USE_SYSTEM_BINARYEN ?= 1
136143

137-
else ifeq ($(shell uname -s),FreeBSD)
144+
else ifeq ($(uname),FreeBSD)
138145
MD5SUM ?= md5
139146
START_GROUP = -Wl,--start-group
140147
END_GROUP = -Wl,--end-group
@@ -449,11 +456,11 @@ report-stdlib-tests-pass:
449456
@rm $(jointmp).*
450457

451458
# Standard library packages that pass tests quickly on the current platform
452-
ifeq ($(shell uname),Darwin)
459+
ifeq ($(uname),Darwin)
453460
TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_DARWIN)
454461
TEST_IOFS := true
455462
endif
456-
ifeq ($(shell uname),Linux)
463+
ifeq ($(uname),Linux)
457464
TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_LINUX)
458465
TEST_IOFS := true
459466
endif

0 commit comments

Comments
 (0)