-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·194 lines (163 loc) · 6.85 KB
/
install
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
#!/usr/bin/env node
const { spawn, execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
async function command(cmd, args, options) {
if (args == null) args = [];
if (options == null) options = {};
if (options.cwd == null) options.cwd = process.cwd();
if (process.platform == 'win32') {
options.shell = cmd.endsWith('.exe') ? false : true;
args = [].concat(args);
for (let i = 0; i < args.length; i++) {
args[i] = '"' + args[i].replace(/"/g, '""') + '"';
}
}
console.log('\n> ' + cmd + ' ' + args.join(' '));
return new Promise((resolve, reject) => {
const child = spawn(cmd, args, {
stdio: 'inherit',
cwd: options.cwd,
env: process.env,
shell: options.shell
});
child.on('close', (code) => {
if (code !== 0) {
reject(new Error(`Child process exited with code ${code}`));
} else {
resolve(code);
}
});
child.on('error', (error) => {
reject(error);
});
});
}
function isLinuxArm64() {
try {
const arch = execSync('uname -m').toString().trim();
return arch == 'aarch64';
} catch (error) {
console.error('Error detecting architecture:', error);
return null;
}
}
// Example usage with async/await
async function main() {
process.chdir(__dirname);
let rawArgs = process.argv.slice(2);
var haxelib = process.platform == 'win32' ? 'haxelib.cmd' : './haxelib';
var haxe = process.platform == 'win32' ? 'haxe.cmd' : './haxe';
let haxeBuildArgs = ['build.hxml'];
let buildCpp = rawArgs.indexOf('--cpp') != -1;
let debug = false;
let i = 0;
while (i < rawArgs.length) {
if (rawArgs[i].startsWith('-D')) {
haxeBuildArgs.push('-D');
haxeBuildArgs.push(rawArgs[i].substring(2));
}
else if (rawArgs[i] == '--debug') {
debug = true;
haxeBuildArgs.push('--debug');
}
i++;
}
// Install dependencies
var haxelibRepoPath = path.join(__dirname, '.haxelib');
if (!fs.existsSync(haxelibRepoPath)) {
fs.mkdirSync(haxelibRepoPath);
}
await command(haxelib, ['dev', 'hxcpp', 'git/hxcpp', '--quiet'], { cwd: __dirname });
if (buildCpp) {
let haxeBuildCppArgs = [
'--cpp', 'build',
'-D', 'HXCPP_DEBUG_LINK',
'-D', 'HXCPP_STACK_LINE',
'-D', 'HXCPP_STACK_TRACE',
'-D', 'HXCPP_CHECK_POINTER',
'-D', 'HXCPP_CPP11',
'-D', 'safeMode'
];
if (process.platform == 'darwin') {
console.log('Build loreline for mac');
await command(haxe, haxeBuildCppArgs.concat(haxeBuildArgs).concat([
'-D', 'mac', '-D', 'mac_arm64', '-D', 'no-compilation'
]));
await command('../haxelib', ['run', 'hxcpp', 'Build.xml', '-DHXCPP_ARM64'].concat(debug ? ['-Ddebug'] : []), { cwd: path.join(__dirname, 'build') });
if (debug) {
fs.renameSync(path.join(__dirname, 'build/Cli-debug'), path.join(__dirname, 'build/loreline-arm64'));
}
else {
fs.renameSync(path.join(__dirname, 'build/Cli'), path.join(__dirname, 'build/loreline-arm64'));
}
await command(haxe, haxeBuildCppArgs.concat(haxeBuildArgs).concat([
'-D', 'mac', '-D', 'mac_x86_64', '-D', 'no-compilation'
]));
await command('../haxelib', ['run', 'hxcpp', 'Build.xml', '-DHXCPP_M64', '-DHXCPP_X86_64'].concat(debug ? ['-Ddebug'] : []), { cwd: path.join(__dirname, 'build') });
if (debug) {
fs.renameSync(path.join(__dirname, 'build/Cli-debug'), path.join(__dirname, 'build/loreline-x86_64'));
}
else {
fs.renameSync(path.join(__dirname, 'build/Cli'), path.join(__dirname, 'build/loreline-x86_64'));
}
if (fs.existsSync(path.join(__dirname, 'loreline'))) {
fs.unlinkSync(path.join(__dirname, 'loreline'));
}
await command('lipo', [
'-create', 'loreline-arm64', 'loreline-x86_64',
'-output', '../loreline'
], { cwd: path.join(__dirname, 'build') });
}
else if (process.platform == 'win32') {
console.log("Build loreline for windows");
await command(haxe, haxeBuildCppArgs.concat(haxeBuildArgs).concat([
'-D', 'windows', '-D', 'no-compilation'
]));
let haxelibCmd = fs.readFileSync(path.join(__dirname, 'haxelib.cmd'), 'utf8');
haxelibCmd = haxelibCmd.split('/git/').join('/../git/');
fs.writeFileSync(path.join(__dirname, 'build', 'haxelib.cmd'), haxelibCmd);
await command(haxelib, ['run', 'hxcpp', 'Build.xml', '-DHXCPP_M64', '-DHXCPP_X86_64'].concat(debug ? ['-Ddebug'] : []), { cwd: path.join(__dirname, 'build') });
if (fs.existsSync(path.join(__dirname, 'loreline.exe'))) {
fs.unlinkSync(path.join(__dirname, 'loreline.exe'));
}
if (debug) {
fs.renameSync(path.join(__dirname, 'build/Cli-debug.exe'), path.join(__dirname, 'loreline.exe'));
}
else {
fs.renameSync(path.join(__dirname, 'build/Cli.exe'), path.join(__dirname, 'loreline.exe'));
}
}
else {
console.log("Build loreline for linux");
if (isLinuxArm64()) {
await command(haxe, haxeBuildCppArgs.concat(haxeBuildArgs).concat([
'-D', 'linux', '-D', 'no-compilation', '-D', 'linux_arm64'
]));
await command('../haxelib', ['run', 'hxcpp', 'Build.xml', '-DHXCPP_ARM64'].concat(debug ? ['-Ddebug'] : []), { cwd: path.join(__dirname, 'build') });
}
else {
await command(haxe, haxeBuildCppArgs.concat(haxeBuildArgs).concat([
'-D', 'linux', '-D', 'no-compilation', '-D', 'linux_x86_64'
]));
await command('../haxelib', ['run', 'hxcpp', 'Build.xml', '-DHXCPP_M64', '-DHXCPP_X86_64'].concat(debug ? ['-Ddebug'] : []), { cwd: path.join(__dirname, 'build') });
}
if (fs.existsSync(path.join(__dirname, 'loreline'))) {
fs.unlinkSync(path.join(__dirname, 'loreline'));
}
if (debug) {
fs.renameSync(path.join(__dirname, 'build/Cli-debug'), path.join(__dirname, 'loreline'));
}
else {
fs.renameSync(path.join(__dirname, 'build/Cli'), path.join(__dirname, 'loreline'));
}
}
}
}
(async () => {
try {
await main();
} catch (error) {
console.error(error);
}
})();