#!/usr/bin/perl

($noclean,         @ARGV) = @ARGV if $ARGV[0] eq "--noclean";
(undef, $root,     @ARGV) = @ARGV if $ARGV[0] eq "--distrib";

$root && @ARGV == 0 or die 
"usage: genhdlists [--noclean] --distrib <root distrib>
";

$depslist = "$root/Mandrake/base/depslist.ordered";
$hdlists = "$root/Mandrake/base/hdlists";

open F, $hdlists or die "unable to open $hdlists";
foreach (<F>) {
    chomp;
    s/\s*#.*$//;
    /^\s*$/ and next;
    m/^\s*(hdlist\S*\.cz2?)\s+(\S+)\s*(.*)$/ or die "invalid hdlist description \"$_\" in hdlists file";

    my ($hdlist, $dir, $descr) = ($1, $2, $3);
    my $command = "genhdlist_cz2";
    $noclean and $command .= " --noclean";
    -e $depslist and $command .= " --ordered-depslist $depslist";
    $command .= " -o $root/Mandrake/base/$hdlist $root/$dir";

    system($command);
    system("touch $root/Mandrake/base/$hdlist");
}
close F;
