Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

220 lines (197 sloc) 6.039 kb
$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));
}
Jump to Line
Something went wrong with that request. Please try again.