File Coverage

example/bzip2.alienfile
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1 1     1   9 use alienfile;
  1         3  
  1         6  
2 1     1   7 use Path::Tiny qw( path );
  1         2  
  1         463  
3              
4             # Because bzip2 does not come with a pkg-config compatible .pc file
5             # we use the CBuilder plugin to guess the appropriate flags
6             # (usually just libs=-lbz2):
7             plugin 'Probe::CBuilder' => (
8             libs => '-lbz2',
9              
10             # The version regex here will attempt to parse out the
11             # bzip2 version number from the output of the test program below.
12             version => qr/version = '(.*?)[,']/,
13              
14             # Both the test program and the version regex are optional, but
15             # if you do not provide them, then you should provide a
16             # sys { gather } declaration for how to obtain the version number.
17             # assuming the version number matters.
18             program => q{
19             #include
20             #include
21              
22             int main(int argc, char *argv[])
23             {
24             printf("version = '%s'\n", BZ2_bzlibVersion());
25             return 0;
26             }
27             },
28             );
29              
30             # in addition to the library, we require that the bzip2 command
31             # is also available.
32             plugin 'Probe::CommandLine' => (
33             command => 'bzip2',
34             secondary => 1,
35             );
36              
37             share {
38              
39             # items in the share block relate to building the package
40             # from source. It is called share because it will be
41             # installed into a dist level share directory in your
42             # perl lib.
43              
44             # The Build::MSYS plugin just makes sure that Alien::MSYS
45             # is used to provide the necessary tools on Windows. It
46             # doesn't do anything on other platforms.
47             plugin 'Build::MSYS';
48              
49             # The Download negotiator picks the best method for
50             # downloading the package.
51             plugin 'Download' => (
52             url => 'https://sourceforge.net/projects/bzip2/files/latest/download',
53             );
54              
55             # The Extract negotiator picks the best method for
56             # extracting from the tarball. We give it a hint
57             # here that we expect the tarball to be .gz compressed
58             # in case it needs to load extra modules to
59             # decompress.
60             plugin Extract => 'tar.gz';
61              
62             # The build stage here is specified as a series of commands.
63             # bzip2 uses make to build and install. It is vital that we
64             # include cccdlflags in the compiler flags, because this will
65             # include any flags necessary for making the library relocatable
66             # which we need to link into a Perl XS .so file.
67             # We also use CC=$Config{cc} to make sure that we use the
68             # same compiler as was used to build Perl.
69             build [
70             [ '%{make}', 'all', "CC=%{perl.config.cc}", "CFLAGS=%{perl.config.cccdlflags} %{perl.config.optimize}", ],
71             [ '%{make}', 'install', 'PREFIX=%{.install.prefix}', ],
72              
73             # we can use a code ref here to determine the version number of
74             # bzip2 from the directory that is extracted from the tarball.
75             # Usually this is something like bzip2-1.0.6 and we just parse
76             # off the bit that looks like a version number.
77             sub {
78             my($build) = @_;
79             my($version) = path(".")->absolute->basename =~ /([0-9\.]+)$/;
80             $build->runtime_prop->{version} = $version;
81             },
82             ];
83              
84             # This package doesn't build a dynamic library by default, but if
85             # it did this would make sure that it wasn't used with XS.
86             # (See Alien::Build::Manual::AlienAuthor for details).
87             plugin 'Gather::IsolateDynamic';
88              
89             # The gather stage determines the appropriate cflags and libs for
90             # using the library that we just built.
91             gather sub {
92             my($build) =@_;
93             my $prefix = $build->runtime_prop->{prefix};
94             $build->runtime_prop->{cflags} = "-I$prefix/include";
95             $build->runtime_prop->{cflags_static} = "-I$prefix/include";
96             $build->runtime_prop->{libs} = "-L$prefix/lib -lbz2";
97             $build->runtime_prop->{libs_static} = "-L$prefix/lib -lbz2";
98             };
99              
100             };