From 801bbca9298a2059f60f34140c22a219435cd0ef Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 13 Feb 2021 22:35:13 +1300 Subject: Add dep files to Makefile Also includes WIP data manager code. --- Makefile | 86 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 26 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 73d957d..1213f92 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,6 @@ REAL_ELF = build/altimeter.elf # options for native (i.e. unit test) UNITY_SRC ?= unity/src -UNITY_O = $(UNITY_SRC)/unity.o CFLAGS += -Wall -Wextra -I$(UNITY_SRC) LDFLAGS += -lm @@ -30,7 +29,7 @@ AVR_COMMON_LDFLAGS += -Wl,-u,vfprintf -lprintf_flt AVR_LDFLAGS += $(AVR_COMMON_LDFLAGS) -mmcu=$(MCU) SIM_LDFLAGS += $(AVR_COMMON_LDFLAGS) -mmcu=$(SIM_MCU) -$(shell mkdir -p build/{real,sim,native}) +$(shell mkdir -p build/{real,sim,native{,/$(UNITY_SRC)}}) all: build/altimeter_sim.elf build/altimeter.hex test size @@ -47,24 +46,44 @@ flash: build/altimeter.hex $(AVRDUDE) -F -V -c avr109 -p $(MCU) -P $(PORT) -b 115200 -U flash:w:$< clean: - rm -rf build/ $(UNITY_O) - -test: \ - $(UNITY_O) \ - build/native/test_runner.o \ - build/native/test_util.o \ - build/native/test_test.o \ - build/native/util.o + rm -rf build/ + +BUILD_DIR = build +SIM_DIR = $(BUILD_DIR)/sim +REAL_DIR = $(BUILD_DIR)/real +NATIVE_DIR = $(BUILD_DIR)/native + +TEST_OBJ = \ + $(NATIVE_DIR)/$(UNITY_SRC)/unity.o \ + $(NATIVE_DIR)/test_runner.o \ + $(NATIVE_DIR)/test_util.o \ + $(NATIVE_DIR)/test_test.o \ + $(NATIVE_DIR)/util.o + +REAL_OBJ = \ + $(REAL_DIR)/barometer_sim.o \ + $(REAL_DIR)/display_sim.o \ + $(REAL_DIR)/altimeter.o \ + $(REAL_DIR)/util.o \ + $(REAL_DIR)/data_manager.o + +SIM_OBJ = \ + $(SIM_DIR)/barometer_sim.o \ + $(SIM_DIR)/display_sim.o \ + $(SIM_DIR)/altimeter.o \ + $(SIM_DIR)/util.o \ + $(SIM_DIR)/data_manager.o + +ALL_OBJ = $(TEST_OBJ) $(REAL_OBJ) $(SIM_OBJ) +ALL_SOURCE = $(ALL_OBJ:.o=.c) + +test: $(TEST_OBJ) $(CC) $(LDFLAGS) -Wl,-T,linker_list.lds -o $@ $^ ./$@ # ELF for real hardware. No mock/sim hardware included (except barometer, # haven't written that code yet) -build/altimeter.elf: \ - build/real/barometer_sim.o \ - build/real/display_sim.o \ - build/real/altimeter.o \ - build/real/util.o +$(REAL_ELF): $(REAL_OBJ) $(AVR_CC) $(AVR_LDFLAGS) -o $@ $^ size: @@ -74,23 +93,38 @@ size: # versions of each component will provide a mocked interface. This allows for # operation in QEMU (see `emu` recipe) without requring SPI, I²C and # peripherals to be emulated. Useful for UI testing and development etc. -build/altimeter_sim.elf: \ - build/sim/barometer_sim.o \ - build/sim/display_sim.o \ - build/sim/altimeter.o \ - build/sim/util.o +build/altimeter_sim.elf: $(SIM_OBJ) $(AVR_CC) $(SIM_LDFLAGS) -o $@ $^ -build/sim/%.o: %.c - $(AVR_CC) $(SIM_CFLAGS) -c -o $@ $^ +build/sim/%.o: %.c build/sim/%.d + $(AVR_CC) $(SIM_CFLAGS) -c -o $@ $< -build/real/%.o: %.c - $(AVR_CC) $(AVR_CFLAGS) -c -o $@ $^ +build/real/%.o: %.c build/real/%.d + $(AVR_CC) $(AVR_CFLAGS) -c -o $@ $< -build/native/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $^ +build/native/%.o: %.c build/native/%.d + $(CC) $(CFLAGS) -c -o $@ $< build/%.hex: build/%.elf $(OBJCOPY) -O ihex -R .eeprom $< $@ +build/sim/%.d: %.c + @set -e; rm -f $@; \ + $(AVR_CC) $(SIM_CFLAGS) -MM -MG $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +build/real/%.d: %.c + @set -e; rm -f $@; \ + $(AVR_CC) $(AVR_CFLAGS) -MM -MG $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +build/native/%.d: %.c + @set -e; rm -f $@; \ + $(CC) $(CFLAGS) -MM -MG $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +include $(ALL_SOURCE:.c=.d) .PHONY: all emu gdb flash clean test size -- cgit v1.1