-
Notifications
You must be signed in to change notification settings - Fork 14
/
build
executable file
·495 lines (432 loc) · 17.5 KB
/
build
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw'$Bin';
use lib "$FindBin::Bin";
use lib "$FindBin::Bin/perl_lib";
BEGIN { $ENV{PERL_JSON_BACKEND} = 0 }
use JSON -support_by_pp;
use Data::Dumper;
use File::Path qw(rmtree);
use Getopt::Long qw(GetOptions);
my $help;
my $conf_use_cached_src;
my $conf_nopackage;
my $ARCH = $ENV{ARCH};
my $os;
GetOptions ("help|?" => \$help,
"nofetch" => \$conf_use_cached_src,
"nopackage" => \$conf_nopackage,
"arch=s" => \$ARCH,
"os=s" => \$os,
) or die ("error in cmdline args\n");
if ($help) {
print "Usage: $0 [options] [plugin_name(s)]\n";
print "Options:\n";
print " --help Show this text\n";
print " --nofetch Don't fetch package sources, use the cached copy\n";
print " --nopackage Don't package the output files\n";
print " --arch=ARCH i686 or x86_64\n";
exit 0;
}
my $ORIGIN=$FindBin::Bin;
chdir($ORIGIN);
my $LIBDIR="";
my $CFLAGS="";
my $LDFLAGS="";
my $CONFIGURE_FLAGS;
my $MULTILIB_DIR;
if (!defined $os) {
if ($^O eq 'darwin') {
$os = 'mac';
$ARCH = 'universal';
}
elsif ($^O eq 'linux') {
$os = 'linux';
}
elsif ($^O eq 'msys') {
$os = 'windows'
}
else {
die "Unsupported OS ($^O)\n";
}
}
if (!defined $ARCH) {
die "Target arch is unspecified. Please use ARCH env variable, or --arch option\n";
}
if ($os eq 'mac') {
$LIBDIR="$ORIGIN/static-deps/lib-x86-64";
}
elsif ($os eq 'linux') {
if ($ARCH eq 'i686') {
$MULTILIB_DIR='i386-linux-gnu';
$LIBDIR="$ORIGIN/static-deps/lib-x86-32";
$CFLAGS="-m32 -I$LIBDIR/include/$MULTILIB_DIR";
$CONFIGURE_FLAGS = "--build=i686-unknown-linux-gnu";
$LDFLAGS="-L$LIBDIR/lib -L$LIBDIR/lib/$MULTILIB_DIR";
}
elsif ($ARCH eq 'x86_64') {
$MULTILIB_DIR='x86_64-linux-gnu';
$LIBDIR="$ORIGIN/static-deps/lib-x86-64";
$CFLAGS="-m64 -fPIC -I$LIBDIR/include/$MULTILIB_DIR";
$CONFIGURE_FLAGS="--build=x86_64-unknown-linux-gnu";
$LDFLAGS="-L$LIBDIR/lib -L$LIBDIR/lib/$MULTILIB_DIR";
}
}
elsif ($os eq 'windows') {
if ($ARCH eq 'x86_64') {
$LIBDIR="/mingw64/";
$CFLAGS="-I static-deps/lib-x86-64/include/";
$LDFLAGS="-Wl,--export-all-symbols"
}
else {
die "unknown arch $ARCH\n";
}
}
$ENV{ARCH} = $ARCH;
my @libpaths = ("");
my $PLUGINFO="$ORIGIN/tools/pluginfo/$ARCH/pluginfo";
my $GTK216_CFLAGS;
my $GTK216_LIBS;
my $GTK310_CFLAGS;
my $GTK310_LIBS;
if ($os eq 'linux') {
if (-e 'static-deps') {
print "static-deps exists, delete for redownload\n";
}
else {
print "downloading static-deps...\n";
mkdir "temp";
system ('curl -s -L http://sourceforge.net/projects/deadbeef/files/staticdeps/ddb-static-deps-latest.tar.bz2/download -o temp/ddb-static-deps.tar.bz2 && mkdir static-deps && tar jxf temp/ddb-static-deps.tar.bz2 -C static-deps') && die "failed to download static-deps\n";
}
print "removing libstdc++ from static-deps...\n";
system ('rm static-deps/lib-x86-64/lib/libstdc++*');
my $AP="$ORIGIN/external/apbuild";
`cd $AP; ./apinit`;
$ENV{CC}="$AP/apgcc";
$ENV{CXX}="$AP/apg++";
$ENV{APBUILD_STATIC_LIBGCC}=1;
$ENV{CFLAGS} = "$CFLAGS -I$LIBDIR/include";
$ENV{CXXFLAGS} = "$CFLAGS -I$LIBDIR/include";
$ENV{LDFLAGS} = "$LDFLAGS -L$LIBDIR/lib";
my $GTK_ROOT_216="$LIBDIR/gtk-2.16.0";
my $GTK_ROOT_310="$LIBDIR/gtk-3.10.8";
$GTK216_CFLAGS = "-I${GTK_ROOT_216}/include/gtk-2.0 -I${GTK_ROOT_216}/lib/gtk-2.0/include -I${GTK_ROOT_216}/include/atk-1.0 -I${GTK_ROOT_216}/include/cairo -I${GTK_ROOT_216}/include/pango-1.0 -I${GTK_ROOT_216}/include -I${GTK_ROOT_216}/include/glib-2.0 -I${GTK_ROOT_216}/lib/glib-2.0/include";
$GTK216_LIBS="-L${GTK_ROOT_216}/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lpthread";
if ($ARCH eq 'i686') {
$GTK310_CFLAGS="-I${GTK_ROOT_310}/include/gtk-3.0 -I${GTK_ROOT_310}/include/pango-1.0 -I${GTK_ROOT_310}/include/gio-unix-2.0/ -I${GTK_ROOT_310}/include/atk-1.0 -I${GTK_ROOT_310}/include/cairo -I${GTK_ROOT_310}/include/gdk-pixbuf-2.0 -I${GTK_ROOT_310}/include/freetype2 -I${GTK_ROOT_310}/include/glib-2.0 -I${GTK_ROOT_310}/lib/glib-2.0/include -I${GTK_ROOT_310}/lib/glib-2.0/include";
$GTK310_LIBS="-L${GTK_ROOT_310}/lib -L${GTK_ROOT_310}/lib/i386-linux-gnu -lgtk-3 -lpango-1.0 -lcairo -lgobject-2.0 -lgthread-2.0 -lglib-2.0";
}
elsif ($ARCH eq 'x86_64') {
$GTK310_CFLAGS="-I${GTK_ROOT_310}/include/gtk-3.0 -I${GTK_ROOT_310}/include/pango-1.0 -I${GTK_ROOT_310}/include/gio-unix-2.0/ -I${GTK_ROOT_310}/include/atk-1.0 -I${GTK_ROOT_310}/include/cairo -I${GTK_ROOT_310}/include/gdk-pixbuf-2.0 -I${GTK_ROOT_310}/include/freetype2 -I${GTK_ROOT_310}/include/glib-2.0 -I${GTK_ROOT_310}/lib/glib-2.0/include";
$GTK310_LIBS="-L${GTK_ROOT_310}/lib -L${GTK_ROOT_310}/lib/x86_64-linux-gnu -lgtk-3 -lpango-1.0 -lcairo -lgobject-2.0 -lgthread-2.0 -lglib-2.0";
}
@libpaths = ("$GTK_ROOT_216", "$GTK_ROOT_310");
}
elsif ($os eq 'windows') {
$ENV{CFLAGS} = "$CFLAGS -Wno-incompatible-pointer-types";
$ENV{CXXFLAGS} = "$CFLAGS";
$ENV{LDFLAGS} = "$LDFLAGS";
$GTK216_CFLAGS=`pkg-config --cflags gtk+-2.0`;
$GTK216_CFLAGS =~ s/\R//g;
$GTK216_LIBS=`pkg-config --libs gtk+-2.0`;
$GTK216_LIBS =~ s/\R//g;
$GTK310_CFLAGS=`pkg-config --cflags gtk+-3.0`;
$GTK310_CFLAGS =~ s/\R//g;
$GTK310_LIBS=`pkg-config --libs gtk+-3.0`;
$GTK310_LIBS =~ s/\R//g;
# -luuid is a static-only library, and libtool can't
# handle it. Smh GTK2 flags already have the right thing that works on
# windows, but not GTK3.
$GTK310_LIBS =~ s/ -luuid / -Wl,-luuid /;
chomp($GTK216_LIBS);
chomp($GTK310_LIBS);
}
if (-e "$LIBDIR/include/deadbeef/deadbeef.h") {
print "deadbeef.h exists, delete for redownload\n";
}
else {
system ("mkdir -p $LIBDIR/include");
mkdir "temp";
system ('curl -s -L http://sourceforge.net/projects/deadbeef/files/staticdeps/ddb-headers-latest.tar.bz2/download -o temp/ddb-headers-latest.tar.bz2') && die "failed to download ddb-headers-latest.tar.bz2\n";
print "unpacking deadbeef headers...\n";
system ("tar jxf temp/ddb-headers-latest.tar.bz2 -C $LIBDIR/include/") && die "Failed to unpack temp/ddb-headers-latest.tar.bz2\n";
}
my %CLEAN_ENV = %ENV;
my @packages;
if (~~@ARGV) {
@packages = @ARGV;
}
else {
@packages = split (/\n/, `ls plugins`);
}
for my $package (@packages) {
%ENV = %CLEAN_ENV;
my $filename = "plugins/$package/manifest.json";
my @platforms_enabled = ('linux', 'windows');
next unless -e $filename;
print "Preparing to build package: $package\n";
open F,"<$filename" or die "failed to read manifest for $package\n";
my $manifest;
{
local $/;
$manifest = <F>;
}
close F;
my $json = JSON->new;
$json->relaxed([1]);
$json->allow_singlequote([1]);
$json->allow_barekey([1]);
$manifest = $json->decode($manifest);
#print Dumper($manifest)."\n";
if ($manifest->{disable}) {
print STDERR "skipping $package because it's disabled in manifest\n";
next;
}
if (exists $manifest->{supported_platforms}) {
@platforms_enabled = ();
for my $p (@{$manifest->{supported_platforms}}) {
push(@platforms_enabled, $p);
}
}
my $package_enabled = grep /^$os$/, @platforms_enabled;
if (!$package_enabled) {
print STDERR "skipping the $package since it doesn't support current platform\n";
next;
}
my $out = $manifest->{make}->{"out_$os"};
if (!($out)) {
$out = $manifest->{make}->{out};
}
if (!$out || !(~~@{$out})) {
print STDERR "skipping $package because it doesn't define output\n";
next;
}
my $ROOT = "temp/$package";
print "getting source code using $manifest->{source}->{type} from $manifest->{source}->{url}\n";
my $rev = 'unknown';
if (!$conf_use_cached_src) {
rmtree $ROOT;
if ($manifest->{source}->{type} eq 'svn') {
system ("svn checkout $manifest->{source}->{url} $ROOT") && die "svn checkout failed\n";
$rev = `cd temp/$package && svn info | grep "Revision" | cut -c11-`;
}
elsif ($manifest->{source}->{type} eq 'git') {
system ("git clone $manifest->{source}->{url} $ROOT") && die "git clone failed\n";
if ($manifest->{source}->{revision}) {
$rev = $manifest->{source}->{revision};
system ("cd $ROOT && git checkout $rev") && die "git checkout $rev failed\n";
}
else {
$rev = `cd temp/$package && git rev-parse --short HEAD`;
}
if ($manifest->{source}->{submodules}) {
system ("cd $ROOT && git submodule update --init") && die "git submodule update failed\n";
}
}
elsif ($manifest->{source}->{type} eq 'hg') {
system ("hg clone --config ui.tls=false $manifest->{source}->{url} $ROOT") && die "hg clone failed\n";
$rev = `cd temp/$package && hg log -r . --template '{node|short}'`;
}
print "\nsource code download success.\n";
print "revision: $rev\n";
chomp $rev;
if (exists $manifest->{source}->{patches}) {
print "\napplying patches\n";
for my $p (@{$manifest->{source}->{patches}}) {
system ("cd $ROOT; patch -p1 <$ORIGIN/plugins/$package/$p") && die "patch failed\n";
}
}
}
if (exists $manifest->{source}->{exec} && !$conf_use_cached_src) {
for my $e (@{$manifest->{source}->{exec}}) {
print "running: $e\n";
system "cd $ROOT/$manifest->{make}->{root}; $e";
}
}
print "\npreparing environment...\n";
if (exists $manifest->{make}->{ENV}) {
for my $n (keys %{$manifest->{make}->{ENV}}) {
my $v = eval("\"$manifest->{make}->{ENV}->{$n}\"");
print "$n=$v\n";
$ENV{$n} = $v;
}
}
if ($os eq 'mac') {
system('rm -rf temp/output/arm64/plugins temp/output/x86_64/plugins');
$ARCH='x86_64';
$ENV{CFLAGS}="-arch x86_64 -fPIC -I$LIBDIR/include";
$ENV{CXXFLAGS}="-arch x86_64 -fPIC -I$LIBDIR/include";
print "Building $package x86_64...\n";
build_plugin($package, $manifest, $ROOT, $out);
$ARCH='arm64';
$ENV{CFLAGS}="-arch arm64 -fPIC -I$LIBDIR/include";
$ENV{CXXFLAGS}="-arch arm64 -fPIC -I$LIBDIR/include";
print "Building $package arm64...\n";
build_plugin($package, $manifest, $ROOT, $out, 1);
$ARCH='universal';
# make universal
system('cp -r temp/output/arm64 temp/output/universal') && die "Copy to temp/output/universal failed\n";
system('mkdir -p temp/output/universal/plugins') && die "Failed to create temp/output/universal/plugins\n";
system('rm temp/output/universal/plugins/*.dylib');
system("for f in temp/output/x86_64/plugins/*.dylib; do ff=`basename \$f`; lipo -create -output temp/output/universal/plugins/\$ff temp/output/x86_64/plugins/\$ff temp/output/arm64/plugins/\$ff; done") && die "lipo failed\n";
}
else {
build_plugin($package, $manifest, $ROOT, $out);
}
my $outdir = "temp/output/$ARCH/plugins";
# copy with custom paths
my @extra_libpaths = ();
for my $copy (@{$manifest->{make}->{copy}}) {
my $path = "$outdir/$copy->{path}";
push @extra_libpaths, $path;
my $files = $copy->{files};
system ("mkdir -p '$path'");
for my $p (@{$files}) {
my $fname = "$ROOT/$p";
if ($os eq 'windows') {
$fname =~ s/\.so$/\.dll/;
}
elsif ($os eq 'mac') {
$fname =~ s/\.so$/\.dylib/;
}
print "copying extra $fname to $path\n";
system ("cp '$fname' '$path/'") && die "Failed to copy $fname to $path\n";
}
}
# get plugin version, and generate descr file
# this is needed e.g. for build-md script to find the right plugin zip
my $ver;
my $descr_fname = "temp/output/$ARCH/$package.descr";
open F,">temp/output/$ARCH/$package.descr" || die "failed to open $descr_fname\n";
# try loading all files from 'out',
# alternating GTK2 and GTK3 libs,
# until we find one that works
my $found = 0;
foreach (@$out) {
foreach my $gtklibpath (@libpaths) {
if ($gtklibpath) {
print "Trying to load $_ with $gtklibpath...\n";
my $addpaths = '';
map { $addpaths .= ":$_"; } @extra_libpaths;
$ENV{LD_LIBRARY_PATH} = "${gtklibpath}/lib:${gtklibpath}/lib/${MULTILIB_DIR}:${LIBDIR}/lib:${LIBDIR}/lib/${MULTILIB_DIR}" . $addpaths;
print "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}\n";
}
my $curr = $_;
$curr = get_dest_filename($curr);
print "getting plugin info: $outdir/$curr\n";
my $config = `$PLUGINFO $outdir/$curr`;
if (!$?) {
my %conf_vars = parse_config ($config);
$ver = $conf_vars{version};
# write description file
print "Got descr from $curr\n";
print F $config;
$found = 1;
last;
}
else {
print "Failed to get descr from $curr\n";
}
}
last if $found;
}
if (!$found) {
die "Failed to get descr for the plugin $package\n";
}
if (!$ver) {
$ver = 'unknown';
}
my $build = '';
if ($manifest->{build}) {
$build = "-$manifest->{build}";
}
my $out_fname = "$package-$rev$build-$os-$ARCH.zip";
print F "revision=\"$rev\"\n";
foreach(@platforms_enabled) {
print F "fname_${_}_$ARCH=\"$package-$rev$build-${_}-$ARCH.zip\"\n";
}
close F;
print "will pack $out_fname\n";
unlink $out_fname;
system ("cd temp/output/$ARCH && zip -r $out_fname plugins") && die "failed to zip $out_fname\n";
}
sub parse_config {
$_ = shift;
my %out;
while (/([a-z_0-9]*)="([^"]*)"\n/g) {
$out{$1} = $2;
}
return %out;
}
sub get_dest_filename {
my $newname = shift;
$newname =~ s/.*\/([^\/]*$)/$1/;
if ($os eq 'mac') {
$newname =~ s/\.so$/\.dylib/;
}
elsif ($os eq 'windows') {
$newname =~ s/\.so$/\.dll/;
}
return $newname;
}
sub build_plugin {
my ($package, $manifest, $ROOT, $out, $force_clean) = @_;
print "changing to: $ROOT/$manifest->{make}->{root}\n";
print "\ninvoking make\n";
if ($manifest->{make}->{type} eq 'make') {
print "make clean...\n";
if ($conf_use_cached_src || $force_clean) {
system ("cd $ROOT/$manifest->{make}->{root}; make clean");
}
print "make...\n";
system ("cd $ROOT/$manifest->{make}->{root}; make") && die "make finished with an error\n";
}
elsif ($manifest->{make}->{type} eq 'autotools') {
system ("cd $ROOT/$manifest->{make}->{root}; make distclean") if $conf_use_cached_src;
if (exists $manifest->{make}->{bootstrap}) {
system ("cd $ROOT/$manifest->{make}->{root}; $manifest->{make}->{bootstrap}") && die "$manifest->{make}->{bootstrap} finished with an error\n";
}
my $conf_flags = $CONFIGURE_FLAGS;
if (exists $manifest->{make}->{configure_flags}) {
$conf_flags .= ' '.$manifest->{make}->{configure_flags};
}
system ("cd $ROOT/$manifest->{make}->{root}; ./configure $conf_flags") && die "configure finished with an error\n";
# Windows libtool patch
if ($os eq 'windows' && -e "$ROOT/$manifest->{make}->{root}/libtool") {
print "patching libtool...\n";
system ("sed -i.bak -r -e \"s/(allow_undefined=)yes/\\1no/\" $ROOT/$manifest->{make}->{root}/libtool") && die "libtool patch finished with an error\n";
}
system ("cd $ROOT/$manifest->{make}->{root}; make clean") if $conf_use_cached_src;
system ("cd $ROOT/$manifest->{make}->{root}; make") && die "make finished with an error\n";
}
elsif ($manifest->{make}->{type} eq 'msbuild') {
system ("cd $ROOT/$manifest->{make}->{root}; MSYS2_ARG_CONV_EXCL=* powershell msbuild /m /p:Configuration=Release .") && die "msbuild finished with an error\n";
}
else {
die "make type '$manifest->{make}->{type}' is not supported\n";
}
next if $conf_nopackage;
print "packaging $package...\n";
# packaging
# each plugin must list its output
# the simple case is "out" list, that's for when plugin only consists of *.so
# output is 1st copied to 'temp/plugins' folder,
# then the plugins folder is zipped
my $outdir = "temp/output/$ARCH/plugins";
system ("rm -rf $outdir") && die "failed to remove $outdir\n";
system ("mkdir -p $outdir") && die "failed to mkdir $outdir\n";
for my $o (@{$out}) {
my $fname = "$ROOT/$o";
my $newname = get_dest_filename($o);
print "copying $fname to $outdir/$newname\n";
# some makefiles produce dlls directly
if ($os eq 'windows' && !-e $fname) {
$fname =~ s/\.so$/\.dll/;
if (!-e $fname) {
die "File $fname not found\n";
}
}
system ("cp $fname $outdir/$newname") && die "failed to copy $o to $outdir/$newname\n";
}
}