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