The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl
use strict;
use Config;
use File::Copy;
chmod(0666,'Makefile');
my $file;

if ($^O eq 'MSWin32')
 {
  if ($Config{'cc'} =~ /gcc/ && $Config{'make'} =~ /dmake/)
   {
    # This is the StrawberryPerl configuration
    $file = 'scripts/makefile.gcc';
   }
  elsif ($Config{'cc'} =~ /gcc/)
   {
    $file = 'scripts/makefile.mingw';
   }
  elsif ($Config{'cc'} =~ /bcc/)
   {
    $file = 'scripts/makefile.bc32';
   }
  else
   {
    $file = 'scripts/makefile.vcwin32';
    warn "Assuming ".$Config{'cc'}." is visual C of some kind\n";
   }
 }
else
 {
  if ($Config{'gccversion'})
   {
    $file = 'scripts/makefile.gcc';
   }
  else
   {
    if (($Config{archname} =~ /^IA64\./) && ($^O eq "hpux"))
     {
      $file = 'scripts/makefile.hp64';
     }
    else
     {
      $file = 'scripts/makefile.std';
      my %makefiles = map { /makefile\.(.*)/ && ($1 => $_) } glob('scripts/makefile.*');
      foreach my $arch (sort keys %makefiles)
       {
        if ($^O =~ /$arch/i)
         {
          $file = $makefiles{$arch};
         }
       }
     }
   }
  warn "Using $file for $^O\nIf make fails read PNG/libpng/INSTALL\n";
 }

copy($file,"Makefile")
   || die "Cannot copy $file to Makefile:$!";

if ($^O eq 'darwin' || $Config{'archname'} =~ m{^amd64-freebsd($|-.*)})
 {
  system(sh => "./configure");
  open my $fh, ">> Makefile" or die "Can't write to Makefile: $!";
  print $fh <<'EOF';

libpng.a: all
	cp .libs/libpng.a libpng.a

clean:
	rm -f libpng.a

# Empty rule needed since ExtUtils::MakeMaker 6.36 (ca.)
test:

EOF
 }

1;