-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.winxed
219 lines (197 loc) · 5.9 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
$include_const "iglobals.pasm";
$loadlib "io_ops";
function main[main](argv) {
var parrot_gmp = {
"name" : 'Parrot-GMP',
"abstract" : 'Parrot bindings for the GNU Multi-Precision Library',
"description" : 'Parrot bindings for the GNU Multi-Precision Library. Currently has bindings for Integer type functions and random initialization functions.',
"authority" : 'http://github.com/bubaflub',
"copyright_holder" : 'Bob Kuo',
"keywords" : ["parrot", "gmp"],
"license_type" : 'Artistic License 2.0',
"license_uri" : 'http://www.perlfoundation.org/artistic_license_2_0',
"checkout_uri" : 'git://github.com/bubaflub/parrot-gmp.git',
"browser_uri" : 'git://github.com/bubaflub/parrot-gmp',
"project_uri" : 'git://github.com/bubaflub/parrot-gmp',
"pir_winxed" : {},
"pbc_pir" : {},
"inst_lib" : [],
"installable_pbc" : {},
"include_winxed" : {},
"manifest_includes" : ["README.md", "setup.winxed"]
};
var config = getinterp()[IGLOBALS_CONFIG_HASH];
${ set_global 'config', config };
if (argv[1] == "test")
do_test();
setup_stable_libraries(parrot_gmp);
load_bytecode('distutils.pir');
using setup;
using register_step_before;
register_step_before("build", check_dependencies);
register_step_before("clean", clean_build_dir);
if (_config('has_libffi') != 1) {
register_step_before("build", build_nci_thunks);
register_step_before("clean", clean_nci_thunks);
register_step_after("install", install_nci_thunks);
}
argv.shift();
setup(argv, parrot_gmp);
}
function setup_stable_libraries(var parrot_gmp) {
parrot_gmp["pbc_pir"]["GMP/raw.pbc"] = "src/GMP/raw.pir";
parrot_gmp["inst_lib"].push("GMP/raw.pbc");
var libs = [
'Common',
'Random',
'Integer'
];
string prefix = "src/GMP/";
for (string source in libs) {
string winxed_file = prefix + source + ".winxed";
string pir_file = prefix + source + ".pir";
string pbc_file = "GMP/" + source + ".pbc";
parrot_gmp["pir_winxed"][pir_file] = winxed_file;
parrot_gmp["pbc_pir"][pbc_file] = pir_file;
parrot_gmp["inst_lib"].push(pbc_file);
}
}
function do_test() {
int result;
string command = _build_command([
"parrot-nqp",
"t/harness"
]);
${ spawnw result, command };
${ exit result };
}
function check_dependencies() {
// Check if Parrot is > 3.2.0
int maj = _config('MAJOR');
int min = _config('MINOR');
if (maj < 3 || (maj == 3 && min < 2)) {
die("You need at least Parrot 3.2.0 to use Parrot-GMP");
}
// Check if Parrot has been built/configured with gmp
int has_gmp = _config('HAS_GMP');
if (!has_gmp) {
die("You need to have Parrot configured with GMP to use Parrot-GMP");
}
// Check GMP version > 4.3
// Also grab other system dependent information
string file = "build/gmp_test.c";
string exe = "build/gmp_test" + string(_config('exe'));
string command = _build_command([
_config('cc'),
_config('ccflags'),
_config('cc_exe_out'),
exe,
file
]);
say(command);
system(command);
var pipe = new "FileHandle";
pipe.encoding('utf8');
pipe.open(exe, "rp");
string output = pipe.readall();
pipe.close();
int exit_status = pipe.exit_status();
if (exit_status != 0) {
die("Could not run " + exe + ": please check that your system has libgmp");
}
var lines = split("\n", output);
var values = split(' ', lines[0]);
int gmp_major = values[0];
int gmp_minor = values[1];
int gmp_patch = values[2];
if (gmp_major < 4 || (gmp_major == 4 && gmp_minor < 2)) {
die("Need GMP version >= 4.2");
}
// TODO: process other values from build/gmp_test
}
function clean_build_dir() {
string exe = "build/gmp_test" + string(_config('exe'));
_unlink_file(exe);
_unlink_file("src/GMP/thunks.c");
_unlink_file("src/GMP/thunks.o");
}
function _unlink_file(string file) {
int e = 0;
${ stat e, file, 0 };
if (e) {
say("unlink " + file);
unlink(file);
}
}
function build_nci_thunks() {
string thunk = "src/GMP/thunks.c";
int result;
string command = _build_command([
"parrot_nci_thunk_gen",
"--dynext",
"--no-warn-dups",
"--output=src/GMP/thunks.c",
"<src/GMP/thunks.nci"
]);
say(command);
${ spawnw result, command };
string file = "src/GMP/thunks.c";
string obj = "GMP/thunks" + string(_config('o'));
command = _build_command([
_config('cc'),
_config('ccflags'),
_config('cc_shared'),
_config('embed-cflags'),
_config('libparrot_linkflags'),
"-Ipmc/pmc_nci.h",
_config('cc_o_out'),
obj,
"-c",
file
]);
say(command);
${ spawnw result, command };
string shared_obj = "GMP/thunks" + string(_config('load_ext'));
command = _build_command([
_config('ld'),
_config('ld_out'),
shared_obj,
obj,
_config('ldflags'),
_config('ld_debug'),
_config('rpath_blib'),
_config('linkflags'),
_config('ld_load_flags')
]);
if(string(_config('parrot_is_shared'))) {
command = command + " " + string(_config('inst_libparrot_ldflags'));
}
say(command);
${ spawnw result, command };
}
function clean_nci_thunks() {
_unlink_file("src/GMP/thunks.c");
_unlink_file("GMP/thunks" + string(_config('o')));
_unlink_file("GMP/thunks" + string(_config('load_ext')));
}
function install_nci_thunks() {
string install_path = string(_config('libdir')) + string(_config('versiondir'));
install_path += string(_config('slash')) + 'dynext' + string(_config('slash'));
string shared_obj = "GMP/thunks" + string(_config('load_ext'));
int result;
string command = _build_command([
'cp',
shared_obj,
install_path
]);
say(command);
${ spawnw result, command };
}
function _config(string key) {
var config;
${ get_global config, 'config' };
return string(config[key]);
}
function _build_command(var commands) {
return string(join(' ', commands));
}