-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalienfile
125 lines (108 loc) · 3.44 KB
/
alienfile
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
## -*- mode: perl -*-
# https://github.com/ebiggers/libdeflate/archive/v1.0.tar.gz
use strict;
use warnings;
use alienfile;
use Path::Tiny qw{path};
use Alien::Build::CommandSequence;
## default helper deps Alien::MSYS for all systems?
meta->interpolator->replace_helper(install => sub {
return 'install';
});
plugin 'Probe::CBuilder' => (
cflags => join(' ', grep { defined && length } $ENV{ALIEN_LIBDEFLATE_PROBE_CFLAGS}),
libs => join(' ', grep { defined && length } $ENV{ALIEN_LIBDEFLATE_PROBE_LDFLAGS}, '-ldeflate'),
version => qr/([0-9\.]+)/,
program => <<'END_OF_CODE');
#include <stdio.h>
#include <libdeflate.h>
int main(int argc, char *argv[]) { printf("%s\n", LIBDEFLATE_VERSION_STRING); return 0; }
END_OF_CODE
meta->around_hook( gather_system => sub {
my $orig = shift;
my ($build) = @_;
$orig->(@_);
if( ! exists $build->runtime_prop->{ffi_name} ) {
$build->runtime_prop->{ffi_name} = 'deflate';
}
});
share {
## *bsd make is incompatible
requires 'Alien::gmake' => 0;
requires 'Config';
plugin 'Download::GitHub' => (
github_user => 'ebiggers',
github_repo => 'libdeflate',
asset_name => qr/^v.*\.tar\.gz$/,
version => qr/([0-9\.]+)/,
);
plugin Extract => ( format => 'tar.gz' );
meta_prop->{destdir} = $^O ne 'MSWin32' ? 1 : 0;
# Available targets:
# ------------------
# -e libdeflate.a
# -e libdeflate.so
# -e gzip
# -e gunzip
# -e benchmark
# -e test_checksums
# -e checksum
my $CC = qq(CC=@{[ $Config::Config{cc} ]});
my $static_lib = 'libdeflate.a';
my $shared_lib = qq(libdeflate.@{[ $Config::Config{so} ]});
my @progs = map { "$_@{[ $Config::Config{_exe} ]}" } qw(gzip gunzip);
build [
[ '%{gmake}',
$CC,
$static_lib, qw(STATIC_LIB_SUFFIX=.a),
@progs,
qw(CFLAGS=-fPIC),
],
[ '%{gmake}',
$CC,
$shared_lib,
],
sub {
my $build = shift;
my @dirs;
my %fileset = (
(map { $_ => path('include')->child($_)->stringify } qw{libdeflate.h}),
(map { $_ => path('lib')->child($_)->stringify } ( $static_lib, $shared_lib )),
(map { $_ => path('bin')->child("libdeflate-$_")->stringify } @progs),
);
my $process_file_cb;
if( exists $ENV{DESTDIR} ) {
$build->log("copy stuff to $ENV{DESTDIR}");
my $destdir = $ENV{DESTDIR};
my $destdir_abs = path($destdir)->child($build->install_prop->{prefix});
$process_file_cb = sub {
$destdir_abs->child(shift)->stringify
};
} else {
$process_file_cb = sub {
path($build->install_prop->{prefix})
->child(shift)->stringify
};
}
push @dirs, $process_file_cb->($_)
for (qw{include lib bin});
Alien::Build::CommandSequence->new(
(map { join ' ', '%{install} -d', $_ } @dirs),
(map {
join ' ', '%{install} -c', $_, $process_file_cb->($fileset{$_})
} keys %fileset),
)->execute($build);
}
];
plugin 'Gather::IsolateDynamic';
after gather => sub {
my $build = shift;
my $prefix = path($build->install_prop->{prefix})->absolute;
my $lib = $prefix->child('lib')->stringify;
my $include = $prefix->child('include');
my $dynamic = $prefix->child('lib', 'dynamic');
$build->runtime_prop->{cflags} = "-I$include";
$build->runtime_prop->{libs} = "-L$dynamic -ldeflate";
$build->runtime_prop->{libs_static} = "-L$lib -ldeflate";
};
};