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