# Makefile for Adam's LED blink example

# Our tools.
CC      = arm-thumb-elf-gcc
LD      = arm-thumb-elf-ld
AS      = arm-thumb-elf-as
CP      = arm-thumb-elf-objcopy

# Commandline options for each tool.
CFLAGS  = -I./ -c -fno-common -O0 -g
AFLAGS  = -ahls -mapcs-32 -o crt.o
LFLAGS  = -v -Map blink.map -Tram-ln.cmd
CPFLAGS = --output-target=ihex

# Our target.
all: blink.hex

clean:
	rm -f *.o *.hex *.elf *.map *.lst core *~

# Convert ELF binary to Intel HEX file.
blink.hex: blink.elf
	$(CP) $(CPFLAGS) blink.elf blink.hex

# Link - this produces an ELF binary.
blink.elf: blink.o crt.o
	$(LD) $(LFLAGS) -o blink.elf crt.o blink.o

# Compile the C runtime.
crt.o: ram-crt.s
	$(AS) $(AFLAGS) ram-crt.s > crt.lst

# Compile the main program.
blink.o: blink.c
	$(CC) $(CFLAGS) -c blink.c
