#!/usr/bin/perl
#
# $Id: write_manifest,v 33.3 2011/01/03 15:05:05 anbrown Exp $
#
# (c) 1999-2011 Morgan Stanley & Co. Incorporated
# See ..../src/LICENSE for terms of distribution.
#
# This is not used to build the distribution, just to keep that pesky
# MANIFEST file up to date...
#
# To run this, from the top level source directory, ./util/write_manifest
#

use strict;

my %skip = map { $_ => 1 } qw(
                              .options/rcsMajor
                              .msbaseline
                              .exclude
                             );
my %files;

warn "Searching source tree for files...\n";
open(FIND, '-|', "find . -type f -print") ||
  die "Unable to fork find: $!\n";
while ( <FIND> ) {
    chomp;
    s|^\./||;
    next if $skip{$_};
    next if /~$/;
    $files{$_} = 1;
}
close(FIND) ||
  die "Error running find: $!\n";

#
# Include generated files
#
foreach my $file (qw(MANIFEST Changes.html README.html)) {
    $files{$file} = 1;
}

warn "Writing new MANIFEST file...\n";
open(NEW, '>', "MANIFEST.$$") ||
  die "Unable to open MANIFEST.$$: $!\n";
foreach (sort keys %files) {
    print NEW "$_\n";
}
close(NEW) ||
  die "Unable to close MANIFEST.$$: $!\n";

rename("MANIFEST.$$","MANIFEST") ||
  die "Unable to rename MANIFEST.$$ to MANIFEST: $!\n";

exit 0;

END {
    unlink "MANIFEST.$$";
}
