forked from artoolkitx/jsartoolkit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makem.js
274 lines (231 loc) · 7.51 KB
/
makem.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* Simple script for running emcc on ARToolKit
* @author zz85 github.com/zz85
*/
var
exec = require('child_process').exec,
path = require('path'),
fs = require('fs'),
child;
var HAVE_NFT = 0;
var EMSCRIPTEN_PATH = process.env.EMSCRIPTEN;
var ARTOOLKIT5_ROOT = process.env.ARTOOLKIT5_ROOT || "../emscripten/artoolkit5";
if (!EMSCRIPTEN_PATH) {
console.log("\nWarning: EMSCRIPTEN environment variable not found.")
console.log("If you get a \"command not found\" error,\ndo `source <path to emsdk>/emsdk_env.sh` and try again.");
}
if(!ARTOOLKIT5_ROOT){
console.log("\nWarning: Environment variable ARTOOLKIT5_ROOT not found. Please make sure you have either cloned the ARToolKit GitHub repository using 'git submodule update --init' or that you have a link from jsartoolkit5/emscripten/artoolkit5 that points to your artoolkit5 clone ot that you set the environment variable ARTOOLKIT5_ROOT to the root directory of ARToolKit5 (eg. /Users/johnd/artoolkit5).\n\n Continuing with looking for ARToolKit5 at jsartoolkit5/emscripten/artoolkit5");
var ARTOOLKIT5_ROOT = "../emscripten/artoolkit5";
}
var EMCC = EMSCRIPTEN_PATH ? path.resolve(EMSCRIPTEN_PATH, 'emcc') : 'emcc';
var EMPP = EMSCRIPTEN_PATH ? path.resolve(EMSCRIPTEN_PATH, 'em++') : 'em++';
var OPTIMIZE_FLAGS = ' -Oz '; // -Oz for smallest size
var MEM = 256 * 1024 * 1024; // 64MB
var SOURCE_PATH = path.resolve(__dirname, '../emscripten/') + '/';
var OUTPUT_PATH = path.resolve(__dirname, '../build/') + '/';
var BUILD_FILE = 'artoolkit.debug.js';
var BUILD_MIN_FILE = 'artoolkit.min.js';
var MAIN_SOURCES = HAVE_NFT ? [
'NFT/ARMarkerNFT.c',
'NFT/trackingSub.c',
'NFT/thread_sub.c',
'ARToolKitJS.cpp'
] : [
'ARToolKitJS.cpp'
];
MAIN_SOURCES = MAIN_SOURCES.map(function(src) {
return path.resolve(SOURCE_PATH, src);
}).join(' ');
var ar_sources = [
'AR/arLabelingSub/*.c',
'AR/*.c',
'ARICP/*.c',
'ARMulti/*.c',
'Gl/gsub_lite.c',
// 'Gl/gsub_es2.c',
// 'ARWrapper/ARToolkitWrapperExportedAPI.cpp',
// 'ARWrapper/ARMarker.cpp',
// 'ARWrapper/ARMarkerMulti.cpp',
// 'ARWrapper/ARController.cpp',
// ARMarkerNFT // trackingSub
// 'ARWrapper/ARPattern.cpp'
].map(function(src) {
return path.resolve(__dirname, ARTOOLKIT5_ROOT + '/lib/SRC/', src);
});
var ar2_sources = [
'handle.c',
'imageSet.c',
'jpeg.c',
'marker.c',
'featureMap.c',
'featureSet.c',
'selectTemplate.c',
'surface.c',
'tracking.c',
'tracking2d.c',
'matching.c',
'matching2.c',
'template.c',
'searchPoint.c',
'coord.c',
'util.c',
].map(function(src) {
return path.resolve(__dirname, ARTOOLKIT5_ROOT + '/lib/SRC/AR2/', src);
});
var kpm_sources = [
'kpmHandle.c*',
'kpmRefDataSet.c*',
'kpmMatching.c*',
'kpmResult.c*',
'kpmUtil.c*',
'kpmFopen.c*',
'FreakMatcher/detectors/DoG_scale_invariant_detector.c*',
'FreakMatcher/detectors/gaussian_scale_space_pyramid.c*',
'FreakMatcher/detectors/gradients.c*',
'FreakMatcher/detectors/harris.c*',
'FreakMatcher/detectors/orientation_assignment.c*',
'FreakMatcher/detectors/pyramid.c*',
'FreakMatcher/facade/visual_database_facade.c*',
'FreakMatcher/matchers/hough_similarity_voting.c*',
'FreakMatcher/matchers/freak.c*',
'FreakMatcher/framework/date_time.c*',
'FreakMatcher/framework/image.c*',
'FreakMatcher/framework/logger.c*',
'FreakMatcher/framework/timers.c*',
].map(function(src) {
return path.resolve(__dirname, ARTOOLKIT5_ROOT + '/lib/SRC/KPM/', src);
});
if (HAVE_NFT) {
ar_sources = ar_sources
.concat(ar2_sources)
.concat(kpm_sources);
}
var DEFINES = ' ';
if (HAVE_NFT) DEFINES += ' -D HAVE_NFT ';
var FLAGS = '' + OPTIMIZE_FLAGS;
FLAGS += ' -Wno-warn-absolute-paths ';
FLAGS += ' -s TOTAL_MEMORY=' + MEM + ' ';
// FLAGS += ' -s FULL_ES2=1 '
FLAGS += ' -s NO_BROWSER=1 '; // for 20k less
FLAGS += ' --memory-init-file 0 '; // for memless file
var PRE_FLAGS = ' --pre-js ' + path.resolve(__dirname, '../js/artoolkit.api.js') +' ';
FLAGS += ' --bind ';
/* DEBUG FLAGS */
var DEBUG_FLAGS = ' -g ';
// DEBUG_FLAGS += ' -s ASSERTIONS=2 '
DEBUG_FLAGS += ' -s ASSERTIONS=1 '
// DEBUG_FLAGS += ' --profiling-funcs '
// DEBUG_FLAGS += ' -s EMTERPRETIFY_ADVISE=1 '
DEBUG_FLAGS += ' -s ALLOW_MEMORY_GROWTH=1';
DEBUG_FLAGS += ' -s DEMANGLE_SUPPORT=1 ';
var INCLUDES = [
path.resolve(__dirname, ARTOOLKIT5_ROOT + '/include'),
OUTPUT_PATH,
SOURCE_PATH,
// 'lib/SRC/KPM/FreakMatcher',
// 'include/macosx-universal/',
// '../jpeg-6b',
].map(function(s) { return '-I' + s }).join(' ');
function format(str) {
for (var f = 1; f < arguments.length; f++) {
str = str.replace(/{\w*}/, arguments[f]);
}
return str;
}
// Lib JPEG Compilation
// Memory Allocations
// jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
var libjpeg_sources = 'jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jquant1.c \
jquant2.c jutils.c jmemmgr.c \
jmemname.c \
jcapimin.c jcapistd.c jctrans.c jcparam.c \
jdatadst.c jcinit.c jcmaster.c jcmarker.c jcmainct.c \
jcprepct.c jccoefct.c jccolor.c jcsample.c jchuff.c \
jcphuff.c jcdctmgr.c jfdctfst.c jfdctflt.c \
jfdctint.c'.split(/\s+/).join(' ../jpeg-6b/')
function clean_builds() {
try {
var stats = fs.statSync(OUTPUT_PATH);
} catch (e) {
fs.mkdirSync(OUTPUT_PATH);
}
try {
var files = fs.readdirSync(OUTPUT_PATH);
if (files.length > 0)
for (var i = 0; i < files.length; i++) {
var filePath = OUTPUT_PATH + '/' + files[i];
if (fs.statSync(filePath).isFile())
fs.unlinkSync(filePath);
}
}
catch(e) { return console.log(e); }
}
var compile_arlib = format(EMCC + ' ' + INCLUDES + ' '
+ ar_sources.join(' ')
+ FLAGS + ' ' + DEFINES + ' -o {OUTPUT_PATH}libar.bc ',
OUTPUT_PATH);
var compile_kpm = format(EMCC + ' ' + INCLUDES + ' '
+ kpm_sources.join(' ')
+ FLAGS + ' ' + DEFINES + ' -o {OUTPUT_PATH}libkpm.bc ',
OUTPUT_PATH);
var compile_libjpeg = format(EMCC + ' ' + INCLUDES + ' '
+ '../jpeg-6b/' + libjpeg_sources
+ FLAGS + ' ' + DEFINES + ' -o {OUTPUT_PATH}libjpeg.bc ',
OUTPUT_PATH);
var compile_combine = format(EMCC + ' ' + INCLUDES + ' '
+ ' {OUTPUT_PATH}*.bc ' + MAIN_SOURCES
+ FLAGS + ' ' + DEBUG_FLAGS + DEFINES + ' -o {OUTPUT_PATH}{BUILD_FILE} ',
OUTPUT_PATH, OUTPUT_PATH, BUILD_FILE);
var compile_combine_min = format(EMCC + ' ' + INCLUDES + ' '
+ ' {OUTPUT_PATH}*.bc ' + MAIN_SOURCES
+ FLAGS + ' ' + DEFINES + PRE_FLAGS + ' -o {OUTPUT_PATH}{BUILD_FILE} ',
OUTPUT_PATH, OUTPUT_PATH, BUILD_MIN_FILE);
var compile_all = format(EMCC + ' ' + INCLUDES + ' '
+ ar_sources.join(' ')
+ FLAGS + ' ' + DEFINES + ' -o {OUTPUT_PATH}{BUILD_FILE} ',
OUTPUT_PATH, BUILD_FILE);
/*
* Run commands
*/
function onExec(error, stdout, stderr) {
if (stdout) console.log('stdout: ' + stdout);
if (stderr) console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
} else {
runJob();
}
}
function runJob() {
if (!jobs.length) {
console.log('Jobs completed');
return;
}
var cmd = jobs.shift();
if (typeof cmd === 'function') {
cmd();
runJob();
return;
}
console.log('\nRunning command: ' + cmd + '\n');
exec(cmd, onExec);
}
var jobs = [];
function addJob(job) {
jobs.push(job);
}
addJob(clean_builds);
addJob(compile_arlib);
// compile_kpm
// addJob(compile_libjpeg);
addJob(compile_combine);
addJob(compile_combine_min);
// addJob(compile_all);
runJob();