Philippe PITTOLI 2024-06-14 16:20:37 +02:00
parent 2a8b4a198f
commit ed9f719fa9
3 changed files with 67 additions and 40 deletions

View File

@ -15,6 +15,12 @@ build: $(BINS)
$(BINS): $(BINS):
$(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS) $(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS)
run-pong:
$(VALGRIND) ./pong
run-pongd:
$(VALGRIND) ./pongd
clean: clean:
rm $(BINS) 2>/dev/null rm $(BINS) 2>/dev/null

View File

@ -1,16 +1,17 @@
const std = @import("std"); const std = @import("std");
const module = std.Build.Module;
fn link_and_install(exe : *std.Build.CompileStep) void { //fn link_and_install(exe : *std.Build.CompileStep) void {
const source_file = std.Build.FileSource.relative("./lib/ipc/src/main.zig"); // const source_file = std.Build.FileSource.relative("./lib/ipc/src/main.zig");
// var empty : []const std.Build.ModuleDependency = &.{}; // // var empty : []const std.Build.ModuleDependency = &.{};
exe.addAnonymousModule("ipc", .{ .source_file = source_file, .dependencies = &.{} }); // exe.addModule("ipc", .{ .source_file = source_file, .dependencies = &.{} });
exe.linkLibC(); // exe.linkLibC();
//
// This declares intent for the executable to be installed into the // // This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default // // standard location when the user invokes the "install" step (the default
// step when running `zig build`). // // step when running `zig build`).
exe.install(); // exe.install();
} //}
// Although this function looks imperative, note that its job is to // Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external // declaratively construct a build graph that will be executed by an external
@ -27,43 +28,63 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize. // set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const ipc_static_lib = b.addStaticLibrary(.{
.name = "ipc",
.optimize = optimize,
.target = target,
.root_source_file = b.path("./lib/ipc/src/main.zig")
});
// const ipc_module = b.dependency("ipc", .{}).module("ipc");
// ipc_module.linkSystemLibrary("ipc", .{ .needed = true });
const ipcd_exe = b.addExecutable(.{ const ipcd_exe = b.addExecutable(.{
.name = "ipcd", .name = "ipcd",
.root_source_file = .{ .path = "src/ipcd.zig" }, .root_source_file = .{ .path = "src/ipcd.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
link_and_install(ipcd_exe); ipcd_exe.linkLibrary(ipc_static_lib);
b.installArtifact(ipc_static_lib);
const tcpd_exe = b.addExecutable(.{ ipcd_exe.linkSystemLibrary("ipc");
.name = "tcpd", ipcd_exe.linkLibC();
.root_source_file = .{ .path = "src/tcpd.zig" }, b.installArtifact(ipcd_exe);
.target = target, //
.optimize = optimize, // const tcpd_exe = b.addExecutable(.{
}); // .name = "tcpd",
link_and_install(tcpd_exe); // .root_source_file = .{ .path = "src/tcpd.zig" },
// .target = target,
const pong_exe = b.addExecutable(.{ // .optimize = optimize,
.name = "pong", // });
.root_source_file = .{ .path = "src/pong.zig" }, // // tcpd_exe.addModule("ipc", module.CreateOptions);
.target = target, // tcpd_exe.linkLibC();
.optimize = optimize, // b.installArtifact(tcpd_exe);
}); //
link_and_install(pong_exe); // const pong_exe = b.addExecutable(.{
// .name = "pong",
const pongd_exe = b.addExecutable(.{ // .root_source_file = .{ .path = "src/pong.zig" },
.name = "pongd", // .target = target,
.root_source_file = .{ .path = "src/pongd.zig" }, // .optimize = optimize,
.target = target, // });
.optimize = optimize, // // pong_exe.addModule("ipc", module.CreateOptions);
}); // pong_exe.linkLibC();
link_and_install(pongd_exe); // b.installArtifact(pong_exe);
//
// const pongd_exe = b.addExecutable(.{
// .name = "pongd",
// .root_source_file = .{ .path = "src/pongd.zig" },
// .target = target,
// .optimize = optimize,
// });
// // pongd_exe.addModule("ipc", module.CreateOptions);
// pongd_exe.linkLibC();
// b.installArtifact(pongd_exe);
const is_static = b.option(bool, "static", "Compile static binaries.") orelse false; const is_static = b.option(bool, "static", "Compile static binaries.") orelse false;
if (is_static) { if (is_static) {
ipcd_exe.linkage = .static; ipcd_exe.linkage = .static;
tcpd_exe.linkage = .static; // tcpd_exe.linkage = .static;
pong_exe.linkage = .static; // pong_exe.linkage = .static;
pongd_exe.linkage = .static; // pongd_exe.linkage = .static;
} }
} }

@ -1 +0,0 @@
Subproject commit 64506bbee0d691b3a0c6d5d97894426c188bc3df

1
zig/lib/ipc Symbolic link
View File

@ -0,0 +1 @@
/tmp/prog/libipc