]> git.imager.perl.org - imager.git/blobdiff - Makefile.PL
ensure we always produce the same Imager::Regops
[imager.git] / Makefile.PL
index 2279fe5b5a62477a4c4ea6d61fef2746666b2ec2..35d80babd04a61f54a89f0decaaf52f1b58d66cf 100644 (file)
@@ -5,9 +5,18 @@ use Cwd;
 use Config;
 use File::Spec;
 use Getopt::Long;
-use vars qw(%Recommends);
 use ExtUtils::Manifest qw(maniread);
+use ExtUtils::Liblist;
 use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS);
+use lib 'inc';
+use Devel::CheckLib;
+
+# EU::MM runs Makefile.PL all in the same process, so sub-modules will
+# see this
+our $BUILDING_IMAGER = 1;
+
+# used to display a summary after we've probed the world
+our %IMAGER_LIBS;
 
 #
 # IM_INCPATH      colon seperated list of paths to extra include paths
@@ -24,7 +33,8 @@ use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CF
 # IM_CFLAGS       Extra flags to pass to the compiler
 # IM_LFLAGS       Extra flags to pass to the linker
 # IM_DFLAGS       Extra flags to pass to the preprocessor
-# IM_SUPPRESS_PROMPT  Suppress the prompt asking about gif support
+
+my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES};
 
 getenv();     # get environment variables
 
@@ -36,17 +46,25 @@ my @enable; # list of drivers to enable
 my @disable; # or list of drivers to disable
 my @incpaths; # places to look for headers
 my @libpaths; # places to look for libraries
-my $noprobe; # non-zero to disable newer probes
-my $noexif; # non-zero to disable EXIF parsing of JPEGs
+my $coverage; # build for coverage testing
+my $assert; # build with assertions
+my $trace_context; # trace context management to stderr
 GetOptions("help" => \$help,
            "enable=s" => \@enable,
            "disable=s" => \@disable,
            "incpath=s", \@incpaths,
            "libpath=s" => \@libpaths,
-           "noprobe" => \$noprobe,
            "verbose|v" => \$VERBOSE,
            "nolog" => \$NOLOG,
-          "noexif" => \$noexif);
+          'coverage' => \$coverage,
+          "assert|a" => \$assert,
+          "tracecontext" => \$trace_context);
+
+setenv();
+
+if ($ENV{AUTOMATED_TESTING}) {
+  $assert = 1;
+}
 
 if ($VERBOSE) { 
   print "Verbose mode\n"; 
@@ -65,6 +83,10 @@ else {
   push @defines, [ IMAGER_LOG => 1, "Logging system" ];
 }
 
+if ($assert) {
+  push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ];
+}
+
 if ($DEBUG_MALLOC) {
   push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
   print "Malloc debugging enabled\n";
@@ -82,7 +104,6 @@ my @libs; # all the places to look for libraries
 
 init();       # initialize global data
 pathcheck();  # Check if directories exist
-distcheck();  # for building dists
 
 if (exists $ENV{IM_ENABLE}) {
   my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
@@ -107,9 +128,6 @@ if ($MANUAL) {
   automatic();
 }
 
-# Make sure there isn't a clash between the gif libraries.
-gifcheck();
-
 my $lib_cflags = '';
 my $lib_lflags = '';
 my $F_LIBS = '';
@@ -132,12 +150,6 @@ for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %forma
 
 }
 
-unless ($noexif) {
-  print "EXIF support enabled\n";
-  push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ];
-  $F_OBJECT .= ' imexif.o';
-}
-
 my $F_INC  = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, 
   grep !$definc{$_}, @incs;
 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, 
@@ -149,34 +161,117 @@ my $OSDEF  = "-DOS_$^O";
 if ($^O eq 'hpux')                { $OSLIBS .= ' -ldld'; }
 if (defined $Config{'d_dlsymun'}) { $OSDEF  .= ' -DDLSYMUN'; }
 
