This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJakefile.js
135 lines (121 loc) · 3.84 KB
/
Jakefile.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const glob = require("glob");
const fs = require("fs");
const cxx = "em++";
const exportName = "-s EXPORT_NAME='_libflifem' -s MODULARIZE=1";
const ports = "-s USE_LIBPNG=1 -s USE_ZLIB=1";
const bind = "--bind wrapper/bind.cpp";
const optimizations = "-D NDEBUG -O2 -ftree-vectorize";
const flags = "-D LODEPNG_NO_COMPILE_PNG -D LODEPNG_NO_COMPILE_DISK";
const misc = "-s ALLOW_MEMORY_GROWTH=1 -s DEMANGLE_SUPPORT=1"
const commandMisc = `${misc} -s EXTRA_EXPORTED_RUNTIME_METHODS=['FS']`;
const libMisc = `${misc} -s RESERVED_FUNCTION_POINTERS=20 -s NO_FILESYSTEM=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -s BINARYEN_METHOD='native-wasm,asmjs'`;
const libdecMisc = `${libMisc} -D DECODER_ONLY`;
const libOptimizations = "-D NDEBUG -Oz --llvm-lto 1 -s USE_SDL=0";
const libraryInclude = `-I ${appendDir("library/")}`
// copied file list on the upstream makefile
// JSON.stringify((list).split(" "), null, 4)
const filesH = [
...glob.sync("maniac/*.hpp"),
...glob.sync("maniac/*.cpp"),
...glob.sync("image/*.hpp"),
...glob.sync("transform/*.hpp"),
"flif-enc.hpp",
"flif-dec.hpp",
"common.hpp",
"flif_config.h",
"fileio.hpp",
"io.hpp",
"io.cpp",
"config.h",
"compiler-specific.hpp",
"../extern/lodepng.h"
].map(item => appendDir(item)).join(' ');
const filesCpp = [
"maniac/chance.cpp",
"maniac/symbol.cpp",
"image/crc32k.cpp",
"image/image.cpp",
"image/image-png.cpp",
"image/image-pnm.cpp",
"image/image-pam.cpp",
"image/image-rggb.cpp",
"image/image-metadata.cpp",
"image/color_range.cpp",
"transform/factory.cpp",
"common.cpp",
"flif-enc.cpp",
"flif-dec.cpp",
"io.cpp",
"../extern/lodepng.cpp"
].map(item => appendDir(item)).join(' ');
const libFilesCpp = [
"maniac/chance.cpp",
"maniac/symbol.cpp",
"image/crc32k.cpp",
"image/image.cpp",
"image/color_range.cpp",
"transform/factory.cpp",
"common.cpp",
"flif-enc.cpp",
"flif-dec.cpp",
"io.cpp",
].map(item => appendDir(item)).join(' ');
/** @param {string} path */
function appendDir(path) {
return `submodules/flif/src/${path}`;
}
/** @type {jake.ExecOptions} */
const jakeExecOptionBag = {
printStdout: true,
printStderr: true
};
/**
* @param {string[]} cmds
* @return {Promise<void>}
*/
function asyncExec(cmds) {
return new Promise((resolve, reject) => {
try {
jake.exec(cmds, resolve, jakeExecOptionBag);
}
catch (e) {
reject(e);
}
});
}
desc("Build libflif");
task("lib", async () => {
const command = `${cxx} ${flags} ${libMisc} -std=c++11 ${bind} ${exportName} ${ports} ${libOptimizations} -g0 -Wall ${libraryInclude} ${libFilesCpp} ${appendDir("library/flif-interface.cpp")} -o built/libflif.js`;
console.log(command);
await asyncExec([command]);
});
desc("Build libflifdec");
task("libdec", async () => {
const command = `${cxx} ${flags} ${libdecMisc} -std=c++11 ${bind} ${exportName} ${ports} ${libOptimizations} -g0 -Wall ${libraryInclude} ${libFilesCpp} ${appendDir("library/flif-interface_dec.cpp")} -o built/libflifdec.js`;
console.log(command);
await asyncExec([command]);
});
desc("Build wrapper");
task("wrapper", async () => {
console.log("Building wrapper...");
await asyncExec(["tsc -p wrapper/tsconfig.json"]);
});
desc("Build worker for wrapper");
task("worker", async () => {
console.log("Building worker...");
await asyncExec(["tsc -p wrapper-worker/tsconfig.json"]);
});
desc("Build sample app");
task("sample", async () => {
console.log("Building sample app...");
await asyncExec(["tsc -p sample/tsconfig.json"]);
});
desc("Build JavaScript part");
task("js", ["wrapper", "worker", "sample"]);
desc("Build all");
task("default", ["js", "lib", "libdec"]);
desc("Clean");
task("clean", [], () => {
console.log("Cleaning...");
fs.unlink("built/");
});