3 use ExtUtils::MakeMaker;
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
17 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
21 NAME => 'Imager::Font::FT2',
22 VERSION_FROM => 'FT2.pm',
23 OBJECT => 'FT2.o freetyp2.o',
24 clean => { FILES => 'testout' },
28 if ($BUILDING_IMAGER) {
30 unshift @INC, "../lib";
34 print "FreeType 2: building independently\n";
35 require Imager::ExtUtils;
36 push @inc, Imager::ExtUtils->includes;
37 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
39 # Imager required configure through use
40 my @Imager_req = ( Imager => "0.78" );
41 if ($MM_ver >= 6.46) {
51 "Test::More" => "0.47",
55 homepage => "http://imager.perl.org/",
58 url => "http://imager.perl.org/svn/trunk/Imager/FT2",
59 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/FT2",
71 require Imager::Probe;
76 code => \&freetype2_probe_ftconfig,
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,
88 incsuffix => "freetype2",
91 incsuffix => "freetype",
96 my $probe_res = Imager::Probe->probe(\%probe);
98 push @inc, $probe_res->{INC};
99 $opts{LIBS} = $probe_res->{LIBS};
100 $opts{DEFINE} = $probe_res->{DEFINE};
103 if ($MM_ver > 6.06) {
104 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
105 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
108 WriteMakefile(%opts);
111 if ($BUILDING_IMAGER) {
112 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
116 die "OS unsupported: FreeType 2 headers/libraries not found\n";
122 FT_Library library = 0;
125 error = FT_Init_FreeType(&library);
127 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
130 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
132 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
139 sub _ft2_test_code_prologue {
141 #include FT_FREETYPE_H
149 my @exe_suffix = $Config{_exe};
150 if ($^O eq 'MSWin32') {
151 push @exe_suffix, qw/.bat .cmd/;
154 for my $dir (File::Spec->path) {
155 for my $suffix (@exe_suffix) {
156 -x File::Spec->catfile($dir, "$name$suffix")
164 # probes for freetype2 by trying to run freetype-config
165 sub freetype2_probe_ftconfig {
168 is_exe('freetype-config') or return;
170 my $cflags = `freetype-config --cflags`
174 my $lflags = `freetype-config --libs`
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
183 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
185 # - freetype 1.x headers are in prefix/include/freetype
186 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
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"
193 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
194 map "-I$_", reverse @incdirs);
197 print "$req->{name}: configured via freetype-config\n";