#! /bin/sh

# Handle exceptional cases in Geomview source distribution.
# We read the distribution list, and insert -C ... -C ${GEOM} sequences
# for each file we know about.  For example
# Where "data/.geomview" appears in the given file,
# replace it with the sequence
#  -C
#  dist
#  data/.geomview
#  -C
#  ..

# GNU tar interprets the -C's as embedded chdir commands.
# The effect is that we can distribute dist/data/.geomview in place of our own.

GEOM=`pwd`

# Ensure DISTLIST.whatever is called MANIFEST instead.
manifest="$1"
if [ "x$manifest" = "x-m" ]; then
   manifest="$2"
   shift 2
fi
test -d dist || mkdir dist
rm -f dist/MANIFEST dist/Geomview
ln -s . dist/Geomview
test -f $manifest && ln $manifest dist/MANIFEST

awk 'BEGIN { BACK = "-C\n'"${GEOM}"'"; }

    /(geomview\/x11|mgexample)\/O\.next/ {
	# Pretend some X-specific things don''t work on NeXT.
	# They won''t with vanilla NeXTStep, though if you have X libs, fine.
	next;
    }

    /makefiles\/(mk.site.*|mk.NeXT)$/ {
	print "-C\nmakefiles/dist";
	print $0;
	print BACK;
	next;
    }


    /'"${manifest:-nonesuch}"'/ {
	print "-C\ndist";
	print "./Geomview/MANIFEST";
	print BACK;
	next;
    }

    { print; }
    
' $@
