3 use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
19 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
23 NAME => 'Imager::Font::FT2',
24 VERSION_FROM => 'FT2.pm',
25 OBJECT => 'FT2.o freetyp2.o',
26 clean => { FILES => 'testout' },
30 if ($BUILDING_IMAGER) {
32 unshift @INC, "../lib";
36 print "FreeType 2: building independently\n";
37 require Imager::ExtUtils;
38 push @inc, Imager::ExtUtils->includes;
39 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
41 # Imager required configure through use
42 my @Imager_req = ( Imager => "0.78" );
43 if ($MM_ver >= 6.46) {
53 "Test::More" => "0.47",
57 homepage => "http://imager.perl.org/",
60 url => "http://imager.perl.org/svn/trunk/Imager/FT2",
61 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/FT2",
73 require Imager::Probe;
78 code => \&freetype2_probe_ftconfig,
80 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
81 libbase => "freetype",
82 testcode => _ft2_test_code(),
83 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
84 testcodeprologue => _ft2_test_code_prologue(),
85 incpath => \@incpaths,
86 libpath => \@libpaths,
90 incsuffix => "freetype2",
93 incsuffix => "freetype",
98 my $probe_res = Imager::Probe->probe(\%probe);
100 push @inc, $probe_res->{INC};
101 $opts{LIBS} = $probe_res->{LIBS};
105 if ($MM_ver > 6.06) {
106 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
107 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
110 WriteMakefile(%opts);
113 if ($BUILDING_IMAGER) {
114 WriteEmptyMakefile(%opts);
118 die "OS unsupported: FreeType 2 headers/libraries not found\n";
124 FT_Library library = 0;
127 error = FT_Init_FreeType(&library);
129 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
132 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
134 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
141 sub _ft2_test_code_prologue {
143 #include FT_FREETYPE_H
151 my @exe_suffix = $Config{_exe};
152 if ($^O eq 'MSWin32') {
153 push @exe_suffix, qw/.bat .cmd/;
156 for my $dir (File::Spec->path) {
157 for my $suffix (@exe_suffix) {
158 -x catfile($dir, "$name$suffix")
166 # probes for freetype2 by trying to run freetype-config
167 sub freetype2_probe_ftconfig {
170 is_exe('freetype-config') or return;
172 my $cflags = `freetype-config --cflags`
176 my $lflags = `freetype-config --libs`
180 # before 2.1.5 freetype-config --cflags could output
181 # the -I options in the wrong order, causing a conflict with
182 # freetype1.x installed with the same --prefix
185 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
187 # - freetype 1.x headers are in prefix/include/freetype
188 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
190 && $incdirs[1] eq "$incdirs[0]/freetype2"
191 && -e "$incdirs[0]/freetype/freetype.h"
192 && -e "$incdirs[0]/freetype/fterrid.h") {
193 print "** freetype-config provided -I options out of order, correcting\n"
195 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
196 map "-I$_", reverse @incdirs);
199 print "$req->{name}: configured via freetype-config\n";