#!/bin/sh

# Configure some things for gkrellmd when make is run.
# This configure is run automatically so no need to run it by hand.
#
# Copyright (C) 2006-2009  Bill Wilson

for i
do
	if [ "$i" = "--without-libsensors" ]
	then
		without_libsensors=yes
	fi
done

rm -f configure.h configure.log test test.o test.c

touch configure.h
exec 5>./configure.log

CC=${CC-gcc}

echo "CC    : ${CC}" 1>& 5
echo "CFLAGS: ${CFLAGS}" 1>& 5

if [ "$without_libsensors" != "yes" ]
then
echo "Checking for libsensors... " 1>& 5

cat << EOF > test.c
#include <stdio.h>
#include <sensors/sensors.h>

int main()
	{
	FILE	*f;

#if SENSORS_API_VERSION < 0x400 /* libsensors 3 code */
	FILE	*f;

	f = fopen("/etc/sensors.conf", "r");
	if (!f)
		return 1;
	if (sensors_init(f) != 0)
		return 1;
	fclose(f);
	return 0;
#else /* libsensors 4 code */
	if (sensors_init(NULL) != 0)
		return 1;
	return 0;
#endif
	}
EOF

$CC ${CFLAGS} -c test.c -o test.o 2>& 5
$CC test.o -o test -lsensors 2>& 5

if [ -x ./test ]
then
	echo 'Defining HAVE_LIBSENSORS' 1>& 5
	echo '#define HAVE_LIBSENSORS 1' >> configure.h
else
	echo "Not found, sensors will not have libsensors support..." 1>& 5
fi
fi
# end of libsensors check


rm -f test test.o test.c

exit 0
