#!/bin/sh

# Find the location of the share directory in the src tree
# Assumes this script is in a first level subdirectory in the same tree
SHAREDIR="$( cd "$(dirname "$0")/../share" 1>/dev/null 2>/dev/null; pwd -P )"
echo "Share directory is ${SHAREDIR}"

(
echo "# DO NOT EDIT sharefiles.mk.  It is automatically generated"
echo "# by running make.  This list is generated by"
echo "# ../admin/make_share_list"
echo "# But note that is is checked in so if there are new files"
echo "# or deleted files, be sure to check in this file with the"
echo "# changes."
echo ""
echo "sharefiles = \\"

# Find all the files in the share directory, and then filter the
# output.  We remove lots of files that we don't want installed like
# files in the fortran directories, CVS files, and other random files.
#
# Then remove the leading dot and append a \ to each line, but not the
# last line.

(cd "${SHAREDIR}"; find . -type f) |
egrep -v '\.ERR$' |
egrep -v 'CVS|Makefile(\.in|\.am)?|^\./Makefile|\.gitignore' |
egrep -v '/fortran/' |
egrep -v 'colnew/ex./' |
egrep -v 'lbfgs/.*\.f' |
egrep -v '/\.#' |
egrep -v '~|#' |
sed -e 's%\./%%' -e 's%$% \\%' |
sort -f -d |
sed '$s/\\$//'
)  > sharefiles.mk.$$

# If the original and new versions are different, update the original
# with the new information, otherwise remove the generated file.

cmp sharefiles.mk sharefiles.mk.$$ >/dev/null 2>/dev/null || mv sharefiles.mk.$$ sharefiles.mk

# remove temporary sharefile.mk.$$ - if it still exists.
rm -f sharefiles.mk.$$
