# .SILENT:

# Atmega88
# CFLAGS= -Os -g -Wall -mmcu=atmega16 -DF_CPU=8000000UL
# LDFLAGS= -mmcu=atmega16

# Atmega32
CFLAGS= -Os -g -Wall -mmcu=atmega32 -DF_CPU=16000000UL
LDFLAGS= -mmcu=atmega32

all: testadc.bin lauflicht.bin testlcd.bin testrs232.bin testsrf02.bin fuellstand.bin testeth.bin spavrtool

rebuild: clean all

spavrtool: spavrtool.c
	gcc -o spavrtool spavrtool.c

blink.elf: blink.o
	avr-gcc $^ -o $@ $(LDFLAGS)

testadc.elf: lcd-i2c.o testadc.o adc.o i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

testlcd.elf: lcd-i2c.o testlcd.o i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

lauflicht.elf: lcd-i2c.o lauflicht.o i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

widelcd.elf: lcd-i2c_wide.o usart.o widelcd.o i2.o
	avr-gcc $^ -o $@ $(LDFLAGS)

fuellstand.elf: fuellstand.o i2c.o usart.o lcd-i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

testsrf02.elf: testsrf02.o usart.o i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

testrs232.elf: testrs232.o lcd-i2c.o usart.o adc.o i2c.o
	avr-gcc $^ -o $@ $(LDFLAGS)

testeth.elf: testeth.o enc28j60.o usart.o i2c.o lcd-i2c.o ipstack.o
	avr-gcc $^ -o $@ $(LDFLAGS)

%.bin: %.elf
	avr-objcopy -j .text -j .data -O binary $^ $@

%.o: %.c
	avr-gcc $(CFLAGS) -c -o $@ $^

clean:
	rm *.o -rf
	rm *.bin -rf
	rm *.elf -rf
	rm *~ -rf
	rm -rf spavrtool

cleanall: clean

source: cleanall

upload:
	echo "avrdude -c avrispmkII -P usb -p m32 -v -U flash:r:avr-net-io-dump.hex:h"
