3 use ExtUtils::MakeMaker;
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
18 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
22 NAME => 'Imager::Font::FT2',
23 VERSION_FROM => 'FT2.pm',
24 OBJECT => 'FT2.o freetyp2.o',
25 clean => { FILES => 'testout' },
29 if ($BUILDING_IMAGER) {
31 unshift @INC, "../lib";
35 print "FreeType 2: building independently\n";
36 require Imager::ExtUtils;
37 push @inc, Imager::ExtUtils->includes;
38 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
40 # Imager required configure through use
41 my @Imager_req = ( Imager => "0.86" );
42 if ($MM_ver >= 6.46) {
52 "Test::More" => "0.47",
56 homepage => "http://imager.perl.org/",
57 repository => "git://git.imager.perl.org/imager.git",
58 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
64 'Scalar::Util' => 1.00,
70 require Imager::Probe;
75 code => \&freetype2_probe_ftconfig,
77 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
78 libbase => "freetype",
79 testcode => _ft2_test_code(),
80 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
81 testcodeprologue => _ft2_test_code_prologue(),
82 incpath => \@incpaths,
83 libpath => \@libpaths,
87 incsuffix => "freetype2",
90 incsuffix => "freetype",
95 my $probe_res = Imager::Probe->probe(\%probe);
97 $IMAGER_LIBS{FT2} = 1;
99 push @inc, $probe_res->{INC};
100 $opts{LIBS} = $probe_res->{LIBS};
101 $opts{DEFINE} = $probe_res->{DEFINE};
103 $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS}
104 if $probe_res->{LDDLFLAGS};
106 if ($MM_ver > 6.06) {
107 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
108 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
111 WriteMakefile(%opts);
114 $IMAGER_LIBS{FT2} = 0;
116 if ($BUILDING_IMAGER) {
117 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
121 die "OS unsupported: FreeType 2 headers/libraries not found\n";
127 FT_Library library = 0;
130 error = FT_Init_FreeType(&library);
132 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
135 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
137 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
144 sub _ft2_test_code_prologue {
146 #include FT_FREETYPE_H
154 my @exe_suffix = $Config{_exe};
155 if ($^O eq 'MSWin32') {
156 push @exe_suffix, qw/.bat .cmd/;
158 elsif ($^O eq 'cygwin') {
159 push @exe_suffix, "";
162 for my $dir (File::Spec->path) {
163 for my $suffix (@exe_suffix) {
164 -x File::Spec->catfile($dir, "$name$suffix")
172 # probes for freetype2 by trying to run freetype-config
173 sub freetype2_probe_ftconfig {
176 is_exe('freetype-config') or return;
178 my $cflags = `freetype-config --cflags`
182 my $lflags = `freetype-config --libs`
186 # before 2.1.5 freetype-config --cflags could output
187 # the -I options in the wrong order, causing a conflict with
188 # freetype1.x installed with the same --prefix
191 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
193 # - freetype 1.x headers are in prefix/include/freetype
194 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
196 && $incdirs[1] eq "$incdirs[0]/freetype2"
197 && -e "$incdirs[0]/freetype/freetype.h"
198 && -e "$incdirs[0]/freetype/fterrid.h") {
199 print "** freetype-config provided -I options out of order, correcting\n"
201 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
202 map "-I$_", reverse @incdirs);
205 print "$req->{name}: configured via freetype-config\n";