#MCU := attiny861
#PART := t861

#MCU := atmega88
#PART := m88

MCU := atmega168
PART := m168

#CFLAGS := -O2 -Wall
CFLAGS := -Wall -W -g -Os -mcall-prologues
#ASFLAGS = -a
CFLAGS  += -I../lib_avr/
LDFLAGS += -L../lib_avr/

SRC += $(filter-out Tes%.c,$(wildcard *.c))
SRC := $(sort $(SRC))		# remove possible duplicates

OBJ := $(SRC:.c=.o)

all:	door.hex

%.hex:	%.out
	avr-size $<
	avr-objcopy -R .eeprom -O ihex $< $@

%.out:	%.o ../lib_avr/$(MCU).a
	avr-gcc -mmcu=$(MCU) -o $@ -Wl,-Map,$*.map -lm $^ ../lib_avr/$(MCU).a

%.o:	%.c
	avr-gcc -mmcu=$(MCU) $(CFLAGS) -Wa,-a=$*.list -c $<

%.load:	%.hex
	avrdude -p $(PART) -c bsd -q -e -E noreset,novcc -U flash:w:$<
	touch %@

dep:
	avr-gcc $(CFLAGS) -MM *.c -mmcu=$(MCU) > depend.mk

clean:
	-rm -f *.o *~ *.hex *.out *.list *.map clean > /dev/null

-include depend.mk
