5 kx #!/bin/env perl
5 kx
5 kx use File::Basename;
5 kx
5 kx my $base;
5 kx my ($toolchain, $hardware, $flavour);
5 kx my $target_build_dir;
5 kx my $fname = "";
5 kx
5 kx sub usage
5 kx {
5 kx print <<EOF;
5 kx
5 kx Usage: dist_clean [options]
5 kx Options:
5 kx --destination=DEST - where DEST is a destination directory.
5 kx --toolchain=TOOLCHAIN - where TOOLCHAIN ia a toolchain name;
5 kx --hardware=HARDWARE - where HARDWARE ia a HARDWARE name;
5 kx --flavour=FLAVOUR - where FLAVOUR ia a FLAVOUR name.
5 kx
5 kx EOF
5 kx exit;
5 kx }
5 kx
5 kx
5 kx foreach ( @ARGV )
5 kx {
5 kx if( /--destination=(\S*)/ )
5 kx {
5 kx $base = $1;
5 kx }
5 kx elsif( /--toolchain=(\S*)/ )
5 kx {
5 kx $toolchain = $1;
5 kx }
5 kx elsif( /--hardware=(\S*)/ )
5 kx {
5 kx $hardware = $1;
5 kx }
5 kx elsif( /--flavour=(\S*)/ )
5 kx {
5 kx $flavour = $1;
5 kx }
5 kx elsif( /--help/ )
5 kx {
5 kx usage;
5 kx }
5 kx }
5 kx
5 kx if( ! defined $base or $base eq "" ) { usage; }
5 kx if( ! defined $toolchain or $toolchain eq "" ) { usage; }
5 kx if( ! defined $hardware or $hardware eq "" ) { usage; }
5 kx if( ! defined $flavour or $flavour eq "" )
5 kx {
5 kx $flavour = "";
5 kx $target_build_dir = "." . $toolchain . "/" . $hardware;
5 kx }
5 kx else
5 kx {
5 kx $target_build_dir = "." . $toolchain . "/" . $hardware . "/" . $flavour;
5 kx }
5 kx
5 kx $fname = $target_build_dir . "/.dist";
5 kx
5 kx open( F, '<', $fname ) or die "Could not open $fname";
5 kx
5 kx while( <F> )
5 kx {
5 kx chomp;
5 kx $f = "$base/$_";
5 kx unlink $f;
5 kx $dirs{dirname($f)}++;
5 kx }
5 kx
5 kx foreach ( sort { length($b) <=> length($a) } keys %dirs )
5 kx {
5 kx while( rmdir )
5 kx {
5 kx $_ = dirname( $_ );
5 kx }
5 kx }