param(
    [ValidateSet("debug", "release", "size")]
    [string]$mode = "size",

    [ValidateSet("native", "c", "js_node", "go")]
    [string]$target = "c",

    [ValidateSet("build", "run")]
    [string]$action = "build"
)

if (-not (Test-Path "build")) {
    New-Item -ItemType Directory -Path "build" | Out-Null
}

if ($mode -eq "debug") {
    v -g -cg -b $target -enable-globals -o build/nude_bug .
}
elseif ($mode -eq "release") {
    v -prod -cflags "-O3" -Wfatal-errors -enable-globals -q -skip-unused -b $target -o build/nude_release .
}
elseif ($mode -eq "size") {
    v -prod -cflags "-Os -s" -Wfatal-errors -enable-globals -q -skip-unused -b $target -o build/nude_optimized .
}

$exe = switch ($mode) {
    "debug"   { "nude_bug.exe" }
    "release" { "nude_release.exe" }
    "size"    { "nude_optimized.exe" }
}

$v_output = Join-Path -Path "build" -ChildPath $exe

if ($action -eq "run") {
    & $v_output
}