-my @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
-              log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
+my @objs = qw(Imager.o context.o draw.o polygon.o image.o io.o iolayer.o
+              log.o gaussian.o conv.o pnm.o raw.o feat.o combine.o
               filters.o dynaload.o stackmach.o datatypes.o
               regmach.o trans2.o quant.o error.o convert.o
-              map.o tags.o palimg.o maskimg.o img16.o rotate.o
-              bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o
-              imext.o);
-
-$Recommends{Imager} =
-  { 'Parse::RecDescent' => 0 };
-
-my %opts=(
-          'NAME'         => 'Imager',
-          'VERSION_FROM' => 'Imager.pm',
-          'LIBS'         => "$LFLAGS -lm $lib_lflags $OSLIBS $F_LIBS",
-          'DEFINE'       => "$OSDEF $CFLAGS",
-          'INC'          => "$lib_cflags $DFLAGS $F_INC",
-          'OBJECT'       => join(' ', @objs, $F_OBJECT),
-          clean          => { FILES=>'testout meta.tmp' },
-          PM             => gen_PM(),
-         );
-
-if ($ExtUtils::MakeMaker::VERSION > 6.06) {
-  $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
+              map.o tags.o palimg.o maskimg.o img8.o img16.o rotate.o
+              bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o
+              imext.o scale.o rubthru.o render.o paste.o compose.o flip.o
+             perlio.o);
+
+if ($Config{useithreads}) {
+  if ($Config{i_pthread}) {
+    print "POSIX threads\n";
+    push @objs, "mutexpthr.o";
+  }
+  elsif ($^O eq 'MSWin32') {
+    print "Win32 threads\n";
+    push @objs, "mutexwin.o";
+  }
+  else {
+    print "Unsupported threading model\n";
+    push @objs, "mutexnull.o";
+    if ($ENV{AUTOMATED_TESTING}) {
+      die "OS unsupported: no threading support code for this platform\n";
+    }
+  }
+}
+else {
+  print "No threads\n";
+  push @objs, "mutexnull.o";
+}
+
+my @typemaps = qw(typemap.local typemap);
+if ($] < 5.008) {
+    unshift @typemaps, "typemap.oldperl";
+}
+
+if ($trace_context) {
+  $CFLAGS .= " -DIMAGER_TRACE_CONTEXT";
+}
+
+my $tests = 't/*.t t/*/*.t';
+if (-d "xt" && scalar(() = glob("xt/*.t"))) {
+  $tests .= " xt/*.t";
+}
+
+my %opts=
+  (
+   'NAME'         => 'Imager',
+   'VERSION_FROM' => 'Imager.pm',
+   'LIBS'         => "$LFLAGS -lm $lib_lflags $OSLIBS $F_LIBS",
+   'DEFINE'       => "$OSDEF $CFLAGS",
+   'INC'          => "$lib_cflags $DFLAGS $F_INC",
+   'OBJECT'       => join(' ', @objs, $F_OBJECT),
+   clean          => { FILES=>'testout rubthru.c scale.c conv.c  filters.c gaussian.c render.c rubthru.c' },
+   PM             => gen_PM(),
+   PREREQ_PM      =>
+   { 
+    'Test::More' => 0.47,
+    'Scalar::Util' => 1.00,
+    'XSLoader'    => 0,
+   },
+   TYPEMAPS       => \@typemaps,
+   test =>        { TESTS => $tests },
+  );
+
+if ($coverage) {
+    if ($Config{gccversion}) {
+       push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs -g';
+       $opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' };
+    }
+    else {
+       die "Don't know the coverage C flags for your compiler\n";
+    }
+}
+
+# eval to prevent warnings about versions with _ in them
+my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
+if ($MM_ver > 6.06) {
+  $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson';
   $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
 }
-if ($ExtUtils::MakeMaker::VERSION > 6.10) {
-  $opts{NO_META} = 1;
+
+if ($MM_ver >= 6.46) {
+  $opts{META_MERGE} =
+    {
+     recommends =>
+     {
+      "Parse::RecDescent" => 0
+     },
+     license => "perl",
+     dynamic_config => 1,
+     no_index =>
+     {
+      directory =>
+      [
+       "PNG",
+       "GIF",
+       "TIFF",
+       "JPEG",
+       "W32",
+       "FT2",
+       "T1",
+      ],
+     },
+     resources =>
+     {
+      homepage => "http://imager.perl.org/",
+      repository => "git://git.imager.perl.org/imager.git",
+      bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
+     },
+    };
 }
 
 make_imconfig(\@defines);
@@ -184,16 +279,36 @@ make_imconfig(\@defines);
 if ($VERBOSE) { print Dumper(\%opts); }
 mkdir('testout',0777); # since we cannot include it in the archive.
 
-make_metafile(\%opts);
+-d "probe" and rmdir "probe";
 
 WriteMakefile(%opts);
 
+my @good;
+my @bad;
+for my $name (sort { lc $a cmp lc $b } keys %IMAGER_LIBS) {
+  if ($IMAGER_LIBS{$name}) {
+    push @good, $name;
+  }
+  else {
+    push @bad, $name;
+  }
+}
+
+print "\n";
+print "Libraries found:\n" if @good;
+print "  $_\n" for @good;
+print "Libraries *not* found:\n" if @bad;
+print "  $_\n" for @bad;
+
 exit;
 
 
 sub MY::postamble {
     my $self = shift;
     my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)';
+    my $mani = maniread;
+
+    my @ims = grep /\.im$/, keys %$mani;
 '
 dyntest.$(MYEXTLIB) : dynfilt/Makefile
        cd dynfilt && $(MAKE) $(PASTHRU)
@@ -206,10 +321,23 @@ imconfig.h : Makefile.PL
        $(PERLRUN) Makefile.PL
        $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
 '.qq!
-lib/Imager/APIRef.pod : \$(C_FILES) apidocs.perl
+lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl
        $perl apidocs.perl lib/Imager/APIRef.pod
 
-!;
+!.join('', map _im_rule($perl, $_), @ims)
+
+}
+
+sub _im_rule {
+  my ($perl, $im) = @_;
+
+  (my $c = $im) =~ s/\.im$/.c/;
+  return <<MAKE;
+
+$c: $im lib/Imager/Preprocess.pm
+       $perl -Ilib -MImager::Preprocess -epreprocess $im $c
+
+MAKE
 
 }
 
