TARGET =attiny85 
F_CPU=16500000

COMPILEC = avr-gcc -Wall -Os -Iusbdrv -I. -DF_CPU=$(F_CPU) -mmcu=$(TARGET) # -DDEBUG_LEVEL=2

OBJECTS =  softuart.o i2cmaster.o usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o

# symbolic targets:
all:	main.hex pc.exe
pc.exe:
	gcc pc.c -o pc.exe -lusb
.c.o:
	$(COMPILEC) -c $< -o $@
.cpp.o:
	$(COMPILECPP) -c $< -o $@
#-Wa,-ahlms=$<.lst

.S.o:
	$(COMPILEC) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILEC) -S $< -o $@
.cpp.s:
	$(COMPILECPP) -S $< -o $@

clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s *.o pc.exe 
# file targets:
main.bin:	$(OBJECTS)
	$(COMPILEC) -o main.bin $(OBJECTS) -Wl,-Map,main.map

main.hex:	main.bin
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.bin main.hex

disasm:	main.bin
	avr-objdump -d main.bin

flash:
	avrdude -c chicken -p $(TARGET) -P ft0 -u -U flash:w:main.hex 

fuses:
	avrdude -c chicken -p $(TARGET) -P ft0 -u -U hfuse:w:0xdd:m -u -U lfuse:w:0xe1:m -B 4800

