]> git.imager.perl.org - imager.git/blob - FT2/Makefile.PL
fc191364a37760febfb0fd9015dee3a3ba86a6ef
[imager.git] / FT2 / Makefile.PL
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
42   my @Imager_req = ( Imager => "0.77" );
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         {
60          url => "http://imager.perl.org/svn/trunk/Imager-Font-FT2",
61          web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-Font-FT2",
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" ],
84    incpath => join($Config{path_sep}, @incpaths),
85    libpath => join($Config{path_sep}, @libpaths),
86    alternatives =>
87    [
88     {
89      incsuffix => "freetype2",
90     },
91     {
92      incsuffix => "freetype",
93     },
94    ],
95   );
96
97 my $probe_res = Imager::Probe->probe(\%probe);
98 if ($probe_res) {
99   push @inc, $probe_res->{INC};
100   $opts{LIBS} = $probe_res->{LIBS};
101
102   $opts{INC} = "@inc";
103
104   if ($MM_ver > 6.06) {
105     $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
106     $opts{ABSTRACT} = 'FreeType 2 font driver for Imager';
107   }
108   
109   WriteMakefile(%opts);
110 }
111 else {
112   if ($BUILDING_IMAGER) {
113     WriteEmptyMakefile(%opts);
114   }
115   else {
116     # fail in good way
117     die "OS unsupported: FreeType 2 headers/libraries not found\n";
118   }
119 }
120
121 sub _ft2_test_code {
122   return <<'CODE';
123 return 0;
124 CODE
125 }
126
127 sub is_exe {
128   my ($name) = @_;
129
130   my @exe_suffix = $Config{_exe};
131   if ($^O eq 'MSWin32') {
132     push @exe_suffix, qw/.bat .cmd/;
133   }
134
135   for my $dir (File::Spec->path) {
136     for my $suffix (@exe_suffix) {
137       -x catfile($dir, "$name$suffix")
138         and return 1;
139     }
140   }
141
142   return;
143 }
144
145 # probes for freetype2 by trying to run freetype-config
146 sub freetype2_probe_ftconfig {
147   my ($req) = @_;
148
149   is_exe('freetype-config') or return;
150
151   my $cflags = `freetype-config --cflags`
152     and !$? or return;
153   chomp $cflags;
154
155   my $lflags = `freetype-config --libs`
156     and !$? or return;
157   chomp $lflags;
158
159   # before 2.1.5 freetype-config --cflags could output
160   # the -I options in the wrong order, causing a conflict with
161   # freetype1.x installed with the same --prefix
162   #
163   # can happen iff:
164   #  - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
165   #    in that order
166   #  - freetype 1.x headers are in prefix/include/freetype
167   my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
168   if (@incdirs == 2 
169       && $incdirs[1] eq "$incdirs[0]/freetype2"
170       && -e "$incdirs[0]/freetype/freetype.h"
171       && -e "$incdirs[0]/freetype/fterrid.h") {
172     print "** freetype-config provided -I options out of order, correcting\n"
173       if $verbose;
174     $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
175                    map "-I$_", reverse @incdirs);
176   }
177
178   print "$req->{name}: configured via freetype-config\n";
179
180   return
181     {
182      INC => $cflags,
183      LIBS => $lflags,
184     };
185 }