# GNU 'make'
#
# 10.2 Catalogue of Built-In Rules
# ================================
#
# Compiling C programs
#      'N.o' is made automatically from 'N.c' with a recipe of the form
#      '$(CC) $(CPPFLAGS) $(CFLAGS) -c'.
#
# Assembling and preprocessing assembler programs
#      'N.o' is made automatically from 'N.s' by running the assembler,
#      'as'.  The precise recipe is '$(AS) $(ASFLAGS)'.
#
#      'N.s' is made automatically from 'N.S' by running the C
#      preprocessor, 'cpp'.  The precise recipe is '$(CPP) $(CPPFLAGS)'.

CPP := arm-none-eabi-cpp
CPPFLAGS :=

AS := arm-none-eabi-as
ASFLAGS :=

CC := arm-none-eabi-gcc
CFLAGS := -march=armv7e-m+fp \
					-mtune=cortex-m4 \
					-mthumb \
					-mfloat-abi=hard \
					-std=gnu90 \
					-ffreestanding \
					-fsingle-precision-constant \
					-pedantic \
					-pedantic-errors \
					-Wall \
					-Wextra \
					-Wconversion \
					-Wstrict-prototypes \
					-Wshadow \
					-Wundef \
					-Wdouble-promotion \
					-Os

LD := arm-none-eabi-ld
LDFLAGS := -nostdlib
LDLIBS :=

OC := arm-none-eabi-objcopy
OCFLAGS := --output-target=binary

#  ---------------------------------------------------------------------------  #

objs := kernel.o
lds := kernel.ld
LDFLAGS += -T $(lds)

elf := kernel.elf
bin := kernel.bin

#  ---------------------------------------------------------------------------  #

all : $(bin)

clean :
	rm -f $(bin) $(elf) $(objs)

.PHONY : all clean

$(bin) : $(elf)
	$(OC) $(OCFLAGS) $< $@

$(elf) : $(objs) $(lds)
	$(LD) $(filter %.o,$^) $(LDFLAGS) $(LDLIBS) -o $@