@@ -251,72 +379,8 @@ sub automatic {
   }
 }
 
-
-sub gifcheck {
-  if ($formats{'gif'} and $formats{'ungif'}) {
-    print "ungif and gif can not coexist - removing ungif support\n";
-    delete $formats{'ungif'};
-  }
-
- RETR:
-  if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
-    my $msg = <<EOFF;
-
-You have libgif or libungif installed.  They are both known to have
-bugs.  Imager can crash or display other strange behaviour after
-reading or writing gif images.  Some of the gif tests can fail since
-they stress some parts of the buggy code.
-
-libungif or libgif 4.1.4 and later is safe.
-
-Of course it's possible your operating system distributor has patched
-all of these problems and you have nothing to worry about.
-
-Do you want to remove gif support? [Y/n]
-EOFF
-    chomp $msg;
-    my $resp = prompt($msg);
-    chomp($resp);
-    if ($resp ne "n") {
-      delete $formats{'gif'};
-      delete $formats{'ungif'};
-      return;
-    }
-  }
-
-  for my $frm (qw(gif ungif)) {
-    checkformat($frm) if ($MANUAL and $formats{$frm});
-  }
-
-  my @dirs;
-  for my $frm (grep $formats{$_}, qw(gif ungif)) {
-    push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
-  }
-  my $minor = 0;
-  my $major = 0;
-  FILES: for my $dir (@dirs) {
-    my $h = "$dir/gif_lib.h";
-    open H, "< $h" or next;
-    while (<H>) {
-      if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
-       $major = $1;
-       $minor = $2;
-       close H;
-       last FILES;
-      }
-    }
-    close H;
-  }
-
-  # we need the version in a #ifdefable form
-
-  push @defines, [ IM_GIFMAJOR => $major, "Parsed giflib version" ];
-  push @defines, [ IM_GIFMINOR => $minor ];
-}
-
-
-sub gd {
-  my($path,$chk)=@_;
+sub grep_directory {
+  my($path, $chk)=@_;
 
 #    print "checking path $path\n";
   if ( !opendir(DH,$path) ) {
@@ -329,35 +393,71 @@ sub gd {
   return map $path, @l;
 }
 
+sub _probe_default {
+  my ($format, $frm) = @_;
+
+  my $lib_check=$formats{$frm}{'libcheck'};
+  my $inc_check=$formats{$frm}{'inccheck'};
+
+  if ($lib_check) {
+    my @l;
+    for my $lp (@libs) {
+      push(@l, grep_directory($lp,$lib_check));
+    }
+    
+    my @i;
+    for my $ip (@incs) {
+      push(@i, $ip) if $inc_check->($ip,$frm);
+    }
+    
+    printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
+    $formats{$frm}{incdir} = \@i;
+    $formats{$frm}{libdir} = \@l;
+    return 1 if scalar(@i && @l);
+  }
+  else {
+    printf("%10s: not available\n", $frm);
+  }
+
+  return 0;
+}
 
 sub checkformat {
   my $frm=shift;
 
   print "  checkformat($frm)\n" if $VERBOSE;
   
-  my $code = $formats{$frm}{'code'};
-  if ($code && !$noprobe) {
-    print "    Calling probe function\n" if $VERBOSE;
-    return 1 if $code->($formats{$frm}, $frm);
-  }
+  my $format = $formats{$frm};
 
-  my $libchk=$formats{$frm}{'libcheck'};
-  my $incchk=$formats{$frm}{'inccheck'};
+  my @probes;
+  if (my $code = $format->{'code'}) {
+    if (ref $code eq 'ARRAY') {
+      push @probes, @$code;
+    }
+    else {
+      push @probes, $code;
+    }
+  }
+  push @probes, \&_probe_default;
 
-  my @l;
-  for my $lp (@libs) {
-    push(@l, gd($lp,$libchk));
+  print "    Calling probe function\n" if $VERBOSE;
+  my $found;
+  for my $func (@probes) {
+    if ($func->($format, $frm)) {
+      ++$found;
+      last;
+    }
   }
 
-  my @i;
-  for my $ip (@incs) {
-    push(@i, $ip) if $incchk->($ip,$frm);
+  $found or return;
+
+  if ($format->{postcheck}) {
+    print "    Calling postcheck function\n" if $VERBOSE;
+    $format->{postcheck}->($format, $frm)
+      or return;
   }
 
-  printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
-  $formats{$frm}{incdir} = \@i;
-  $formats{$frm}{libdir} = \@l;
-  return scalar(@i && @l);
+  return 1;
 }
 
 
@@ -394,14 +494,20 @@ sub init {
 
   my @definc = qw(/usr/include);
   @definc{@definc}=(1) x @definc;
-  @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
-        map { split /\Q$Config{path_sep}/} @incpaths );
+  @incs=
+    (
+     split(/\Q$Config{path_sep}/, $INCPATH),
+     map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths 
+    );
   if ($Config{locincpth}) {
     push @incs, grep -d, split ' ', $Config{locincpth};
   }
   if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
     push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
   }
+  if ($Config{incpath}) {
+    push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath};
+  }
   push @incs, grep -d,
       qw(/sw/include 
          /usr/include/freetype2
@@ -416,7 +522,7 @@ sub init {
   }
 
   @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
-    map { split /\Q$Config{path_sep}/} @libpaths );
+    map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths );
   if ($Config{loclibpth}) {
     push @libs, grep -d, split ' ', $Config{loclibpth};
   }
@@ -442,87 +548,6 @@ sub init {
   }
   push @libs, grep -d, qw(/usr/local/lib);
 
-  $formats{'jpeg'}={
-                   order=>'21',
-                   def=>'HAVE_LIBJPEG',
-                   inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
-                   libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
-                   libfiles=>'-ljpeg',
-                   objfiles=>'jpeg.o',
-                   docs=>q{
-                           In order to use jpeg with this module you need to have libjpeg
-                           installed on your computer}
-                  };
-
-  $formats{'tiff'}={
-                   order=>'23',
-                   def=>'HAVE_LIBTIFF',
-                   inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
-                   libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
-                   libfiles=>'-ltiff',
-                   objfiles=>'tiff.o',
-                   docs=>q{
-                           In order to use tiff with this module you need to have libtiff
-                           installed on your computer}
-                  };
-
-  $formats{'png'}={
-                  order=>'22',
-                  def=>'HAVE_LIBPNG',
-                  inccheck=>sub { -e catfile($_[0], 'png.h') },
-                  libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
-                  libfiles=>'-lpng -lz',
-                  objfiles=>'png.o',
-                  docs=>q{
-                          Png stands for Portable Network Graphics and is intended as
-                          a replacement for gif on the web. It is patent free and
-                          is recommended by the w3c, you need libpng to use these formats},
-                   code => \&png_probe,
-                 };
-
-  $formats{'gif'}={
-                  order=>'20',
-                  def=>'HAVE_LIBGIF',
-                  inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
-                  libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
-                  libfiles=>'-lgif',
-                  objfiles=>'gif.o',
-                  docs=>q{
-                          gif is the de facto standard for webgraphics at the moment,
-                          it does have some patent problems. If you have giflib and
-                          are not in violation with the unisys patent you should use
-                          this instead of the 'ungif' option.  Note that they cannot
-                          be in use at the same time}
-                 };
-
-  $formats{'ungif'}={
-                    order=>'21',
-                    def=>'HAVE_LIBGIF',
-                    inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
-                    libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
-                    libfiles=>'-lungif',
-                    objfiles=>'gif.o',
-                    docs=>q{
-                            gif is the de facto standard for webgraphics at the moment,
-                            it does have some patent problems. If you have libungif and
-                            want to create images free from LZW patented compression you
-                            should use this option instead of the 'gif' option}
-                   };
-
-  $formats{'T1-fonts'}={
-                       order=>'30',
-                       def=>'HAVE_LIBT1',
-                       inccheck=>sub { -e catfile($_[0], 't1lib.h') },
-                       libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
-                       libfiles=>'-lt1',
-                       objfiles=>'',
-                       docs=>q{
-                               postscript t1 fonts are scalable fonts. They can include 
-                               ligatures and kerning information and generally yield good
-                               visual quality. We depend on libt1 to rasterize the fonts
-                               for use in images.}
-                      };
-
   $formats{'TT-fonts'}=
     {
      order=>'31',
@@ -531,7 +556,7 @@ sub init {
                        && !-e catfile($_[0], 'fterrors.h') },
      libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
      libfiles=>'-lttf',
-     objfiles=>'',
+     objfiles=>'fontft1.o',
      code => \&freetype1_probe,
      docs=>q{
 Truetype fonts are scalable fonts. They can include 
@@ -540,34 +565,6 @@ visual quality esp on low resultions. The freetype library is
 used to rasterize for us. The only drawback is that there
 are alot of badly designed fonts out there.}
                       };
-  $formats{'w32'} = {
-                    order=>40,
-                    def=>'HAVE_WIN32',
-                    inccheck=>sub { -e catfile($_[0], 'windows.h') },
-                    libcheck=>sub { lc $_[0] eq 'gdi32.lib' 
-                                      || lc $_[0] eq 'libgdi32.a' },
-                    libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
-                    objfiles=>'win32.o',
-                    docs => <<DOCS
-Uses the Win32 GDI for rendering text.
-
-This currently only works on under normal Win32 and cygwin.
-DOCS
-                   };
-  $formats{'freetype2'} = {
-                           order=>'29',
-                           def=>'HAVE_FT2',
-                           inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
-                           libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
-                           libfiles=>'-lfreetype',
-                           objfiles=>'freetyp2.o',
-                           docs=><<DOCS,
-Freetype 2 supports both Truetype and Type 1 fonts, both of which are
-scalable.  It also supports a variety of other fonts.
-DOCS
-                           code => \&freetype2_probe,
-                          };
-
   # Make fix indent
   for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/  /mg; }
 }
