c7924ddb0b022699deb94c3f86b02db8b5c17f8c
[imager.git] / PNG / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
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
17 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
18
19 my %opts = 
20   (
21    NAME => 'Imager::File::PNG',
22    VERSION_FROM => 'PNG.pm',
23    OBJECT => 'PNG.o impng.o',
24   );
25
26 my @inc;
27 if ($BUILDING_IMAGER) {
28   push @inc, "-I..";
29   unshift @INC, "../lib";
30 }
31 else {
32   unshift @INC, "inc";
33   print "PNG: building independently\n";
34   require Imager::ExtUtils;
35   push @inc, Imager::ExtUtils->includes;
36   $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
37
38   # Imager required configure through use
39   my @Imager_req = ( Imager => "0.77" );
40   if ($MM_ver >= 6.46) {
41     $opts{META_MERGE} =
42       {
43        configure_requires => 
44        {
45         @Imager_req,
46        },
47        build_requires => 
48        {
49         @Imager_req,
50         "Test::More" => "0.47",
51        },
52        resources =>
53        {
54         homepage => "http://imager.perl.org/",
55         repository =>
56         {
57          url => "http://imager.perl.org/svn/trunk/Imager-File-PNG",
58          web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-File-PNG",
59          type => "svn",
60         },
61        },
62       };
63     $opts{PREREQ_PM} =
64       {
65        @Imager_req,
66       };
67   }
68 }
69
70 require Imager::Probe;
71
72 my %probe =
73   (
74    name => "PNG",
75    altname => "Generic",
76    pkg => [ qw/libpng14 libpng12 libpng10 libpng/ ],
77    inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
78    libbase => "png",
79    testcode => _png_test_code(),
80    testcodeheaders => [ "png.h", "stdio.h" ],
81    incpath => join($Config{path_sep}, @incpaths),
82    libpath => join($Config{path_sep}, @libpaths),
83    alternatives =>
84    [
85     {
86      altname => "v1.4",
87      incsuffix => "libpng14",
88      libbase => "png14",
89     },
90     {
91      altname => "v1.2",
92      incsuffix => "libpng12",
93      libbase => "png12",
94     },
95     {
96      altname => "v1.0",
97      incsuffix => "libpng10",
98      libbase => "png10",
99     },
100    ],
101   );
102
103 my $probe_res = Imager::Probe->probe(\%probe);
104 if ($probe_res) {
105   push @inc, $probe_res->{INC};
106   $opts{LIBS} = $probe_res->{LIBS};
107   
108   $opts{INC} = "@inc";
109   
110   if ($MM_ver > 6.06) {
111     $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
112     $opts{ABSTRACT} = 'PNG Image file support';
113   }
114   
115   WriteMakefile(%opts);
116 }
117 else {
118   if ($BUILDING_IMAGER) {
119     WriteEmptyMakefile(%opts);
120   }
121   else {
122     # fail in good way
123     die "OS unsupported: PNG libraries or headers not found\n";
124   }
125 }
126
127 sub _png_test_code {
128   return <<'CODE';
129
130 fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(),  (long)PNG_LIBPNG_VER);
131 return 0;
132 CODE
133 }