Skip to content

Commit db3d413

Browse files
committed
Minor makefile enhancements
1 parent 7f9702f commit db3d413

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ ARCHFLAGS ?=
3939
CFLAGS_EXTRA = -Werror -Wall -Wextra
4040
# Place functions / data into separate sections to allow unused code removal
4141
CFLAGS_EXTRA += -ffunction-sections -fdata-sections
42+
# Auto-generate header dependency files (.d) alongside object files
43+
CFLAGS_EXTRA += -MMD -MP
4244

4345
# C standard to use (default to c90 if not specified)
4446
CSTD ?= -std=c90
@@ -262,6 +264,13 @@ scan:$(BUILD_DIR)
262264
$(BUILD_DIR):
263265
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
264266

267+
# Rebuild all objects when compiler flags change (e.g. SHE=1 DMA=1 vs default)
268+
BUILD_OPTIONS := $(CC) $(CFLAGS) $(DEF) $(INC)
269+
BUILD_OPTIONS_FILE := $(BUILD_DIR)/.build_options
270+
$(BUILD_OPTIONS_FILE): $(BUILD_DIR) FORCE
271+
@echo '$(BUILD_OPTIONS)' | cmp -s - $@ || echo '$(BUILD_OPTIONS)' > $@
272+
FORCE:
273+
265274
$(BUILD_DIR)/$(BIN).hex: $(BUILD_DIR)/$(BIN).elf
266275
@echo "Generating HEX binary: $(notdir $@)"
267276
$(CMD_ECHO) $(OBJCOPY) -O ihex $< $@
@@ -273,10 +282,13 @@ $(BUILD_DIR)/%.o: %.s
273282
# Add additional flag here to avoid pragma
274283
$(BUILD_DIR)/wh_test_check_struct_padding.o: CFLAGS+=-Wpadded -DWOLFHSM_CFG_NO_CRYPTO
275284

276-
$(BUILD_DIR)/%.o: %.c
285+
$(BUILD_DIR)/%.o: %.c $(BUILD_OPTIONS_FILE)
277286
@echo "Compiling C file: $(notdir $<)"
278287
$(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<
279288

289+
# Include auto-generated dependency files (if they exist)
290+
-include $(OBJS_C:.o=.d)
291+
280292
$(BUILD_DIR)/$(BIN).elf: $(OBJS_ASM) $(OBJS_C)
281293
@echo "Linking ELF binary: $(notdir $@)"
282294
$(CMD_ECHO) $(CC) $(LDFLAGS) $(SRC_LD) -o $@ $^ $(LIBS)
@@ -292,17 +304,16 @@ clean:
292304
$(BUILD_DIR)/*.hex \
293305
$(BUILD_DIR)/*.map \
294306
$(BUILD_DIR)/*.o \
307+
$(BUILD_DIR)/*.d \
295308
$(BUILD_DIR)/*.a \
296309
$(BUILD_DIR)/*.sym \
297310
$(BUILD_DIR)/*.disasm \
298311
$(BUILD_DIR)/*.gcda \
299-
$(BUILD_DIR)/*.gcno
312+
$(BUILD_DIR)/*.gcno \
313+
$(BUILD_DIR)/.build_options
300314

301-
# No prereq's here to stop from rebuilding with different options
302-
run:
303-
ifeq (,$(wildcard $(BUILD_DIR)/$(BIN).elf))
304-
$(error $(BUILD_DIR)/$(BIN).elf not found. Try: make)
305-
else
315+
# Rebuild if sources or flags changed before running
316+
run: build_app
306317
ifeq ($(TSAN),1)
307318
# TSAN options:
308319
# - fail fast on first data race detected
@@ -312,7 +323,6 @@ ifeq ($(TSAN),1)
312323
else
313324
$(BUILD_DIR)/$(BIN).elf
314325
endif
315-
endif
316326

317327
# Coverage target: build with coverage, run tests, and generate report
318328
coverage:

0 commit comments

Comments
 (0)