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