DEVICE = atmega644p
AVRDUDE = avrdude  
#F_CPU   = 16000000
F_CPU   = 2000000


CFLAGS = -O1 -ffreestanding -funroll-loops 
COMPILE = avr-gcc -Wall -I../common/ -I. $(CFLAGS)  -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
OBJECTS = ../common/nRF905/nRF905.cpp ../common/nRF905/nRF905_spi.cpp ../common/codecrypt/chacha.cpp ../common/cpusleep.cpp 1wire/onewire.o 1wire/ds18x20.o 1wire/crc8.o main.cpp 

all:	main.hex

.cpp.o:
	$(COMPILE) -std=c++11 -c $< -o $@
.c.o:
	$(COMPILE) -c $< -o $@
	
.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@

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

install:	all
	$(AVRDUDE) -c avrisp2 -P usb -p $(DEVICE) -U flash:w:main.hex:i



clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s

main.bin:	$(OBJECTS)
	$(COMPILE) -o main.bin $(OBJECTS)

main.hex:	main.bin
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.bin main.hex
	./checksize main.bin

disasm:	main.bin
	avr-objdump -d main.bin

