+
+sub make_imconfig {
+ my ($defines) = @_;
+
+ open CONFIG, "> imconfig.h"
+ or die "Cannot create imconfig.h: $!\n";
+ print CONFIG <<EOS;
+/* This file is automatically generated by Makefile.PL.
+ Don't edit this file, since any changes will be lost */
+
+#ifndef IMAGER_IMCONFIG_H
+#define IMAGER_IMCONFIG_H
+EOS
+ for my $define (@$defines) {
+ if ($define->[2]) {
+ print CONFIG "\n/*\n $define->[2]\n*/\n\n";
+ }
+ print CONFIG "#define $define->[0] $define->[1]\n";
+ }
+ print CONFIG "\n#endif\n";
+ close CONFIG;
+}
+
+# probes for freetype2 by trying to run freetype-config
+sub freetype2_probe {
+ my ($frm, $frmkey) = @_;
+
+ is_exe('freetype-config') or return;
+
+ my $cflags = `freetype-config --cflags`
+ and !$? or return;
+ chomp $cflags;
+
+ $frm->{cflags} = $cflags;
+ my $lflags = `freetype-config --libs`
+ and !$? or return;
+ chomp $lflags;
+ $frm->{libfiles} = $lflags;
+
+ printf "%10s: configured via freetype-config\n", $frmkey;
+
+ return 1;
+}
+
+# probes for libpng via pkg-config
+sub png_probe {
+ my ($frm, $frmkey) = @_;
+
+ is_exe('pkg-config') or return;
+
+ my $cflags;
+ my $config;
+ for my $check_conf (qw(libpng libpng12 libpng10)) {
+ $cflags = `pkg-config $check_conf --cflags`;
+ if ($cflags && !$?) {
+ $config = $check_conf;
+ last;
+ }
+ }
+ $config or return;
+
+ my $lflags = `pkg-config $config --libs`
+ and !$? or return;
+
+ chomp $cflags;
+ chomp $lflags;
+ $frm->{cflags} = $cflags;
+ $frm->{libfiles} = $lflags;
+
+ printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
+
+ return 1;
+}
+
+sub catfile {
+ return File::Spec->catfile(@_);
+}
+
+sub is_exe {
+ my ($name) = @_;
+
+ for my $dir (File::Spec->path) {
+ -x catfile($dir, "$name$Config{_exe}")
+ and return 1;
+ }
+
+ return;
+}
+
+sub usage {
+ print STDERR <<EOS;
+Usage: $0 [--enable feature1,feature2,...] [--incpath ...] [--libpath ...]
+ $0 [--disable feature1,feature2,...] [--incpath ...] [--libpath ...]
+ $0 --help
+Possible feature names are:
+ png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
+EOS
+ exit 1;
+
+}