2022-12-11 02:47:11 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
2022-12-15 07:42:56 +00:00
|
|
|
fn path(comptime suffix: []const u8) []const u8 {
|
|
|
|
if (suffix[0] == '/') @compileError("expected a relative path");
|
|
|
|
return comptime (std.fs.path.dirname(@src().file) orelse ".") ++ std.fs.path.sep_str ++ suffix;
|
|
|
|
}
|
|
|
|
|
2022-12-15 07:33:43 +00:00
|
|
|
const pkgs = struct {
|
|
|
|
const Pkg = std.build.Pkg;
|
|
|
|
|
|
|
|
pub const gdbstub: Pkg = .{
|
|
|
|
.name = "gdbstub",
|
2022-12-15 07:42:56 +00:00
|
|
|
.source = .{ .path = path("src/lib.zig") },
|
2022-12-15 07:33:43 +00:00
|
|
|
.dependencies = &[_]Pkg{network},
|
|
|
|
};
|
|
|
|
|
|
|
|
// https://github.com/MasterQ32/zig-network
|
|
|
|
pub const network: Pkg = .{
|
|
|
|
.name = "network",
|
2022-12-15 07:42:56 +00:00
|
|
|
.source = .{ .path = path("lib/zig-network/network.zig") },
|
2022-12-15 07:33:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn link(exe: *std.build.LibExeObjStep) void {
|
|
|
|
exe.addPackage(pkgs.gdbstub);
|
|
|
|
}
|
|
|
|
|
2022-12-11 02:47:11 +00:00
|
|
|
pub fn build(b: *std.build.Builder) void {
|
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const mode = b.standardReleaseOptions();
|
|
|
|
|
2022-12-15 07:33:43 +00:00
|
|
|
// -- library --
|
|
|
|
const lib = b.addStaticLibrary("gdbstub", "src/lib.zig");
|
|
|
|
lib.addPackage(pkgs.network);
|
2022-12-11 02:47:11 +00:00
|
|
|
|
2022-12-15 07:33:43 +00:00
|
|
|
lib.setBuildMode(mode);
|
|
|
|
lib.install();
|
|
|
|
|
|
|
|
const lib_tests = b.addTest("src/lib.zig");
|
|
|
|
lib_tests.setBuildMode(mode);
|
|
|
|
|
|
|
|
const test_step = b.step("lib-test", "Run Library Tests");
|
|
|
|
test_step.dependOn(&lib_tests.step);
|
|
|
|
|
|
|
|
// -- Executable --
|
|
|
|
const exe = b.addExecutable("gdbserver", "src/main.zig");
|
|
|
|
link(exe);
|
2022-12-11 02:47:11 +00:00
|
|
|
|
|
|
|
exe.setTarget(target);
|
|
|
|
exe.setBuildMode(mode);
|
|
|
|
exe.install();
|
|
|
|
|
|
|
|
const run_cmd = exe.run();
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
2022-12-15 07:33:43 +00:00
|
|
|
if (b.args) |args| run_cmd.addArgs(args);
|
2022-12-11 02:47:11 +00:00
|
|
|
|
|
|
|
const run_step = b.step("run", "Run the app");
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
}
|