older versions of EU::MM don't export WriteEmptyMakefile, but do provide it
[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;
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',
30160513 24 clean => { FILES => 'testout' },
e5ee047b
TC
25 );
26
27my @inc;
28if ($BUILDING_IMAGER) {
29 push @inc, "-I..";
30 unshift @INC, "../lib";
31}
32else {
33 unshift @INC, "inc";
34 print "TIFF: 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
893474f1 40 my @Imager_req = ( Imager => "0.78" );
e5ee047b
TC
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/TIFF",
59 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/TIFF",
e5ee047b
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 => "TIFF",
76 inccheck => sub { -e File::Spec->catfile($_[0], "tiffio.h") },
77 libbase => "tiff",
78 testcode => _tiff_test_code(),
79 testcodeheaders => [ "tiffio.h", "stdio.h", "string.h" ],
0c3c1180
TC
80 incpath => \@incpaths,
81 libpath => \@libpaths,
e5ee047b
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} = 'TIFF image file support for Imager';
94 }
95
96 WriteMakefile(%opts);
97}
98else {
99 if ($BUILDING_IMAGER) {
d24404be 100 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
e5ee047b
TC
101 }
102 else {
103 # fail in good way
104 die "OS unsupported: TIFF libraries or headers not found\n";
105 }
106}
107
108sub _tiff_test_code {
109 return <<'CODE';
110static const char ver_base[] = ", Version ";
111static const size_t ver_base_len = sizeof(ver_base) - 1;
112const char *ver_str = TIFFGetVersion();
113const char *ver_start = strstr(ver_str, ver_base);
114const char *ver_end;
115int ver_len;
116
117if (ver_start && ver_start[ver_base_len] >= '3' && ver_start[ver_base_len] < '9') {
118 ver_start += ver_base_len;
119 ver_end = ver_start;
120 while (*ver_end && (*ver_end == '.' || *ver_end >= '0' && *ver_end <= '9'))
121 ++ver_end;
122 ver_len = ver_end - ver_start;
123}
124else {
125 ver_start = "(unknown)";
126 ver_len = strlen(ver_start);
127}
128
129fprintf(stderr, "TIFF: library version %.*s, header version %ld\n", ver_len, ver_start, TIFFLIB_VERSION);
130if (TIFFLIB_VERSION == 20090820) {
131 fprintf(stderr, "TIFF: this appears to be libtiff 3.9.0 which introduced a serious bug\n");
132 fprintf(stderr, "TIFF: please install 3.9.1\n");
133 return 1;
134}
135return 0;
136CODE
137}