]> git.imager.perl.org - imager.git/blob - PNG/Makefile.PL
support tied file handles
[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 my @alts =
72   (
73    {
74     altname => "v1.5",
75     incsuffix => "libpng15",
76     libbase => "png15",
77    },
78    {
79     altname => "v1.4",
80     incsuffix => "libpng14",
81     libbase => "png14",
82    },
83    {
84     altname => "v1.2",
85     incsuffix => "libpng12",
86     libbase => "png12",
87    },
88    {
89     altname => "v1.0",
90     incsuffix => "libpng10",
91     libbase => "png10",
92    },
93   );
94
95 my %probe =
96   (
97    name => "PNG",
98    altname => "Generic",
99    pkg => [ qw/libpng15 libpng14 libpng12 libpng10 libpng/ ],
100    inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
101    libbase => "png",
102    testcode => _png_test_code(),
103    testcodeheaders => [ "png.h", "stdio.h" ],
104    incpath => \@incpaths,
105    libpath => \@libpaths,
106    verbose => $verbose,
107    alternatives =>
108    [
109     @alts,
110     {
111      altname => "base (+libz)",
112      libbase => [ "png", "z" ],
113     },
114     ( # a static libpng may require libz too
115      map +{
116            %$_,
117            altname => "$_->{altname} (+libz)",
118            libbase => [ $_->{libbase}, "z" ],
119           }, @alts
120     ),
121    ],
122   );
123
124 my $probe_res = Imager::Probe->probe(\%probe);
125 if ($probe_res) {
126   $IMAGER_LIBS{PNG} = 1;
127
128   push @inc, $probe_res->{INC};
129   $opts{LIBS} = $probe_res->{LIBS};
130   $opts{DEFINE} = $probe_res->{DEFINE};
131   $opts{INC} = "@inc";
132   
133   if ($MM_ver > 6.06) {
134     $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
135     $opts{ABSTRACT} = 'PNG Image file support';
136   }
137   
138   WriteMakefile(%opts);
139 }
140 else {
141   $IMAGER_LIBS{PNG} = 0;
142
143   if ($BUILDING_IMAGER) {
144     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
145   }
146   else {
147     # fail in good way
148     die "OS unsupported: PNG libraries or headers not found\n";
149   }
150 }
151
152 sub _png_test_code {
153   return <<'CODE';
154
155 fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(),  (long)PNG_LIBPNG_VER);
156 return 0;
157 CODE
158 }