Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 74 lines (59 sloc) 1.317 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#!/usr/bin/perl

use Cwd;

our $msg;

clean_build_files();
defined($msg) and print $msg;

1;

sub recurse_dirs {
  foreach my $i (@_) {
    my $orig_dir = cwd;

    unless (-d $i && chdir $i) {
      $msg = "clean.pl: could not enter '$i'.\n";
      return 0;
    }
    print "Entering '$i'\n";

    clean_build_files($i) or return 0;

    print "Leaving '$i'\n";
    unless (chdir $orig_dir) {
      $msg = "clean.pl: original directory disappeared.\n";
      return 0;
    }
  }
  return 1;
}

sub delete_file {
  if (-f $_[0]) {
    print "Deleting '$_[0]'.\n";
    unless (unlink $_[0]) {
      $msg = "clean.pl: could not delete '$_[0]'.\n";
      return 0;
    }
  }
  return 1;
}

sub clean_build_files {
  # recurse build directories
  opendir (my $dir, '.') or die "Cannot read current directory.\n";
  my @dirs = grep { -d $_ && not $_ =~ /^\./ } readdir($dir);
  closedir ($dir);
  recurse_dirs(@dirs) or return 0;

  ## Clean up build files ##
  my @files;

  # remove object files
  @files = <*.o>;
  foreach my $i (@files) {
    delete_file($i) or return 0;
  }

  # remove exe files
  @files = <*.exe*>;
  foreach my $i (@files) {
    delete_file($i) or return 0;
  }
  @files = <7kaa*>;
  foreach my $i (@files) {
    if (-f $i && -x $i) {
      delete_file($i) or return 0;
    }
  }

  return 1;
}
Something went wrong with that request. Please try again.