PRG            = scope
OBJ            = main.o ./libs/usart.o ./libs/spi.o
MCU_TARGET     = atmega8
AVRDUDE_PART   = m8

OPTIMIZE       = -O1
# OPTIMIZE      = -Os

CC             = avr-gcc
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
OBJCOPY        = avr-objcopy
OBJDUMP        = avr-objdump

all: hex

./libs/spi.o: ./libs/spi.h
./libs/usart.o: ./libs/usart.h
#./libs/timer.o: ./libs/timer.h

hex:  $(PRG).hex

%.hex: %.elf
        $(OBJCOPY) -j .text -j .data -O ihex $< $@

$(PRG).elf: $(OBJ)
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

load: $(PRG).hex
        avrdude -p $(AVRDUDE_PART) -c stk500v2 -P /dev/ttyUSB1 -B 2 -U flash:w:$<

clean:
        rm -rf *.o $(PRG).elf $(PRG).hex ./libs/*.o