]> git.imager.perl.org - imager.git/blob - PNG/Makefile.PL
try probing for a valid ivdformat if the %Config value is bad
[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 $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
19
20 my %opts = 
21   (
22    NAME => 'Imager::File::PNG',
23    VERSION_FROM => 'PNG.pm',
24    OBJECT => 'PNG.o impng.o',
25    clean => { FILES => 'testout' },
26   );
27
28 my @inc;
29 if ($BUILDING_IMAGER) {
30   push @inc, "-I..";
31   unshift @INC, "../lib";
32 }
33 else {
34   unshift @INC, "inc";
35   print "PNG: building independently\n";
36   require Imager::ExtUtils;
37   push @inc, Imager::ExtUtils->includes;
38   $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
39
40   # Imager required configure through use
41   my @Imager_req = ( Imager => "0.90" );
42   if ($MM_ver >= 6.46) {
43     $opts{META_MERGE} =
44       {
45        configure_requires => 
46        {
47         @Imager_req,
48        },
49        build_requires => 
50        {
51         @Imager_req,
52         "Test::More" => "0.47",
53        },
54        resources =>
55        {
56         homepage => "http://imager.perl.org/",
57         repository => "git://git.imager.perl.org/imager.git",
58         bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
59        },
60       };
61     $opts{PREREQ_PM} =
62       {
63        @Imager_req,
64        XSLoader => 0,
65       };
66   }
67 }
68
69 require Imager::Probe;
70
71 # these are mostly needed when pkg-config isn't available
72 my @alts =
73   (
74    {
75     altname => "v1.6",
76     incsuffix => "libpng16",
77     libbase => "png16",
78    },
79    {
80     altname => "v1.5",
81     incsuffix => "libpng15",
82     libbase => "png15",
83    },
84    {
85     altname => "v1.4",
86     incsuffix => "libpng14",
87     libbase => "png14",
88    },
89    {
90     altname => "v1.2",
91     incsuffix => "libpng12",
92     libbase => "png12",
93    },
94    {
95     altname => "v1.0",
96     incsuffix => "libpng10",
97     libbase => "png10",
98    },
99   );
100
101 my %probe =
102   (
103    name => "PNG",
104    altname => "Generic",
105    pkg => [ qw/libpng libpng16 libpng15 libpng14 libpng12 libpng10/ ],
106    inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
107    libbase => "png",
108    testcode => _png_test_code(),
109    testcodeheaders => [ "png.h", "stdio.h" ],
110    incpath => \@incpaths,
111    libpath => \@libpaths,
112    verbose => $verbose,
113    alternatives =>
114    [
115     @alts,
116     {
117      altname => "base (+libz)",
118      libbase => [ "png", "z" ],
119     },
120     ( # a static libpng may require libz too
121      map +{
122            %$_,
123            altname => "$_->{altname} (+libz)",
124            libbase => [ $_->{libbase}, "z" ],
125           }, @alts
126     ),
127    ],
128   );
129
130 my $probe_res = Imager::Probe->probe(\%probe);
131 if ($probe_res) {
132   $IMAGER_LIBS{PNG} = 1;
133
134   push @inc, $probe_res->{INC};
135   $opts{LIBS} = $probe_res->{LIBS};
136   $opts{DEFINE} = $probe_res->{DEFINE};
137   $opts{INC} = "@inc";
138   
139   if ($MM_ver > 6.06) {
140     $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
141     $opts{ABSTRACT} = 'PNG Image file support';
142   }
143   
144   WriteMakefile(%opts);
145 }
146 else {
147   $IMAGER_LIBS{PNG} = 0;
148
149   if ($BUILDING_IMAGER) {
150     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
151   }
152   else {
153     # fail in good way
154     die "OS unsupported: PNG libraries or headers not found\n";
155   }
156 }
157
158 sub _png_test_code {
159   return <<'CODE';
160
161 fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(),  (long)PNG_LIBPNG_VER);
162
163   if (png_access_version_number() != PNG_LIBPNG_VER) {
164      fprintf(stderr, "PNG: Your header version number doesn't match the library version number\n");
165      return 1;
166   }
167 return 0;
168 CODE
169 }