CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
NM = arm-none-eabi-nm
LKR = linker.lkr
OPT = -Os -g -ggdb3
FLAGS	= $(OPT) -mthumb -mcpu=cortex-m3 -march=armv7-m -flto
CCFLAGS = $(FLAGS) -I. -ffunction-sections -fdata-sections -fomit-frame-pointer -DCLOCK_SPEED=48000000 -fmerge-all-constants -U_FORTIFY_SOURCE -fsplit-wide-types -free
LDFLAGS = $(FLAGS) -Wl,--gc-sections -Wl,-T $(LKR)


APP = VMU_comms
OBJS = crt_stm32f103.o main.o printf.o mapleWire.o mapleComms.o
all: $(APP).bin

$(APP).bin:	$(OBJS) $(LKR)
	$(LD) -o $(APP).elf $(LDFLAGS) $(OBJS)
	$(OBJCOPY) -I elf32-littlearm -O binary $(APP).elf $(APP).bin -j.text -j.vectors -j.data -j.rodata

%.o : %.c Makefile
	$(CC) $(CCFLAGS) -c $< -o $@

%.o : %.S Makefile
	$(CC) $(CCFLAGS) -c $< -o $@

clean:
	rm -f $(OBJS) $(APP).bin $(APP).elf $(APP).hex

