#!/bin/sh
# Handle Bison version issues for getdate.y
#

b_version=`bison --version | sed -n -e '/^bison/s/.*)  *//p'`

if [ -z "$b_version" ]
then
    echo "Arrgh ... cannot get bison version from ..."
    bison --version
    exit 1
fi

if [ ! -f getdate.y.in ]
then
    echo "Arrgh ... cannot find getdate.y.in"
    exit 1
fi

rm -f getdate.y
cat <<End-of-File >getdate.y
/*
 * DO NOT EDIT THIS FILE ... CHANGES HERE WILL BE LOST
 *
 * This file created from getdate.y.in (make changes there!)
 * by fix_getdate_y on ${PACKAGE_BUILD_DATE:-`date`}.
 */

End-of-File

# From the bison CHANGELOG
# 2012-10-26
#	version 2.6.4
# 2012-10-25
# 	src/parse-gram.y (%pure-parser, %name-prefix): Replace with...
#	 	(%define api.pure, %define api.prefix)
#
case "$b_version"
in
    2.[0-5]*|2.6.[0-3])
	sed -e 's/^PUT-PURE-DECL-HERE.*/%pure-parser/' <getdate.y.in >>getdate.y
	;;
    2.6.[4-9]|2.[7-9]*|3.*)
	sed -e 's/^PUT-PURE-DECL-HERE.*/%define api.pure full/' <getdate.y.in >>getdate.y
	;;
    *)
	rm -f getdate.y
	echo "Arrgh ... don't know what to do with bison version $b_version"
	exit 1
	;;
esac

chmod a-w getdate.y

exit 0