@@ -604,6 +601,13 @@ sub getenv {
 
 }
 
+# populate the environment so that sub-modules get the same info
+sub setenv {
+  $ENV{IM_VERBOSE} = 1 if $VERBOSE;
+  $ENV{IM_INCPATH} = join $Config{path_sep}, @incpaths if @incpaths;
+  $ENV{IM_LIBPATH} = join $Config{path_sep}, @libpaths if @libpaths;
+}
+
 sub make_imconfig {
   my ($defines) = @_;
 
@@ -622,20 +626,47 @@ EOS
     }
     print CONFIG "#define $define->[0] $define->[1]\n";
   }
-  print CONFIG "\n#endif\n";
-  close CONFIG;
-}
+  if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) {
+    print CONFIG <<EOS;
+/*
+
+Compiler supports the GCC __attribute__((format...)) syntax.
+
+*/
+
+#define IMAGER_FORMAT_ATTR 1
+
+EOS
+  }
+
+  if ($Config{d_snprintf}) {
+    print CONFIG <<EOS;
+/* We can use snprintf() */
+#define IMAGER_SNPRINTF 1
+
+EOS
+  }
 
-# use pkg-config to probe for libraries
-# works around the junk that pkg-config dumps on FreeBSD
-sub _pkg_probe {
-  my ($pkg) = @_;
+  if ($Config{d_vsnprintf}) {
+    print CONFIG <<EOS;
+/* We can use vsnprintf() */
+#define IMAGER_VSNPRINTF 1
 
-  is_exe('pkg-config') or return;
+EOS
+  }
+
+  print CONFIG <<EOS;
+/*
+ Type and format code for formatted output as with printf.
 
-  my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
+ This is intended for formatting i_img_dim values.
+*/
+typedef $Config{ivtype} i_dim_format_t;
+#define i_DF $Config{ivdformat}
+EOS
 
-  !system("pkg-config $pkg --exists $redir");
+  print CONFIG "\n#endif\n";
+  close CONFIG;
 }
 
 # probes for freetype1 by scanning @incs for the includes and 
