1// Copyright © 2020-2021 Sören Tempel
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16const std = @import("std");
17const Target = std.Target;
18const Zig = std.zig;
19const FileSource = std.build.FileSource;
20const Builder = std.build.Builder;
21const FeatureSet = std.Target.Cpu.Feature.Set;
22
23pub fn build(b: *Builder) void {
24 var fe310_cpu_feat = FeatureSet.empty;
25 const m: std.Target.riscv.Feature = .m;
26 const a: std.Target.riscv.Feature = .a;
27 const c: std.Target.riscv.Feature = .c;
28 fe310_cpu_feat.addFeature(@enumToInt(a));
29 fe310_cpu_feat.addFeature(@enumToInt(m));
30 fe310_cpu_feat.addFeature(@enumToInt(c));
31
32 const target = Zig.CrossTarget{
33 .cpu_arch = Target.Cpu.Arch.riscv32,
34 .os_tag = Target.Os.Tag.freestanding,
35 .abi = Target.Abi.none,
36 .cpu_features_sub = std.Target.riscv.cpu.baseline_rv32.features,
37 .cpu_features_add = fe310_cpu_feat,
38 };
39
40 const mode = b.standardReleaseOptions();
41
42 const exe = b.addExecutable("main", "src/init.zig");
43 exe.setLinkerScriptPath(FileSource{ .path = "fe310_g000.ld" });
44 exe.setTarget(target);
45 exe.setBuildMode(mode);
46
47 exe.addCSourceFile("src/start.S", &[_][]const u8{});
48 exe.addCSourceFile("src/irq.S", &[_][]const u8{});
49 exe.addCSourceFile("src/clock.c", &[_][]const u8{});
50
51 exe.addPackage(std.build.Pkg{
52 .name = "zoap",
53 .path = FileSource{ .path = "./zoap/src/zoap.zig" },
54 });
55
56 b.default_step.dependOn(&exe.step);
57 b.installArtifact(exe);
58}