]> git.imager.perl.org - imager.git/blob - FT2/Makefile.PL
change version to avoid indexer confusion
[imager.git] / FT2 / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker;
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::Font::FT2',
22    VERSION_FROM => 'FT2.pm',
23    OBJECT => 'FT2.o freetyp2.o',
24    clean => { FILES => 'testout' },
25   );
26
27 my @inc;
28 if ($BUILDING_IMAGER) {
29   push @inc, "-I..";
30   unshift @INC, "../lib";
31 }
32 else {
33   unshift @INC, "inc";
34   print "FreeType 2: 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
40   my @Imager_req = ( Imager => "0.78" );
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         {
58          url => "http://imager.perl.org/svn/trunk/Imager/FT2",
59          web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/FT2",
60          type => "svn",
61         },
62        },
63       };
64     $opts{PREREQ_PM} =
65       {
66        @Imager_req,
67       };
68   }
69 }
70
71 require Imager::Probe;
72
73 my %probe =
74   (
75    name => "FreeType 2",
76    code => \&freetype2_probe_ftconfig,
77    inccheck =>
78    sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
79    libbase => "freetype",
80    testcode => _ft2_test_code(),
81    testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
82    testcodeprologue => _ft2_test_code_prologue(),
83    incpath => \@incpaths,
84    libpath => \@libpaths,
85    alternatives =>
86    [
87     {
88      incsuffix => "freetype2",
89     },
90     {
91      incsuffix => "freetype",
92     },
93    ],
94   );
95
96 my $probe_res = Imager::Probe->probe(\%probe);
97 if ($probe_res) {
98   push @inc, $probe_res->{INC};
99   $opts{LIBS} = $probe_res->{LIBS};
100   $opts{DEFINE} = $probe_res->{DEFINE};
101   $opts{INC} = "@inc";
102
103   if ($MM_ver > 6.06) {
104     $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
105     $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
106   }
107   
108   WriteMakefile(%opts);
109 }
110 else {
111   if ($BUILDING_IMAGER) {
112     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
113   }
114   else {
115     # fail in good way
116     die "OS unsupported: FreeType 2 headers/libraries not found\n";
117   }
118 }
119
120 sub _ft2_test_code {
121   return <<'CODE';
122 FT_Library library = 0;
123 FT_Face face = 0;
124 FT_Error error;
125 error = FT_Init_FreeType(&library);
126 if (error) {
127   fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
128   return 1;
129 }
130 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
131 if (error) {
132   fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
133   return 1;
134 }
135 return 0;
136 CODE
137 }
138
139 sub _ft2_test_code_prologue {
140   return <<'CODE';
141 #include FT_FREETYPE_H
142
143 CODE
144 }
145
146 sub is_exe {
147   my ($name) = @_;
148
149   my @exe_suffix = $Config{_exe};
150   if ($^O eq 'MSWin32') {
151     push @exe_suffix, qw/.bat .cmd/;
152   }
153
154   for my $dir (File::Spec->path) {
155     for my $suffix (@exe_suffix) {
156       -x File::Spec->catfile($dir, "$name$suffix")
157         and return 1;
158     }
159   }
160
161   return;
162 }
163
164 # probes for freetype2 by trying to run freetype-config
165 sub freetype2_probe_ftconfig {
166   my ($req) = @_;
167
168   is_exe('freetype-config') or return;
169
170   my $cflags = `freetype-config --cflags`
171     and !$? or return;
172   chomp $cflags;
173
174   my $lflags = `freetype-config --libs`
175     and !$? or return;
176   chomp $lflags;
177
178   # before 2.1.5 freetype-config --cflags could output
179   # the -I options in the wrong order, causing a conflict with
180   # freetype1.x installed with the same --prefix
181   #
182   # can happen iff:
183   #  - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
184   #    in that order
185   #  - freetype 1.x headers are in prefix/include/freetype
186   my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
187   if (@incdirs == 2 
188       && $incdirs[1] eq "$incdirs[0]/freetype2"
189       && -e "$incdirs[0]/freetype/freetype.h"
190       && -e "$incdirs[0]/freetype/fterrid.h") {
191     print "** freetype-config provided -I options out of order, correcting\n"
192       if $verbose;
193     $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
194                    map "-I$_", reverse @incdirs);
195   }
196
197   print "$req->{name}: configured via freetype-config\n";
198
199   return
200     {
201      INC => $cflags,
202      LIBS => $lflags,
203     };
204 }