move TIFF into its own module
[imager.git] / TIFF / Makefile.PL
CommitLineData
e5ee047b
TC
1#!perl -w
2use strict;
3use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
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::TIFF',
22 VERSION_FROM => 'TIFF.pm',
23 OBJECT => 'TIFF.o imtiff.o',
24 );
25
26my @inc;
27if ($BUILDING_IMAGER) {
28 push @inc, "-I..";
29 unshift @INC, "../lib";
30}
31else {
32 unshift @INC, "inc";
33 print "TIFF: building independently\n";
34 require Imager::ExtUtils;
35 push @inc, Imager::ExtUtils->includes;
36 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
37
38 # Imager required configure through use
39 my @Imager_req = ( Imager => "0.77" );
40 if ($MM_ver >= 6.46) {
41 $opts{META_MERGE} =
42 {
43 configure_requires =>
44 {
45 @Imager_req,
46 },
47 build_requires =>
48 {
49 @Imager_req,
50 "Test::More" => "0.47",
51 },
52 resources =>
53 {
54 homepage => "http://imager.perl.org/",
55 repository =>
56 {
57 url => "http://imager.perl.org/svn/trunk/Imager-File-TIFF",
58 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-File-TIFF",
59 type => "svn",
60 },
61 },
62 };
63 $opts{PREREQ_PM} =
64 {
65 @Imager_req,
66 };
67 }
68}
69
70require Imager::Probe;
71
72my %probe =
73 (
74 name => "TIFF",
75 inccheck => sub { -e File::Spec->catfile($_[0], "tiffio.h") },
76 libbase => "tiff",
77 testcode => _tiff_test_code(),
78 testcodeheaders => [ "tiffio.h", "stdio.h", "string.h" ],
79 incpath => join($Config{path_sep}, @incpaths),
80 libpath => join($Config{path_sep}, @libpaths),
81 );
82
83my $probe_res = Imager::Probe->probe(\%probe);
84if ($probe_res) {
85 push @inc, $probe_res->{INC};
86 $opts{LIBS} = $probe_res->{LIBS};
87
88 $opts{INC} = "@inc";
89
90 if ($MM_ver > 6.06) {
91 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
92 $opts{ABSTRACT} = 'TIFF image file support for Imager';
93 }
94
95 WriteMakefile(%opts);
96}
97else {
98 if ($BUILDING_IMAGER) {
99 WriteEmptyMakefile(%opts);
100 }
101 else {
102 # fail in good way
103 die "OS unsupported: TIFF libraries or headers not found\n";
104 }
105}
106
107sub _tiff_test_code {
108 return <<'CODE';
109static const char ver_base[] = ", Version ";
110static const size_t ver_base_len = sizeof(ver_base) - 1;
111const char *ver_str = TIFFGetVersion();
112const char *ver_start = strstr(ver_str, ver_base);
113const char *ver_end;
114int ver_len;
115
116if (ver_start && ver_start[ver_base_len] >= '3' && ver_start[ver_base_len] < '9') {
117 ver_start += ver_base_len;
118 ver_end = ver_start;
119 while (*ver_end && (*ver_end == '.' || *ver_end >= '0' && *ver_end <= '9'))
120 ++ver_end;
121 ver_len = ver_end - ver_start;
122}
123else {
124 ver_start = "(unknown)";
125 ver_len = strlen(ver_start);
126}
127
128fprintf(stderr, "TIFF: library version %.*s, header version %ld\n", ver_len, ver_start, TIFFLIB_VERSION);
129if (TIFFLIB_VERSION == 20090820) {
130 fprintf(stderr, "TIFF: this appears to be libtiff 3.9.0 which introduced a serious bug\n");
131 fprintf(stderr, "TIFF: please install 3.9.1\n");
132 return 1;
133}
134return 0;
135CODE
136}