// Rumpk Build System
// Orchestrates L0 (Zig) and L1 (Nim) compilation
// Markus Maiwald (Architect) | Voxis Forge (AI)

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    // =========================================================
    // L0: Hardware Abstraction Layer (Zig)
    // =========================================================

    const hal = b.addStaticLibrary(.{
        .name = "rumpk_hal",
        .root_source_file = b.path("hal/abi.zig"),
        .target = target,
        .optimize = optimize,
    });

    // Freestanding kernel - no libc
    hal.root_module.red_zone = false;
    hal.root_module.stack_check = .none;

    // Microui Integration (Phase 3.5b)
    hal.addIncludePath(b.path("libs/microui"));
    hal.addCSourceFile(.{
        .file = b.path("libs/microui/microui.c"),
        .flags = &.{"-std=c99"},
    });

    b.installArtifact(hal);

    // =========================================================
    // Boot: Entry Point (Assembly + Zig)
    // =========================================================

    const boot = b.addObject(.{
        .name = "boot",
        .root_source_file = b.path("boot/header.zig"),
        .target = target,
        .optimize = optimize,
    });

    boot.root_module.red_zone = false;
    boot.root_module.stack_check = .none;

    // =========================================================
    // Tests
    // =========================================================

    const hal_tests = b.addTest(.{
        .root_source_file = b.path("hal/abi.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_tests = b.addRunArtifact(hal_tests);
    const test_step = b.step("test", "Run Rumpk HAL tests");
    test_step.dependOn(&run_tests.step);
}
