]> git.imager.perl.org - imager.git/blob - GIF/Makefile.PL
replace (imager|tony)@imager.perl.org with tonyc@cpan.org
[imager.git] / GIF / 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::GIF',
23    VERSION_FROM => 'GIF.pm',
24    OBJECT => 'GIF.o imgif.o',
25    clean => { FILES => 'testout' },
26   );
27
28 my @inc;
29 if ($BUILDING_IMAGER) {
30   unshift @inc, "-I..";
31   unshift @INC, "../lib";
32 }
33 else {
34   unshift @INC, "inc";
35   print "GIF: 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.84" );
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 =>
58         {
59          url => "http://imager.perl.org/svn/trunk/Imager/GIF",
60          web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/GIF",
61          type => "svn",
62         },
63        },
64       };
65     $opts{PREREQ_PM} =
66       {
67        @Imager_req,
68       };
69   }
70 }
71
72 require Imager::Probe;
73
74 my %probe =
75   (
76    name => "GIF",
77    inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
78    libbase => "gif",
79    testcode => _gif_test_code(),
80    testcodeheaders => [ "gif_lib.h", "stdio.h" ],
81    incpath => \@incpaths,
82    libpath => \@libpaths,
83   );
84
85 my $probe_res = Imager::Probe->probe(\%probe);
86 if ($probe_res) {
87   $IMAGER_LIBS{GIF} = 1;
88
89   push @inc, $probe_res->{INC};
90   $opts{LIBS} = $probe_res->{LIBS};
91   $opts{DEFINE} = $probe_res->{DEFINE};
92   $opts{INC} = "@inc";
93   
94   if ($MM_ver > 6.06) {
95     $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
96     $opts{ABSTRACT} = 'GIF Image file support';
97   }
98   
99   WriteMakefile(%opts);
100 }
101 else {
102   $IMAGER_LIBS{GIF} = 0;
103
104   if ($BUILDING_IMAGER) {
105     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
106   }
107   else {
108     # fail in good way
109     die "OS unsupported: GIF libraries or headers not found\n";
110   }
111 }
112
113 sub _gif_test_code {
114   return <<'CODE';
115 /* TODO: test DGifOpen() and processing with callbacks */
116 GifFileType *gf;
117 const char vers[] = GIF_LIB_VERSION;
118 const char *versp = vers;
119 int ver_maj;
120 int ver_min;
121 gf=DGifOpenFileName("testimg/expected.gif");
122 if (!gf) {
123   fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
124   return 1;
125 }
126 if (gf->SWidth != 16 || gf->SHeight != 16) {
127   fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
128   return 1;
129 }
130 /* crashes in older versions of giflib */
131 EGifSetGifVersion("89a");
132 EGifSetGifVersion("87a");
133
134 /* skip the " Version " */
135 while (*versp && (*versp < '0' || *versp > '9'))
136   ++versp;
137 if (!*versp) {
138   fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
139   return 1;
140 }
141 ver_maj = 0;
142 while (*versp && *versp >= '0' && *versp <= '9') {
143   ver_maj *= 10;
144   ver_maj += *versp++ - '0';
145 }
146 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
147   fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
148   return 1;
149 }
150 ++versp; /* skip '.' */
151 ver_min = 0;
152 while (*versp && *versp >= '0' && *versp <= '9') {
153   ver_min *= 10;
154   ver_min += *versp++ - '0';
155 }
156 if (ver_maj < 4) {
157   fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
158   return 1;
159 }
160 if (ver_maj == 4 && ver_min < 1) {
161   fprintf(stderr, "GIF: you need at least giflib 4.1\n");
162   return 1;
163 }
164 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
165 return 0;
166 CODE
167 }