| 1 |
#!perl -w |
| 2 |
use strict; |
| 3 |
use ExtUtils::MakeMaker; |
| 4 |
use Getopt::Long; |
| 5 |
use Config; |
| 6 |
|
| 7 |
my $verbose = $ENV{IM_VERBOSE}; |
| 8 |
my @libpaths; |
| 9 |
my @incpaths; |
| 10 |
|
| 11 |
GetOptions("incpath=s", \@incpaths, |
| 12 |
"libpath=s" => \@libpaths, |
| 13 |
"verbose|v" => \$verbose); |
| 14 |
|
| 15 |
our $BUILDING_IMAGER; |
| 16 |
our %IMAGER_LIBS; |
| 17 |
|
| 18 |
my %opts = |
| 19 |
( |
| 20 |
NAME => 'Imager::File::PNG', |
| 21 |
VERSION_FROM => 'PNG.pm', |
| 22 |
OBJECT => 'PNG.o impng.o', |
| 23 |
clean => { FILES => 'testout' }, |
| 24 |
); |
| 25 |
|
| 26 |
if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
| 27 |
$opts{LICENSE} = "perl_5"; |
| 28 |
$opts{AUTHOR} = 'Tony Cook <[email protected]>'; |
| 29 |
$opts{ABSTRACT} = 'PNG Image file support for Imager'; |
| 30 |
$opts{META_MERGE} = |
| 31 |
{ |
| 32 |
'meta-spec' => |
| 33 |
{ |
| 34 |
version => "2", |
| 35 |
url => "https://metacpan.org/pod/CPAN::Meta::Spec", |
| 36 |
}, |
| 37 |
resources => |
| 38 |
{ |
| 39 |
homepage => "http://imager.perl.org/", |
| 40 |
repository => |
| 41 |
{ |
| 42 |
type => "git", |
| 43 |
url => "git://github.com/tonycoz/imager.git", |
| 44 |
web => "https://github.com/tonycoz/imager.git", |
| 45 |
}, |
| 46 |
bugtracker => |
| 47 |
{ |
| 48 |
web => "https://github.com/tonycoz/imager/issues", |
| 49 |
}, |
| 50 |
}, |
| 51 |
}; |
| 52 |
} |
| 53 |
|
| 54 |
my @inc; |
| 55 |
if ($BUILDING_IMAGER) { |
| 56 |
push @inc, "-I.."; |
| 57 |
unshift @INC, "../lib"; |
| 58 |
} |
| 59 |
else { |
| 60 |
unshift @INC, "inc"; |
| 61 |
print "PNG: building independently\n"; |
| 62 |
require Imager::ExtUtils; |
| 63 |
push @inc, Imager::ExtUtils->includes; |
| 64 |
$opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ]; |
| 65 |
|
| 66 |
# Imager required configure through use |
| 67 |
my @Imager_req = ( Imager => "0.90" ); |
| 68 |
if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
| 69 |
$opts{META_MERGE}{prereqs} = |
| 70 |
{ |
| 71 |
configure => |
| 72 |
{ |
| 73 |
requires => |
| 74 |
{ |
| 75 |
@Imager_req, |
| 76 |
}, |
| 77 |
}, |
| 78 |
build => |
| 79 |
{ |
| 80 |
requires => |
| 81 |
{ |
| 82 |
@Imager_req, |
| 83 |
"Test::More" => "0.47", |
| 84 |
} |
| 85 |
}, |
| 86 |
runtime => |
| 87 |
{ |
| 88 |
requires => |
| 89 |
{ |
| 90 |
@Imager_req, |
| 91 |
} |
| 92 |
}, |
| 93 |
test => |
| 94 |
{ |
| 95 |
requires => |
| 96 |
{ |
| 97 |
"Test::More" => "0.47", |
| 98 |
} |
| 99 |
}, |
| 100 |
}; |
| 101 |
$opts{PREREQ_PM} = |
| 102 |
{ |
| 103 |
@Imager_req, |
| 104 |
XSLoader => 0, |
| 105 |
}; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
require Imager::Probe; |
| 110 |
|
| 111 |
# these are mostly needed when pkg-config isn't available |
| 112 |
my @alts = |
| 113 |
( |
| 114 |
{ |
| 115 |
altname => "v1.6", |
| 116 |
incsuffix => "libpng16", |
| 117 |
libbase => "png16", |
| 118 |
}, |
| 119 |
{ |
| 120 |
altname => "v1.5", |
| 121 |
incsuffix => "libpng15", |
| 122 |
libbase => "png15", |
| 123 |
}, |
| 124 |
{ |
| 125 |
altname => "v1.4", |
| 126 |
incsuffix => "libpng14", |
| 127 |
libbase => "png14", |
| 128 |
}, |
| 129 |
{ |
| 130 |
altname => "v1.2", |
| 131 |
incsuffix => "libpng12", |
| 132 |
libbase => "png12", |
| 133 |
}, |
| 134 |
{ |
| 135 |
altname => "v1.0", |
| 136 |
incsuffix => "libpng10", |
| 137 |
libbase => "png10", |
| 138 |
}, |
| 139 |
); |
| 140 |
|
| 141 |
my %probe = |
| 142 |
( |
| 143 |
name => "PNG", |
| 144 |
altname => "Generic", |
| 145 |
pkg => [ qw/libpng libpng16 libpng15 libpng14 libpng12 libpng10/ ], |
| 146 |
inccheck => sub { -e File::Spec->catfile($_[0], "png.h") }, |
| 147 |
libbase => "png", |
| 148 |
testcode => _png_test_code(), |
| 149 |
testcodeheaders => [ "png.h", "stdio.h" ], |
| 150 |
incpath => \@incpaths, |
| 151 |
libpath => \@libpaths, |
| 152 |
verbose => $verbose, |
| 153 |
alternatives => |
| 154 |
[ |
| 155 |
@alts, |
| 156 |
{ |
| 157 |
altname => "base (+libz)", |
| 158 |
libbase => [ "png", "z" ], |
| 159 |
}, |
| 160 |
( # a static libpng may require libz too |
| 161 |
map +{ |
| 162 |
%$_, |
| 163 |
altname => "$_->{altname} (+libz)", |
| 164 |
libbase => [ $_->{libbase}, "z" ], |
| 165 |
}, @alts |
| 166 |
), |
| 167 |
], |
| 168 |
); |
| 169 |
|
| 170 |
my $probe_res = Imager::Probe->probe(\%probe); |
| 171 |
if ($probe_res) { |
| 172 |
$IMAGER_LIBS{PNG} = 1; |
| 173 |
|
| 174 |
push @inc, $probe_res->{INC}; |
| 175 |
$opts{LIBS} = $probe_res->{LIBS}; |
| 176 |
$opts{DEFINE} = $probe_res->{DEFINE}; |
| 177 |
$opts{INC} = "@inc"; |
| 178 |
|
| 179 |
WriteMakefile(%opts); |
| 180 |
} |
| 181 |
else { |
| 182 |
$IMAGER_LIBS{PNG} = 0; |
| 183 |
|
| 184 |
if ($BUILDING_IMAGER) { |
| 185 |
ExtUtils::MakeMaker::WriteEmptyMakefile(%opts); |
| 186 |
} |
| 187 |
else { |
| 188 |
# fail in good way |
| 189 |
die "OS unsupported: PNG libraries or headers not found\n"; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
sub _png_test_code { |
| 194 |
return <<'CODE'; |
| 195 |
|
| 196 |
fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(), (long)PNG_LIBPNG_VER); |
| 197 |
|
| 198 |
if (png_access_version_number() != PNG_LIBPNG_VER) { |
| 199 |
fprintf(stderr, "PNG: Your header version number doesn't match the library version number\n"); |
| 200 |
return 1; |
| 201 |
} |
| 202 |
return 0; |
| 203 |
CODE |
| 204 |
} |