#!/usr/bin/perl

use strict;
use XML::Simple;
use Data::Dumper;

my $xml = new XML::Simple;

my $data = $xml->XMLin(".distfiles", KeyAttr => {entry => "path"});

#print Dumper($data);
my @files;
#print Dumper($data->{"target"}->{"entry"});
foreach my $key (keys %{$data->{target}->{entry}}) {
    my $entry = $data->{target}->{entry}->{$key};
    if ($key eq ".") {
        next;
    }
    if ($entry->{"wc-status"}->{"item"} eq "deleted") {
        next;
    }
    if ($entry->{"wc-status"}->{"item"} ne "unversioned") {
        if (! -d $key) {
            push(@files, $key);
        }
    }
}
open(DISTFILE, ">distfiles.mk");
print DISTFILE "# This File is automatically generated by make dist-update\n";
print DISTFILE "# Any Edits on this file will be lost next time dist-update is run\n\n";
print DISTFILE "DISTFILES = ";
foreach my $file (values @files) {
    print DISTFILE "    $file \\\n";
}
#always add vers.cpp
print DISTFILE "    cpp/src/vers.cpp\n";
    