minifb-zig/lib/minifb/build.zig

72 lines
2.4 KiB
Zig
Raw Permalink Normal View History

2021-11-24 03:24:38 +00:00
const std = @import("std");
// fn thisDir() []const u8 {
// return std.fs.path.dirname(@src().file) orelse ".";
// }
pub fn build(b: *std.build.Builder) void {
// TODO Use mode to set debug flags in MiniFB
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
var main_tests = b.addTest("src/minifb.zig");
main_tests.setBuildMode(mode);
main_tests.setTarget(target);
2021-11-24 18:15:33 +00:00
link(b, main_tests);
2021-11-24 03:24:38 +00:00
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}
pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) void {
const lib = buildLibrary(b, step);
step.linkLibrary(lib);
}
fn fromHere(allocator: std.mem.Allocator, path: []const u8) []const u8 {
2021-11-24 03:24:38 +00:00
const here = std.fs.path.dirname(@src().file) orelse ".";
return std.fs.path.join(allocator, &.{here, path}) catch unreachable;
}
fn buildLibrary(b: *std.build.Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
// var main_abs = std.fs.path.join(b.allocator, &.{thisDir(), "src/minifb.zig"}) catch unreachable;
const lib = b.addStaticLibrary("minifb", fromHere(b.allocator, "src/minifb.zig"));
lib.setBuildMode(step.build_mode);
var sources = std.ArrayList([]const u8) .init(b.allocator);
for ([_][]const u8{
"upstream/src/MiniFB_common.c",
"upstream/src/MiniFB_internal.c",
//"upstream/src/MiniFB_internal.h",
"upstream/src/MiniFB_timer.c",
//"upstream/src/WindowData.h",
//"upstream/src/windows/WindowData_Win.h",
"upstream/src/windows/WinMiniFB.c",
}) |path| {
// const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path}) catch unreachable;
sources.append(fromHere(b.allocator, path)) catch unreachable;
}
// TODO More than Windows
lib.addCSourceFiles(sources.items, &[_][]const u8{
"-Wall",
"-Wextra",
"-pedantic",
"-Wno-switch",
"-Wno-unused-function",
"-Wno-implicit-fallthrough",
"-std=c11",
});
const include_abs = fromHere(b.allocator, "upstream/include");
const src_abs = fromHere(b.allocator, "upstream/src");
lib.addIncludeDir(include_abs);
lib.addIncludeDir(src_abs);
step.addIncludeDir(include_abs);
step.addIncludeDir(src_abs);
lib.linkSystemLibraryName("gdi32");
lib.linkLibC();
lib.install();
return lib;
}