CC = clang
CFLAGS = -Wall -Wextra -g -std=c11
COMMON_SRCS = forth_core.c forth_dict.c forth_words.c forth_interp.c main.c

LINUX_SRCS = $(COMMON_SRCS) platform_linux.c
KERNEL_SRCS = $(COMMON_SRCS) platform_kernel.c kernel_entry.S
KERNEL_LD = kernel.ld

TARGET = forth
KERNEL_TARGET = forth.kernel

all: $(TARGET)

$(TARGET): $(LINUX_SRCS) forth.h
	$(CC) $(CFLAGS) -static -nostdlib -ffreestanding -fno-stack-protector -o $@ $(LINUX_SRCS)

$(KERNEL_TARGET): $(KERNEL_SRCS) forth.h $(KERNEL_LD)
	$(CC) $(CFLAGS) -ffreestanding -nostdlib -fno-stack-protector -mno-red-zone -o $@ $(KERNEL_SRCS) -T$(KERNEL_LD) -Wl,--build-id=none

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

.PHONY: all clean
