PREFIX ?= arm-none-eabi-
CC = $(PREFIX)gcc
OBJCOPY = $(PREFIX)objcopy
SIZE = $(PREFIX)size
FLAGS = -mcpu=cortex-m0plus -mthumb -Os -g3 -std=c11 -Wall -Wextra -Werror -ffunction-sections -fdata-sections -DSTM32G071xx -Ivendor/device -Ivendor/core -I..
SRC = board-boot.c board.c main.c serial.c ../analog.c ../control.c ../buttons.c ../modbus.c ../storage.c ../protocol.c vendor/system_stm32g0xx.c vendor/startup_stm32g071xx.s
all: build/PUMP-TANK-A01.bin build/PUMP-TANK-A01.hex
build/PUMP-TANK-A01.elf: $(SRC) ../*.h board.h board-boot.h board-gpio.h board-watchdog.h board-adc.h board-eeprom.h board-output.h board-fast-inputs.h analog-calibration.h linker.ld
	mkdir -p build
	$(CC) $(FLAGS) $(SRC) -Tlinker.ld -Wl,--gc-sections,-Map=build/PUMP-TANK-A01.map --specs=nano.specs --specs=nosys.specs -nostartfiles -lm -lc -lgcc -o $@
	$(SIZE) $@
build/%.bin: build/%.elf
	$(OBJCOPY) -O binary $< $@
build/%.hex: build/%.elf
	$(OBJCOPY) -O ihex $< $@
clean:
	rm -f build/*.elf build/*.bin build/*.hex build/*.map
.PHONY: all clean
