-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.winxed
205 lines (186 loc) · 5.62 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
$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};
}