Commit | Line | Data |
---|---|---|
50c75381 TC |
1 | #!perl -w |
2 | use strict; | |
d24404be | 3 | use ExtUtils::MakeMaker; |
50c75381 TC |
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; | |
d97c8dbd | 16 | our %IMAGER_LIBS; |
50c75381 | 17 | |
50c75381 TC |
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 | ||
572d5255 TC |
26 | if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
27 | $opts{LICENSE} = "perl_5"; | |
28 | $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>'; | |
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://git.imager.perl.org/imager.git", | |
44 | web => "http://git.imager.perl.org/imager.git", | |
45 | }, | |
46 | bugtracker => | |
47 | { | |
48 | web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager", | |
49 | mailto => 'bug-Imager@rt.cpan.org', | |
50 | }, | |
51 | }, | |
52 | }; | |
53 | } | |
54 | ||
50c75381 TC |
55 | my @inc; |
56 | if ($BUILDING_IMAGER) { | |
57 | push @inc, "-I.."; | |
58 | unshift @INC, "../lib"; | |
59 | } | |
60 | else { | |
61 | unshift @INC, "inc"; | |
62 | print "FreeType 2: building independently\n"; | |
63 | require Imager::ExtUtils; | |
64 | push @inc, Imager::ExtUtils->includes; | |
65 | $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ]; | |
66 | ||
67 | # Imager required configure through use | |
5eac8456 | 68 | my @Imager_req = ( Imager => "0.95" ); |
572d5255 TC |
69 | if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
70 | $opts{META_MERGE}{prereqs} = | |
50c75381 | 71 | { |
572d5255 TC |
72 | configure => |
73 | { | |
74 | requires => | |
75 | { | |
76 | @Imager_req, | |
77 | }, | |
78 | }, | |
79 | build => | |
50c75381 | 80 | { |
572d5255 TC |
81 | requires => |
82 | { | |
83 | @Imager_req, | |
84 | 'Scalar::Util' => 1.00, | |
85 | "Test::More" => "0.47", | |
86 | } | |
50c75381 | 87 | }, |
572d5255 | 88 | runtime => |
50c75381 | 89 | { |
572d5255 TC |
90 | requires => |
91 | { | |
92 | @Imager_req, | |
93 | 'Scalar::Util' => 1.00, | |
94 | } | |
50c75381 | 95 | }, |
572d5255 | 96 | test => |
50c75381 | 97 | { |
572d5255 TC |
98 | requires => |
99 | { | |
100 | "Test::More" => "0.47", | |
101 | 'Scalar::Util' => 1.00, | |
102 | } | |
50c75381 TC |
103 | }, |
104 | }; | |
105 | $opts{PREREQ_PM} = | |
106 | { | |
107 | @Imager_req, | |
98d6ae27 | 108 | 'Scalar::Util' => 1.00, |
a5919365 | 109 | XSLoader => 0, |
50c75381 TC |
110 | }; |
111 | } | |
112 | } | |
113 | ||
114 | require Imager::Probe; | |
115 | ||
116 | my %probe = | |
117 | ( | |
118 | name => "FreeType 2", | |
119 | code => \&freetype2_probe_ftconfig, | |
120 | inccheck => | |
121 | sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") }, | |
122 | libbase => "freetype", | |
123 | testcode => _ft2_test_code(), | |
124 | testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ], | |
b73378f5 | 125 | testcodeprologue => _ft2_test_code_prologue(), |
0c3c1180 TC |
126 | incpath => \@incpaths, |
127 | libpath => \@libpaths, | |
50c75381 TC |
128 | alternatives => |
129 | [ | |
130 | { | |
131 | incsuffix => "freetype2", | |
132 | }, | |
133 | { | |
134 | incsuffix => "freetype", | |
135 | }, | |
136 | ], | |
0987aae1 | 137 | verbose => $verbose, |
50c75381 TC |
138 | ); |
139 | ||
140 | my $probe_res = Imager::Probe->probe(\%probe); | |
141 | if ($probe_res) { | |
d97c8dbd TC |
142 | $IMAGER_LIBS{FT2} = 1; |
143 | ||
50c75381 TC |
144 | push @inc, $probe_res->{INC}; |
145 | $opts{LIBS} = $probe_res->{LIBS}; | |
03e49392 | 146 | $opts{DEFINE} = $probe_res->{DEFINE}; |
50c75381 | 147 | $opts{INC} = "@inc"; |
ba751dab TC |
148 | $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS} |
149 | if $probe_res->{LDDLFLAGS}; | |
50c75381 | 150 | |
50c75381 TC |
151 | WriteMakefile(%opts); |
152 | } | |
153 | else { | |
d97c8dbd TC |
154 | $IMAGER_LIBS{FT2} = 0; |
155 | ||
50c75381 | 156 | if ($BUILDING_IMAGER) { |
d24404be | 157 | ExtUtils::MakeMaker::WriteEmptyMakefile(%opts); |
50c75381 TC |
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'; | |
b73378f5 TC |
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 | } | |
50c75381 TC |
180 | return 0; |
181 | CODE | |
182 | } | |
183 | ||
b73378f5 TC |
184 | sub _ft2_test_code_prologue { |
185 | return <<'CODE'; | |
186 | #include FT_FREETYPE_H | |
187 | ||
188 | CODE | |
189 | } | |
190 | ||
50c75381 TC |
191 | sub is_exe { |
192 | my ($name) = @_; | |
193 | ||
194 | my @exe_suffix = $Config{_exe}; | |
195 | if ($^O eq 'MSWin32') { | |
196 | push @exe_suffix, qw/.bat .cmd/; | |
197 | } | |
c9eba720 TC |
198 | elsif ($^O eq 'cygwin') { |
199 | push @exe_suffix, ""; | |
200 | } | |
50c75381 TC |
201 | |
202 | for my $dir (File::Spec->path) { | |
203 | for my $suffix (@exe_suffix) { | |
8eb5a69c | 204 | -x File::Spec->catfile($dir, "$name$suffix") |
50c75381 TC |
205 | and return 1; |
206 | } | |
207 | } | |
208 | ||
209 | return; | |
210 | } | |
211 | ||
212 | # probes for freetype2 by trying to run freetype-config | |
213 | sub freetype2_probe_ftconfig { | |
214 | my ($req) = @_; | |
215 | ||
216 | is_exe('freetype-config') or return; | |
217 | ||
218 | my $cflags = `freetype-config --cflags` | |
219 | and !$? or return; | |
220 | chomp $cflags; | |
221 | ||
222 | my $lflags = `freetype-config --libs` | |
223 | and !$? or return; | |
224 | chomp $lflags; | |
225 | ||
226 | # before 2.1.5 freetype-config --cflags could output | |
227 | # the -I options in the wrong order, causing a conflict with | |
228 | # freetype1.x installed with the same --prefix | |
229 | # | |
230 | # can happen iff: | |
231 | # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags | |
232 | # in that order | |
233 | # - freetype 1.x headers are in prefix/include/freetype | |
234 | my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags; | |
235 | if (@incdirs == 2 | |
236 | && $incdirs[1] eq "$incdirs[0]/freetype2" | |
237 | && -e "$incdirs[0]/freetype/freetype.h" | |
238 | && -e "$incdirs[0]/freetype/fterrid.h") { | |
239 | print "** freetype-config provided -I options out of order, correcting\n" | |
240 | if $verbose; | |
241 | $cflags = join(' ', grep(!/-I/, split ' ', $cflags), | |
242 | map "-I$_", reverse @incdirs); | |
243 | } | |
244 | ||
245 | print "$req->{name}: configured via freetype-config\n"; | |
246 | ||
247 | return | |
248 | { | |
249 | INC => $cflags, | |
250 | LIBS => $lflags, | |
251 | }; | |
252 | } |