#!/bin/sh
echo

error() {
	echo Not working.  "$@" 1>&2
	exit 1
}

gnumake() {
	echo trying $1 ...
	[ x"`$1 -v 2>&1 | grep GNU`" != x ] && gmake=$1
}
gnumake gmake || gnumake make || error 'You need GNU Make.'
$gmake mrproper > /dev/null 2>&1 || error $gmake mrproper failed.

cat > a.c << "EOF"
#include <stdio.h>
int main()
{
	return 0;
}
EOF

echo trying gcc ...
(gcc -o a.out a.c >/dev/null 2>&1 && echo CC=gcc -Wall > config.mak) ||
(echo trying c89 ...; \
 c89 -o a.out a.c >/dev/null 2>&1 && echo CC=c89 > config.mak) ||
(echo trying cc ...; \
 cc -o a.out a.c >/dev/null 2>&1 && echo CC=cc > config.mak) ||
\
error "Can't find working C compiler."
rm -f a.out a.c
echo

echo trying xmms-config ...
xmms-config --libs >/dev/null 2>/dev/null ||
error 'Are you sure XMMS libs and headers are installed?'
echo

./find-def-plug.sh
echo

for i in "$@"; do
	echo "$i" >> config.mak
done

echo Type $gmake now.
echo
