-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.winxed
316 lines (201 loc) · 6.18 KB
/
setup.winxed
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#! winxed
/*
=head1 NAME
setup.winxed - Python distutils style
=head1 DESCRIPTION
=head2 Functions
=over 4
=item C<main>
run distutils
=cut
*/
function main(var argv) {
using extern distutils;
/* ignore first element in argv (program name) */
argv.shift();
using build_pir_winxed;
using build_c_dynext;
register_step_before('build', build_pir_winxed);
register_step_after('build', build_c_dynext);
using clean_pir_winxed;
using clean_c_dynext;
register_step_after('clean', clean_pir_winxed);
register_step_before('clean', clean_c_dynext);
var conf = load_setup_json();
setup(argv:[flat], conf:[flat,named]);
}
/*
=item C<load_setup_json>
read setup.json
=cut
*/
function load_setup_json() {
var file = open('setup.json');
string json_str = file.readall();
file.close();
var json = load_language('data_json');
var promise = json.compile(json_str);
return promise();
}
/*
=item C<build_pir_winxed()>
compile Winxed files to PIR
=cut
*/
function build_pir_winxed(var kv[named, slurpy]) {
var hash = kv['pir_winxed'];
if (!hash) return;
string flags = get_value('pir_winxed_flags', '':[named('default')], kv:[flat,named]);
var jobs = new 'ResizableStringArray'();
var temp;
${ loadlib temp, 'os' };
for (string pir in hash) {
string winxed = hash[pir];
if (newer(pir, winxed)) continue;
mkpath(dirname(pir), 1:[named('verbose')]);
var os = new 'OS'();
string cwd = os.cwd();
string cmd = sprintf("cd %s; ./winxed --target=pir -o %s %s %s", [
get_winxed_dir(), cwd + '/' + pir, flags, cwd + '/' + winxed
]);
jobs.push(cmd);
}
run_jobs(jobs);
}
/*
=item C<get_winxed_dir()>
Get the directory in which winxed lives
=cut
*/
function get_winxed_dir() {
var env = new 'Env';
string path = env['WINXED_PATH'];
if (path == '')
die("Cannot find winxed.\n" +
"Please add $WINXED_PATH to your environment\n" +
"or bug NotFound about making winxed installable.\n");
return path;
}
/*
=item C<clean_pir_winxed()>
cleanup PIR files generated from Winxed files
=cut
*/
function clean_pir_winxed(var kv[named, slurpy]) {
var hash = kv['pir_winxed'];
if (!hash) return;
for (string pir in hash)
unlink(pir, 1:[named('verbose')]);
}
/*
=item C<build_c_dynext>
=cut
*/
function build_c_dynext(kv[named, slurpy]) {
var hash = kv['c_dynext'];
if (!hash) return;
var config = get_config();
mkpath('dynext', 1:[named('verbose')]);
for (string dyn_name in hash) {
var opts = hash[dyn_name];
string dyn_file = dyn_filename(dyn_name);
string ccflags = opts['ccflags'];
ccflags += get_cflags();
// mostly taken from distutils.pir '__build_dynpmc_alone'
string ldflags = join(' ', [
opts['ldflags'], config['ld_load_flags'],
config['parrot_is_shared'] ? config['inst_libparrot_ldflags'] : ''
]);
var jobs = new 'ResizableStringArray'();
var o_files = new 'ResizableStringArray'();
for (string src in opts['src']) {
var obj = c_to_o_file(src);
o_files.push(obj);
if (newer(obj, src)) continue;
// mostly stolen from distutils.pir '__compile_cc'
string cmd = join(' ', [
config['cc'], '-c', config['cc_o_out'], obj,
'-I', get_incdir(), '-I', get_incdir() + '/pmc', '-I', cwd(),
ccflags, src
]);
jobs.push(cmd);
}
run_jobs(jobs);
string cmd = join(' ', [
config['ld'], config['ld_out'], dyn_file, ldflags, join(' ', o_files)
]);
system(cmd, 1:[named('verbose')]);
/* XXX don't have access to has_strip outside of distutils.pir */
}
}
/*
=item C<clean_c_dynext()>
=cut
*/
function clean_c_dynext(kv[named, slurpy]) {
var hash = kv['c_dynext'];
if (!hash) return;
for (string dyn_name in hash) {
var opts = hash[dyn_name];
for (string src in opts['src'])
unlink(c_to_o_file(src), 1:[named('verbose')]);
unlink(dyn_filename(dyn_name), 1:[named('verbose')]);
}
}
/*
=item C<c_to_o_file()>
=cut
*/
function c_to_o_file(string cfile) {
int strlen = length(cfile);
string obj_ext = get_config()['o'];
string ofile = substr(cfile, strlen - 2, 2) == '.c' ?
substr(cfile, 0, strlen - 2) + obj_ext :
cfile + obj_ext;
return ofile;
}
/*
=item C<dyn_filename()>
=cut
*/
function dyn_filename(string dyn) {
string load_ext = get_load_ext();
return 'dynext/lib' + dyn + load_ext;
}
/*
=item C<compile_dynlib>
compile a Parrot dynlib from a set of C source files using (optional) flags
mostly stolen from C<distutils.pir>
=cut
*/
function compile_dynlib(string name, var sources, string cflags, string ldflags) {
cflags = join(' ', [cflags, get_cflags()]);
ldflags = join(' ', [ldflags, get_ldflags()]);
mkpath('dynext', 1:[named('verbose')]);
string obj_ext = get_obj();
var objects = new 'ResizableStringArray'();
for (string src in sources) {
int strlen = length(src);
var obj = substr(src, strlen - 2, 2) == '.c' ?
substr(src, 0, strlen - 2) + obj_ext :
src + obj_ext;
__compile_cc(obj, src, cflags);
objects.push(obj);
}
var config = get_config();
string load_ext = get_load_ext();
string dynext = 'dynext/' + name + load_ext;
string cmd = join( ' ', [ config['ld'], config['ld_out'], dynext, ldflags,
config['ld_load_flags'], config['parrot_is_shared'] ?
config['inst_libparrot_ldflags'] : '' ] )
+ join(' ', objects);
system(cmd, 1:[named('verbose')]);
// XXX no access to _has_strip outside of distutils.pir
// if (_has_strip(cflags))
// system('strip ' + dynext, 1:[named(verbose)]);
}
/*
=back
=cut
vim: expandtab shiftwidth=4 ft=javascript:
*/