]>
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 $MM_ver = eval $ExtUtils::MakeMaker::VERSION; |
19 | ||
20 | my %opts = | |
21 | ( | |
22 | NAME => 'Imager::Font::FT2', | |
23 | VERSION_FROM => 'FT2.pm', | |
24 | OBJECT => 'FT2.o freetyp2.o', | |
25 | clean => { FILES => 'testout' }, | |
26 | ); | |
27 | ||
28 | my @inc; | |
29 | if ($BUILDING_IMAGER) { | |
30 | push @inc, "-I.."; | |
31 | unshift @INC, "../lib"; | |
32 | } | |
33 | else { | |
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 | |
fa61d195 | 41 | my @Imager_req = ( Imager => "0.84_01" ); |
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, | |
64 | }; | |
65 | } | |
66 | } | |
67 | ||
68 | require Imager::Probe; | |
69 | ||
70 | my %probe = | |
71 | ( | |
72 | name => "FreeType 2", | |
73 | code => \&freetype2_probe_ftconfig, | |
74 | inccheck => | |
75 | sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") }, | |
76 | libbase => "freetype", | |
77 | testcode => _ft2_test_code(), | |
78 | testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ], | |
b73378f5 | 79 | testcodeprologue => _ft2_test_code_prologue(), |
0c3c1180 TC |
80 | incpath => \@incpaths, |
81 | libpath => \@libpaths, | |
50c75381 TC |
82 | alternatives => |
83 | [ | |
84 | { | |
85 | incsuffix => "freetype2", | |
86 | }, | |
87 | { | |
88 | incsuffix => "freetype", | |
89 | }, | |
90 | ], | |
91 | ); | |
92 | ||
93 | my $probe_res = Imager::Probe->probe(\%probe); | |
94 | if ($probe_res) { | |
d97c8dbd TC |
95 | $IMAGER_LIBS{FT2} = 1; |
96 | ||
50c75381 TC |
97 | push @inc, $probe_res->{INC}; |
98 | $opts{LIBS} = $probe_res->{LIBS}; | |
03e49392 | 99 | $opts{DEFINE} = $probe_res->{DEFINE}; |
50c75381 | 100 | $opts{INC} = "@inc"; |
ba751dab TC |
101 | $opts{LDDLFLAGS} = $probe_res->{LDDLFLAGS} |
102 | if $probe_res->{LDDLFLAGS}; | |
50c75381 TC |
103 | |
104 | if ($MM_ver > 6.06) { | |
5b480b14 | 105 | $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>'; |
50c75381 TC |
106 | $opts{ABSTRACT} = 'FreeType 2 font driver for Imager'; |
107 | } | |
108 | ||
109 | WriteMakefile(%opts); | |
110 | } | |
111 | else { | |
d97c8dbd TC |
112 | $IMAGER_LIBS{FT2} = 0; |
113 | ||
50c75381 | 114 | if ($BUILDING_IMAGER) { |
d24404be | 115 | ExtUtils::MakeMaker::WriteEmptyMakefile(%opts); |
50c75381 TC |
116 | } |
117 | else { | |
118 | # fail in good way | |
119 | die "OS unsupported: FreeType 2 headers/libraries not found\n"; | |
120 | } | |
121 | } | |
122 | ||
123 | sub _ft2_test_code { | |
124 | return <<'CODE'; | |
b73378f5 TC |
125 | FT_Library library = 0; |
126 | FT_Face face = 0; | |
127 | FT_Error error; | |
128 | error = FT_Init_FreeType(&library); | |
129 | if (error) { | |
130 | fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error); | |
131 | return 1; | |
132 | } | |
133 | error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face); | |
134 | if (error) { | |
135 | fprintf(stderr, "FreeType 2: cannot load font: %d\n", error); | |
136 | return 1; | |
137 | } | |
50c75381 TC |
138 | return 0; |
139 | CODE | |
140 | } | |
141 | ||
b73378f5 TC |
142 | sub _ft2_test_code_prologue { |
143 | return <<'CODE'; | |
144 | #include FT_FREETYPE_H | |
145 | ||
146 | CODE | |
147 | } | |
148 | ||
50c75381 TC |
149 | sub is_exe { |
150 | my ($name) = @_; | |
151 | ||
152 | my @exe_suffix = $Config{_exe}; | |
153 | if ($^O eq 'MSWin32') { | |
154 | push @exe_suffix, qw/.bat .cmd/; | |
155 | } | |
156 | ||
157 | for my $dir (File::Spec->path) { | |
158 | for my $suffix (@exe_suffix) { | |
8eb5a69c | 159 | -x File::Spec->catfile($dir, "$name$suffix") |
50c75381 TC |
160 | and return 1; |
161 | } | |
162 | } | |
163 | ||
164 | return; | |
165 | } | |
166 | ||
167 | # probes for freetype2 by trying to run freetype-config | |
168 | sub freetype2_probe_ftconfig { | |
169 | my ($req) = @_; | |
170 | ||
171 | is_exe('freetype-config') or return; | |
172 | ||
173 | my $cflags = `freetype-config --cflags` | |
174 | and !$? or return; | |
175 | chomp $cflags; | |
176 | ||
177 | my $lflags = `freetype-config --libs` | |
178 | and !$? or return; | |
179 | chomp $lflags; | |
180 | ||
181 | # before 2.1.5 freetype-config --cflags could output | |
182 | # the -I options in the wrong order, causing a conflict with | |
183 | # freetype1.x installed with the same --prefix | |
184 | # | |
185 | # can happen iff: | |
186 | # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags | |
187 | # in that order | |
188 | # - freetype 1.x headers are in prefix/include/freetype | |
189 | my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags; | |
190 | if (@incdirs == 2 | |
191 | && $incdirs[1] eq "$incdirs[0]/freetype2" | |
192 | && -e "$incdirs[0]/freetype/freetype.h" | |
193 | && -e "$incdirs[0]/freetype/fterrid.h") { | |
194 | print "** freetype-config provided -I options out of order, correcting\n" | |
195 | if $verbose; | |
196 | $cflags = join(' ', grep(!/-I/, split ' ', $cflags), | |
197 | map "-I$_", reverse @incdirs); | |
198 | } | |
199 | ||
200 | print "$req->{name}: configured via freetype-config\n"; | |
201 | ||
202 | return | |
203 | { | |
204 | INC => $cflags, | |
205 | LIBS => $lflags, | |
206 | }; | |
207 | } |