Specifically, do not recursively expand $(CFLAGS) because this leads to
repeatedly performing compile tests (e. g. cc-disable-warning) on every
recipe execution.
Without (nproc=32):
```
$ time env -i PATH=/usr/bin BCACHEFS_FUSE=1 NO_RUST=1 make -j$(nproc)
<...>
[LD] bcachefs
72,48s user 11,29s system 190% cpu 44,036 total
```
With:
```
$ time env -i PATH=/usr/bin BCACHEFS_FUSE=1 NO_RUST=1 make -j$(nproc)
<...>
[LD] bcachefs
66,79s user 5,17s system 1955% cpu 3,679 total
```
CARGO_CLEAN_ARGS = --quiet
endif
CARGO_CLEAN_ARGS = --quiet
endif
+# Prevent recursive expansions of $(CFLAGS) to avoid repeatedly performing
+# compile tests
+CFLAGS:=$(CFLAGS)
+
CFLAGS+=-std=gnu11 -O2 -g -MMD -Wall -fPIC \
-Wno-pointer-sign \
-Wno-deprecated-declarations \
CFLAGS+=-std=gnu11 -O2 -g -MMD -Wall -fPIC \
-Wno-pointer-sign \
-Wno-deprecated-declarations \
-DNO_BCACHEFS_SYSFS \
-DVERSION_STRING='"$(VERSION)"' \
$(EXTRA_CFLAGS)
-DNO_BCACHEFS_SYSFS \
-DVERSION_STRING='"$(VERSION)"' \
$(EXTRA_CFLAGS)
+
+# Intenionally not doing the above to $(LDFLAGS) because we rely on
+# recursive expansion here (CFLAGS is not yet completely built by this line)
LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
ifdef CARGO_TOOLCHAIN_VERSION
LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
ifdef CARGO_TOOLCHAIN_VERSION
-SRCS=$(sort $(shell find . -type f ! -path '*/.*/*' -iname '*.c'))
-DEPS=$(SRCS:.c=.d)
+SRCS:=$(sort $(shell find . -type f ! -path '*/.*/*' -iname '*.c'))
+DEPS:=$(SRCS:.c=.d)
%.o: %.c
@echo " [CC] $@"
%.o: %.c
@echo " [CC] $@"
@echo " [AR] $@"
$(Q)ar -rc $@ $+
@echo " [AR] $@"
$(Q)ar -rc $@ $+
-RUST_SRCS=$(shell find rust-src/src rust-src/bch_bindgen/src -type f -iname '*.rs')
+RUST_SRCS:=$(shell find rust-src/src rust-src/bch_bindgen/src -type f -iname '*.rs')
rust-src/target/release/libbcachefs_rust.a: $(RUST_SRCS)
$(CARGO_BUILD)
rust-src/target/release/libbcachefs_rust.a: $(RUST_SRCS)
$(CARGO_BUILD)