Skip to content

Commit 96db886

Browse files
committed
Expose build options, add shared library and incremental build
1 parent c755836 commit 96db886

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

build.zig

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,29 @@ pub fn build(b: *std.Build) void {
5656
const target = b.standardTargetOptions(.{});
5757
const optimize = b.standardOptimizeOption(.{});
5858

59-
const prefix = "/usr/local";
60-
61-
const janetconf_header = "src/conf/janetconf.h";
62-
const libdir = prefix ++ "/lib";
63-
// JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1 2> /dev/null || echo local)\""
64-
const janet_build = "\"local\"";
59+
const prefix = b.option([]const u8, "prefix", "Installation prefix") orelse "/usr/local";
60+
61+
const janetconf_header = b.option([]const u8, "janetconf_header", "Path to configuration heaeder") orelse "src/conf/janetconf.h";
62+
const includedir = b.option([]const u8, "includedir", "Header installation path") orelse b.fmt("{s}/include", .{prefix});
63+
_ = includedir;
64+
const bindir = b.option([]const u8, "bindir", "Binary installation path") orelse b.fmt("{s}/bin", .{prefix});
65+
_ = bindir;
66+
const libdir = b.option([]const u8, "libdir", "Library installation path") orelse b.fmt("{s}/lib", .{prefix});
67+
// TODO: JANET_BUILD?="\"$(shell git log --pretty=format:'%h' -n 1 2> /dev/null || echo local)\""
68+
const janet_build = b.option([]const u8, "janet_build", "Build version identifier") orelse "\"local\"";
6569
// const clibs = [_][]const u8{ "-lm", "-lpthread" };
66-
const janet_path = libdir ++ "/janet";
70+
const janet_path = b.option([]const u8, "janet_path", "Janet library installation path") orelse b.fmt("{s}/janet", .{libdir});
71+
const janet_manpath = b.option([]const u8, "janet_manpath", "Man page installation path") orelse b.fmt("{s}/share/man/man1/", .{prefix});
72+
_ = janet_manpath;
73+
const janet_pkg_config_path = b.option([]const u8, "janet_pkg_config_path", "pkg-config files installation path") orelse b.fmt("{s}/pkgconfig", .{libdir});
74+
_ = janet_pkg_config_path;
75+
const janet_dist_dir = b.option([]const u8, "janet_dist_dir", "Output directory for distribution files") orelse "janet-dist";
76+
_ = janet_dist_dir;
77+
const jpm_tag = b.option([]const u8, "jpm_tag", "Git tag for jpm build") orelse "master";
78+
_ = jpm_tag;
79+
const spork_tag = b.option([]const u8, "spork_tag", "Git tag for spork build") orelse "master";
80+
_ = spork_tag;
81+
const has_shared = b.option(bool, "has_shared", "Build shared library") orelse true;
6782

6883
const cflags = [_][]const u8{ "-O2", "-g" };
6984

@@ -93,14 +108,13 @@ pub fn build(b: *std.Build) void {
93108
// janet_boot_run.addArg(".");
94109
janet_boot_run.addDirectoryArg(b.path(""));
95110
janet_boot_run.addArg("JANET_PATH");
96-
janet_boot_run.addArg("'" ++ janet_path ++ "=");
111+
janet_boot_run.addArg(b.fmt("'{s}'", .{janet_path}));
97112

98-
// TODO
113+
const janet_no_amalg = b.option(bool, "janet_no_amalg", "Disable amalgamated build") orelse false;
99114
// Disable amalgamated build
100-
// ifeq ($(JANET_NO_AMALG), 1)
101-
// JANET_TARGET_OBJECTS+=$(patsubst src/%.c,build/%.bin.o,$(JANET_CORE_SOURCES))
102-
// JANET_BOOT_FLAGS+=image-only
103-
// endif
115+
if (janet_no_amalg) {
116+
janet_boot_run.addArg("image-only");
117+
}
104118

105119
const janet_boot_output = janet_boot_run.captureStdOut();
106120
b.getInstallStep().dependOn(&b.addInstallFile(janet_boot_output, "c/janet.c").step);
@@ -118,6 +132,12 @@ pub fn build(b: *std.Build) void {
118132
.file = b.path("src/mainclient/shell.c"),
119133
.flags = &build_cflags,
120134
});
135+
if (janet_no_amalg) {
136+
janet_mod.addCSourceFiles(.{
137+
.files = &(core_sources),
138+
.flags = &build_cflags,
139+
});
140+
}
121141
janet_mod.addIncludePath(b.path("src/include"));
122142
janet_mod.addIncludePath(b.path("src/conf"));
123143
const janet_exe = b.addExecutable(.{
@@ -133,12 +153,21 @@ pub fn build(b: *std.Build) void {
133153
const janet_h_output = janet_h.addOutputFileArg("janet.h");
134154
b.getInstallStep().dependOn(&b.addInstallFile(janet_h_output, "janet.h").step);
135155

136-
const janet_library = b.addLibrary(.{
156+
if (has_shared) {
157+
const janet_library = b.addLibrary(.{
158+
.name = "janet",
159+
.linkage = .dynamic,
160+
.root_module = janet_mod,
161+
});
162+
b.installArtifact(janet_library);
163+
}
164+
165+
const janet_static_library = b.addLibrary(.{
137166
.name = "janet",
138167
.linkage = .static,
139-
.root_module = janet_boot_mod,
168+
.root_module = janet_mod,
140169
});
141-
b.installArtifact(janet_library);
170+
b.installArtifact(janet_static_library);
142171

143172
const mod = b.addModule("janet", .{
144173
.root_source_file = b.path("src/root.zig"),

0 commit comments

Comments
 (0)