#!/bin/sh

# Copyright (C) 2004 Valery Reznic
# This file is part of the Elf Statifier project
# 
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License.
# See LICENSE file in the doc directory.

PROCESSOR=`uname -m` || exit
# Compatability translation (stollen from rpm macros)
COMPAT_PROCESSOR="$PROCESSOR"
case "$PROCESSOR" in
	i386 | i486 | i586 | i686 | athlon) COMPAT_PROCESSOR=i386;;
esac || exit

Output=config
Temp=$Output.tmp
Input=configs/$Output.$COMPAT_PROCESSOR
[ -f $Input ] || {
	echo "$0: processor '$PROCESSOR' not supported." 1>&2
	exit 1
}

rm -f $Temp || exit
(
	echo "# Don't change this file. It generated by '$0' from '$Input'" &&
	echo                                                                &&
	echo "PROCESSOR        := $PROCESSOR"                               &&
	echo "COMPAT_PROCESSOR := $COMPAT_PROCESSOR"                        &&
	echo                                                                &&
	cat $Input                                                          &&
	:
) > $Temp || { rm -f $Temp; exit 1; }

if cmp $Temp $Output >/dev/null 2>&1; then
	# Output file was not changed from previous invokation. 
	# Just clear Temp file
	rm -f $Temp # Here I not exit with error.
	exit 0
else
	mv -f $Temp $Output || exit
fi
exit 0
