forked from Kode/kincmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koremake.js
208 lines (190 loc) · 4 KB
/
koremake.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
"use strict";
var version = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
if (version < 4.0) {
console.log('Sorry, this requires at least node version 4.0.');
process.exit(1);
}
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
String.prototype.replaceAll = function (find, replace) {
return this.replace(new RegExp(escapeRegExp(find), 'g'), replace);
};
var os = require('os');
var Options = require('./Options.js');
var Platform = require('./Platform.js');
var GraphicsApi = require('./GraphicsApi.js');
var VisualStudioVersion = require('./VisualStudioVersion.js');
var VrApi = require('./VrApi.js');
var defaultTarget;
if (os.platform() === "linux") {
defaultTarget = Platform.Linux;
}
else if (os.platform() === "win32") {
defaultTarget = Platform.Windows;
}
else {
defaultTarget = Platform.OSX;
}
var options = [
{
full: 'from',
value: true,
description: 'Location of your project',
default: '.'
},
{
full: 'to',
value: true,
description: 'Build location',
default: 'build'
},
{
full: 'target',
short: 't',
value: true,
description: 'Target platform',
default: defaultTarget
},
{
full: 'vr',
value: true,
description: 'Target VR device',
default: VrApi.None
},
{
full: 'pch',
description: 'Use precompiled headers for C++ targets',
value: false
},
{
full: 'intermediate',
description: 'Intermediate location for object files.',
value: true,
default: '',
hidden: true
},
{
full: 'graphics',
short: 'g',
description: 'Graphics api to use',
value: true,
default: GraphicsApi.Direct3D9
},
{
full: 'visualstudio',
short: 'v',
description: 'Version of Visual Studio to use',
value: true,
default: VisualStudioVersion.VS2015
},
{
full: 'nokrafix',
description: 'Switch off the new shader compiler',
value: false
},
{
full: 'compile',
description: 'Compile executable',
value: false
},
{
full: 'run',
description: 'Run executable',
value: false
},
{
full: 'update',
description: 'Update Kore and it\'s submodules',
value: false
},
{
full: 'debug',
description: 'Compile in debug mode',
value: false
}
];
var parsedOptions = {
};
function printHelp() {
console.log('khamake options:\n');
for (var o in options) {
var option = options[o];
if (option.hidden) continue;
if (option.short) console.log('-' + option.short + ' ' + '--' + option.full);
else console.log('--' + option.full);
console.log(option.description);
console.log();
}
}
for (var o in options) {
var option = options[o];
if (option.value) {
parsedOptions[option.full] = option.default;
}
else {
parsedOptions[option.full] = false;
}
}
var args = process.argv;
for (var i = 2; i < args.length; ++i) {
var arg = args[i];
if (arg[0] == '-') {
if (arg[1] == '-') {
if (arg.substr(2) === 'help') {
printHelp();
process.exit(0);
}
for (var o in options) {
var option = options[o];
if (arg.substr(2) === option.full) {
if (option.value) {
++i;
parsedOptions[option.full] = args[i];
}
else {
parsedOptions[option.full] = true;
}
}
}
}
else {
if (arg[1] === 'h') {
printHelp();
process.exit(0);
}
for (var o in options) {
var option = options[o];
if (option.short && arg[1] === option.short) {
if (option.value) {
++i;
parsedOptions[option.full] = args[i];
}
else {
parsedOptions[option.full] = true;
}
}
}
}
}
else {
parsedOptions.target = arg;
}
}
if (parsedOptions.graphics === GraphicsApi.OpenGL) {
parsedOptions.graphics = GraphicsApi.OpenGL2;
}
if (parsedOptions.run) {
parsedOptions.compile = true;
}
if (parsedOptions.update) {
console.log("Updating everything...");
require('child_process').spawnSync('git', ['submodule', 'foreach', '--recursive', 'git', 'pull', 'origin', 'master'], { stdio: 'inherit', stderr: 'inherit' });
process.exit(0);
}
require('./main.js').run(
parsedOptions,
{
info: console.log,
error: console.log
}, function () { });