@@ -686,99 +717,17 @@ sub freetype1_probe {
   return 1;
 }
 
-# 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;
-
-  my $lflags = `freetype-config --libs`
-    and !$? or return;
-  chomp $lflags;
-
-  # before 2.1.5 freetype-config --cflags could output
-  # the -I options in the wrong order, causing a conflict with
-  # freetype1.x installed with the same --prefix
-  #
-  # can happen iff:
-  #  - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
-  #    in that order
-  #  - freetype 1.x headers are in prefix/include/freetype
-  my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
-  if (@incdirs == 2 
-      && $incdirs[1] eq "$incdirs[0]/freetype2"
-      && -e "$incdirs[0]/freetype/freetype.h"
-      && -e "$incdirs[0]/freetype/fterrid.h") {
-    print "** freetype-config provided -I options out of order, correcting\n"
-      if $VERBOSE;
-    $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
-                  map "-I$_", reverse @incdirs);
-  }
-  $frm->{cflags} = $cflags;
-  $frm->{lflags} = $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 $config;
-  for my $check_conf (qw(libpng libpng12 libpng10)) {
-    if (_pkg_probe($check_conf)) {
-      $config = $check_conf;
-      last;
-    }
-  }
-  $config or return;
-
-  my $cflags = `pkg-config $config --cflags`
-    and !$? or return;
-
-  my $lflags = `pkg-config $config --libs`
-    and !$? or return;
-
-  chomp $cflags;
-  chomp $lflags;
-  $frm->{cflags} = $cflags;
-  $frm->{lflags} = $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,...] [other options]
        $0 [--disable feature1,feature2,...]  [other options]
        $0 --help
 Possible feature names are:
