# Simple Makefile Volker Oth (c) 1999
# edited by AVRfreaks.net nov.2001

#----- Make Faire 2013 1⥳

########### change these lines according to your project ##################

CC             = avr-gcc

#put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603 etc.)
MCU = attiny85

#put the name of the target file here (without extension)
TRG	 = 1key

#put your C sourcefiles here 
OBJ = 1key.o ir.o fs.o eeprom.o delay.o

#assembler flags
	ASFLAGS = -Wa, -gstabs

###### dependencies, add any dependencies you need here ###################

# by hoshi
OPTIMIZE			= -Os
CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS)
LDFLAGS       = -Wl,-Map,$(TRG).map
OBJCOPY        = avr-objcopy
OBJDUMP        = avr-objdump

all:	$(TRG).hex $(TRG).lst

# $(TRG).o : $(TRG).c $(OBJ)

# ir.o:	ir.c
# 	avr-gcc -g -Wall -O3 -mmcu=attiny85    -c -o ir.o ir.c

%.hex:	%.elf
	$(OBJCOPY) -j .text -j .data -O ihex $< $@

$(TRG).elf:	$(OBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

%.lst:	%.elf
	$(OBJDUMP) -h -S $< > $@

size:
	avr-size 1key.elf
	echo -n "STACK="; echo "ibase=16; 025F-" `avr-nm $(TRG).elf | grep " _end" | perl -ne 's/\s.+//; tr/[a-z]/[A-Z]/; print'` "+800000" | bc

clean:
	touch dummy.o
	rm *.o
	if [ -e $(TRG).hex ]; then rm $(TRG).hex; fi
	if [ -e $(TRG).map ]; then rm *.map; fi
	if [ -e $(TRG).lst ]; then rm *.lst; fi
	if [ -e $(TRG).elf ]; then rm *.elf; fi
	touch \#dummyfile
	touch dummyfile~
	rm \#* *~

write: $(TRG).hex
	avrdude -E noreset -y -p t85 -c bsd -U lfuse:w:0xf1:m
	avrdude -E noreset -y -p t85 -c bsd -U flash:w:$(TRG).hex
	./fuseCheck.pl

eeprom_r:
	avrdude -E noreset -y -p t85 -c bsd -U eeprom:r:$(TRG)_eeprom.hex:i

eeprom_w: $(TRG)_eeprom.hex
	avrdude -E noreset -y -p t85 -c bsd -U eeprom:w:$(TRG)_eeprom.hex:i

# fuse:
#	avrdude -E noreset -y -p t85 -c bsd -U hfuse:w:0xdf:m

# вٻ(RC 1MHz)
#	avrdude -E noreset -y -p t85 -c bsd -U lfuse:w:0x62:m
# RC 8MHz
#	avrdude -E noreset -y -p t85 -c bsd -U lfuse:w:0xe2:m
# å 4MHz
#	avrdude -E noreset -y -p t85 -c bsd -U lfuse:w:0xdc:m
# PLL 16MHz
#	avrdude -E noreset -y -p t85 -c bsd -U lfuse:w:0xf1:m
# WDT ͭ(Ѥʤ)
# avrdude -E noreset -y -p t85 -c bsd -U hfuse:w:0xcf:m
# BOD ͭ(2.7V)
#	avrdude -E noreset -y -p t85 -c bsd -U hfuse:w:0xdd:m

