Skip to content

Commit 93ba45f

Browse files
committed
Generator nodejs script to have consistent bash script with same C flags.
1 parent 3100b91 commit 93ba45f

2 files changed

Lines changed: 153 additions & 0 deletions

File tree

gen/genBins.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
const fs = require("fs");
2+
const { GenBase } = require("./genbase");
3+
const flags = [
4+
"DALLOW_COVERING_INDEX_SCAN=1",
5+
"DENABLE_FTS3_PARENTHESIS=1",
6+
"DENABLE_LOAD_EXTENSION=1",
7+
"DENABLE_SOUNDEX=1",
8+
"DENABLE_STAT4=1",
9+
"DENABLE_UPDATE_DELETE_LIMIT=1",
10+
"DHAVE_READLINE=1",
11+
"DSQLITE_DQS=0",
12+
"DSQLITE_ENABLE_DBPAGE_VTAB=1",
13+
"DSQLITE_ENABLE_DBSTAT_VTAB=1",
14+
"DSQLITE_ENABLE_EXPLAIN_COMMENTS=1",
15+
"DSQLITE_ENABLE_FTS3=1",
16+
"DSQLITE_ENABLE_FTS4=1",
17+
"DSQLITE_ENABLE_FTS5=1",
18+
"DSQLITE_ENABLE_GEOPOLY=1",
19+
"DSQLITE_ENABLE_JSON1=1",
20+
"DSQLITE_ENABLE_MATH_FUNCTIONS=1",
21+
"DSQLITE_ENABLE_OFFSET_SQL_FUNC=1",
22+
"DSQLITE_ENABLE_RBU=1",
23+
"DSQLITE_ENABLE_RTREE=1",
24+
"DSQLITE_ENABLE_RTREE=1",
25+
"DSQLITE_ENABLE_STMTVTAB=1",
26+
"DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1",
27+
"DSQLITE_HAVE_ZLIB=1",
28+
"DSQLITE_INTROSPECTION_PRAGMAS=1",
29+
"DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1",
30+
"DSQLITE_OMIT_DEPRECATED=1",
31+
"DSQLITE_THREADSAFE=1",
32+
"DSQLITE_USE_URI=1",
33+
];
34+
35+
class Generator extends GenBase {
36+
run() {
37+
this.genLinux();
38+
this.genMac();
39+
this.genWindows();
40+
}
41+
42+
genLinux() {
43+
let path = "bin/compile-linux.sh";
44+
this.lines = [];
45+
this.linuxContent();
46+
fs.writeFileSync(path, this.content, "utf-8");
47+
fs.chmodSync(path, 0o755);
48+
}
49+
50+
linuxContent() {
51+
this.push("#!/usr/bin/env bash");
52+
this.push("mkdir dist");
53+
this.push("gcc \\");
54+
this.withIndent(() => {
55+
flags.forEach((flag) => {
56+
this.push(`-${flag} \\`);
57+
});
58+
59+
this.push("src/shell.c src/sqlite3.c -o dist/sqlite3-ubuntu \\");
60+
this.push("-ldl -lz -lm -lreadline -lncurses");
61+
});
62+
63+
this.push(`chmod +x dist/sqlite3-ubuntu`);
64+
}
65+
66+
genMac() {
67+
let path = "bin/compile-mac.sh";
68+
this.lines = [];
69+
this.linuxContent();
70+
fs.writeFileSync(path, this.content, "utf-8");
71+
fs.chmodSync(path, 0o755);
72+
}
73+
74+
macContent() {
75+
this.push("#!/usr/bin/env bash");
76+
this.push("mkdir dist");
77+
this.push("gcc \\");
78+
this.withIndent(() => {
79+
flags.forEach((flag) => {
80+
this.push(`-${flag} \\`);
81+
});
82+
83+
this.push("src/shell.c src/sqlite3.c -o dist/sqlite3-mac \\");
84+
this.push("-ldl -lz -lm -lreadline -lncurses");
85+
});
86+
87+
this.push(`chmod +x dist/sqlite3-mac`);
88+
}
89+
90+
genWindows() {
91+
let path = "bin/compile-windows.sh";
92+
this.lines = [];
93+
this.windowsContent();
94+
fs.writeFileSync(path, this.content, "utf-8");
95+
// fs.chmodSync(path, 0o755);
96+
}
97+
98+
windowsContent() {
99+
this.push("#!/usr/bin/env bash");
100+
this.push("mkdir dist");
101+
this.push("gcc \\");
102+
this.withIndent(() => {
103+
flags.forEach((flag) => {
104+
this.push(`-${flag} \\`);
105+
});
106+
107+
this.push("-I. src/shell.c src/sqlite3.c -o dist/sqlite3.exe");
108+
});
109+
}
110+
}
111+
112+
new Generator().run();

gen/genbase.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Generator base class
3+
* - provides basic functions to help with code generation
4+
*/
5+
6+
class GenBase {
7+
lines = [];
8+
prefix = "";
9+
indentLevel = 0;
10+
11+
get content() {
12+
return this.lines.join("\n");
13+
}
14+
15+
push(line) {
16+
this.lines.push(this.prefix + line);
17+
}
18+
19+
indentUp(amount = 1) {
20+
this.indentLevel += amount;
21+
this.setPrefix();
22+
}
23+
24+
indentDown(amount = 1) {
25+
this.indentLevel -= amount;
26+
this.setPrefix();
27+
}
28+
29+
setPrefix() {
30+
this.prefix = Array(this.indentLevel).fill(" ").join("");
31+
}
32+
33+
withIndent(func, amount = 1) {
34+
this.indentUp(amount);
35+
func();
36+
this.indentDown(amount);
37+
}
38+
}
39+
module.exports = {
40+
GenBase,
41+
};

0 commit comments

Comments
 (0)