
# device can be atmega8, atmega88 or atmega168
DEVICE = atmega8
F_CPU = 12000000

# BOOTSTART is 0x1800 for atmega8 and atmega88. But is 0x3800 for atmega168
BOOTSTART = 0x1800


CFLAGS = $(DEFINES) -Iusbdrv -I. -DDEBUG_LEVEL=0 -DF_CPU=$(F_CPU)
OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o

COMPILE = avr-gcc -Wall -Os $(CFLAGS) -mmcu=$(DEVICE)
LD_FLAGS = -Wl,--section-start=.text=$(BOOTSTART) -Wl,-Ttext=$(BOOTSTART)

all: main.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 $@

main.elf:	$(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS) $(LD_FLAGS)

main.hex:	main.elf
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size --format=avr --mcu=$(DEVICE) main.elf

clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s

