Debian Codegraph @

FT2/Makefile.PL

raw
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker;
4 use Getopt::Long;
5 use Config;
6
7 my $verbose = $ENV{IM_VERBOSE};
8 my @libpaths;
9 my @incpaths;
10
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
14
15 our $BUILDING_IMAGER;
16 our %IMAGER_LIBS;
17
18 my %opts =
19 (
20 NAME => 'Imager::Font::FT2',
21 VERSION_FROM => 'FT2.pm',
22 OBJECT => 'FT2.o freetyp2.o',
23 clean => { FILES => 'testout' },
24 );
25
26 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
27 $opts{LICENSE} = "perl_5";
28 $opts{AUTHOR} = 'Tony Cook <[email protected]>';
29 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
30 $opts{META_MERGE} =
31 {
32 'meta-spec' =>
33 {
34 version => "2",
35 url => "https://metacpan.org/pod/CPAN::Meta::Spec",
36 },
37 resources =>
38 {
39 homepage => "http://imager.perl.org/",
40 repository =>
41 {
42 type => "git",
43 url => "git://github.com/tonycoz/imager.git",
44 web => "https://github.com/tonycoz/imager.git",
45 },
46 bugtracker =>
47 {
48 web => "https://github.com/tonycoz/imager/issues",
49 },
50 },
51 };
52 }
53
54 my @inc;
55 if ($BUILDING_IMAGER) {
56 push @inc, "-I..";
57 unshift @INC, "../lib";
58 }
59 else {
60 unshift @INC, "inc";
61 print "FreeType 2: building independently\n";
62 require Imager::ExtUtils;
63 push @inc, Imager::ExtUtils->includes;
64 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
65
66 # Imager required configure through use
67 my @Imager_req = ( Imager => "0.95" );
68 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
69 $opts{META_MERGE}{prereqs} =
70 {
71 configure =>
72 {
73 requires =>
74 {
75 @Imager_req,
76 },
77 },
78 build =>
79 {
80 requires =>
81 {
82 @Imager_req,
83 'Scalar::Util' => 1.00,
84 "Test::More" => "0.47",
85 }
86 },
87 runtime =>
88 {
89 requires =>
90 {
91 @Imager_req,
92 'Scalar::Util' => 1.00,
93 }
94 },
95 test =>
96 {
97 requires =>
98 {
99 "Test::More" => "0.47",
100 'Scalar::Util' => 1.00,
101 }
102 },
103 };
104 $opts{PREREQ_PM} =
105 {
106 @Imager_req,
107 'Scalar::Util' => 1.00,
108 XSLoader => 0,
109 };
110 }
111 }
112
113 require Imager::Probe;
114
115 my %probe =
116 (
117 name => "FreeType 2",
118 code => \&freetype2_probe_ftconfig,
119 inccheck =>
120 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
121 libbase => "freetype",
122 testcode => _ft2_test_code(),
123 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
124 testcodeprologue => _ft2_test_code_prologue(),
125 incpath => \@incpaths,
126 libpath => \@libpaths,
127 pkg => [ "freetype2" ],
128 alternatives =>
129 [
130 {
131 incsuffix => "freetype2",
132 },
133 {
134 incsuffix => "freetype",
135 },
136 ],
137 verbose => $verbose,
138 );
139
140 my $probe_res = Imager::Probe->probe(\%probe);
141 if ($probe_res) {
142 $IMAGER_LIBS{FT2} = 1;
143
144 push @inc, $probe_res->{INC};
145 $opts{LIBS} = $probe_res->{LIBS};
146 $opts{DEFINE} = $probe_res->{DEFINE};
147 $opts{INC} = "@inc";
148 $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS}
149 if $probe_res->{LDDLFLAGS};
150
151 WriteMakefile(%opts);
152 }
153 else {
154 $IMAGER_LIBS{FT2} = 0;
155
156 if ($BUILDING_IMAGER) {
157 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
158 }
159 else {
160 # fail in good way
161 die "OS unsupported: FreeType 2 headers/libraries not found\n";
162 }
163 }
164
165 sub _ft2_test_code {
166 return <<'CODE';
167 FT_Library library = 0;
168 FT_Face face = 0;
169 FT_Error error;
170 error = FT_Init_FreeType(&library);
171 if (error) {
172 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
173 return 1;
174 }
175 error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
176 if (error) {
177 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
178 return 1;
179 }
180 FT_Done_Face(face);
181 FT_Done_FreeType(library);
182 return 0;
183 CODE
184 }
185
186 sub _ft2_test_code_prologue {
187 return <<'CODE';
188 #include FT_FREETYPE_H
189
190 CODE
191 }
192
193 sub is_exe {
194 my ($name) = @_;
195
196 my @exe_suffix = $Config{_exe};
197 if ($^O eq 'MSWin32') {
198 push @exe_suffix, qw/.bat .cmd/;
199 }
200 elsif ($^O eq 'cygwin') {
201 push @exe_suffix, "";
202 }
203
204 for my $dir (File::Spec->path) {
205 for my $suffix (@exe_suffix) {
206 -x File::Spec->catfile($dir, "$name$suffix")
207 and return 1;
208 }
209 }
210
211 return;
212 }
213
214 # probes for freetype2 by trying to run freetype-config
215 sub freetype2_probe_ftconfig {
216 my ($req) = @_;
217
218 is_exe('freetype-config') or return;
219
220 my $cflags = `freetype-config --cflags`
221 and !$? or return;
222 chomp $cflags;
223
224 my $lflags = `freetype-config --libs`
225 and !$? or return;
226 chomp $lflags;
227
228 # before 2.1.5 freetype-config --cflags could output
229 # the -I options in the wrong order, causing a conflict with
230 # freetype1.x installed with the same --prefix
231 #
232 # can happen iff:
233 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
234 # in that order
235 # - freetype 1.x headers are in prefix/include/freetype
236 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
237 if (@incdirs == 2
238 && $incdirs[1] eq "$incdirs[0]/freetype2"
239 && -e "$incdirs[0]/freetype/freetype.h"
240 && -e "$incdirs[0]/freetype/fterrid.h") {
241 print "** freetype-config provided -I options out of order, correcting\n"
242 if $verbose;
243 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
244 map "-I$_", reverse @incdirs);
245 }
246
247 print "$req->{name}: configured via freetype-config\n";
248
249 return
250 {
251 INC => $cflags,
252 LIBS => $lflags,
253 };
254 }