#----------------------------------------------------------------------------------
#   FILENAME:       Makefile
#
#   DESCRIPTION:    Makefile for compiling and linking a program to run in Flash
#                   memory
#----------------------------------------------------------------------------------

OUTFILE_FLASH=led_on_off

TARGET=AT91SAM7S256

# Paths to standard and maths library files - assumes default YAGARTO installation
LIBGCC=C:\ARM\yagarto\lib\gcc\arm-none-eabi\4.5.1\libgcc.a
LIBC=C:\ARM\yagarto\arm-none-eabi\lib\libc.a
LIBM=C:\ARM\yagarto\arm-none-eabi\lib\libm.a

# Optimisation settings
# optimisation for size
#OPTIM=-Os
# no optimisation - for debug mode
OPTIM=-O0

AS=arm-none-eabi-gcc
CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
CCFLAGS=-g -mcpu=arm7tdmi $(OPTIM) -Wall -D$(TARGET)
ASFLAGS=-D__ASSEMBLY__ -D$(TARGET) -g -mcpu=arm7tdmi -c $(OPTIM) -Wall

# Linker flags.
#  -Wl,... :    tell GCC to pass this to linker.
#  -Map    :    create map file
#  --cref  :    add cross reference to map file
LDFLAGS_F+=-nostartfiles -Wl,-Map,out.map,--cref
LDFLAGS_F+=-T Flash.ld


#----------------------------------------------------------------------------------
# TODO: Add all the object files generated for you project to the framework
#		objects listed below
#----------------------------------------------------------------------------------
OBJS=startup.o \
     main.o \
	   

rebuild: clean all

all: flash

flash: $(OBJS)
	$(LD) $(LDFLAGS_F)  -n -o $(OUTFILE_FLASH).elf $(OBJS) $(LIBGCC) $(LIBC) $(LIBM)
	$(OBJCOPY) --strip-debug --strip-unneeded $(OUTFILE_FLASH).elf -O binary $(OUTFILE_FLASH).bin
	
#----------------------------------------------------------------------------------
# TODO: Add your object file compilation instructions
#----------------------------------------------------------------------------------

main.o: main.c
	$(CC) -c $(CCFLAGS) main.c -o main.o

startup.o:  startup.S
	$(AS) $(ASFLAGS) startup.S -o startup.o
	

clean:
	rm -f *.o *.bin *.elf *.map
