# Project configuration:
OBJS  = test.o rs232.o
BIN   = test

#Hardware
MCU     = atmega16
ROM_START = 0x00

#Compiler flags
CCFLAGS = -g  -Os -Wall -Wstrict-prototypes -mmcu=$(MCU) -mcall-prologues
#-S für ASM-Output

#Linker flags
LDFLAGS = -Wl,-Map=$(BIN).map,--cref,--section-start=.text=$(ROM_START) -mmcu=$(MCU) 

# Assembler config
#ASTFLAG = -gstabs,-ahlms=$(<:.c=.lst)

# Compiler configuration:
CC      = avr-gcc
LD      = avr-gcc
OBJCOPY = avr-objcopy

# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
	--change-section-address .data-0x800000 \
	--change-section-address .bss-0x800000 \
	--change-section-address .noinit-0x800000 \
	--change-section-address .eeprom-0x810000 

#Do all
all: image extcoff upload

#create ROM-Image
image: $(BIN)
	avr-size $(BIN).elf

#Upload
upload:
#	avrdude -pm8 -cstk200 -e -i main.hex

#clean source directory
clean:
	rm *.o
	rm *.bak

# Build rules:
%.o: %.c
	$(CC) $(CCFLAGS) $(ASTFLAG) -c $<

$(BIN): $(OBJS)
	$(LD) $(LDFLAGS) -o$(BIN).elf $^
	avr-objcopy -O ihex $(BIN).elf $(BIN).hex
	avr-objdump.exe -t -h -S $(BIN).elf >$(BIN).lst
	
coff: $(BIN).elf
	$(COFFCONVERT) -O coff-avr $< $(BIN).cof

extcoff: $(BIN).elf
	$(COFFCONVERT) -O coff-ext-avr $< $(BIN).cof