]> git.imager.perl.org - imager.git/blob - GIF/Makefile.PL
avoid a possible sign-extension for offsets/sizes in SGI
[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 %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 <tonyc@cpan.org>';
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://git.imager.perl.org/imager.git",
44        web => "http://git.imager.perl.org/imager.git",
45       },
46       bugtracker =>
47       {
48        web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
49        mailto => 'bug-Imager@rt.cpan.org',
50       },
51      },
52     };
53 }
54
55 my @inc;
56 if ($BUILDING_IMAGER) {
57   unshift @inc, "-I..";
58   unshift @INC, "../lib";
59 }
60 else {
61   unshift @INC, "inc";
62   print "GIF: building independently\n";
63   require Imager::ExtUtils;
64   push @inc, Imager::ExtUtils->includes;
65   $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
66
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} =
71       {
72        configure =>
73        {
74         requires =>
75         {
76          @Imager_req,
77         },
78        },
79        build =>
80        {
81         requires =>
82         {
83          @Imager_req,
84          "Test::More" => "0.47",
85         }
86        },
87        runtime =>
88        {
89         requires =>
90         {
91          @Imager_req,
92         }
93        },
94        test =>
95        {
96         requires =>
97         {
98          "Test::More" => "0.47",
99         }
100        },
101       };
102     $opts{PREREQ_PM} =
103       {
104        @Imager_req,
105        XSLoader => 0,
106       };
107   }
108 }
109
110 require Imager::Probe;
111
112 my %probe =
113   (
114    name => "GIF",
115    inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
116    libbase => "gif",
117    testcode => _gif_test_code(),
118    testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
119    incpath => \@incpaths,
120    libpath => \@libpaths,
121    verbose => $verbose,
122   );
123
124 my $probe_res = Imager::Probe->probe(\%probe);
125 if ($probe_res) {
126   $IMAGER_LIBS{GIF} = 1;
127
128   push @inc, $probe_res->{INC};
129   $opts{LIBS} = $probe_res->{LIBS};
130   $opts{DEFINE} = $probe_res->{DEFINE};
131   $opts{INC} = "@inc";
132
133   WriteMakefile(%opts);
134 }
135 else {
136   $IMAGER_LIBS{GIF} = 0;
137
138   if ($BUILDING_IMAGER) {
139     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
140   }
141   else {
142     # fail in good way
143     die "OS unsupported: GIF libraries or headers not found\n";
144   }
145 }
146
147 sub _gif_test_code {
148   return <<'CODE';
149 /* TODO: test DGifOpen() and processing with callbacks */
150 GifFileType *gf;
151 #ifdef GIF_LIB_VERSION
152 const char vers[] = GIF_LIB_VERSION;
153 const char *versp = vers;
154 int ver_maj;
155 int ver_min;
156 #else
157 int ver_maj = GIFLIB_MAJOR;
158 int ver_min = GIFLIB_MINOR;
159 #endif
160 GifColorType colors[2];
161 ColorMapObject *map;
162 FILE *fh;
163 char buf[6];
164 int mode;
165 int error;
166 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
167 gf=DGifOpenFileName("testimg/expected.gif", &error);
168 #else
169 gf=DGifOpenFileName("testimg/expected.gif");
170 #endif
171 if (!gf) {
172   fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
173   return 1;
174 }
175 if (gf->SWidth != 16 || gf->SHeight != 16) {
176   fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
177   return 1;
178 }
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");
183 #endif
184
185 #ifdef GIF_LIB_VERSION
186 /* skip the " Version " */
187 while (*versp && (*versp < '0' || *versp > '9'))
188   ++versp;
189 if (!*versp) {
190   fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
191   return 1;
192 }
193 ver_maj = 0;
194 while (*versp && *versp >= '0' && *versp <= '9') {
195   ver_maj *= 10;
196   ver_maj += *versp++ - '0';
197 }
198 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
199   fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
200   return 1;
201 }
202 ++versp; /* skip '.' */
203 ver_min = 0;
204 while (*versp && *versp >= '0' && *versp <= '9') {
205   ver_min *= 10;
206   ver_min += *versp++ - '0';
207 }
208 #endif
209 if (ver_maj < 4) {
210   fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
211   return 1;
212 }
213 if (ver_maj == 4 && ver_min < 1) {
214   fprintf(stderr, "GIF: you need at least giflib 4.1\n");
215   return 1;
216 }
217
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);
223
224 #else
225   gf=EGifOpenFileName("probe.gif", 0);
226   EGifSetGifVersion(mode ? "89a" : "87a");
227 #endif
228   if (!gf) {
229     fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
230     return 1;
231   }
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);
236 #else
237   map = MakeMapObject(2, colors);
238 #endif
239   EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
240   EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
241   EGifPutPixel(gf, 0);
242 #if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
243   EGifCloseFile(gf, &error);
244 #else
245   EGifCloseFile(gf);
246 #endif
247
248   fh = fopen("probe.gif", "r");
249   if (!fh) {
250     fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
251     return 1;
252   }
253   errno = 0;
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);
257     return 1;
258   }
259   fclose(fh);
260   remove("probe.gif");
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);
263     return 1;
264   }
265 }
266
267 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
268 return 0;
269 CODE
270 }