]> git.imager.perl.org - imager.git/blob - GIF/Makefile.PL
Revert the ivdformat probing
[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.94" );
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 %probe =
72   (
73    name => "GIF",
74    inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
75    libbase => "gif",
76    testcode => _gif_test_code(),
77    testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
78    incpath => \@incpaths,
79    libpath => \@libpaths,
80    verbose => $verbose,
81   );
82
83 my $probe_res = Imager::Probe->probe(\%probe);
84 if ($probe_res) {
85   $IMAGER_LIBS{GIF} = 1;
86
87   push @inc, $probe_res->{INC};
88   $opts{LIBS} = $probe_res->{LIBS};
89   $opts{DEFINE} = $probe_res->{DEFINE};
90   $opts{INC} = "@inc";
91   
92   if ($MM_ver > 6.06) {
93     $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
94     $opts{ABSTRACT} = 'GIF Image file support';
95   }
96   
97   WriteMakefile(%opts);
98 }
99 else {
100   $IMAGER_LIBS{GIF} = 0;
101
102   if ($BUILDING_IMAGER) {
103     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
104   }
105   else {
106     # fail in good way
107     die "OS unsupported: GIF libraries or headers not found\n";
108   }
109 }
110
111 sub _gif_test_code {
112   return <<'CODE';
113 /* TODO: test DGifOpen() and processing with callbacks */
114 GifFileType *gf;
115 #ifdef GIF_LIB_VERSION
116 const char vers[] = GIF_LIB_VERSION;
117 const char *versp = vers;
118 int ver_maj;
119 int ver_min;
120 #else
121 int ver_maj = GIFLIB_MAJOR;
122 int ver_min = GIFLIB_MINOR;
123 #endif
124 GifColorType colors[2];
125 ColorMapObject *map;
126 FILE *fh;
127 char buf[6];
128 int mode;
129 int error;
130 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
131 gf=DGifOpenFileName("testimg/expected.gif", &error);
132 #else
133 gf=DGifOpenFileName("testimg/expected.gif");
134 #endif
135 if (!gf) {
136   fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
137   return 1;
138 }
139 if (gf->SWidth != 16 || gf->SHeight != 16) {
140   fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
141   return 1;
142 }
143 #if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
144 /* crashes in older versions of giflib, not used in giflib 5 */
145 EGifSetGifVersion("89a");
146 EGifSetGifVersion("87a");
147 #endif
148
149 #ifdef GIF_LIB_VERSION
150 /* skip the " Version " */
151 while (*versp && (*versp < '0' || *versp > '9'))
152   ++versp;
153 if (!*versp) {
154   fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
155   return 1;
156 }
157 ver_maj = 0;
158 while (*versp && *versp >= '0' && *versp <= '9') {
159   ver_maj *= 10;
160   ver_maj += *versp++ - '0';
161 }
162 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
163   fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
164   return 1;
165 }
166 ++versp; /* skip '.' */
167 ver_min = 0;
168 while (*versp && *versp >= '0' && *versp <= '9') {
169   ver_min *= 10;
170   ver_min += *versp++ - '0';
171 }
172 #endif
173 if (ver_maj < 4) {
174   fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
175   return 1;
176 }
177 if (ver_maj == 4 && ver_min < 1) {
178   fprintf(stderr, "GIF: you need at least giflib 4.1\n");
179   return 1;
180 }
181
182 /* test we write both GIF87a and GIF89a files */
183 for (mode = 0; mode < 2; ++mode) {
184 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
185   gf=EGifOpenFileName("probe.gif", 0, &error);
186   EGifSetGifVersion(gf, mode);
187
188 #else
189   gf=EGifOpenFileName("probe.gif", 0);
190   EGifSetGifVersion(mode ? "89a" : "87a");
191 #endif
192   if (!gf) {
193     fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
194     return 1;
195   }
196   colors[0].Red = colors[0].Green = colors[0].Blue = 0;
197   colors[1].Red = colors[1].Green = colors[1].Blue = 0;
198 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
199   map = GifMakeMapObject(2, colors);
200 #else
201   map = MakeMapObject(2, colors);
202 #endif
203   EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
204   EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
205   EGifPutPixel(gf, 0);
206 #if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
207   EGifCloseFile(gf, &error);
208 #else
209   EGifCloseFile(gf);
210 #endif
211
212   fh = fopen("probe.gif", "r");
213   if (!fh) {
214     fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
215     return 1;
216   }
217   errno = 0;
218   memset(buf, 0, sizeof(buf));
219   if (fread(buf, 1, 6, fh) != 6) {
220     fprintf(stderr, "GIF: cannot read probe.gif header (%d)\n", errno);
221     return 1;
222   }
223   fclose(fh);
224   remove("probe.gif");
225   if (memcmp(buf, mode ? "GIF89a" : "GIF87a", 6)) {
226     fprintf(stderr, "GIF: incorrect header on test - 4.2.0 bug? (mode %d, buf %-6s)\n", mode, buf);
227     return 1;
228   }
229 }
230
231 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
232 return 0;
233 CODE
234 }