Skip to content

Commit 8ec5b2c

Browse files
willieyzmkannwischer
authored andcommitted
speed up make
Signed-off-by: willieyz <[email protected]>
1 parent a898c41 commit 8ec5b2c

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

Makefile

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ endif
3232

3333
W := $(EXEC_WRAPPER)
3434

35-
# Detect available SHA256 command
36-
SHA256SUM := $(shell command -v shasum >/dev/null 2>&1 && echo "shasum -a 256" || (command -v sha256sum >/dev/null 2>&1 && echo "sha256sum" || echo ""))
37-
ifeq ($(SHA256SUM),)
38-
$(error Neither 'shasum' nor 'sha256sum' found. Please install one of these tools.)
39-
endif
35+
BUILD_DIR ?= test/build
4036

37+
# Skip includes for clean target
38+
ifneq ($(MAKECMDGOALS),clean)
4139
include test/mk/config.mk
4240
include test/mk/compiler.mk
4341
include test/mk/auto.mk
4442
include test/mk/components.mk
4543
include test/mk/rules.mk
44+
endif
4645

4746
quickcheck: test
4847

@@ -52,6 +51,12 @@ build: func kat acvp
5251
test: run_kat run_func run_acvp run_unit
5352
$(Q)echo " Everything checks fine!"
5453

54+
# Detect available SHA256 command
55+
SHA256SUM := $(shell command -v shasum >/dev/null 2>&1 && echo "shasum -a 256" || (command -v sha256sum >/dev/null 2>&1 && echo "sha256sum" || echo ""))
56+
ifeq ($(SHA256SUM),)
57+
$(error Neither 'shasum' nor 'sha256sum' found. Please install one of these tools.)
58+
endif
59+
5560
run_kat_44: kat_44
5661
set -o pipefail; $(W) $(MLDSA44_DIR)/bin/gen_KAT44 | $(SHA256SUM) | cut -d " " -f 1 | xargs ./META.sh ML-DSA-44 kat-sha256
5762
run_kat_65: kat_65
@@ -230,16 +235,27 @@ else
230235
@echo "No specific feature detection available for $(ARCH)"
231236
endif
232237

233-
clean:
234-
-$(RM) -rf *.gcno *.gcda *.lcov *.o *.so
235-
-$(RM) -rf $(BUILD_DIR)
236-
-make clean -C examples/bring_your_own_fips202 >/dev/null
237-
-make clean -C examples/basic >/dev/null
238-
-make clean -C examples/monolithic_build >/dev/null
239-
-make clean -C examples/monolithic_build_multilevel >/dev/null
240-
-make clean -C examples/monolithic_build_native >/dev/null
241-
-make clean -C examples/monolithic_build_multilevel_native >/dev/null
242-
-make clean -C examples/custom_backend >/dev/null
243-
-make clean -C examples/multilevel_build >/dev/null
244-
-make clean -C examples/multilevel_build_native >/dev/null
245-
238+
EXAMPLE_DIRS := \
239+
examples/bring_your_own_fips202 \
240+
examples/bring_your_own_fips202_static \
241+
examples/custom_backend \
242+
examples/basic \
243+
examples/basic_deterministic \
244+
examples/monolithic_build \
245+
examples/monolithic_build_native \
246+
examples/monolithic_build_multilevel \
247+
examples/monolithic_build_multilevel_native \
248+
examples/multilevel_build \
249+
examples/multilevel_build_native
250+
251+
EXAMPLE_CLEAN_TARGETS := $(EXAMPLE_DIRS:%=clean-%)
252+
253+
.PHONY: $(EXAMPLE_CLEAN_TARGETS)
254+
255+
$(EXAMPLE_CLEAN_TARGETS): clean-%:
256+
@echo " CLEAN $*"
257+
-@$(MAKE) clean -C $* >/dev/null
258+
259+
clean: $(EXAMPLE_CLEAN_TARGETS)
260+
@echo " RM $(BUILD_DIR)"
261+
-@$(RM) -rf $(BUILD_DIR)

test/mk/components.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ $(MLDSA87_DIR)/bin/%: CFLAGS += -DMLD_CONFIG_PARAMETER_SET=87
8585

8686
# Link tests with respective library (except test_unit which includes sources directly)
8787
define ADD_SOURCE
88-
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): LDLIBS += -L$(BUILD_DIR) -l$(1)
89-
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): $(BUILD_DIR)/$(1)/test/$(2).c.o $(BUILD_DIR)/lib$(1).a
88+
$(BUILD_DIR)/$(1)/bin/$(2)$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)
89+
$(BUILD_DIR)/$(1)/bin/$(2)$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/$(2).c.o $(BUILD_DIR)/lib$(1).a
9090
endef
9191

9292

9393
# Special rule for test_unit - link against unit libraries with exposed internal functions
9494
define ADD_SOURCE_UNIT
95-
$(BUILD_DIR)/$(1)/bin/test_unit$(shell echo $(1) | tr -d -c 0-9): LDLIBS += -L$(BUILD_DIR) -l$(1)_unit
96-
$(BUILD_DIR)/$(1)/bin/test_unit$(shell echo $(1) | tr -d -c 0-9): $(BUILD_DIR)/$(1)/test/test_unit.c.o $(BUILD_DIR)/lib$(1)_unit.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
95+
$(BUILD_DIR)/$(1)/bin/test_unit$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)_unit
96+
$(BUILD_DIR)/$(1)/bin/test_unit$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/test_unit.c.o $(BUILD_DIR)/lib$(1)_unit.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
9797
endef
9898

9999

test/mk/config.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ $(foreach var,$(RETAINED_VARS),$(eval $(call CAPTURE_VAR,$(var))))
9292
CYCLES ?=
9393
OPT ?= 1
9494

95-
BUILD_DIR ?= test/build
96-
9795
MAKE_OBJS = $(2:%=$(1)/%.o)
9896
OBJS = $(call MAKE_OBJS,$(BUILD_DIR),$(1))
9997

0 commit comments

Comments
 (0)