MCU=atmega328p
CC=avr-gcc
OBJCOPY=avr-objcopy
PROJECT=dust
# optimize for size:
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -ffunction-sections -fno-split-wide-types
#-------------------
all: $(PROJECT).hex
#-------------------
$(PROJECT).hex : $(PROJECT).out
	$(OBJCOPY) -j .text -j .data -O ihex $(PROJECT).elf $(PROJECT).hex
$(PROJECT).out : $(PROJECT).c
	$(CC) $(CFLAGS) $(PROJECT).c -o $(PROJECT).elf
# you need to erase first before loading the program.
# load (program) the software into the eeprom:
load: $(PROJECT).hex
	#avrdude -c usbasp -p $(MCU) -U flash:w:$(PROJECT).hex
	avrdude  -D -c arduino -p $(MCU) -P /dev/ttyUSB0 -U flash:w:$(PROJECT).hex

clean:
	rm -f *.o *.map *.out *.hex *.elf
