# Makefile to build Dilbert 2 for both GCC and IAR
#
# Larry Barello May, 2001
#
# Uses GCC tools (make, rm)
#
# Generic stuff.
#
	PROG	= c:/progra~1/atmel/avrstu~1/stk500/stk500.exe
	RM	= $(AVR)/bin/rm -f

	GCCMCU	= at90s2313

#GCC Equates
	FORMAT	= ihex
	GCCLIB	=
	GCCINC	= -I. -I$(AVRX)/avrx -I$(AVR)/avr/inc
	LDFLAGS = -Wl,-lm,-Map=$(<:.o=.gcc),--cref,-v -mmcu=$(GCCMCU)
	AFLAGS	= -c -mmcu=$(GCCMCU) -Wa,-gstabs -mmcu=$(GCCMCU) -I$(GCCINC)
	CFLAGS	= -Os -fno-reorder-blocks -Wall -g -mmcu=$(GCCMCU) $(TARGET)
	BIN	= $(AVR)/bin/avr-objcopy
	CC	= avr-gcc
	AS	= avr-gcc -x assembler-with-cpp
	ELFCOF  = elfcoff
	CP      = cp
	OUT     = coff
	SHELL   = sh.exe

#specific stuff to my build

	SRC	= Tether.c
	ASRC	= TetherSup.s new_lcd.s

	GCCOBJ	= $(SRC:.c=.o) $(ASRC:.s=.o)

# GCC Rules

%o: %c
	$(CC) -c $< $(GCCINC) $(CFLAGS) -o $@

%s: %c
	$(CC) -S $< $(GCCINC) $(CFLAGS) -o $@

%o: %s
	$(AS) $(AFLAGS) $< -o $@

%elf: %o
	$(CC) $< $(GCCLIB) $(LDFLAGS) -o $@

%obj: %elf
	$(BIN) -O avrobj -R .eeprom $< $@

%cof: %elf
	$(ELFCOF) $< $(OUT) $@ $*sym
#	$(CP) $(OUT)/$@ .
#	$(CP) $(OUT)/*sym .
#	$(CP) $(OUT)/*S .

%ok:
	@echo "Errors: none"

%hex: %elf
	$(BIN) -O $(FORMAT) $< $@

%eep: %elf
	$(BIN) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@

# Rules specific to my project (default to GCC)

gcc:	Tether.obj Tether.eep Tether.hex Tether.cof Tether.ok



clean:
	$(RM) *.o *.lst *.map
	$(RM) *.rom *.eep *.hex
	$(RM) *.obj *.?_sym $(SRC:.c=.s)

# Command line STK500 programmer

burn.eep:	Tether.eep
	$(PROG) -d$(GCCMCU) -ie$< -ve -pe -z


burn.hex:	Tether.hex
	$(PROG) -d$(GCCMCU) -if$< -vf -pf -e -z

burn:	burn.hex burn.eep

Tether.elf:   $(GCCOBJ) $(GCCLIB)
	$(CC) $(GCCOBJ) $(GCCLIB) $(LDFLAGS) -mmcu=$(GCCMCU) -o $@

assembly: $(SRC:.c=.s)

Tether.o:	makefile hardware.h Tether.c
TetherSup.o:	makefile hardware.h TetherSup.s
lcdio.o:	makefile lcdio.h lcdio.s
lcd.o:		makefile lcd.inc lcd.s
