Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1802469f3baff4576f61accfb5a197d86a6a6964
116 lines
3.1 KiB
Zig
116 lines
3.1 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const c_flags = [_][]const u8{
|
|
"-std=c99",
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-O2",
|
|
};
|
|
|
|
// RNG library
|
|
const rng_lib = b.addLibrary(.{
|
|
.name = "rng",
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
rng_lib.addCSourceFiles(.{
|
|
.files = &[_][]const u8{"libs/rng/rng.c"},
|
|
.flags = &c_flags,
|
|
});
|
|
rng_lib.addIncludePath(b.path("libs/rng"));
|
|
|
|
// Map library
|
|
const map_lib = b.addLibrary(.{
|
|
.name = "map",
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
map_lib.addCSourceFiles(.{
|
|
.files = &[_][]const u8{
|
|
"libs/map/map.c",
|
|
"libs/map/utils.c",
|
|
},
|
|
.flags = &c_flags,
|
|
});
|
|
// map.h includes common.h and settings.h which live in src/
|
|
map_lib.addIncludePath(b.path("src"));
|
|
// map.c includes rng/rng.h via libs/ root
|
|
map_lib.addIncludePath(b.path("libs"));
|
|
// utils.h is co-located with map.c
|
|
map_lib.addIncludePath(b.path("libs/map"));
|
|
|
|
// Zig combat library
|
|
const combat_lib = b.addLibrary(.{
|
|
.name = "combat",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("libs/combat/combat.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
// common.h and settings.h live in src/; rng.h exposed bare from libs/rng
|
|
combat_lib.addIncludePath(b.path("src"));
|
|
combat_lib.addIncludePath(b.path("libs/rng"));
|
|
|
|
// C sources remaining in src/
|
|
const c_sources = [_][]const u8{
|
|
"src/audio.c",
|
|
"src/enemy.c",
|
|
"src/items.c",
|
|
"src/main.c",
|
|
"src/movement.c",
|
|
"src/player.c",
|
|
"src/render.c",
|
|
"src/settings.c",
|
|
};
|
|
|
|
// Main executable
|
|
const exe = b.addExecutable(.{
|
|
.name = "roguelike",
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
|
|
exe.addCSourceFiles(.{
|
|
.files = &c_sources,
|
|
.flags = &c_flags,
|
|
});
|
|
|
|
// src/ for own headers; libs/ so "rng/rng.h" and "map/map.h" resolve
|
|
exe.addIncludePath(b.path("src"));
|
|
exe.addIncludePath(b.path("libs"));
|
|
|
|
exe.linkLibrary(rng_lib);
|
|
exe.linkLibrary(map_lib);
|
|
exe.linkLibrary(combat_lib);
|
|
exe.linkSystemLibrary("raylib");
|
|
exe.linkSystemLibrary("m");
|
|
exe.linkSystemLibrary("pthread");
|
|
exe.linkSystemLibrary("dl");
|
|
exe.linkSystemLibrary("rt");
|
|
|
|
b.installArtifact(exe);
|
|
|
|
// Run step
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
const run_step = b.step("run", "Build and run the roguelike");
|
|
run_step.dependOn(&run_cmd.step);
|
|
}
|