-
Notifications
You must be signed in to change notification settings - Fork 38
/
build.js
48 lines (39 loc) · 1.12 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Generate c source from js files
const fs = require("fs-extra");
const os = require("os");
const path = require("path");
const minimist = require("minimist");
const childProcess = require("child_process");
// Parse options
var argv = minimist(process.argv.slice(2));
// const target = argv.target || "rp2";
// const board = argv.board || "pico";
const buildPath = path.join(__dirname, "build");
const srcGenPath = path.join(__dirname, "src/gen");
if (argv.clean) {
clean();
} else {
build();
}
function clean() {
fs.removeSync(buildPath);
fs.removeSync(srcGenPath);
}
function build() {
// ensure /build
fs.ensureDirSync(buildPath);
// execute cmake and make
process.chdir(buildPath);
const params = [".."];
if (argv.target) params.push(`-DTARGET=${argv.target}`);
if (argv.board) params.push(`-DBOARD=${argv.board}`);
if (argv.modules) params.push(`-DMODULES=${argv.modules}`);
// build everything
const cores = os.cpus().length;
cmd("cmake", params);
cmd("make", [`-j${cores}`]);
process.chdir(__dirname);
}
function cmd(cmd, args) {
childProcess.spawnSync(cmd, args, { stdio: "inherit" });
}