#!/bin/bash
# The script changes the versions of the toolchains and creates intermediate patch
# files required for build.
# This should be executed whenever the new set of the source is taken for building
# The following new files will be created:
# 1. bfd dir - configure.in-h8300, configure-h8300, configure.in-sh, configure-sh, configure.in-m32c, configure-m32c
# 2. gcc dir - version.c-h8300, version.c-sh, version.c-m32c
# 3. gcc dir - Makefile.in.diff (patch file for protoize and unprotoize utilities)
# Prerequisites: autoconf
# 						            Created on: 01/04/2004

#export TIMELIMIT=4
#CPU=m32c
#BINUTILS_VERSION=GNUM16CM32C_v0701
#GCC_VERSION=4.2-20061205
#GCC_VERSION_INTERNAL=4.2-GNUM16CM32C_v0701
#SOURCE_DIR_PATH=/home/kpit/fsfsrc
#GCCSRCDIR=$SOURCE_DIR_PATH/"gcc-"$GCC_VERSION

#GCC_VERSION_INTERNAL_QUOTES='"'$GCC_VERSION_INTERNAL'"'
#KPITGNUTOOLS_URL='"'"<"URL:http:"\/\/"www.kpitgnutools.com">"'"'

echo
CURRENT_DIR=`pwd`
echo
echo "Do you want to change the Binutils verison to "$BINUTILS_VERSION_INTERNAL" ([y]/n) ?"
./timed_read
retdata=$?
if [ $retdata = 14 ] || [ $retdata = 1 ];  then
	cd $BINUTILSSRCDIR
	cd ./bfd
	echo "Creating changed version files in binutils..."
	sed "/^AM_INIT_AUTOMAKE(bfd,.*$/s|^.*$|AM_INIT_AUTOMAKE(bfd,$BINUTILS_VERSION_INTERNAL)|g" configure.in > configure.in-$CPU
	/home/suma/autoconf/prefix/bin/autoconf configure.in-$CPU > configure-$CPU
fi

cd $CURRENT_DIR

echo
echo "Do you want to change the Gcc verison to "$GCC_VERSION_INTERNAL" ([y]/n) ?"
./timed_read
retdata=$?
if [ $retdata = 14 ] || [ $retdata = 1 ];  then
	cd $GCCSRCDIR
	cd ./gcc
	echo "Creating changed version files in Gcc..."
	echo $GCC_VERSION_INTERNAL > BASE-VER
	sed "/^const\ char\ bug_report_url\[\].*$/s/^.*$/const\ char\ bug_report_url[]\ \=\ $KPITGNUTOOLS_URL;/g" version.c > version.c-$CPU
fi

cd $CURRENT_DIR

echo
echo "Do you want to create the makefile.in.diff patch file required for mingw builds ([y]/n) ?"
./timed_read
retdata=$?
if [ $retdata = 14 ] || [ $retdata = 1 ];  then
	cd $GCCSRCDIR
	cd ./gcc
	echo "Creating the patch file..."
	sed '/^proto\:.*SYSCALLS\.c\.X/s/SYSCALLS.*$//g' Makefile.in > Makefile.in.out
	diff -C 2 Makefile.in Makefile.in.out > Makefile.in.diff	
	rm -f Makefile.in.out
fi

cd $CURRENT_DIR


