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