0.84_01 development release
[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
TC
17
18my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
19
20my %opts =
21 (
22 NAME => 'Imager::File::GIF',
23 VERSION_FROM => 'GIF.pm',
24 OBJECT => 'GIF.o imgif.o',
30160513 25 clean => { FILES => 'testout' },
ec6d8908
TC
26 );
27
28my @inc;
29if ($BUILDING_IMAGER) {
30 unshift @inc, "-I..";
31 unshift @INC, "../lib";
32}
33else {
34 unshift @INC, "inc";
35 print "GIF: building independently\n";
36 require Imager::ExtUtils;
37 push @inc, Imager::ExtUtils->includes;
38 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
39
40 # Imager required configure through use
fa61d195 41 my @Imager_req = ( Imager => "0.84_01" );
ec6d8908
TC
42 if ($MM_ver >= 6.46) {
43 $opts{META_MERGE} =
44 {
45 configure_requires =>
46 {
47 @Imager_req,
48 },
49 build_requires =>
50 {
51 @Imager_req,
52 "Test::More" => "0.47",
53 },
54 resources =>
55 {
56 homepage => "http://imager.perl.org/",
04b6f77c
TC
57 repository => "git://git.imager.perl.org/imager.git",
58 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
ec6d8908
TC
59 },
60 };
61 $opts{PREREQ_PM} =
62 {
63 @Imager_req,
64 };
65 }
66}
67
68require Imager::Probe;
69
70my %probe =
71 (
72 name => "GIF",
73 inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
74 libbase => "gif",
75 testcode => _gif_test_code(),
76 testcodeheaders => [ "gif_lib.h", "stdio.h" ],
0c3c1180
TC
77 incpath => \@incpaths,
78 libpath => \@libpaths,
ec6d8908
TC
79 );
80
81my $probe_res = Imager::Probe->probe(\%probe);
82if ($probe_res) {
d97c8dbd
TC
83 $IMAGER_LIBS{GIF} = 1;
84
ec6d8908
TC
85 push @inc, $probe_res->{INC};
86 $opts{LIBS} = $probe_res->{LIBS};
03e49392 87 $opts{DEFINE} = $probe_res->{DEFINE};
ec6d8908
TC
88 $opts{INC} = "@inc";
89
90 if ($MM_ver > 6.06) {
5b480b14 91 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
ec6d8908
TC
92 $opts{ABSTRACT} = 'GIF Image file support';
93 }
94
95 WriteMakefile(%opts);
96}
97else {
d97c8dbd
TC
98 $IMAGER_LIBS{GIF} = 0;
99
ec6d8908 100 if ($BUILDING_IMAGER) {
d24404be 101 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
ec6d8908
TC
102 }
103 else {
104 # fail in good way
105 die "OS unsupported: GIF libraries or headers not found\n";
106 }
107}
108
109sub _gif_test_code {
110 return <<'CODE';
111/* TODO: test DGifOpen() and processing with callbacks */
112GifFileType *gf;
113const char vers[] = GIF_LIB_VERSION;
114const char *versp = vers;
115int ver_maj;
116int ver_min;
ec6d8908
TC
117gf=DGifOpenFileName("testimg/expected.gif");
118if (!gf) {
119 fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
120 return 1;
121}
122if (gf->SWidth != 16 || gf->SHeight != 16) {
123 fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
124 return 1;
125}
126/* crashes in older versions of giflib */
127EGifSetGifVersion("89a");
128EGifSetGifVersion("87a");
129
130/* skip the " Version " */
131while (*versp && (*versp < '0' || *versp > '9'))
132 ++versp;
133if (!*versp) {
134 fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
135 return 1;
136}
137ver_maj = 0;
138while (*versp && *versp >= '0' && *versp <= '9') {
139 ver_maj *= 10;
140 ver_maj += *versp++ - '0';
141}
142if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
143 fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
144 return 1;
145}
146++versp; /* skip '.' */
147ver_min = 0;
148while (*versp && *versp >= '0' && *versp <= '9') {
149 ver_min *= 10;
150 ver_min += *versp++ - '0';
151}
152if (ver_maj < 4) {
153 fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
154 return 1;
155}
156if (ver_maj == 4 && ver_min < 1) {
157 fprintf(stderr, "GIF: you need at least giflib 4.1\n");
158 return 1;
159}
160fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);
161return 0;
162CODE
163}