# AVR-GCC Makefile
#**************************************************************
.SUFFIXES:
.SUFFIXES:	.S .c .o .obj .elf .eep .rom

#--- define some variables based on the AVR base path in $(AVR)
CC	= avr-gcc
AS	= avr-gcc -x assembler-with-cpp	
RM	= rm -f
RN	= mv
CP      = cp
BIN	= avr-objcopy
INCDIR	= .
LIBDIR	= $(AVR)/avr/lib
SHELL   = $(AVR)/bin/sh.exe

#--- default mcu type
MCU = at90s8515

#--- default compiler flags -ahlmsn
CPFLAGS = -g -Os -Wall -Wstrict-prototypes -Wa,-adhlmsn=$(<:.c=.lst) -mmcu=$(MCU)

#--- default assembler flags 
ASFLAGS = -mmcu=$(MCU) -Wa,-mmcu=$(MCU),-gstabs

#--- default linker flags
LDFLAGS = -Wl,-Map=$(<:.o=.map),--cref -mmcu=$(MCU)

#--- output format can be srec, ihex 
ROMFORMAT 	= srec
EEPROMFORMAT    = ihex


#--- compile: instructions to create assembler and/or object files from C source
#.c.o:
%o : %c 
	$(CC) -c $(CPFLAGS) -I$(INCDIR) $< -o $@

%s : %c
	$(CC) -s $(CPFLAGS) -I$(INCDIR) $< -o $@


#--- assemble: instructions to create object file from assembler source
%o : %S
	$(AS) -x assembler-with-cpp $(ASFLAGS) -I$(INCDIR) -c $< -o $@


#--- link: instructions to create elf output file from object files
%elf:	%o
	$(CC) $^ $(LIB) $(LDFLAGS) -o $@


#--- create avrobj file from elf output file
%obj: %elf
	$(BIN) -O avrobj -R .eeprom $< $@

#--- create flash and eeprom bin file (ihex, srec) from elf output file
%rom: %elf
	$(BIN) -O $(ROMFORMAT) -R .eeprom $< $@

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


#*************************** add your projects below **************************************


#--- this defines the aims of the make process
all:	test_i2cmaster
	#done with target all

clean:
	$(RM) *.rom *.eep *.obj
	$(RM) *.o *.elf *.lst *.map



#-------- test i2c master library
test_i2cmaster:			test_i2cmaster.obj test_i2cmaster.rom
	#done with target test_i2cmaster
	
test_i2cmaster.elf:	test_i2cmaster.o i2cmaster.o

test_i2cmaster.o:	test_i2cmaster.c i2cmaster.h



#-------- I2C master library
i2cmaster.o:	i2cmaster.S

