match error message strings to those from T1Lib
[imager.git] / FT2 / Makefile.PL
CommitLineData
50c75381
TC
1#!perl -w
2use strict;
d24404be 3use ExtUtils::MakeMaker;
50c75381
TC
4use Getopt::Long;
5use Config;
6
7my $verbose = $ENV{IM_VERBOSE};
8my @libpaths;
9my @incpaths;
10
11GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
14
15our $BUILDING_IMAGER;
d97c8dbd 16our %IMAGER_LIBS;
50c75381 17
50c75381
TC
18my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
19
20my %opts =
21 (
22 NAME => 'Imager::Font::FT2',
23 VERSION_FROM => 'FT2.pm',
24 OBJECT => 'FT2.o freetyp2.o',
25 clean => { FILES => 'testout' },
26 );
27
28my @inc;
29if ($BUILDING_IMAGER) {
30 push @inc, "-I..";
31 unshift @INC, "../lib";
32}
33else {
34 unshift @INC, "inc";
35 print "FreeType 2: building independently\n";
36 require Imager::ExtUtils;
37 push @inc, Imager::ExtUtils->includes;
38 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
39
40 # Imager required configure through use
32d74dbe 41 my @Imager_req = ( Imager => "0.86" );
50c75381
TC
42 if ($MM_ver >= 6.46) {
43 $opts{META_MERGE} =
44 {
45 configure_requires =>
46 {
47 @Imager_req,
48 },
49 build_requires =>
50 {
51 @Imager_req,
52 "Test::More" => "0.47",
53 },
54 resources =>
55 {
56 homepage => "http://imager.perl.org/",
04b6f77c
TC
57 repository => "git://git.imager.perl.org/imager.git",
58 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
50c75381
TC
59 },
60 };
61 $opts{PREREQ_PM} =
62 {
63 @Imager_req,
a5919365 64 XSLoader => 0,
50c75381
TC
65 };
66 }
67}
68
69require Imager::Probe;
70
71my %probe =
72 (
73 name => "FreeType 2",
74 code => \&freetype2_probe_ftconfig,
75 inccheck =>
76 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
77 libbase => "freetype",
78 testcode => _ft2_test_code(),
79 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
b73378f5 80 testcodeprologue => _ft2_test_code_prologue(),
0c3c1180
TC
81 incpath => \@incpaths,
82 libpath => \@libpaths,
50c75381
TC
83 alternatives =>
84 [
85 {
86 incsuffix => "freetype2",
87 },
88 {
89 incsuffix => "freetype",
90 },
91 ],
92 );
93
94my $probe_res = Imager::Probe->probe(\%probe);
95if ($probe_res) {
d97c8dbd
TC
96 $IMAGER_LIBS{FT2} = 1;
97
50c75381
TC
98 push @inc, $probe_res->{INC};
99 $opts{LIBS} = $probe_res->{LIBS};
03e49392 100 $opts{DEFINE} = $probe_res->{DEFINE};
50c75381 101 $opts{INC} = "@inc";
ba751dab
TC
102 $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS}
103 if $probe_res->{LDDLFLAGS};
50c75381
TC
104
105 if ($MM_ver > 6.06) {
5b480b14 106 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
50c75381
TC
107 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
108 }
109
110 WriteMakefile(%opts);
111}
112else {
d97c8dbd
TC
113 $IMAGER_LIBS{FT2} = 0;
114
50c75381 115 if ($BUILDING_IMAGER) {
d24404be 116 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
50c75381
TC
117 }
118 else {
119 # fail in good way
120 die "OS unsupported: FreeType 2 headers/libraries not found\n";
121 }
122}
123
124sub _ft2_test_code {
125 return <<'CODE';
b73378f5
TC
126FT_Library library = 0;
127FT_Face face = 0;
128FT_Error error;
129error = FT_Init_FreeType(&library);
130if (error) {
131 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
132 return 1;
133}
134error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
135if (error) {
136 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
137 return 1;
138}
50c75381
TC
139return 0;
140CODE
141}
142
b73378f5
TC
143sub _ft2_test_code_prologue {
144 return <<'CODE';
145#include FT_FREETYPE_H
146
147CODE
148}
149
50c75381
TC
150sub is_exe {
151 my ($name) = @_;
152
153 my @exe_suffix = $Config{_exe};
154 if ($^O eq 'MSWin32') {
155 push @exe_suffix, qw/.bat .cmd/;
156 }
157
158 for my $dir (File::Spec->path) {
159 for my $suffix (@exe_suffix) {
8eb5a69c 160 -x File::Spec->catfile($dir, "$name$suffix")
50c75381
TC
161 and return 1;
162 }
163 }
164
165 return;
166}
167
168# probes for freetype2 by trying to run freetype-config
169sub freetype2_probe_ftconfig {
170 my ($req) = @_;
171
172 is_exe('freetype-config') or return;
173
174 my $cflags = `freetype-config --cflags`
175 and !$? or return;
176 chomp $cflags;
177
178 my $lflags = `freetype-config --libs`
179 and !$? or return;
180 chomp $lflags;
181
182 # before 2.1.5 freetype-config --cflags could output
183 # the -I options in the wrong order, causing a conflict with
184 # freetype1.x installed with the same --prefix
185 #
186 # can happen iff:
187 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
188 # in that order
189 # - freetype 1.x headers are in prefix/include/freetype
190 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
191 if (@incdirs == 2
192 && $incdirs[1] eq "$incdirs[0]/freetype2"
193 && -e "$incdirs[0]/freetype/freetype.h"
194 && -e "$incdirs[0]/freetype/fterrid.h") {
195 print "** freetype-config provided -I options out of order, correcting\n"
196 if $verbose;
197 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
198 map "-I$_", reverse @incdirs);
199 }
200
201 print "$req->{name}: configured via freetype-config\n";
202
203 return
204 {
205 INC => $cflags,
206 LIBS => $lflags,
207 };
208}