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 }); 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 libflex = b.addStaticLibrary(.{ .name = "flex", .target = target, .optimize = optimize, }); libflex.addCSourceFile(.{ .file = .{ .path = "libflex/libflex.c" }, .flags = &.{} }); libflex.linkLibC(); libflex.installHeader("libflex/libflex.h", "libflex.h"); { const rolexhound = b.addExecutable(.{ .name = "rolexhound", .target = target, .optimize = optimize, .root_source_file = .{ .path = "rolexhound/main.c" } }); rolexhound.linkLibrary(libflex); rolexhound.linkLibC(); try linkPkgConfigOutput(b, rolexhound, &.{ "--cflags", "--libs", "libnotify" }); b.installArtifact(rolexhound); const run_rolexhound = b.addRunArtifact(rolexhound); if (b.args) |args| { run_rolexhound.addArgs(args); } const run_step = b.step("rolexhound", "Run the server"); run_step.dependOn(&run_rolexhound.step); } { const smartwatch = b.addExecutable(.{ .name = "smartwatch", .target = target, .optimize = optimize, .root_source_file = .{ .path = "smartwatch/main.c" } }); smartwatch.linkLibrary(libflex); smartwatch.linkLibC(); b.installArtifact(smartwatch); const run_smartwatch = b.addRunArtifact(smartwatch); if (b.args) |args| { run_smartwatch.addArgs(args); } const run_step = b.step("smartwatch", "Run the client"); run_step.dependOn(&run_smartwatch.step); } }