60 lines
2.1 KiB
Zig
60 lines
2.1 KiB
Zig
const std = @import("std");
|
|
const zcc = @import("compile_commands");
|
|
const Build = std.Build;
|
|
|
|
pub fn build(b: *Build) !void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "brainfuck",
|
|
.optimize = optimize,
|
|
.target = target
|
|
});
|
|
exe.addIncludePath(.{ .path = "src" });
|
|
exe.addIncludePath(.{ .path = "include" });
|
|
exe.addCSourceFile(.{ .file = b.path("src/main.c") });
|
|
exe.addCSourceFile(.{ .file = b.path("src/bf_compiler.c") });
|
|
exe.addCSourceFile(.{ .file = b.path("src/bf_emulator.c") });
|
|
exe.linkLibC();
|
|
|
|
if (b.option(bool, "tinycc", "Toggle 'tinycc' compiler backend (Enabled by default)") orelse true) {
|
|
if (b.lazyDependency("tinycc", .{})) |tinycc| {
|
|
const tinycc_source = tinycc.path(".");
|
|
|
|
const configure_cmd = b.addSystemCommand(&.{ "./configure", "--config-musl" });
|
|
_ = configure_cmd.captureStdOut();
|
|
configure_cmd.setCwd(tinycc_source);
|
|
|
|
const make_cmd = b.addSystemCommand(&.{ "make", "libtcc.a" });
|
|
_ = make_cmd.captureStdOut();
|
|
make_cmd.setCwd(tinycc_source);
|
|
make_cmd.step.dependOn(&configure_cmd.step);
|
|
|
|
const install_cmd = b.addSystemCommand(&.{ "make", "install" });
|
|
_ = install_cmd.captureStdOut();
|
|
install_cmd.setEnvironmentVariable("DESTDIR", "build");
|
|
install_cmd.setCwd(tinycc_source);
|
|
install_cmd.step.dependOn(&make_cmd.step);
|
|
|
|
exe.step.dependOn(&install_cmd.step);
|
|
exe.addObjectFile(tinycc.path("libtcc.a"));
|
|
exe.addIncludePath(tinycc.path("build/usr/local/include"));
|
|
|
|
exe.root_module.addCMacro("BF_BACKEND_TINYCC", "");
|
|
}
|
|
}
|
|
|
|
zcc.createStep(b, "cdb", .{ .target = exe });
|
|
|
|
b.installArtifact(exe);
|
|
|
|
const run_exe = b.addRunArtifact(exe);
|
|
if (b.args) |args| {
|
|
run_exe.addArgs(args);
|
|
}
|
|
|
|
const run_step = b.step("run", "Run program");
|
|
run_step.dependOn(&run_exe.step);
|
|
}
|