const std = @import("std"); fn linkPkgConfigOutput(b: *std.build.Builder, obj: *std.build.LibExeObjStep, pkg_config_args: []const []const u8) !void { var argv = std.ArrayList([]const u8).init(b.allocator); try argv.append("pkg-config"); try argv.appendSlice(pkg_config_args); const result = try std.ChildProcess.exec(.{ .allocator = b.allocator, .argv = argv.items }); var cflags = std.ArrayList([]const u8).init(b.allocator); defer cflags.deinit(); const stdout_trimmed = std.mem.trim(u8, result.stdout, " \n"); var cflags_iter = std.mem.splitScalar(u8, stdout_trimmed, ' '); while (cflags_iter.next()) |cflag| { if (std.mem.startsWith(u8, cflag, "-l")) { obj.linkSystemLibrary(cflag[2..]); } else if (std.mem.startsWith(u8, cflag, "-I")) { obj.addIncludePath(.{ .path = cflag[2..] }); } } } pub fn build(b: *std.build.Builder) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ .name = "rolexhound", .target = target, .optimize = optimize, .root_source_file = .{ .path = "src/main.c" } }); exe.linkLibC(); try linkPkgConfigOutput(b, exe, &.{ "--cflags", "--libs", "libnotify" }); b.installArtifact(exe); const run_exe = b.addRunArtifact(exe); if (b.args) |args| { run_exe.addArgs(args); } const run_step = b.step("run", "Launch program"); run_step.dependOn(&run_exe.step); }