CC=arm-none-eabi-gcc

CMSIS=../CMSIS_Atmel

CDEFS=-D__SAMD21J18A__
COPTS=-g -O -mthumb -mcpu=cortex-m0plus -std=gnu99 -Wall -Wextra
CINCS=-I$(CMSIS)/Device/ATMEL -I$(CMSIS)/Device/ATMEL/samd21/include -I$(CMSIS)/CMSIS/Include

CFLAGS=$(CDEFS) $(COPTS) $(CINCS)
LDFLAGS=-mthumb -mcpu=cortex-m0plus -nostartfiles -Wl,-Map=test.map -T$(CMSIS)/Device/ATMEL/samd21/source/as_gcc/samd21j18a_flash.ld

all: test.elf

test.elf: test.c
	$(CC) -o test.elf $(CFLAGS) $(LDFLAGS) $(CMSIS)/Device/ATMEL/samd21/source/as_gcc/startup_samd21.c $(CMSIS)/Device/ATMEL/samd21/source/system_samd21.c test.c

.PHONY: clean
clean:
	rm -f test.elf test.map *.o
