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