# vim: ft=python

kernel = module("kernel",
    kind = "exe",
    default = True,
    output = "jsix.elf",
    targets = [ "kernel" ],
    description = "jsix kernel",
    deps = [ "util", "cpu", "bootproto", "j6" ],
    sources = [
        "apic.cpp",
        "assert.cpp",
        "boot.s",
        "clock.cpp",
        "cpprt.cpp",
        "cpu.cpp",
        "debug.s",
        "device_manager.cpp",
        "frame_allocator.cpp",
        "gdt.cpp",
        "gdtidt.s",
        "heap_allocator.cpp",
        "hpet.cpp",
        "idt.cpp",
        "interrupts.cpp",
        "interrupts.s",
        "io.cpp",
        "logger.cpp",
        "main.cpp",
        "memory.cpp",
        "memory.h.cog",
        "memory_bootstrap.cpp",
        "msr.cpp",
        "objects/channel.cpp",
        "objects/endpoint.cpp",
        "objects/kobject.cpp",
        "objects/thread.cpp",
        "objects/process.cpp",
        "objects/system.cpp",
        "objects/vm_area.cpp",
        "page_table.cpp",
        "page_tree.cpp",
        "pci.cpp",
        "printf/printf.c",
        "scheduler.cpp",
        "smp.cpp",
        "smp.s",
        "syscall.cpp.cog",
        "syscall.h.cog",
        "syscall.s",
        "syscall_verify.cpp.cog",
        "syscalls.inc.cog",
        "syscalls/channel.cpp",
        "syscalls/endpoint.cpp",
        "syscalls/event.cpp",
        "syscalls/handle.cpp",
        "syscalls/object.cpp",
        "syscalls/process.cpp",
        "syscalls/system.cpp",
        "syscalls/thread.cpp",
        "syscalls/vm_area.cpp",
        "sysconf.cpp",
        "sysconf.h.cog",
        "task.s",
        "tss.cpp",
        "vm_space.cpp",
    ])

from glob import glob
from os.path import join

layout = join(source_root, "definitions/memory_layout.yaml")
sysconf = join(source_root, "definitions/sysconf.yaml")
definitions = glob(join(source_root, 'definitions/**/*.def'), recursive=True)

kernel.add_depends(["memory.h.cog"], [layout])
kernel.add_depends(["sysconf.h.cog"], [sysconf])
kernel.add_depends([
        "syscall.cpp.cog",
        "syscall.h.cog",
        "syscalls.inc.cog",
        "syscall_verify.cpp.cog",
    ], definitions)

kernel.variables['ldflags'] = ["${ldflags}", "-T", "${source_root}/src/kernel/kernel.ld"]
