From 954352db4f3d86904e492c15a338c8e01eeed897 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 12 Dec 2021 13:30:32 -0700 Subject: [PATCH] Support Linux with GL or X11 in build.zig --- build.zig | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index f2c631e..19910d7 100644 --- a/build.zig +++ b/build.zig @@ -7,7 +7,6 @@ const base_cflags: []const []const u8 = &.{ "-Wno-switch", "-Wno-unused-function", "-Wno-implicit-fallthrough", - "-std=c11", }; pub fn build(b: *std.build.Builder) !void { @@ -24,7 +23,6 @@ pub fn build(b: *std.build.Builder) !void { "src/MiniFB_common.c", "src/MiniFB_internal.c", "src/MiniFB_timer.c", - "src/windows/WinMiniFB.c", }); const use_opengl = b.option(bool, "opengl", "Use OpenGL") orelse false; @@ -32,15 +30,39 @@ pub fn build(b: *std.build.Builder) !void { const lib = b.addStaticLibrary("minifb-zig-port", null); lib.addIncludeDir("src"); lib.addIncludeDir("include"); - lib.linkSystemLibraryName("gdi32"); lib.linkLibC(); lib.setBuildMode(mode); lib.install(); - if (use_opengl) { - try c_flags.append("-DUSE_OPENGL_API"); - try c_sources.append("src/gl/MiniFB_GL.c"); - lib.linkSystemLibraryName("Opengl32"); + + switch (target.getOsTag()) { + std.Target.Os.Tag.windows => { + try c_sources.append("src/windows/WinMiniFB.c"); + lib.linkSystemLibraryName("gdi32"); + if (use_opengl) { + try c_flags.append("-DUSE_OPENGL_API"); + try c_sources.append("src/gl/MiniFB_GL.c"); + lib.linkSystemLibraryName("opengl32"); + } + }, + std.Target.Os.Tag.linux => { + try c_sources.append("src/MiniFB_linux.c"); + try c_sources.append("src/x11/X11MiniFB.c"); + lib.linkSystemLibrary("rt"); + lib.linkSystemLibrary("X11"); + + if (use_opengl) { + try c_flags.append("-DUSE_OPENGL_API"); + try c_sources.append("src/gl/MiniFB_GL.c"); + lib.linkSystemLibrary("GL"); + } + + // TODO wayland + }, + else => { + return error.PlatformNotSupported; + }, } + lib.addCSourceFiles(c_sources.items, c_flags.items); addExample(b, "noise", "tests/noise.c", lib, target, mode);