# makefile, written by guido socher
MCU=atmega8
CC=avr-gcc
OBJCOPY=avr-objcopy
# optimize for size:
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
#-------------------
.PHONY: test1 all
all: main.hex test1.hex 
#-------------------
help: 
	@echo "Usage: make all|load|rdfuse|fuse"
	@echo "or the test software:"
	@echo "Usage: make test1|load_test1|rdfuse|fuse"
#-------------------
main.hex : main.out 
	$(OBJCOPY) -R .eeprom -O ihex main.out main.hex 
	avr-size main.out
	@echo " "
	@echo "Expl.: data=initialized data, bss=uninitialized data, text=code"
	@echo " "
main.out : main.o analog.o 
	$(CC) $(CFLAGS) -o main.out -Wl,-Map,main.map main.o analog.o 
main.o : main.c analog.h 
	$(CC) $(CFLAGS) -Os -c main.c
#------------------
analog.o : analog.c analog.h 
	$(CC) $(CFLAGS) -Os -c analog.c
#------------------
# hardware test, led only:
test1: test1.hex
#
test1.o : test1.c  
	$(CC) $(CFLAGS) -Os -c test1.c
test1.hex : test1.o 
	$(CC) $(CFLAGS) -o test1.out -Wl,-Map,test1.map test1.o 
	$(OBJCOPY) -R .eeprom -O ihex test1.out test1.hex 
	avr-size test1.out
	@echo " "
	@echo "Expl.: data=initialized data, bss=uninitialized data, text=code"
	@echo " "
load_test1: test1.hex
	./prg_load_uc test1.hex
#-------------------
load: main.hex
	./prg_load_uc main.hex
# here is a pre-compiled version in case you have trouble with
# your development environment
load_pre: main_pre.hex
	./prg_load_uc main_pre.hex
#
#-------------------
# fuse byte settings:
#  Atmel AVR ATmega8 
#  Fuse Low Byte      = 0xe1 (1MHz internal), 0xe3 (4MHz internal), 0xe4 (8MHz internal)
#  Fuse High Byte     = 0xd9 
#  Factory default is 0xe1 for low byte and 0xd9 for high byte
# Check this with make rdfuses
rdfuse:
	./prg_fusebit_uc -r
# use internal RC oscillator 8 Mhz
fuse:
	./prg_fusebit_uc -w 8
#-------------------
clean:
	rm -f *.o *.map *.out test*.hex main.hex
#-------------------
