1
0
libflex/build.zig
2024-10-01 23:22:22 +03:00

84 lines
2.5 KiB
Zig

const std = @import("std");
const Build = std.Build;
fn linkPkgConfigOutput(b: *Build, obj: *Build.Step.Compile, 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.run(.{
.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: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const libflex = b.addStaticLibrary(.{
.name = "flex",
.target = target,
.optimize = optimize,
});
libflex.addCSourceFile(.{
.file = b.path("libflex/libflex.c"),
.flags = &.{}
});
libflex.linkLibC();
libflex.installHeader(b.path("libflex/libflex.h"), "libflex.h");
{
const rolexhound = b.addExecutable(.{
.name = "rolexhound",
.target = target,
.optimize = optimize
});
rolexhound.addCSourceFile(.{ .file = b.path("rolexhound/main.c") });
rolexhound.linkLibrary(libflex);
rolexhound.linkLibC();
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
});
smartwatch.addCSourceFile(.{ .file = b.path("smartwatch/main.c") });
smartwatch.linkLibrary(libflex);
smartwatch.linkLibC();
try linkPkgConfigOutput(b, smartwatch, &.{ "--cflags", "--libs", "libnotify" });
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);
}
}