#makeppd.pl
use File::DosGlob qw(glob);
use File::Path;
use File::Basename;
use Config;

$make='nmake.exe';

END {print "\nDONE -- PRESS ENTER\n";<STDIN>};

# system('perl Makefile.PL');
# system($make) and die "Failed to make!\n";

system($make, 'dist'); # this creates the ordinary distribution

# I need the archive to find the version number!
# If you comment this out, always copy the archive to current directory.

# this part of code finds the latest distribution, I don't have time to
# explore how to find the version number

@archives = sort (grep {!/-PPM\.tar\.gz$/i} <*.tar.gz>);
$archive = $archives[-1];

($name = $archive) =~ s/\.tar\.gz$//;

($module = $name) =~ s/-[\d.]+$//;

($file = $module) =~ s/^.*-(.*?)$/$1/;

$module =~ s/-/\\/g;

my $archname = $Config{'archname'};
print "Module name : $file\n";
print "Newest archive is $archive\n";
print "Archive name: $archname\n";

# system($make, 'ppd');
# you may do something like
mkpath([ $archname ]);
system($make, 'ppd', "BINARY_LOCATION=$archname/$name-PPM.tar.gz");
# if you do not apply my path to ExtUtils\MM_Unix.pm

$html = "blib/html/lib/$module.html";
$htmlDir = dirname($html);
mkpath([ $htmlDir ]) or die "can't create $htmlDir: $!\n";
my @cmd = 
qq{pod2html.bat "-htmlroot=." "$file.pm" "-outfile=$html"};
print(@cmd, "\n");
system(@cmd);

system("tar cvf $archname/$name-PPM.tar blib");
system("gzip --best $archname/$name-PPM.tar");

# rmtree(['blib', 'pod2html-dircache', 'pod2html-itemcache', 'pm_to_blib']);
