#! perl -w
die unless defined $ARGV[0];

while(<STDIN>){
    next if /^\s*--/;
    s/^\s*constraints:/ /;
    s/,$//;
    next if /^\s+(\S+)\s+installed\s*$/;
    die unless /^\s+(\S+)\s+==(\S+)\s*$/;
    $z{$1}=$2;
}
# hsx2hs for clckwrks
# markdown-unlit for generics-eot
# alex and happy compiled before any of these on their own

# nothing in initial because we now rely on old build for all of these
#for(qw/gtk2hs-buildtools hscolour c2hs cpphs hsx2hs markdown-unlit/){
#    $initial{$_}=1;
#}
if($ARGV[0]eq'initial'){
    for(sort keys%initial){
        &outpackage($_);
    }
print "\n";
} elsif($ARGV[0]eq'rest') {
    for(sort keys%z){
        next if $initial{$_};
        next if $_ eq 'cabal-install';
        &outpackage($_);
    }
    print "\n";
} elsif($ARGV[0]eq'config'){
    for(sort keys%z){
        print "constraint: $_ == $z{$_}\n"
    }
} else {
    die;
}
sub outpackage {
    my $p=shift;
    print " ",$p;
}
