Advertisement
abnercoimbre

build.zig for Terminal Click (unreleased)

Jan 19th, 2023 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.70 KB | Source Code | 0 0
  1. // (C) 2023 Terminal Click - All Rights Reserved
  2. //
  3. // Zig Build File (expects zig v0.10.0)
  4. //
  5. // @author: Abner Coimbre <abner@terminal.click>
  6. //
  7.  
  8. const std = @import("std");
  9. const bld = @import("std").build.Builder;
  10.  
  11. pub fn build(b: *bld) void {
  12.     b.setPreferredReleaseMode(.Debug);
  13.  
  14.     const mode = b.standardReleaseOptions();
  15.     const target = b.standardTargetOptions(.{});
  16.     const exe = b.addExecutable("TerminalClick", null);
  17.     exe.setTarget(target);
  18.     exe.setBuildMode(mode);
  19.  
  20.     const win_args = &[_][]const u8{
  21.         "-Iinc",
  22.         "",
  23.         "-DSOKOL_D3D11",
  24.         "-O0",
  25.         "-ggdb3",
  26.         "-fno-sanitize=undefined",
  27.         "-std=c99",
  28.     };
  29.  
  30.     const macos_args = &[_][]const u8{
  31.         "-Iinc",
  32.         "-ObjC",
  33.         "-DSOKOL_METAL",
  34.         "-O0",
  35.         "-ggdb3",
  36.         "-fno-sanitize=undefined",
  37.         "-std=c99",
  38.     };
  39.  
  40.     const linux_args = &[_][]const u8{
  41.         "-Iinc",
  42.         "-D_GNU_SOURCE",
  43.         "-DSOKOL_GLCORE33",
  44.         "-O0",
  45.         "-ggdb3",
  46.         "-fno-sanitize=undefined",
  47.         "-std=c99",
  48.     };
  49.  
  50.     var c_args: []const []const u8 = undefined;
  51.  
  52.     const tag = exe.target.getOs().tag;
  53.  
  54.     if (tag == .windows) {
  55.         c_args = win_args;
  56.     } else if (tag == .macos) {
  57.         c_args = macos_args;
  58.     } else if (tag == .linux) {
  59.         c_args = linux_args;
  60.     } else {
  61.         std.debug.print("Error: Unsupported operating system! Contact Abner\n", .{});
  62.         std.process.exit(1);
  63.     }
  64.  
  65.     exe.addCSourceFile("src/main.c", c_args); // Unity build.
  66.     exe.linkLibC();
  67.  
  68.     if (tag == .windows) {
  69.         exe.linkSystemLibrary("kernel32");
  70.         exe.linkSystemLibrary("gdi32");
  71.         exe.linkSystemLibrary("d3d11");
  72.     } else if (tag == .macos) {
  73.         exe.linkFramework("MetalKit");
  74.         exe.linkFramework("Metal");
  75.         exe.linkFramework("Cocoa");
  76.         exe.linkFramework("QuartzCore");
  77.     } else if (tag == .linux) {
  78.         // On a fresh Pop OS install it seems we needed the following commands:
  79.         // sudo apt install libgl-dev
  80.         // sudo apt install libxi-dev
  81.         // sudo apt install libxcursor-dev
  82.         exe.linkSystemLibrary("GL");
  83.         exe.linkSystemLibrary("X11");
  84.         exe.linkSystemLibrary("Xi");
  85.         exe.linkSystemLibrary("Xcursor");
  86.     } else {
  87.         std.debug.print("[TC] Unsupported operating system! Contact Abner\n", .{});
  88.         std.process.exit(1);
  89.     }
  90.  
  91.     exe.install();
  92.  
  93.     const run_cmd = exe.run();
  94.     run_cmd.step.dependOn(b.getInstallStep());
  95.     if (b.args) |args| {
  96.         run_cmd.addArgs(args);
  97.     }
  98.  
  99.     const run_step = b.step("run", "Run the app");
  100.     run_step.dependOn(&run_cmd.step);
  101. }
  102.  
Tags: Zig
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement