#!/bin/sh
#
# $Id$
#
# Make Release - Creates an EPICS release
#   By Matthew Needes and Bob Zieman
#
#  MakeRelease [-b]
#
#    [-b] - For fully built release
#


if [ ! -d src ]; then
	echo "Cannot find src directory, are you at the top of EPICS base ?"
	exit 1
fi


FULLY_BUILT=NO
if [ "${1}" = "-b" ]; then
	FULLY_BUILT=YES
	shift
	if [ "${1}" != "." ]; then
		echo "TOP: Cannot create a fully built release.";
		exit 1;
	fi
fi

# Retrieve EPICS release string from config/CONFIG_BASE_VERSION
. config/CONFIG_BASE_VERSION

if [ -z "${EPICS_VERSION}" ];
	then
		echo "TOP:  Cannot retrieve release number from config/CONFIG_BASE_VERSION";
		exit 1;
	fi

RELS="R${EPICS_VERSION}.${EPICS_REVISION}.${EPICS_MODIFICATION}.${EPICS_UPDATE_NAME}${EPICS_UPDATE_LEVEL}";

echo TOP: Creating ../${RELS}.tar;

if [ -f ${RELS}.tar* ];
	then
		echo "TOP: This release has already been created.";
		echo "TOP: Remove tar file or edit config/CONFIG_BASE_VERSION.";
		exit 1;
	fi

# Create list of files and dirs to include in tar file

cd ..

ls base/README* base/*.bat | xargs tar cvf ${RELS}.tar

ls base/Make* > /tmp/make_release.out.$$;

ls base/*COPYRIGHT* >> /tmp/make_release.out.$$;


if [ -d startup ];
	then
		find startup -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;
	fi

# binary / library / default.dctsdr / <rec>Record.h / etc.
if [ $FULLY_BUILT = "YES" ];
	then
		find base/include -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;

		find base/man -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;

		find base/bin -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;

		find base/lib -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;

		find base/dbd -name CVS -prune -o ! -type d -print \
				>> /tmp/make_release.out.$$;

	fi

find base/config -name CVS -prune -o -name SCCS -prune -o ! -type d -print \
		| grep -v '/O\..*$' >> /tmp/make_release.out.$$

find base/src -name CVS -prune -o -name SCCS -prune -o ! -type d -print \
		| grep -v '/O\..*$' >> /tmp/make_release.out.$$

cat /tmp/make_release.out.$$ | xargs tar rvf ${RELS}.tar 
		
rm /tmp/make_release.out.$$

