#!/bin/sh

if test "$1" = "--help" ; then
cat << EOT
usage:	configure [--name=[VALUE] | NAME=[VALUE] |
	--with-name=[VALUE] | --without-name] ...

VALUE may not contain carriage return or line feed
Any values not explicitly set are reset to their defaults
EOT
elif test "$1" = "--version" ; then
cat << EOT
micro configure 0.1.1, Copyright (C) 2002 by Dimitar Zhekov

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
	
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Report bugs to jimmy@is-vn.bg
EOT
elif test -f Makefile ; then
	if test -f Makefile.in ; then
		cp -f Makefile.in Makefile
	else
		cp -a Makefile Makefile.in
	fi
	w=`echo -e "[\t ]*"`
	r=`echo -e "\r"`
	for i ; do
		if test "$i" != "`echo "$i" | sed -e 1q`" ; then
			echo "$0: `echo "$i" | sed -e "s/$r/^M/" -e 1q`^J...: contains line feed"
		elif echo "$i" | grep $r > /dev/null ; then
			echo "$0: `echo "$i" | sed -e "s/$r.*//"`^M...: contains carriage return"
		elif test -n "$i" ; then
			i=`echo "$i" | sed -e "s$r^--with-\([a-z][a-z0-9]*\)=\|^--without-\([a-z][a-z0-9]*\)\\$$r--\1\2=$r"`
			if echo "$i" | grep "^--[a-z][a-z0-9]*=\|^[A-Z][A-Z0-9]*=" > /dev/null ; then
				n=`echo "$i" | sed -e "s$r^-*$r$r" -e "s$r=.*$r$r"`
				if grep "^$n$w=" Makefile > /dev/null ; then
					cp Makefile $$
					sed -e "s$r^\($n$w=$w\).*$r\1`echo "$i" | sed -e "s$r^.*=$r$r"`$r" $$ > Makefile
					grep "^$n$w=" Makefile /dev/null
				else
					echo "$0: $n: not found in Makefile"
				fi
				unset n
			else
				echo "$0: $i: not recognized"
			fi
		fi
	done
	unset i
	unset r
	unset w
	if test -f $$ ; then
		rm -f $$
	else
		rm -f Makefile.in
	fi
else
	echo "$0: Makefile: not found"
	false
fi
