3 use ExtUtils::MakeMaker;
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
20 NAME => 'Imager::Font::FT2',
21 VERSION_FROM => 'FT2.pm',
22 OBJECT => 'FT2.o freetyp2.o',
23 clean => { FILES => 'testout' },
26 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
27 $opts{LICENSE} = "perl_5";
28 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
29 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
35 url => "https://metacpan.org/pod/CPAN::Meta::Spec",
39 homepage => "http://imager.perl.org/",
43 url => "git://git.imager.perl.org/imager.git",
44 web => "http://git.imager.perl.org/imager.git",
48 web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
49 mailto => 'bug-Imager@rt.cpan.org',
56 if ($BUILDING_IMAGER) {
58 unshift @INC, "../lib";
62 print "FreeType 2: building independently\n";
63 require Imager::ExtUtils;
64 push @inc, Imager::ExtUtils->includes;
65 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
67 # Imager required configure through use
68 my @Imager_req = ( Imager => "0.95" );
69 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
70 $opts{META_MERGE}{prereqs} =
84 'Scalar::Util' => 1.00,
85 "Test::More" => "0.47",
93 'Scalar::Util' => 1.00,
100 "Test::More" => "0.47",
101 'Scalar::Util' => 1.00,
108 'Scalar::Util' => 1.00,
114 require Imager::Probe;
118 name => "FreeType 2",
119 code => \&freetype2_probe_ftconfig,
121 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
122 libbase => "freetype",
123 testcode => _ft2_test_code(),
124 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
125 testcodeprologue => _ft2_test_code_prologue(),
126 incpath => \@incpaths,
127 libpath => \@libpaths,
131 incsuffix => "freetype2",
134 incsuffix => "freetype",
140 my $probe_res = Imager::Probe->probe(\%probe);
142 $IMAGER_LIBS{FT2} = 1;
144 push @inc, $probe_res->{INC};
145 $opts{LIBS} = $probe_res->{LIBS};
146 $opts{DEFINE} = $probe_res->{DEFINE};
148 $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS}
149 if $probe_res->{LDDLFLAGS};
151 WriteMakefile(%opts);
154 $IMAGER_LIBS{FT2} = 0;
156 if ($BUILDING_IMAGER) {
157 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
161 die "OS unsupported: FreeType 2 headers/libraries not found\n";
167 FT_Library library = 0;
170 error = FT_Init_FreeType(&library);
172 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
175 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
177 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
184 sub _ft2_test_code_prologue {
186 #include FT_FREETYPE_H
194 my @exe_suffix = $Config{_exe};
195 if ($^O eq 'MSWin32') {
196 push @exe_suffix, qw/.bat .cmd/;
198 elsif ($^O eq 'cygwin') {
199 push @exe_suffix, "";
202 for my $dir (File::Spec->path) {
203 for my $suffix (@exe_suffix) {
204 -x File::Spec->catfile($dir, "$name$suffix")
212 # probes for freetype2 by trying to run freetype-config
213 sub freetype2_probe_ftconfig {
216 is_exe('freetype-config') or return;
218 my $cflags = `freetype-config --cflags`
222 my $lflags = `freetype-config --libs`
226 # before 2.1.5 freetype-config --cflags could output
227 # the -I options in the wrong order, causing a conflict with
228 # freetype1.x installed with the same --prefix
231 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
233 # - freetype 1.x headers are in prefix/include/freetype
234 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
236 && $incdirs[1] eq "$incdirs[0]/freetype2"
237 && -e "$incdirs[0]/freetype/freetype.h"
238 && -e "$incdirs[0]/freetype/fterrid.h") {
239 print "** freetype-config provided -I options out of order, correcting\n"
241 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
242 map "-I$_", reverse @incdirs);
245 print "$req->{name}: configured via freetype-config\n";