5.1 Makefile Structure

Main Makefile

# Project configuration
PROJECT = d3tui
TARGET = $(PROJECT).elf
VERSION = 0.2.0

# Toolchain
KOS_BASE ?= /opt/toolchains/dc/kos
KOS_CC_PREFIX ?= sh-elf-

# Include KOS makefiles
include $(KOS_BASE)/makefile
include kos.mk

# Source files
SRCS = \
    src/main.c \
    src/core/d3tui_terminal.c \
    src/core/d3tui_render.c \
    src/core/d3tui_font.c \
    src/core/d3tui_input.c \
    src/core/d3tui_vmu.c \
    src/utils/d3tui_memory.c \
    src/utils/d3tui_shachi.c

# Include directories
INCS = \
    include \
    src/core \
    src/utils \
    $(KOS_BASE)/include \
    $(SPECTRE_PATH)/include

# Libraries
LIBS = \
    -lkos \
    -lshachi

# Build rules
all: $(TARGET)

$(TARGET): $(OBJS)
    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)

clean:
    rm -f $(OBJS) $(TARGET)

.PHONY: all clean

kos.mk

# KOS-specific rules
KOS_CFLAGS = -D_KOS -D_DREAMCAST -D__DC__
KOS_LDFLAGS = -T $(KOS_BASE)/utils/ld/scripts/dreamcast.ld

CFLAGS += $(KOS_CFLAGS) -I$(KOS_BASE)/include -I$(KOS_BASE)/kernel/arch/dreamcast/include
LDFLAGS += $(KOS_LDFLAGS)

# SPECTRE integration
SPECTRE_PATH ?= /from/library/polygon/SPECTRE
ifneq ($(wildcard $(SPECTRE_PATH)/include),)
CFLAGS += -I$(SPECTRE_PATH)/include -DD3TUI_USE_SPECTRE
LIBS += -L$(SPECTRE_PATH)/lib -lshachi
endif

# Debug vs Release
ifdef DEBUG
CFLAGS += -g -O0 -DDEBUG -DD3TUI_DEBUG
else
CFLAGS += -O2 -DNDEBUG
endif