[RT #65955] handle LD_RUN_PATH ignores with -rpath in lddlflags
[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;
16
50c75381
TC
17my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
18
19my %opts =
20 (
21 NAME => 'Imager::Font::FT2',
22 VERSION_FROM => 'FT2.pm',
23 OBJECT => 'FT2.o freetyp2.o',
24 clean => { FILES => 'testout' },
25 );
26
27my @inc;
28if ($BUILDING_IMAGER) {
29 push @inc, "-I..";
30 unshift @INC, "../lib";
31}
32else {
33 unshift @INC, "inc";
34 print "FreeType 2: building independently\n";
35 require Imager::ExtUtils;
36 push @inc, Imager::ExtUtils->includes;
37 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
38
39 # Imager required configure through use
ba751dab 40 my @Imager_req = ( Imager => "0.82" );
50c75381
TC
41 if ($MM_ver >= 6.46) {
42 $opts{META_MERGE} =
43 {
44 configure_requires =>
45 {
46 @Imager_req,
47 },
48 build_requires =>
49 {
50 @Imager_req,
51 "Test::More" => "0.47",
52 },
53 resources =>
54 {
55 homepage => "http://imager.perl.org/",
56 repository =>
57 {
3a882231
TC
58 url => "http://imager.perl.org/svn/trunk/Imager/FT2",
59 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager/FT2",
50c75381
TC
60 type => "svn",
61 },
62 },
63 };
64 $opts{PREREQ_PM} =
65 {
66 @Imager_req,
67 };
68 }
69}
70
71require Imager::Probe;
72
73my %probe =
74 (
75 name => "FreeType 2",
76 code => \&freetype2_probe_ftconfig,
77 inccheck =>
78 sub { -e File::Spec->catfile($_[0], "freetype/ftbitmap.h") },
79 libbase => "freetype",
80 testcode => _ft2_test_code(),
81 testcodeheaders => [ "stdio.h", "string.h", "ft2build.h" ],
b73378f5 82 testcodeprologue => _ft2_test_code_prologue(),
0c3c1180
TC
83 incpath => \@incpaths,
84 libpath => \@libpaths,
50c75381
TC
85 alternatives =>
86 [
87 {
88 incsuffix => "freetype2",
89 },
90 {
91 incsuffix => "freetype",
92 },
93 ],
94 );
95
96my $probe_res = Imager::Probe->probe(\%probe);
97if ($probe_res) {
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) {
106 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
107 $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
108 }
109
110 WriteMakefile(%opts);
111}
112else {
113 if ($BUILDING_IMAGER) {
d24404be 114 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
50c75381
TC
115 }
116 else {
117 # fail in good way
118 die "OS unsupported: FreeType 2 headers/libraries not found\n";
119 }
120}
121
122sub _ft2_test_code {
123 return <<'CODE';
b73378f5
TC
124FT_Library library = 0;
125FT_Face face = 0;
126FT_Error error;
127error = FT_Init_FreeType(&library);
128if (error) {
129 fprintf(stderr, "FreeType 2: cannot initialize library: %d\n", error);
130 return 1;
131}
132error = FT_New_Face(library, "fontfiles/dodge.ttf", 0, &face);
133if (error) {
134 fprintf(stderr, "FreeType 2: cannot load font: %d\n", error);
135 return 1;
136}
50c75381
TC
137return 0;
138CODE
139}
140
b73378f5
TC
141sub _ft2_test_code_prologue {
142 return <<'CODE';
143#include FT_FREETYPE_H
144
145CODE
146}
147
50c75381
TC
148sub 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) {
8eb5a69c 158 -x File::Spec->catfile($dir, "$name$suffix")
50c75381
TC
159 and return 1;
160 }
161 }
162
163 return;
164}
165
166# probes for freetype2 by trying to run freetype-config
167sub 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}