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

#----- DigiSpark

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

CC             = avr-gcc
CXX = $(CC)

#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	 = sound

#put your C sourcefiles here 
OBJ = main.o

#assembler flags
ASFLAGS =  -gstabs -mmcu=$(MCU)  -DF_CPU=16500000L -DDEBUG_LEVEL=0

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

# by hoshi
OPTIMIZE	= -Os
CFLAGS		= -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS) -I/usr/local/avr/include/ -DF_CPU=16500000L -DDEBUG_LEVEL=0
CXXFLAGS        = $(CFLAGS) 
LDFLAGS       = -Wl,-Map,$(TRG).map
OBJCOPY        = avr-objcopy
OBJDUMP        = avr-objdump

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

# $(TRG).o : $(TRG).c
# 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

# 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 $< > $@

MML = orphee.mml

data:
	perl mml2c.pl -1 -1 -1 -1 $(MML) > note.h
	perl waitTag.pl note.h > tmp.h ; mv tmp.h note.h

size:
	avr-size $(TRG).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
	micronucleus --run $(TRG).hex


