forked from NotAShelf/rogged
build: move map & rng logic to their own libraries
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1802469f3baff4576f61accfb5a197d86a6a6964
This commit is contained in:
parent
702b4258e0
commit
26aa295f82
17 changed files with 136 additions and 93 deletions
67
build.zig
67
build.zig
|
|
@ -4,6 +4,51 @@ 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",
|
||||
|
|
@ -14,29 +59,20 @@ pub fn build(b: *std.Build) void {
|
|||
.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.linkSystemLibrary("raylib");
|
||||
combat_lib.addIncludePath(b.path("libs/rng"));
|
||||
|
||||
// C sources (everything except combat, which is now Zig)
|
||||
// C sources remaining in src/
|
||||
const c_sources = [_][]const u8{
|
||||
"src/audio.c",
|
||||
"src/enemy.c",
|
||||
"src/items.c",
|
||||
"src/main.c",
|
||||
"src/map.c",
|
||||
"src/player.c",
|
||||
"src/movement.c",
|
||||
"src/player.c",
|
||||
"src/render.c",
|
||||
"src/rng.c",
|
||||
"src/settings.c",
|
||||
"src/utils.c",
|
||||
};
|
||||
|
||||
const c_flags = [_][]const u8{
|
||||
"-std=c99",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
};
|
||||
|
||||
// Main executable
|
||||
|
|
@ -54,7 +90,12 @@ pub fn build(b: *std.Build) void {
|
|||
.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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue