Debian Codegraph @

GIF/Makefile.PL

raw
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 %opts =
19 (
20 NAME => 'Imager::File::GIF',
21 VERSION_FROM => 'GIF.pm',
22 OBJECT => 'GIF.o imgif.o',
23 clean => { FILES => 'testout' },
24 );
25
26 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
27 $opts{LICENSE} = "perl_5";
28 $opts{AUTHOR} = 'Tony Cook <[email protected]>';
29 $opts{ABSTRACT} = 'GIF Image file support for Imager';
30 $opts{META_MERGE} =
31 {
32 'meta-spec' =>
33 {
34 version => "2",
35 url => "https://metacpan.org/pod/CPAN::Meta::Spec",
36 },
37 resources =>
38 {
39 homepage => "http://imager.perl.org/",
40 repository =>
41 {
42 type => "git",
43 url => "git://github.com/tonycoz/imager.git",
44 web => "https://github.com/tonycoz/imager.git",
45 },
46 bugtracker =>
47 {
48 web => "https://github.com/tonycoz/imager/issues",
49 },
50 },
51 };
52 }
53
54 my @inc;
55 if ($BUILDING_IMAGER) {
56 unshift @inc, "-I..";
57 unshift @INC, "../lib";
58 }
59 else {
60 unshift @INC, "inc";
61 print "GIF: building independently\n";
62 require Imager::ExtUtils;
63 push @inc, Imager::ExtUtils->includes;
64 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
65
66 # Imager required configure through use
67 my @Imager_req = ( Imager => "0.94" );
68 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
69 $opts{META_MERGE}{prereqs} =
70 {
71 configure =>
72 {
73 requires =>
74 {
75 @Imager_req,
76 },
77 },
78 build =>
79 {
80 requires =>
81 {
82 @Imager_req,
83 "Test::More" => "0.47",
84 }
85 },
86 runtime =>
87 {
88 requires =>
89 {
90 @Imager_req,
91 }
92 },
93 test =>
94 {
95 requires =>
96 {
97 "Test::More" => "0.47",
98 }
99 },
100 };
101 $opts{PREREQ_PM} =
102 {
103 @Imager_req,
104 XSLoader => 0,
105 };
106 }
107 }
108
109 require Imager::Probe;
110
111 my %probe =
112 (
113 name => "GIF",
114 inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
115 libbase => "gif",
116 testcode => _gif_test_code(),
117 testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
118 incpath => \@incpaths,
119 libpath => \@libpaths,
120 verbose => $verbose,
121 );
122
123 my $probe_res = Imager::Probe->probe(\%probe);
124 if ($probe_res) {
125 $IMAGER_LIBS{GIF} = 1;
126
127 push @inc, $probe_res->{INC};
128 $opts{LIBS} = $probe_res->{LIBS};
129 $opts{DEFINE} = $probe_res->{DEFINE};
130 $opts{INC} = "@inc";
131
132 WriteMakefile(%opts);
133 }
134 else {
135 $IMAGER_LIBS{GIF} = 0;
136
137 if ($BUILDING_IMAGER) {
138 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
139 }
140 else {
141 # fail in good way
142 die "OS unsupported: GIF libraries or headers not found\n";
143 }
144 }
145
146 sub _gif_test_code {
147 return <<'CODE';
148 /* TODO: test DGifOpen() and processing with callbacks */
149 GifFileType *gf;
150 #ifdef GIF_LIB_VERSION
151 const char vers[] = GIF_LIB_VERSION;
152 const char *versp = vers;
153 int ver_maj;
154 int ver_min;
155 #else
156 int ver_maj = GIFLIB_MAJOR;
157 int ver_min = GIFLIB_MINOR;
158 #endif
159 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
160 int errorcode;
161 #endif
162 GifColorType colors[2];
163 ColorMapObject *map;
164 FILE *fh;
165 char buf[6];
166 int mode;
167 int error;
168 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
169 gf=DGifOpenFileName("testimg/expected.gif", &error);
170 #else
171 gf=DGifOpenFileName("testimg/expected.gif");
172 #endif
173 if (!gf) {
174 fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
175 return 1;
176 }
177 if (gf->SWidth != 16 || gf->SHeight != 16) {
178 fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
179 return 1;
180 }
181 #if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
182 /* crashes in older versions of giflib, not used in giflib 5 */
183 EGifSetGifVersion("89a");
184 EGifSetGifVersion("87a");
185 #endif
186 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
187 DGifCloseFile(gf, &errorcode);
188 #else
189 DGifCloseFile(gf);
190 #endif
191
192 #ifdef GIF_LIB_VERSION
193 /* skip the " Version " */
194 while (*versp && (*versp < '0' || *versp > '9'))
195 ++versp;
196 if (!*versp) {
197 fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
198 return 1;
199 }
200 ver_maj = 0;
201 while (*versp && *versp >= '0' && *versp <= '9') {
202 ver_maj *= 10;
203 ver_maj += *versp++ - '0';
204 }
205 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
206 fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
207 return 1;
208 }
209 ++versp; /* skip '.' */
210 ver_min = 0;
211 while (*versp && *versp >= '0' && *versp <= '9') {
212 ver_min *= 10;
213 ver_min += *versp++ - '0';
214 }
215 #endif
216 if (ver_maj < 4) {
217 fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
218 return 1;
219 }
220 if (ver_maj == 4 && ver_min < 1) {
221 fprintf(stderr, "GIF: you need at least giflib 4.1\n");
222 return 1;
223 }
224
225 /* test we write both GIF87a and GIF89a files */
226 for (mode = 0; mode < 2; ++mode) {
227 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
228 gf=EGifOpenFileName("probe.gif", 0, &error);
229 EGifSetGifVersion(gf, mode);
230
231 #else
232 gf=EGifOpenFileName("probe.gif", 0);
233 EGifSetGifVersion(mode ? "89a" : "87a");
234 #endif
235 if (!gf) {
236 fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
237 return 1;
238 }
239 colors[0].Red = colors[0].Green = colors[0].Blue = 0;
240 colors[1].Red = colors[1].Green = colors[1].Blue = 0;
241 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
242 map = GifMakeMapObject(2, colors);
243 #else
244 map = MakeMapObject(2, colors);
245 #endif
246 EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
247 EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
248 EGifPutPixel(gf, 0);
249 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
250 GifFreeMapObject(map);
251 #else
252 FreeMapObject(map);
253 #endif
254 #if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
255 EGifCloseFile(gf, &error);
256 #else
257 EGifCloseFile(gf);
258 #endif
259
260 fh = fopen("probe.gif", "r");
261 if (!fh) {
262 fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
263 return 1;
264 }
265 errno = 0;
266 memset(buf, 0, sizeof(buf));
267 if (fread(buf, 1, 6, fh) != 6) {
268 fprintf(stderr, "GIF: cannot read probe.gif header (%d)\n", errno);
269 return 1;
270 }
271 fclose(fh);
272 remove("probe.gif");
273 if (memcmp(buf, mode ? "GIF89a" : "GIF87a", 6)) {
274 fprintf(stderr, "GIF: incorrect header on test - 4.2.0 bug? (mode %d, buf %-6s)\n", mode, buf);
275 return 1;
276 }
277 }
278
279 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
280 return 0;
281 CODE
282 }