# Processortyp M fuer Compiler, N fuer avrdude:
M=atmega328p
N=m328p

M2=atmega328p
#N2=m328pb
N2=m328p

M3=attiny13a
N3=t13a

M8=atmega8a  #ATmega8A
N8=m8

# Compileraufrufe:
C=avr-gcc -mmcu=$M -Wall -Os -c
A=avr-as
L=avr-gcc -mmcu=$M -Wall -Os
L2=avr-gcc -mmcu=$(M2) -Wall -Os
L3=avr-gcc -mmcu=$(M3) -Wall -Os
L8=avr-gcc -mmcu=$(M8) -Wall -Os

# fuer avrdude-Aufruf unter Linux:
TTY=/dev/ttyUSB0
# fuer avrdude-Aufruf unter MacOSX:
#TTY=/dev/tty.serial-0001

# verwendeter Programmer:
#P=avr910  #fuer mySmartUSB MK2
P=stk500v2 #fuer mySmartUSB light

all: prop1.hex ledtest.hex irsender.hex trafotakt.hex trafotakt2.hex

prop1.hex: prop1.cc
	$L prop1.cc -o prop1.elf
	avr-objcopy -O ihex -R .eeprom prop1.elf prop1.hex
	avr-objdump -h -S prop1.elf > prop1.lss

ledtest.hex: ledtest.cc
	$(L2) ledtest.cc -o ledtest.elf
	avr-objcopy -O ihex -R .eeprom ledtest.elf ledtest.hex
	avr-objdump -h -S ledtest.elf > ledtest.lss

irsender.hex: irsender.cc
	$(L3) irsender.cc -o irsender.elf
	avr-objcopy -O ihex -R .eeprom irsender.elf irsender.hex
	avr-objdump -h -S irsender.elf > irsender.lss

trafotakt.hex: trafotakt.cc
	$(L3) trafotakt.cc -o trafotakt.elf
	avr-objcopy -O ihex -R .eeprom trafotakt.elf trafotakt.hex
	avr-objdump -h -S trafotakt.elf > trafotakt.lss

trafotakt2.hex: trafotakt2.cc
	$(L8) trafotakt2.cc -o trafotakt2.elf
	avr-objcopy -O ihex -R .eeprom trafotakt2.elf trafotakt2.hex
	avr-objdump -h -S trafotakt2.elf > trafotakt2.lss

check:
	avrdude -p $N -c $P -P $(TTY) -v
checkf:
	avrdude -p $N -F -c $P -P $(TTY) -v
check2:
	avrdude -p $(N2) -c $P -P $(TTY) -v
check3:
	avrdude -p $(N3) -c $P -P $(TTY) -v
check8:
	avrdude -p $(N8) -c $P -P $(TTY) -v

checkfuses:
	avrdude -p $N -c $P -P $(TTY) -U hfuse:r:-:h -U lfuse:r:-:h

# Fuses fuer Quarz, fuer ATmega8 oder ATmega32 oder ATmega328P:
fusesetzen:
	avrdude -p $N -c $P -P $(TTY) -U lfuse:w:0xFF:m
	avrdude -p $N -c $P -P $(TTY) -U hfuse:w:0xD9:m

# Fuses fuer interner Takt fuer ATmega8:
fusesetzen8:
	avrdude -p $(N8) -c $P -P $(TTY) -U lfuse:w:0xE4:m
	avrdude -p $(N8) -c $P -P $(TTY) -U hfuse:w:0xD9:m

install1: prop1.hex
	avrdude -p $N -c $P -P $(TTY) -U flash:w:prop1.hex:i

install2: ledtest.hex
	avrdude -p $(N2) -c $P -P $(TTY) -U flash:w:ledtest.hex:i

install3: irsender.hex
	avrdude -p $(N3) -c $P -P $(TTY) -U flash:w:irsender.hex:i

install4: trafotakt.hex
	avrdude -p $(N3) -c $P -P $(TTY) -U flash:w:trafotakt.hex:i

install8: trafotakt2.hex
	avrdude -p $(N8) -c $P -P $(TTY) -U flash:w:trafotakt2.hex:i

clean:
	rm -f *~ *.o *.elf
clean_all:
	rm -f *~ *.o *.elf *.lss *.hex
