-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle-header.js
74 lines (64 loc) · 2.02 KB
/
single-header.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
const fs = require('fs');
let header = '';
let src_top = '#include "soso.h"\n\n';
let src = '';
log.info('Generating header...');
try {
const data = fs.readFileSync(__dirname + '/src/soso/soso.h', {encoding: 'utf8'}).replace('#include <sht/sht.h>', '');
let cut = data.indexOf('//--- Internals ---//');
header += data.slice(0, cut);
src_top += data.slice(cut) + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
fs.writeFileSync(__dirname + '/soso.h', header, {flag: 'w'});
} catch (err) {
throw new Error(err);
}
log.info('Generating compile unit...');
try {
const data = fs.readFileSync(__dirname + '/ext/sht/murmur3.h', {encoding: 'utf8'});
src_top += data + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
const data = fs.readFileSync(__dirname + '/ext/sht/murmur3.c', {encoding: 'utf8'}).replace('#include "murmur3.h"', '');
src += data + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
const data = fs.readFileSync(__dirname + '/ext/sht/sht.h', {encoding: 'utf8'}).replace('#pragma once', '');
src_top += data + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
const data = fs.readFileSync(__dirname + '/ext/sht/sht.c', {encoding: 'utf8'}).replace('#include "murmur3.h"', '').replace('#include "sht.h"', '');
src += data + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
const data = fs.readFileSync(__dirname + '/src/soso/random.c', {encoding: 'utf8'}).replace('#include "soso.h"', '');
src += data + '\n\n';
} catch (err) {
throw new Error(err);
}
try {
const data = fs.readFileSync(__dirname + '/src/soso/soso.c', {encoding: 'utf8'}).replace('#include <sht/murmur3.h>', '').replace('#include "soso.h"', '');
src += data;
} catch (err) {
throw new Error(err);
}
try {
fs.writeFileSync(__dirname + '/soso.c', src_top + '\n' + src, {flag: 'w'});
} catch (err) {
throw new Error(err);
}
log.info('Done');
// Need empty project to not make kmake fail
let project = new Project('ThisIsNotAProject');
resolve(project);