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

206 lines (186 sloc) 5.759 kb
$include_const "iglobals.pasm";
$loadlib "io_ops";
function main[main](argv) {
var parrot_libgit2 = {
"name" : 'parrot-libgit2',
"abstract" : 'Parrot bindings for libgit2',
"description" : 'Parrot bindings for libgit2 - the linkable git library',
"authority" : 'http://github.com/leto',
"copyright_holder" : 'Jonathan "Duke" Leto',
"keywords" : ["parrot", "git", "libgit2"],
"license_type" : 'GNU General Public License v3',
"license_uri" : 'http://www.gnu.org/licenses/gpl.html',
"checkout_uri" : 'git://github.com/leto/parrot-libgit2.git',
"browser_uri" : 'git://github.com/leto/parrot-libgit2',
"project_uri" : 'git://github.com/leto/parrot-libgit2',
"pir_winxed" : {},
"pbc_pir" : {},
"inst_lib" : [],
"installable_pbc" : {},
"include_winxed" : {},
"manifest_includes" : ["README.md", "setup.winxed"]
};
if (argv[1] == "test"){
build_test();
do_test();
}
setup_stable_libraries(parrot_libgit2);
load_bytecode('distutils.pir');
using setup;
using register_step_before;
register_step_before("build", check_dependencies);
register_step_before("build", build_nci);
register_step_before("build", build_lib);
register_step_before("clean", clean_build_dir);
register_step_before("install", install_clib);
register_step_before("uninstall", uninstall_clib);
argv.shift();
setup(argv, parrot_libgit2);
}
function setup_stable_libraries(var parrot_libgit2) {
var libs = [
'Blob',
'Cache',
'Config',
'Common',
'Commit',
'Index',
'Object',
'Odb',
'Oid',
'RefCache',
'AttrCache',
'Repository',
'Reference',
'Remote',
'RevParse',
'RevWalk',
'Tag',
'Tree',
'TreeIndex'
];
var core = [
'git2',
'parrotgit'
];
string prefix = "./src/Git2/";
for (string source in libs) {
string winxed_file = prefix + source + ".winxed";
string pir_file = prefix + source + ".pir";
string pbc_file = prefix + source + ".pbc";
parrot_libgit2["pir_winxed"][pir_file] = winxed_file;
parrot_libgit2["pbc_pir"][pbc_file] = pir_file;
parrot_libgit2["inst_lib"].push(pbc_file);
}
prefix = "./src/";
for(string source in core){
string pir_file = prefix + source + ".pir";
string pbc_file = prefix + source + ".pbc";
parrot_libgit2["pbc_pir"][pbc_file] = pir_file;
parrot_libgit2["inst_lib"].push(pbc_file);
}
}
function build_test() {
int result;
string cmd = "make rosella";
${ spawnw result, cmd};
}
function install_clib(){
//TODO use pkg-config
var env = new 'Env';
string parrotgitdir;
if (env['LIBPARROTGIT_INSTALL_DIR'] == ''){
parrotgitdir = "/usr/local/lib/";
}
else{
parrotgitdir = env['LIBPARROTGIT_INSTALL_DIR'];
}
string cmd = "cp libparrotgit.so " + parrotgitdir;
int result;
${spawnw result, cmd};
}
function uninstall_clib(){
var env = new 'Env';
string parrotgitdir;
if (env['LIBPARROTGIT_INSTALL_DIR'] == ''){
parrotgitdir = "/usr/local/lib/";
}
else{
parrotgitdir = env['LIBPARROTGIT_INSTALL_DIR'];
}
string filename = parrotgitdir + "libparrotgit.so";
int result;
unlink(filename);
}
function build_nci() {
var env = new 'Env';
string libgit_dir;
string cmd = "pkg-config --variable=includedir libgit2 > version";
var out;
int result;
${ getstdout out};
if (env['LIBGIT2_INSTALL_DIR'] == ''){
var s = new 'FileHandle';
${ spawnw result, cmd};
s.open("./version");
string output = s.readline();
libgit_dir = substr(output, 0, length(output) - 1);
}
else {
libgit_dir = env['LIBGIT2_INSTALL_DIR'];
}
var ncifile = new 'FileHandle';
ncifile.open("src/git2.nci", "rw");
ncifile.print("# THIS FILE IS GENERATED, edit ./bin/header2nci.pl to make changes here\n");
ncifile.print("[package]\nGit2::Raw\n\n[lib]\n\nlibgit2.so\n\n[defs]\n");
ncifile.close();
string ncigencmd = "perl ./bin/header2nci.pl " + libgit_dir + "/git2.h >> src/git2.nci";
${ spawnw result, ncigencmd};
ncigencmd = "for i in `ls " + libgit_dir + "/git2/*.h | sort -d`; do perl ./bin/header2nci.pl $i >> src/git2.nci; done";
${ spawnw result, ncigencmd};
string def2pir = "perl ./bin/ncidef2pir.pl src/git2.nci";
${ spawnw result, def2pir};
def2pir = "perl ./bin/ncidef2pir.pl src/parrotgit.nci";
${ spawnw result, def2pir};
}
function build_lib(){
int result;
string compile = "gcc -fPIC -c src/parrotgit.c -o src/parrotgit.o && gcc -shared -o libparrotgit.so src/parrotgit.o -lgit2";
${spawnw result, compile};
}
function do_test() {
int result;
string cmd = "parrot-nqp t/harness";
${ spawnw result, cmd };
${ exit result };
}
function check_dependencies() {
var config = getinterp()[IGLOBALS_CONFIG_HASH];
// Check if Parrot is > 3.5.0
int maj = config['MAJOR'];
int min = config['MINOR'];
if (maj < 3 || (maj == 3 && min < 5)) {
die("You need at least Parrot 3.5.0 to use parrot-libgit2");
}
// Check if Parrot has been built/configured with libffi
int has_libffi = config['has_libffi'];
if (!has_libffi) {
die("You need to have Parrot configured with libffi to use parrot-libgit2");
}
}
function clean_build_dir() {
var config = getinterp()[IGLOBALS_CONFIG_HASH];
string exe = "build/git2_test" + string(config['exe']);
int e = 0;
${ stat e, exe, 0 };
if (e) {
say("unlink " + exe);
unlink(exe);
}
unlink("src/git2.pbc");
unlink("src/git2.nci");
unlink("libparrotgit.so");
int result = 0;
string cmd = "rm -rf rosella";
${ spawnw result, cmd};
}
Jump to Line
Something went wrong with that request. Please try again.