# FatFS Makefile for ARM (Nintendont kernel)

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------

.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

PREFIX	:= $(DEVKITARM)/bin/arm-none-eabi-
CC	:= $(PREFIX)gcc
AS	:= $(PREFIX)as
LD	:= $(PREFIX)gcc
AR	:= $(PREFIX)ar
STRIP	:= $(PREFIX)strip

CFLAGS	:= -mbig-endian -O3 -std=gnu89 -g -I. -Wall \
	   -mcpu=arm926ej-s -msoft-float -mfloat-abi=soft \
	   -fdata-sections -ffunction-sections -fno-builtin-toupper -fno-builtin-memcpy \
	   -fno-builtin-memset -fno-builtin-memcmp -fno-builtin-malloc -fno-builtin-free

ARFLAGS	:= cru

TARGET	:= libfatfs-arm.a
OBJECTS	:= ff-arm.o ff_utf8-arm.o option/ccsbcs-arm.o

.PHONY: FORCE

all: $(TARGET)

-include $(OBJECTS:.o=.d)

$(TARGET): $(OBJECTS)
	@echo  "AR	$@"
	@$(AR) $(ARFLAGS) $@ $(OBJECTS)

%-arm.o : %.c
	@echo  "CC	$@"
	@$(CC) $(CFLAGS) -c -MMD -MP -MF $(@:.o=.d) -o $@ $<

clean:
	-$(RM) -f *-arm.a *-arm.o *-arm.d option/*-arm.o option/*-arm.d
