MCU=msp430g2210
CC=msp430-gcc
MSPDEBUG=mspdebug
FLAGS=-O2

main.elf: main.o morse.o si406x.o delay.o
	$(CC) -mmcu=$(MCU) $(FLAGS) -o $@ $^
	msp430-size $@

main.o: main.c morse.h si406x.h delay.h
	$(CC) -mmcu=$(MCU) $(FLAGS) -c -o $@ $<

si406x.o: si406x.c si406x.h
	$(CC) -mmcu=$(MCU) $(FLAGS) -c -o $@ $<

morse.o: morse.c morse.h message.h
	$(CC) -mmcu=$(MCU) $(FLAGS) -c -o $@ $<

# It's necessary to edit encoder.py to insert your own MO-* message and call sign.
message.h: encoder.py
	if grep -q N0CALL encoder.py ; then /bin/echo -e "\nEdit encoder.py with your call sign!\n"; false; fi
	python $< > $@

delay.o: delay.s delay.h
	msp430-as -mmcu=$(MCU) -o delay.o delay.s

install: main.elf
	$(MSPDEBUG) rf2500 "prog main.elf"

clean:
	rm -f *.bak *.o message.h main.elf
