move TIFF into its own module
[imager.git] / TIFF / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
4 use Getopt::Long;
5 use Config;
6
7 my $verbose = $ENV{IM_VERBOSE};
8 my @libpaths;
9 my @incpaths;
10
11 GetOptions("incpath=s", \@incpaths,
12            "libpath=s" => \@libpaths,
13            "verbose|v" => \$verbose);
14
15 our $BUILDING_IMAGER;
16
17 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
18
19 my %opts = 
20   (
21    NAME => 'Imager::File::TIFF',
22    VERSION_FROM => 'TIFF.pm',
23    OBJECT => 'TIFF.o imtiff.o',
24   );
25
26 my @inc;
27 if ($BUILDING_IMAGER) {
28   push @inc, "-I..";
29   unshift @INC, "../lib";
30 }
31 else {
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
70 require Imager::Probe;
71
72 my %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
83 my $probe_res = Imager::Probe->probe(\%probe);
84 if ($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 }
97 else {
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
107 sub _tiff_test_code {
108   return <<'CODE';
109 static const char ver_base[] = ", Version ";
110 static const size_t ver_base_len = sizeof(ver_base) - 1;
111 const char *ver_str = TIFFGetVersion();
112 const char *ver_start = strstr(ver_str, ver_base);
113 const char *ver_end;
114 int ver_len;
115
116 if (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 }
123 else {
124   ver_start = "(unknown)";
125   ver_len = strlen(ver_start);
126 }
127
128 fprintf(stderr, "TIFF: library version %.*s, header version %ld\n", ver_len, ver_start, TIFFLIB_VERSION);
129 if (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 }
134 return 0;
135 CODE
136 }