+
+sub cleanup {
+ my ( $relroot, $reldir ) = @_;
+
+ require File::Path;
+
+ my @cmds = (
+ [ qw{make distclean} ],
+ [ qw{git clean -dxf} ],
+ );
+
+ foreach my $cmd (@cmds) {
+ print join( ' ', "Running:", @$cmd, "\n" );
+ system @$cmd;
+ die "fail to run ".(join(' ', @$cmd) ) unless $? == 0;
+ }
+
+ if ( -d "$relroot/$reldir" ) {
+ print "Removing directory $relroot/$reldir\n";
+ File::Path::rmtree("$relroot/$reldir");
+ }
+
+ # always clean both
+ my @files = ( "$relroot/$reldir.tar.gz", "$relroot/$reldir.tar.xz" );
+
+ foreach my $f ( @files ) {
+ next unless -f $f;
+ print "Removing file '$f'\n";
+ unlink($f);
+ }
+
+ return;
+
+}
+
+1;