#! /bin/bash
# Last edited on 2010-07-03 01:45:02 by stolfi

# Given a bunch of directories, prepares a tar file for export.


dirs=( "$@" )

# Find all possible executable files:
# Assume that a ".c" minus the "c" is a possible executable.
find "${dirs[@]}" -name '*.c' -print \
  | sed -e 's:[.]c$::g' \
  | sort \
  > .execs

( ls -1 [A-Z]*.make 00-README ; 
  find "${dirs[@]}" \( -type f -o -type l \) -print \
) | sort \
  > .all-files

cat .all-files \
  | egrep -v -e '/(JUNK|OLD|LATER|SAVE)/' \
  | egrep -v -e '[-/](out|ot|out_old)[-/]' \
  | egrep -v -e '[~]$' \
  | egrep -v -e '[.](out|ps|eps|zip|tgz|tar[.]gz|o|ho|a|out|toc|aux|lof|lot|blg|bbl|dvi|errs|[0])$' \
  | egrep -v -e '[ /]([.][a-z]*|extract-ho-deps|Deps.make)$' \
  | bool 1-2 - .execs \
  > .files-to-tar

bool 1-2 .all-files .files-to-tar \
  > .files-to-omit
