]> git.imager.perl.org - imager.git/blob - PNG/Makefile.PL
add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / PNG / Makefile.PL
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 <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://github.com/tonycoz/imager.git",
44        web => "https://github.com/tonycoz/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
55 my @inc;
56 if ($BUILDING_IMAGER) {
57   push @inc, "-I..";
58   unshift @INC, "../lib";
59 }
60 else {
61   unshift @INC, "inc";
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
68   my @Imager_req = ( Imager => "0.90" );
69   if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
70     $opts{META_MERGE}{prereqs} =
71       {
72        configure =>
73        {
74         requires =>
75         {
76          @Imager_req,
77         },
78        },
79        build =>
80        {
81         requires =>
82         {
83          @Imager_req,
84          "Test::More" => "0.47",
85         }
86        },
87        runtime =>
88        {
89         requires =>
90         {
91          @Imager_req,
92         }
93        },
94        test =>
95        {
96         requires =>
97         {
98          "Test::More" => "0.47",
99         }
100        },
101       };
102     $opts{PREREQ_PM} =
103       {
104        @Imager_req,
105        XSLoader => 0,
106       };
107   }
108 }
109
110 require Imager::Probe;
111
112 # these are mostly needed when pkg-config isn't available
113 my @alts =
114   (
115    {
116     altname => "v1.6",
117     incsuffix => "libpng16",
118     libbase => "png16",
119    },
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
142 my %probe =
143   (
144    name => "PNG",
145    altname => "Generic",
146    pkg => [ qw/libpng libpng16 libpng15 libpng14 libpng12 libpng10/ ],
147    inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
148    libbase => "png",
149    testcode => _png_test_code(),
150    testcodeheaders => [ "png.h", "stdio.h" ],
151    incpath => \@incpaths,
152    libpath => \@libpaths,
153    verbose => $verbose,
154    alternatives =>
155    [
156     @alts,
157     {
158      altname => "base (+libz)",
159      libbase => [ "png", "z" ],
160     },
161     ( # a static libpng may require libz too
162      map +{
163            %$_,
164            altname => "$_->{altname} (+libz)",
165            libbase => [ $_->{libbase}, "z" ],
166           }, @alts
167     ),
168    ],
169   );
170
171 my $probe_res = Imager::Probe->probe(\%probe);
172 if ($probe_res) {
173   $IMAGER_LIBS{PNG} = 1;
174
175   push @inc, $probe_res->{INC};
176   $opts{LIBS} = $probe_res->{LIBS};
177   $opts{DEFINE} = $probe_res->{DEFINE};
178   $opts{INC} = "@inc";
179
180   WriteMakefile(%opts);
181 }
182 else {
183   $IMAGER_LIBS{PNG} = 0;
184
185   if ($BUILDING_IMAGER) {
186     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
187   }
188   else {
189     # fail in good way
190     die "OS unsupported: PNG libraries or headers not found\n";
191   }
192 }
193
194 sub _png_test_code {
195   return <<'CODE';
196
197 fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(),  (long)PNG_LIBPNG_VER);
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   }
203 return 0;
204 CODE
205 }