#
# Copyright (c) 2026, Chloe M.
# Provided under the BSD-3 clause
#
# Description:  AMD64 port build script
# Author:		Chloe M.
#

.SILENT:
include ../../../mk/stos.mk

ASMFILES = $(shell find . -name "*.S")
ASMOFILES = $(ASMFILES:.S=.S.o)

CFILES = $(shell find . -name "*.c")
OFILES = $(CFILES:.c=.o)

MISC_OFILES = $(ASMOFILES)
MISC_OFILES += $(OFILES)
MISC_OFILES += $(shell find $(ST_PROJECT_ROOT)/paw/spkg/ -name "*.o")
MISC_OFILES += $(shell find $(ST_PROJECT_ROOT)/paw/stos/ -name "*.o" | grep -v "arch")

KERNEL_PATH =       \
	$(ST_PROJECT_ROOT)/artifacts/stoskrnl.sys
CFLAGS =				\
	$(SYS_CFLAGS)		\
	-I../../target		\
	-I../../head/		\
	-I$(ST_PROJECT_ROOT)/sdk/head

.PHONY: all
all: bin

.PHONY: bin
bin: $(OFILES) $(ASMOFILES)
	$(PROMPT) "LD" $(KERNEL_PATH)
	$(SYS_LD) -Tdevel/link.ld $(MISC_OFILES) -o $(KERNEL_PATH)

%.o: %.c
	$(PROMPT) "CC" $<
	$(SYS_CC) -c $< $(CFLAGS) -o $@

%.S.o: %.S
	$(PROMPT) "AS" $<
	$(SYS_CC) -c $< $(CFLAGS) -o $@
