3 use ExtUtils::MakeMaker;
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
20 NAME => 'Imager::File::GIF',
21 VERSION_FROM => 'GIF.pm',
22 OBJECT => 'GIF.o imgif.o',
23 clean => { FILES => 'testout' },
26 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
27 $opts{LICENSE} = "perl_5";
28 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
29 $opts{ABSTRACT} = 'GIF Image file support for Imager';
35 url => "https://metacpan.org/pod/CPAN::Meta::Spec",
39 homepage => "http://imager.perl.org/",
43 url => "git://git.imager.perl.org/imager.git",
44 web => "http://git.imager.perl.org/imager.git",
48 web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
49 mailto => 'bug-Imager@rt.cpan.org',
56 if ($BUILDING_IMAGER) {
58 unshift @INC, "../lib";
62 print "GIF: building independently\n";
63 require Imager::ExtUtils;
64 push @inc, Imager::ExtUtils->includes;
65 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
67 # Imager required configure through use
68 my @Imager_req = ( Imager => "0.94" );
69 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
70 $opts{META_MERGE}{prereqs} =
84 "Test::More" => "0.47",
98 "Test::More" => "0.47",
110 require Imager::Probe;
115 inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
117 testcode => _gif_test_code(),
118 testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
119 incpath => \@incpaths,
120 libpath => \@libpaths,
124 my $probe_res = Imager::Probe->probe(\%probe);
126 $IMAGER_LIBS{GIF} = 1;
128 push @inc, $probe_res->{INC};
129 $opts{LIBS} = $probe_res->{LIBS};
130 $opts{DEFINE} = $probe_res->{DEFINE};
133 WriteMakefile(%opts);
136 $IMAGER_LIBS{GIF} = 0;
138 if ($BUILDING_IMAGER) {
139 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
143 die "OS unsupported: GIF libraries or headers not found\n";
149 /* TODO: test DGifOpen() and processing with callbacks */
151 #ifdef GIF_LIB_VERSION
152 const char vers[] = GIF_LIB_VERSION;
153 const char *versp = vers;
157 int ver_maj = GIFLIB_MAJOR;
158 int ver_min = GIFLIB_MINOR;
160 GifColorType colors[2];
166 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
167 gf=DGifOpenFileName("testimg/expected.gif", &error);
169 gf=DGifOpenFileName("testimg/expected.gif");
172 fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
175 if (gf->SWidth != 16 || gf->SHeight != 16) {
176 fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
179 #if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
180 /* crashes in older versions of giflib, not used in giflib 5 */
181 EGifSetGifVersion("89a");
182 EGifSetGifVersion("87a");
185 #ifdef GIF_LIB_VERSION
186 /* skip the " Version " */
187 while (*versp && (*versp < '0' || *versp > '9'))
190 fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
194 while (*versp && *versp >= '0' && *versp <= '9') {
196 ver_maj += *versp++ - '0';
198 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
199 fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
202 ++versp; /* skip '.' */
204 while (*versp && *versp >= '0' && *versp <= '9') {
206 ver_min += *versp++ - '0';
210 fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
213 if (ver_maj == 4 && ver_min < 1) {
214 fprintf(stderr, "GIF: you need at least giflib 4.1\n");
218 /* test we write both GIF87a and GIF89a files */
219 for (mode = 0; mode < 2; ++mode) {
220 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
221 gf=EGifOpenFileName("probe.gif", 0, &error);
222 EGifSetGifVersion(gf, mode);
225 gf=EGifOpenFileName("probe.gif", 0);
226 EGifSetGifVersion(mode ? "89a" : "87a");
229 fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
232 colors[0].Red = colors[0].Green = colors[0].Blue = 0;
233 colors[1].Red = colors[1].Green = colors[1].Blue = 0;
234 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
235 map = GifMakeMapObject(2, colors);
237 map = MakeMapObject(2, colors);
239 EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
240 EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
242 #if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
243 EGifCloseFile(gf, &error);
248 fh = fopen("probe.gif", "r");
250 fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
254 memset(buf, 0, sizeof(buf));
255 if (fread(buf, 1, 6, fh) != 6) {
256 fprintf(stderr, "GIF: cannot read probe.gif header (%d)\n", errno);
261 if (memcmp(buf, mode ? "GIF89a" : "GIF87a", 6)) {
262 fprintf(stderr, "GIF: incorrect header on test - 4.2.0 bug? (mode %d, buf %-6s)\n", mode, buf);
267 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);