#!/bin/bash
# Copyright (C) 2006  Nathan (Acorn) Pooley
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# 
# 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 (gpl.txt) for more details. 
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to 
# the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# 
# You can contact the author, Nathan (Acorn) Pooley, by writing
# to Nathan (Acorn) Pooley, 949 Buckeye Drive, Sunnyvale, CA  94086, USA
# or through the form at http://www.rawbw.com/~acorn/wand/feedback.html
# 
#@DOC@ set up to build all software

_notice() {
	echo ""
	echo "Wand Software Version 1.1 Copyright (C) 2006 Nathan (Acorn) Pooley"
	echo "Wand software comes with ABSOLUTELY NO WARRANTY; for details"
	echo "see gpl.txt.  This is free software, and you are welcome"
	echo "to redistribute it under certain conditions; see gpl.txt for"
	echo "details."
	echo ""
}

tmp=tmp_config
tmp2=tmp_config2
err=0
\rm -f $tmp $tmp2

#
# check for Linux
#
ver=`uname`
if [[ $ver != [Ll][Ii][Nn][Uu][Xx] ]] ; then
	echo "WARNING: This software has been tested only on Linux and might or"
	echo "might not work on other operating systems."
	echo ""
fi

#
# check for sed
#
sed --version > $tmp 2>&1 || err=1
if (( err )) ; then
	_notice
	echo "ERROR: This software requires that sed be in"
	echo "the current PATH."
	exit 1
fi

#
# check for grep
#
grep --version > $tmp 2>&1 || err=1
if (( err )) ; then
	_notice
	echo "ERROR: This software requires that grep be in"
	echo "the current PATH."
	exit 1
fi

#
# check for make
#
make --version > $tmp 2>&1 || gmake --version > $tmp 2>&1 || err=1
if (( ! err )) ; then
	head $tmp | grep -i 'GNU *Make' > $tmp2 2>&1 || err=1
fi
if (( err )) ; then
	_notice
	echo "ERROR: This software requires gnu make"
	echo "You can download it for free from"
	echo "         http://savannah.gnu.org/projects/make/"
	exit 1
fi

#
# check for gcc
#
gcc --version > $tmp 2>&1 || err=1
if (( err )) ; then
	_notice
	echo "ERROR: This software requires that gcc (The Gnu C compiler) be in"
	echo "the current PATH."
	echo "You can download gcc for free from"
	echo "      http://gcc.gnu.org/"
	exit 1
fi
echo "found `type gcc`"

#
# check for cpp
#
cpp --version > $tmp 2>&1 || err=1
if (( err )) ; then
	_notice
	echo "ERROR: This software requires that cpp (The C preprocessor) be in"
	echo "the current PATH."
	exit 1
fi
echo "found `type cpp`"

#
# check for gputils
#
gpasm --version > $tmp 2>&1 || err=1
if (( err )) ; then
	_notice
	echo "ERROR: This software requires that gpasm be in"
	echo "the current PATH.  The gpasm program is part of the"
	echo "gputils softwafre package.  To get gputils try:"
	echo "      http://gputils.sourceforge.net/"
	echo "On a debian based system (e.q. Ubuntu) try:"
	echo "      apt-get install gputils"
	exit 1
fi
echo "found `type gpasm`"

#
# success
#
\rm -f $tmp $tmp2
_notice
echo "To build this software type 'make' from the top level directory (the"
echo "directory where the configure script is located)."
