hopefully avoid coverity complaining about a float vs int comparison
[imager.git] / TIFF / Makefile.PL
CommitLineData
e5ee047b
TC
1#!perl -w
2use strict;
d24404be 3use ExtUtils::MakeMaker;
e5ee047b
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;
e5ee047b 17
05c9b356 18my $define = "";
a24e8b4a
TC
19my $fp_rep = unpack("H*", pack("f", 1.25));
20if ($fp_rep eq "0000a03f" || $fp_rep eq "3fa00000") {
05c9b356
TC
21 $define = "-DIEEEFP_TYPES";
22}
23
e5ee047b
TC
24my %opts =
25 (
26 NAME => 'Imager::File::TIFF',
27 VERSION_FROM => 'TIFF.pm',
28 OBJECT => 'TIFF.o imtiff.o',
05c9b356 29 DEFINE => $define,
30160513 30 clean => { FILES => 'testout' },
e5ee047b
TC
31 );
32
572d5255
TC
33if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
34 $opts{LICENSE} = "perl_5";
35 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
36 $opts{ABSTRACT} = 'TIFF image file support for Imager';
37 $opts{META_MERGE} =
38 {
39 'meta-spec' =>
40 {
41 version => "2",
42 url => "https://metacpan.org/pod/CPAN::Meta::Spec",
43 },
44 resources =>
45 {
46 homepage => "http://imager.perl.org/",
47 repository =>
48 {
49 type => "git",
50 url => "git://git.imager.perl.org/imager.git",
51 web => "http://git.imager.perl.org/imager.git",
52 },
53 bugtracker =>
54 {
55 web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
56 mailto => 'bug-Imager@rt.cpan.org',
57 },
58 },
59 };
60}
61
e5ee047b
TC
62my @inc;
63if ($BUILDING_IMAGER) {
64 push @inc, "-I..";
65 unshift @INC, "../lib";
66}
67else {
68 unshift @INC, "inc";
69 print "TIFF: building independently\n";
70 require Imager::ExtUtils;
71 push @inc, Imager::ExtUtils->includes;
72 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
73
74 # Imager required configure through use
06115805 75 my @Imager_req = ( Imager => "0.94" );
572d5255
TC
76 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
77 $opts{META_MERGE}{prereqs} =
e5ee047b 78 {
572d5255
TC
79 configure =>
80 {
81 requires =>
82 {
83 @Imager_req,
84 },
85 },
86 build =>
e5ee047b 87 {
572d5255
TC
88 requires =>
89 {
90 @Imager_req,
91 "Test::More" => "0.47",
92 }
e5ee047b 93 },
572d5255 94 runtime =>
e5ee047b 95 {
572d5255
TC
96 requires =>
97 {
98 @Imager_req,
99 }
e5ee047b 100 },
572d5255 101 test =>
e5ee047b 102 {
572d5255
TC
103 requires =>
104 {
105 "Test::More" => "0.47",
106 }
e5ee047b
TC
107 },
108 };
109 $opts{PREREQ_PM} =
110 {
111 @Imager_req,
a5919365 112 XSLoader => 0,
e5ee047b
TC
113 };
114 }
115}
116
117require Imager::Probe;
118
119my %probe =
120 (
121 name => "TIFF",
122 inccheck => sub { -e File::Spec->catfile($_[0], "tiffio.h") },
123 libbase => "tiff",
124 testcode => _tiff_test_code(),
125 testcodeheaders => [ "tiffio.h", "stdio.h", "string.h" ],
0c3c1180
TC
126 incpath => \@incpaths,
127 libpath => \@libpaths,
0987aae1 128 verbose => $verbose,
e5ee047b
TC
129 );
130
131my $probe_res = Imager::Probe->probe(\%probe);
132if ($probe_res) {
d97c8dbd
TC
133 $IMAGER_LIBS{TIFF} = 1;
134
e5ee047b
TC
135 push @inc, $probe_res->{INC};
136 $opts{LIBS} = $probe_res->{LIBS};
05c9b356 137 $opts{DEFINE} .= " $probe_res->{DEFINE}";
e5ee047b
TC
138 $opts{INC} = "@inc";
139
e5ee047b
TC
140 WriteMakefile(%opts);
141}
142else {
d97c8dbd
TC
143 $IMAGER_LIBS{TIFF} = 0;
144
e5ee047b 145 if ($BUILDING_IMAGER) {
d24404be 146 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
e5ee047b
TC
147 }
148 else {
149 # fail in good way
150 die "OS unsupported: TIFF libraries or headers not found\n";
151 }
152}
153
154sub _tiff_test_code {
155 return <<'CODE';
156static const char ver_base[] = ", Version ";
157static const size_t ver_base_len = sizeof(ver_base) - 1;
158const char *ver_str = TIFFGetVersion();
159const char *ver_start = strstr(ver_str, ver_base);
160const char *ver_end;
161int ver_len;
162
163if (ver_start && ver_start[ver_base_len] >= '3' && ver_start[ver_base_len] < '9') {
164 ver_start += ver_base_len;
165 ver_end = ver_start;
166 while (*ver_end && (*ver_end == '.' || *ver_end >= '0' && *ver_end <= '9'))
167 ++ver_end;
168 ver_len = ver_end - ver_start;
169}
170else {
171 ver_start = "(unknown)";
172 ver_len = strlen(ver_start);
173}
174
175fprintf(stderr, "TIFF: library version %.*s, header version %ld\n", ver_len, ver_start, TIFFLIB_VERSION);
176if (TIFFLIB_VERSION == 20090820) {
177 fprintf(stderr, "TIFF: this appears to be libtiff 3.9.0 which introduced a serious bug\n");
178 fprintf(stderr, "TIFF: please install 3.9.1\n");
179 return 1;
180}
181return 0;
182CODE
183}