#!/bin/sh
# $Id: save-ncurses,v 1.8 2006/12/18 21:32:39 tom Exp $
#
# save the built-stuff from configuring & building ncurses, to make it simpler
# to do rebuilds
#
SRC=`pwd`
if test -d ../../save-ncurses
then
	DST=../../save-ncurses
else
	DST=../save-ncurses
fi

THIS=`basename $SRC`
THAT=`echo $THIS|sed -e s/ncurses//`
if test "$THIS" = "$THAT"
then
	echo '? cannot save '$SRC
	exit 1
fi

FILES="config.status include/ncurses_cfg.h"
if ( egrep '^s%@host_os@%.*%g' config.status >/dev/null 2>/dev/null )
then
	# autoconf 2.13
	GRPL='^s%@'
	GRPR='@%.*%g'
	SED1='s/s%@'
	SED2='@%//'
	SED3='s/%g//'
	FILES="$FILES config.cache"
elif ( egrep '^s,@host_os@,.*,;t' config.status >/dev/null 2>/dev/null )
then
	# autoconf 2.52
	GRPL='^s,@'
	GRPR='@,.*,;t'
	SED1='s/s,@'
	SED2='@,//'
	SED3='s/,;t t//'
else
	echo 'Cannot parse config.status'
	exit 1
fi

for f in $FILES
do
	if test ! -f $f
	then
		echo '? nothing to save: '$f
		exit 1
	fi
done
test -f config.cache && FILE="$FILES config.cache"

if test ! -d $DST
then
	mkdir $DST
fi

cd $SRC

Host=`egrep "${GRPL}host_os${GRPR}"       config.status | sed -e "${SED1}host_os${SED2}" -e "${SED3}" -e 's/ //g'`
Comp=`egrep "${GRPL}CC${GRPR}"            config.status | sed -e "${SED1}CC${SED2}"      -e "${SED3}"`
Modl=`egrep "${GRPL}DFT_LWR_MODEL${GRPR}" config.status | sed -e "${SED1}DFT_LWR_MODEL${SED2}"    -e "${SED3}"`
Libs=`egrep "${GRPL}LIB_SUFFIX${GRPR}"    config.status | sed -e "${SED1}LIB_SUFFIX${SED2}"    -e "${SED3}"`
OUT=${Host}-${Comp}-${Modl}-ncurses${Libs}

echo Creating ${OUT}:

chmod u+wx $DST
rm -f $DST/${OUT}.tgz
rm -rf $DST/$OUT

mkdir $DST/$OUT
tar cvf - $FILES *.out *.log include/*.h |(cd $DST/$OUT; tar xf -)

cd $DST
archive $OUT
chmod -w .
