Skip to content

Commit a49078c

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

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

test/Makefile

Lines changed: 8 additions & 6 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
@@ -277,6 +279,9 @@ $(BUILD_DIR)/%.o: %.c
277279
@echo "Compiling C file: $(notdir $<)"
278280
$(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<
279281

282+
# Include auto-generated dependency files (if they exist)
283+
-include $(OBJS_C:.o=.d)
284+
280285
$(BUILD_DIR)/$(BIN).elf: $(OBJS_ASM) $(OBJS_C)
281286
@echo "Linking ELF binary: $(notdir $@)"
282287
$(CMD_ECHO) $(CC) $(LDFLAGS) $(SRC_LD) -o $@ $^ $(LIBS)
@@ -292,17 +297,15 @@ clean:
292297
$(BUILD_DIR)/*.hex \
293298
$(BUILD_DIR)/*.map \
294299
$(BUILD_DIR)/*.o \
300+
$(BUILD_DIR)/*.d \
295301
$(BUILD_DIR)/*.a \
296302
$(BUILD_DIR)/*.sym \
297303
$(BUILD_DIR)/*.disasm \
298304
$(BUILD_DIR)/*.gcda \
299305
$(BUILD_DIR)/*.gcno
300306

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
307+
# Rebuild if sources or flags changed before running
308+
run: build_app
306309
ifeq ($(TSAN),1)
307310
# TSAN options:
308311
# - fail fast on first data race detected
@@ -312,7 +315,6 @@ ifeq ($(TSAN),1)
312315
else
313316
$(BUILD_DIR)/$(BIN).elf
314317
endif
315-
endif
316318

317319
# Coverage target: build with coverage, run tests, and generate report
318320
coverage:

0 commit comments

Comments
 (0)