144 lines
2.2 KiB
D
Executable File
144 lines
2.2 KiB
D
Executable File
#!/usr/bin/env rdmd
|
|
|
|
import std.stdio;
|
|
import std.file;
|
|
import std.array;
|
|
import std.process;
|
|
import core.stdc.stdlib : exit;
|
|
|
|
enum Mode
|
|
{
|
|
Debug,
|
|
Release,
|
|
};
|
|
|
|
enum Compiler
|
|
{
|
|
LDC,
|
|
DMD,
|
|
};
|
|
|
|
// Config
|
|
Mode mode;
|
|
Compiler compiler;
|
|
|
|
int COMPILER = 0;
|
|
int VERSION = 1;
|
|
int CFLAG = 2;
|
|
int OUT = 3;
|
|
|
|
// General globals
|
|
string[] ARGS;
|
|
|
|
bool HasFlag(string flag)
|
|
{
|
|
bool result;
|
|
|
|
foreach(arg; ARGS)
|
|
{
|
|
if(arg == flag)
|
|
{
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void main(string[] args)
|
|
{
|
|
ARGS = args;
|
|
|
|
string out_name = "build/Pixel";
|
|
|
|
if(HasFlag("release")) mode = Mode.Release;
|
|
if(HasFlag("dmd")) compiler = Compiler.DMD;
|
|
|
|
enum string[string] DMD_LOOKUP = [
|
|
"compiler": "dmd",
|
|
"version": "-version=",
|
|
"cflag": "-P=",
|
|
"out": "-of=",
|
|
"include": "-I=",
|
|
];
|
|
|
|
enum string[string] LDC_LOOKUP = [
|
|
"compiler": "ldc2",
|
|
"version": "--d-version=",
|
|
"cflag": "--Xcc=",
|
|
"out": "--of=",
|
|
"include": "-I",
|
|
];
|
|
|
|
auto lookup = compiler == Compiler.DMD ? DMD_LOOKUP : LDC_LOOKUP;
|
|
|
|
string[] libs = ["SDL3", "vulkan", "X11", "Xfixes", "stdc++"];
|
|
string[] dirs = ["dlib/dlib", "dlib/vulkan", "source"];
|
|
string[] files = ["dlib/build/libvma.a"];
|
|
string[] cflags = [
|
|
"-DBUILD_VULKAN",
|
|
"-Idlib/external",
|
|
];
|
|
string[] versions = ["BUILD_VULKAN"];
|
|
string[] scripts = [
|
|
"./dlib/build.sh",
|
|
"glslang --target-env vulkan1.2 -gVS -o build/pixel.comp.spv shaders/pixel.comp.glsl"
|
|
];
|
|
string[] flags = [
|
|
"-Jbuild",
|
|
"-Jdlib/build",
|
|
lookup["out"] ~ out_name,
|
|
lookup["include"] ~ "dlib/dlib",
|
|
];
|
|
|
|
if(HasFlag("-v")) flags ~= "-v";
|
|
|
|
final switch(mode)
|
|
{
|
|
case Mode.Debug:
|
|
{
|
|
versions ~= "VULKAN_DEBUG";
|
|
} break;
|
|
case Mode.Release:
|
|
{
|
|
|
|
} break;
|
|
}
|
|
|
|
execute(["mkdir", "-p"]);
|
|
|
|
foreach(path; dirs)
|
|
{
|
|
foreach(string file_name; dirEntries(path, "*.{d,c}", SpanMode.depth))
|
|
{
|
|
files ~= file_name;
|
|
}
|
|
}
|
|
|
|
foreach(lib; libs)
|
|
{
|
|
flags ~= "-L-l" ~ lib;
|
|
}
|
|
|
|
foreach(cflag; cflags)
|
|
{
|
|
flags ~= lookup["cflag"] ~ cflag;
|
|
}
|
|
|
|
foreach(ver; versions)
|
|
{
|
|
flags ~= lookup["version"] ~ ver;
|
|
}
|
|
|
|
foreach(script; scripts)
|
|
{
|
|
execute(script.split(" "));
|
|
}
|
|
|
|
auto result = execute([lookup["compiler"]] ~ files ~ flags);
|
|
|
|
writeln(result.output);
|
|
exit(result.status);
|
|
}
|