File: Makefile.PL

package info (click to toggle)
libimager-perl 1.012%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,376 kB
  • sloc: perl: 31,562; ansic: 27,846; makefile: 53; cpp: 4
file content (270 lines) | stat: -rw-r--r-- 6,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!perl -w
use strict;
use ExtUtils::MakeMaker;
use Getopt::Long;
use Config;

my $verbose = $ENV{IM_VERBOSE};
my @libpaths;
my @incpaths;

GetOptions("incpath=s", \@incpaths,
           "libpath=s" => \@libpaths,
           "verbose|v" => \$verbose);

our $BUILDING_IMAGER;
our %IMAGER_LIBS;

my %opts = 
  (
   NAME => 'Imager::File::GIF',
   VERSION_FROM => 'GIF.pm',
   OBJECT => 'GIF.o imgif.o',
   clean => { FILES => 'testout' },
  );

if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
  $opts{LICENSE} = "perl_5";
  $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
  $opts{ABSTRACT} = 'GIF Image file support for Imager';
  $opts{META_MERGE} =
    {
     'meta-spec' =>
     {
      version => "2",
      url => "https://metacpan.org/pod/CPAN::Meta::Spec",
     },
     resources =>
     {
      homepage => "http://imager.perl.org/",
      repository =>
      {
       type => "git",
       url => "git://github.com/tonycoz/imager.git",
       web => "https://github.com/tonycoz/imager.git",
      },
      bugtracker =>
      {
       web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
       mailto => 'bug-Imager@rt.cpan.org',
      },
     },
    };
}

my @inc;
if ($BUILDING_IMAGER) {
  unshift @inc, "-I..";
  unshift @INC, "../lib";
}
else {
  unshift @INC, "inc";
  print "GIF: building independently\n";
  require Imager::ExtUtils;
  push @inc, Imager::ExtUtils->includes;
  $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];

  # Imager required configure through use
  my @Imager_req = ( Imager => "0.94" );
  if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
    $opts{META_MERGE}{prereqs} =
      {
       configure =>
       {
	requires =>
	{
	 @Imager_req,
	},
       },
       build =>
       {
	requires =>
	{
	 @Imager_req,
	 "Test::More" => "0.47",
	}
       },
       runtime =>
       {
	requires =>
	{
	 @Imager_req,
	}
       },
       test =>
       {
	requires =>
	{
	 "Test::More" => "0.47",
	}
       },
      };
    $opts{PREREQ_PM} =
      {
       @Imager_req,
       XSLoader => 0,
      };
  }
}

require Imager::Probe;

my %probe =
  (
   name => "GIF",
   inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
   libbase => "gif",
   testcode => _gif_test_code(),
   testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
   incpath => \@incpaths,
   libpath => \@libpaths,
   verbose => $verbose,
  );

my $probe_res = Imager::Probe->probe(\%probe);
if ($probe_res) {
  $IMAGER_LIBS{GIF} = 1;

  push @inc, $probe_res->{INC};
  $opts{LIBS} = $probe_res->{LIBS};
  $opts{DEFINE} = $probe_res->{DEFINE};
  $opts{INC} = "@inc";

  WriteMakefile(%opts);
}
else {
  $IMAGER_LIBS{GIF} = 0;

  if ($BUILDING_IMAGER) {
    ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
  }
  else {
    # fail in good way
    die "OS unsupported: GIF libraries or headers not found\n";
  }
}

sub _gif_test_code {
  return <<'CODE';
/* TODO: test DGifOpen() and processing with callbacks */
GifFileType *gf;
#ifdef GIF_LIB_VERSION
const char vers[] = GIF_LIB_VERSION;
const char *versp = vers;
int ver_maj;
int ver_min;
#else
int ver_maj = GIFLIB_MAJOR;
int ver_min = GIFLIB_MINOR;
#endif
GifColorType colors[2];
ColorMapObject *map;
FILE *fh;
char buf[6];
int mode;
int error;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
gf=DGifOpenFileName("testimg/expected.gif", &error);
#else
gf=DGifOpenFileName("testimg/expected.gif");
#endif
if (!gf) {
  fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
  return 1;
}
if (gf->SWidth != 16 || gf->SHeight != 16) {
  fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
  return 1;
}
#if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
/* crashes in older versions of giflib, not used in giflib 5 */
EGifSetGifVersion("89a");
EGifSetGifVersion("87a");
#endif

#ifdef GIF_LIB_VERSION
/* skip the " Version " */
while (*versp && (*versp < '0' || *versp > '9'))
  ++versp;
if (!*versp) {
  fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
  return 1;
}
ver_maj = 0;
while (*versp && *versp >= '0' && *versp <= '9') {
  ver_maj *= 10;
  ver_maj += *versp++ - '0';
}
if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
  fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
  return 1;
}
++versp; /* skip '.' */
ver_min = 0;
while (*versp && *versp >= '0' && *versp <= '9') {
  ver_min *= 10;
  ver_min += *versp++ - '0';
}
#endif
if (ver_maj < 4) {
  fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
  return 1;
}
if (ver_maj == 4 && ver_min < 1) {
  fprintf(stderr, "GIF: you need at least giflib 4.1\n");
  return 1;
}

/* test we write both GIF87a and GIF89a files */
for (mode = 0; mode < 2; ++mode) {
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
  gf=EGifOpenFileName("probe.gif", 0, &error);
  EGifSetGifVersion(gf, mode);

#else
  gf=EGifOpenFileName("probe.gif", 0);
  EGifSetGifVersion(mode ? "89a" : "87a");
#endif
  if (!gf) {
    fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
    return 1;
  }
  colors[0].Red = colors[0].Green = colors[0].Blue = 0;
  colors[1].Red = colors[1].Green = colors[1].Blue = 0;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
  map = GifMakeMapObject(2, colors);
#else
  map = MakeMapObject(2, colors);
#endif
  EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
  EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
  EGifPutPixel(gf, 0);
#if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
  EGifCloseFile(gf, &error);
#else
  EGifCloseFile(gf);
#endif

  fh = fopen("probe.gif", "r");
  if (!fh) {
    fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
    return 1;
  }
  errno = 0;
  memset(buf, 0, sizeof(buf));
  if (fread(buf, 1, 6, fh) != 6) {
    fprintf(stderr, "GIF: cannot read probe.gif header (%d)\n", errno);
    return 1;
  }
  fclose(fh);
  remove("probe.gif");
  if (memcmp(buf, mode ? "GIF89a" : "GIF87a", 6)) {
    fprintf(stderr, "GIF: incorrect header on test - 4.2.0 bug? (mode %d, buf %-6s)\n", mode, buf);
    return 1;
  }
}

fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
return 0;
CODE
}