# Name: Makefile
#
# A simple program for the attiny44 .
#
# electronut.in

DEVICE      = attiny44
CLOCK      = 16000000
PROGRAMMER = usbtiny
OBJECTS    = hello_echo44.o

# for atmega - unset CKDIV8
FUSES       = -U lfuse:w:0x5E:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m    


# Tune the lines below only if you know what you are doing:
AVRDUDE = avrdude -c $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:  hello_echo44.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -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:
	$(COMPILE) -S $< -o $@

flash:	all
	$(AVRDUDE) -U flash:w:hello_echo44.hex:i

fuse:
	$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
	bootloadHID hello_echo44.hex

clean:
	rm -f hello_echo44.hex hello_echo44.elf $(OBJECTS)

# file targets:
hello_echo44.elf: $(OBJECTS)
	$(COMPILE) -o hello_echo44.elf $(OBJECTS)

hello_echo44.hex: hello_echo44.elf
	rm -f hello_echo44.hex
	avr-objcopy -j .text -j .data -O ihex hello_echo44.elf hello_echo44.hex
	avr-size --format=avr --mcu=$(DEVICE) hello_echo44.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:	hello_echo44.elf
	avr-objdump -d hello_echo44.elf

cpp:
	$(COMPILE) -E hello_echo44.c
