eliminate use vars
[imager.git] / GIF / Makefile.PL
CommitLineData
ec6d8908
TC
1#!perl -w
2use strict;
d24404be 3use ExtUtils::MakeMaker;
ec6d8908
TC
4use Getopt::Long;
5use Config;
6
7my $verbose = $ENV{IM_VERBOSE};
8my @libpaths;
9my @incpaths;
10
11GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
14
15our $BUILDING_IMAGER;
d97c8dbd 16our %IMAGER_LIBS;
ec6d8908 17
ec6d8908
TC
18my %opts =
19 (
20 NAME => 'Imager::File::GIF',
21 VERSION_FROM => 'GIF.pm',
22 OBJECT => 'GIF.o imgif.o',
30160513 23 clean => { FILES => 'testout' },
ec6d8908
TC
24 );
25
572d5255
TC
26if (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",
08a0751c
TC
43 url => "git://github.com/tonycoz/imager.git",
44 web => "https://github.com/tonycoz/imager.git",
572d5255
TC
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
ec6d8908
TC
55my @inc;
56if ($BUILDING_IMAGER) {
57 unshift @inc, "-I..";
58 unshift @INC, "../lib";
59}
60else {
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
06115805 68 my @Imager_req = ( Imager => "0.94" );
572d5255
TC
69 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
70 $opts{META_MERGE}{prereqs} =
ec6d8908 71 {
572d5255 72 configure =>
ec6d8908 73 {
572d5255
TC
74 requires =>
75 {
76 @Imager_req,
77 },
ec6d8908 78 },
572d5255 79 build =>
ec6d8908 80 {
572d5255
TC
81 requires =>
82 {
83 @Imager_req,
84 "Test::More" => "0.47",
85 }
ec6d8908 86 },
572d5255 87 runtime =>
ec6d8908 88 {
572d5255
TC
89 requires =>
90 {
91 @Imager_req,
92 }
93 },
94 test =>
95 {
96 requires =>
97 {
98 "Test::More" => "0.47",
99 }
ec6d8908
TC
100 },
101 };
102 $opts{PREREQ_PM} =
103 {
104 @Imager_req,
a5919365 105 XSLoader => 0,
ec6d8908
TC
106 };
107 }
108}
109
110require Imager::Probe;
111
112my %probe =
113 (
114 name => "GIF",
115 inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
116 libbase => "gif",
117 testcode => _gif_test_code(),
d0ffc81a 118 testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
0c3c1180
TC
119 incpath => \@incpaths,
120 libpath => \@libpaths,
0987aae1 121 verbose => $verbose,
ec6d8908
TC
122 );
123
124my $probe_res = Imager::Probe->probe(\%probe);
125if ($probe_res) {
d97c8dbd
TC
126 $IMAGER_LIBS{GIF} = 1;
127
ec6d8908
TC
128 push @inc, $probe_res->{INC};
129 $opts{LIBS} = $probe_res->{LIBS};
03e49392 130 $opts{DEFINE} = $probe_res->{DEFINE};
ec6d8908 131 $opts{INC} = "@inc";
572d5255 132
ec6d8908
TC
133 WriteMakefile(%opts);
134}
135else {
d97c8dbd
TC
136 $IMAGER_LIBS{GIF} = 0;
137
ec6d8908 138 if ($BUILDING_IMAGER) {
d24404be 139 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
ec6d8908
TC
140 }
141 else {
142 # fail in good way
143 die "OS unsupported: GIF libraries or headers not found\n";
144 }
145}
146
147sub _gif_test_code {
148 return <<'CODE';
149/* TODO: test DGifOpen() and processing with callbacks */
150GifFileType *gf;
0dfd57de 151#ifdef GIF_LIB_VERSION
ec6d8908
TC
152const char vers[] = GIF_LIB_VERSION;
153const char *versp = vers;
154int ver_maj;
155int ver_min;
0dfd57de
TC
156#else
157int ver_maj = GIFLIB_MAJOR;
158int ver_min = GIFLIB_MINOR;
159#endif
d0ffc81a
TC
160GifColorType colors[2];
161ColorMapObject *map;
162FILE *fh;
163char buf[6];
164int mode;
7b486870 165int error;
7a5f7bc6
TC
166#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
167gf=DGifOpenFileName("testimg/expected.gif", &error);
168#else
ec6d8908 169gf=DGifOpenFileName("testimg/expected.gif");
7a5f7bc6 170#endif
ec6d8908
TC
171if (!gf) {
172 fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
173 return 1;
174}
175if (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}
7a5f7bc6
TC
179#if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
180/* crashes in older versions of giflib, not used in giflib 5 */
ec6d8908
TC
181EGifSetGifVersion("89a");
182EGifSetGifVersion("87a");
7a5f7bc6 183#endif
ec6d8908 184
0dfd57de 185#ifdef GIF_LIB_VERSION
ec6d8908
TC
186/* skip the " Version " */
187while (*versp && (*versp < '0' || *versp > '9'))
188 ++versp;
189if (!*versp) {
190 fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
191 return 1;
192}
193ver_maj = 0;
194while (*versp && *versp >= '0' && *versp <= '9') {
195 ver_maj *= 10;
196 ver_maj += *versp++ - '0';
197}
198if (*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 '.' */
203ver_min = 0;
204while (*versp && *versp >= '0' && *versp <= '9') {
205 ver_min *= 10;
206 ver_min += *versp++ - '0';
207}
0dfd57de 208#endif
ec6d8908
TC
209if (ver_maj < 4) {
210 fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
211 return 1;
212}
213if (ver_maj == 4 && ver_min < 1) {
214 fprintf(stderr, "GIF: you need at least giflib 4.1\n");
215 return 1;
216}
d0ffc81a
TC
217
218/* test we write both GIF87a and GIF89a files */
219for (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);
7b486870
TC
242#if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
243 EGifCloseFile(gf, &error);
244#else
d0ffc81a 245 EGifCloseFile(gf);
7b486870 246#endif
d0ffc81a
TC
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);
a963cbec 260 remove("probe.gif");
d0ffc81a
TC
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 }
d0ffc81a
TC
265}
266
ec6d8908
TC
267fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
268return 0;
269CODE
270}