Skip to content

Commit

Permalink
fat: rewrite makefile as snippet
Browse files Browse the repository at this point in the history
Signed-off-by: James Archer <[email protected]>
  • Loading branch information
JE-Archer authored and Ivan-Velickovic committed Jan 10, 2025
1 parent f935dfe commit 3e3d1c5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 121 deletions.
107 changes: 0 additions & 107 deletions components/fs/fat/Makefile

This file was deleted.

75 changes: 75 additions & 0 deletions components/fs/fat/fat.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# Copyright 2025, UNSW
#
# SPDX-License-Identifier: BSD-2-Clause
#
# This Makefile snippet builds the FAT component
#
# NOTES:
# Requires variables:
# LIONSOS
# TARGET
# MICROKIT_SDK
# MICROKIT_BOARD
# MICROKIT_CONFIG
# CPU
# FAT_LIBC_INCLUDE
# FAT_LIBC_LIB
# Generates fat.elf

FAT_SRC_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
FAT_FF15_SRC_DIR := $(LIONSOS)/dep/ff15
FAT_LIBMICROKITCO_DIR := $(LIONSOS)/dep/libmicrokitco

FAT_CFLAGS := \
-I$(FAT_LIBC_INCLUDE) \
-I$(FAT_LIBMICROKITCO_DIR) \
-I$(FAT_FF15_SRC_DIR) \
-I$(FAT_SRC_DIR)/config

FAT_OBJ := \
fat/ff15/ff.o \
fat/ff15/ffunicode.o \
fat/event.o \
fat/op.o \
fat/io.o

CHECK_FAT_FLAGS_MD5 := .fat_cflags-$(shell echo -- $(CFLAGS) $(FAT_CFLAGS) | shasum | sed 's/ *-//')

$(CHECK_FAT_FLAGS_MD5):
-rm -f .fat_cflags-*
touch $@

FAT_LIBMICROKITCO_OBJ := libmicrokitco/libmicrokitco.a
FAT_LIBMICROKITCO_OPT_PATH := $(FAT_SRC_DIR)/config

fat/$(FAT_LIBMICROKITCO_OBJ): fat
make -f $(FAT_LIBMICROKITCO_DIR)/Makefile \
LIBMICROKITCO_PATH=$(FAT_LIBMICROKITCO_DIR) \
TARGET=$(TARGET) \
MICROKIT_SDK:=$(MICROKIT_SDK) \
BUILD_DIR:=fat \
MICROKIT_BOARD:=$(MICROKIT_BOARD) \
MICROKIT_CONFIG:=$(MICROKIT_CONFIG) \
CPU:=$(CPU) \
LLVM:=1 \
LIBMICROKITCO_OPT_PATH=$(FAT_LIBMICROKITCO_OPT_PATH)

fat:
mkdir -p fat

fat/ff15:
mkdir -p fat/ff15

fat/ff15/%.o: CFLAGS += $(FAT_CFLAGS)
fat/ff15/%.o: $(FAT_FF15_SRC_DIR)/%.c $(FAT_LIBC_INCLUDE) $(CHECK_FAT_FLAGS_MD5) |fat/ff15
$(CC) -c $(CFLAGS) $< -o $@

fat/%.o: CFLAGS += $(FAT_CFLAGS)
fat/%.o: $(FAT_SRC_DIR)/%.c $(FAT_LIBC_INCLUDE) $(CHECK_FAT_FLAGS_MD5) |fat
$(CC) -c $(CFLAGS) $< -o $@

fat.elf: $(FAT_OBJ) fat/$(FAT_LIBMICROKITCO_OBJ) $(FAT_LIBC_LIB)
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

-include $(FAT_OBJ:.o=.d)
19 changes: 5 additions & 14 deletions examples/fileio/fileio.mk
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ CFLAGS := \
-I$(BOARD_DIR)/include \
-target $(TARGET) \
-DBOARD_$(MICROKIT_BOARD) \
-I$(LIONSOS)/include \
-I$(SDDF)/include \
-I${CONFIG_INCLUDE} \
-DVIRTIO_MMIO_NET_OFFSET=0xc00
Expand Down Expand Up @@ -116,21 +117,11 @@ micropython.elf: mpy-cross libsddf_util_debug.a libco.a
FROZEN_MANIFEST=$(abspath ./manifest.py) \
V=1

fat.elf: musllibc/lib/libc.a
make -C $(LIONSOS)/components/fs/fat \
CC=$(CC) \
LD=$(LD) \
CPU=$(CPU) \
BUILD_DIR=$(abspath .) \
CONFIG=$(MICROKIT_CONFIG) \
MICROKIT_SDK=$(MICROKIT_SDK) \
MICROKIT_BOARD=$(MICROKIT_BOARD) \
LIBC_DIR=$(abspath $(BUILD_DIR)/musllibc) \
BUILD_DIR=$(abspath .) \
CONFIG_INCLUDE=$(abspath $(CONFIG_INCLUDE)) \
TARGET=$(TARGET)
FAT_LIBC_LIB := musllibc/lib/libc.a
FAT_LIBC_INCLUDE := musllibc/include
include $(LIONSOS)/components/fs/fat/fat.mk

musllibc/lib/libc.a:
musllibc/lib/libc.a musllibc/include:
make -C $(MUSL) \
C_COMPILER=aarch64-none-elf-gcc \
TOOLPREFIX=aarch64-none-elf- \
Expand Down

0 comments on commit 3e3d1c5

Please sign in to comment.