-  png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
+  T1-fonts
 Other options:
   --verbose | -v
     Verbose library probing (or set IM_VERBOSE in the environment)
@@ -788,8 +737,10 @@ Other options:
     Add to the include search path
   --libpath dir
     Add to the library search path
-  --noprobe
-    Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
+  --coverage
+    Build for coverage testing.
+  --assert
+    Build with assertions active.
 EOS
   exit 1;
 
@@ -830,81 +781,25 @@ sub gen_PM {
   \%pm;
 }
 
-sub make_metafile {
-  my ($opts) = @_;
-
-  # extract the version
-  my $version = MM->parse_version($opts->{VERSION_FROM})
-    or die "Could not extract version number from $opts->{VERSION_FROM}\n";
-
-  # we don't set this on older EU::MM and it corrupts META.yml
-  # so don't generate it
-  return unless $opts->{AUTHOR};
-
-  my $meta = <<YAML;
---- #YAML:1.0
-name: $opts->{NAME}
-version: $version
-version_from: $opts->{VERSION_FROM}
-author: $opts->{AUTHOR}
-abstract: $opts->{ABSTRACT}
-installdirs: site
-YAML
-  if (keys %{$Recommends{$opts->{NAME}}}) {
-    $meta .= "recommends:\n";
-    while (my ($module, $version) = each %{$Recommends{$opts->{NAME}}}) {
-      $meta .= "  $module: $version\n";
-    }
-  }
-  $meta .= <<YAML;
-license: perl
-dynamic_config: 1
-distribution_type: module
-generated_by: $opts->{NAME} version $version
-YAML
-  my $save_meta;
-  if (open META, "< META.yml") {
-    my $old_meta = do { local $/; <META> };
-    close META;
+my $home;
+sub _tilde_expand {
+  my ($path) = @_;
 
-    $save_meta = $old_meta ne $meta;
-  }
-  else {
-    ++$save_meta;
-  }
-  if ($save_meta) {
-    print "Updating META.yml\n";
-    open META, "> META.yml" or die "Cannot create META.yml: $!";
-    print META $meta;
-    close META;
-  }
-}
-
-# this is intended to only be running on the development
-# machines
-sub distcheck {
-  if (-e '.svn') {
-    # update Changes if needed
-    my $write_changes;
-    # get the last revision from Changes
-    if (open CHANGES, "< Changes") {
-      <CHANGES>;
-      my ($changes_rev) = <CHANGES> =~ /^r(\d+)/
-       or ++$write_changes;
-
-      my ($revision) = grep s/^Revision: //, `svn info`
-       or die "Could not get Revision from svn";
-      chomp $revision;
-
-      $write_changes ||= $changes_rev != $revision;
-      close CHANGES;
+  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};
     }
-    else {
-      ++$write_changes;
-    }
-    if ($write_changes) {
-      print "Updating Changes file\n";
-      system 'svn log -v -r HEAD:943 >Changes';
+    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;