+
+# probes for freetype1 by scanning @incs for the includes and
+# @libs for the libs. This is done separately because freetype's headers
+# are stored in a freetype or freetype1 directory under PREFIX/include.
+#
+# we could find the files with the existing mechanism, but it won't set
+# -I flags correctly.
+#
+# This could be extended to freetype2 too, but freetype-config catches
+# that
+sub freetype1_probe {
+ my ($frm, $frmkey) = @_;
+
+ my $found_inc;
+ INCS:
+ for my $inc (@incs) {
+ for my $subdir (qw/freetype freetype1/) {
+ my $path = File::Spec->catfile($inc, $subdir, 'freetype.h');
+ -e $path or next;
+ $path = File::Spec->catfile($inc, $subdir, 'fterrors.h');
+ -e $path and next;
+
+ $found_inc = File::Spec->catdir($inc, $subdir);
+ last INCS;
+ }
+ }
+
+ my $found_lib;
+ LIBS:
+ for my $lib (@libs) {
+ my $a_path = File::Spec->catfile($lib, "libttf$aext");
+ my $l_path = File::Spec->catfile($lib, "libttf.$lext");
+ if (-e $a_path || -e $l_path) {
+ $found_lib = $lib;
+ last LIBS;
+ }
+ }
+
+ return unless $found_inc && $found_lib;
+ printf("%10s: includes %s - libraries %s\n", $frmkey,
+ ($found_inc ? 'found' : 'not found'),
+ ($found_lib ? 'found' : 'not found'));
+
+ $frm->{cflags} = "-I$found_inc";
+ $frm->{libfiles} = "-lttf";
+
+ return 1;
+}
+
+sub catfile {
+ return File::Spec->catfile(@_);
+}
+
+sub usage {
+ print STDERR <<EOS;
+Usage: $0 [--enable feature1,feature2,...] [other options]
+ $0 [--disable feature1,feature2,...] [other options]
+ $0 --help
+Possible feature names are:
+ T1-fonts
+Other options:
+ --verbose | -v
+ Verbose library probing (or set IM_VERBOSE in the environment)
+ --nolog
+ Disable logging (or set IM_NOLOG in the environment)
+ --incpath dir
+ Add to the include search path
+ --libpath dir
+ Add to the library search path
+ --coverage
+ Build for coverage testing.
+ --assert
+ Build with assertions active.
+EOS
+ exit 1;
+
+}
+
+# generate the PM MM argument
+# I'd prefer to modify the public version, but there doesn't seem to be
+# a public API to do that
+sub gen_PM {
+ my %pm;
+ my $instbase = '$(INST_LIBDIR)';
+
+ # first the basics, .pm and .pod files
+ $pm{"Imager.pm"} = "$instbase/Imager.pm";
+
+ my $mani = maniread();
+
+ for my $filename (keys %$mani) {
+ if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) {
+ (my $work = $filename) =~ s/^lib//;
+ $pm{$filename} = $instbase . $work;
+ }
+ }
+
+ # need the typemap
+ $pm{typemap} = $instbase . '/Imager/typemap';
+
+ # and the core headers
+ for my $filename (keys %$mani) {
+ if ($filename =~ /^\w+\.h$/) {
+ $pm{$filename} = $instbase . '/Imager/include/' . $filename;
+ }
+ }
+
+ # and the generated header
+ $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h';
+
+ \%pm;
+}
+
+my $home;
+sub _tilde_expand {
+ my ($path) = @_;
+
+ if ($path =~ m!^~[/\\]!) {
+ defined $home or $home = $ENV{HOME};
+ if (!defined $home && $^O eq 'MSWin32'
+ && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) {
+ $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH};
+ }
+ unless (defined $home) {
+ $home = eval { (getpwuid($<))[7] };
+ }
+ defined $home or die "You supplied $path, but I can't find your home directory\n";
+ $path =~ s/^~//;
+ $path = File::Spec->catdir($home, $path);
+ }
+
+ $path;
+}
+
+1;