#!/bin/sh
# $Id: save-lynx,v 1.4 2001/12/27 12:59:27 tom Exp $
#
# save the built-stuff from configuring & building lynx, to make it simpler
# to do rebuilds
#
SRC=`pwd`
DST=../save-lynx

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

for f in config.status lynx_cfg.h
do
	if test ! -f $f
	then
		echo '? nothing to save: '$f
		exit 1
	fi
done

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

cd $SRC

. ./config.cache

FILES="config.status"
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

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}" -e 's/ //g'`
Disp=`egrep "${GRPL}SCREEN${GRPR}" config.status  | sed -e "${SED1}SCREEN${SED2}"  -e "${SED3}" -e 's/ //g'`
Opts=`egrep "${GRPL}CFLAGS${GRPR}" config.status  | sed -e "${SED1}CFLAGS${SED2}"  -e "${SED3}" -e 's/-[IUD][^ ]*//g' -e 's/-[Wf][a-z0-9-]*//g' -e 's/-g//' -e 's/-O[0-9]*//' -e 's/ //g'`

Disp=$cf_cv_screen
case ".$cf_cv_ncurses_version" in
.[1-9]*) #(vi
	Disp="ncurses${cf_cv_ncurses_version}"
	;;
esac
if ( egrep 'define[ 	]+USE_COLOR_STYLE' lynx_cfg.h 2>&1 >/dev/null ) then
	Style=styled
else
	Style=nostyle
fi
Opts=`egrep "${GRPL}CFLAGS${GRPR}" config.status  | sed -e "${SED1}CFLAGS${SED2}"  -e "${SED3}" -e 's/-[IUD][^ ]*//g' -e 's/-[Wf][a-z0-9-]*//g' -e 's/-g//' -e 's/-O[0-9]*//' -e 's/ //g'`
OUT=${Host}-${Comp}${Opts}-${Disp}-${Style}

if [ -f main.o -a ! -f size.out ]
then
	size *.o >size.out
fi

echo Creating ${OUT}:

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

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

cd $DST
archive $OUT
chmod -w .
