#!/usr/bin/env perl

#A  Greg Gamble ... based in part on Frank Lbeck's packpack
## 
##  Usage: make_zoo
##
##  Uses perl and zoo to create just the <pname>-<version>.zoo
##  and copies the README to README.<pname> (both are placed in
##  the pkg directory).
##

#set values of <pname> and <version>
$pname = "example";
$version = "1.2";

#if <version> is in file VERSION uncomment and capture it this way
#$version = `cat VERSION`;
#chomp $version;

#remove files created during installation
system( "make clean" );

#remove old .zoo file
system( "rm -f ../$pname-$version.zoo" );

#copy README in pkg directory 
system( "cp -f README ../README.$pname" );

### Create new .zoo file in pkg directory ###################################
chdir "..";

# substrings (mainly suffixes) that determine files we want to exclude
$prune = "[._]cvs|[.]bbl|[.]aux|[.]toc|[.][ib]lg|[.]log|[.]lab|[.]ind|[.]idx".
#         "|zoo|make_".         # uncomment to exclude make_doc, make_zoo etc.
         "|[.]sw[op]|[.-]bak|~|[.][#]";

# Create the .zoo file
system( "find $pname -path '*/CVS' -prune -o -print | egrep -v '$prune' |".
        "zoo ahI $pname-$version.zoo" );

@files = `find $pname -path '*/CVS' -prune -o -print | egrep -v '$prune'`;
# Mark some files as text files
for $file ( @files ) {
  chomp $file;
  if ($file =~ /[.](txt|g(|[id])|htm(|l)|[ch]|xml|tex|bib|six|tst|mst)$/ ||
      $file =~ /(VERSION|README|INSTALL|Makefile|configure|make_)/) {
    system( "(echo '!TEXT!'; echo '/END') | zoo c $pname-$version.zoo $file" );
  }
}
