#!/bin/sh
# Name: run_checks
# Project: Sharity
# Author: Christian Starkjohann <cs@obdev.at>
# Creation Date: 2002-03-24
# Tabsize: 4
# Copyright: (c) 2002 by Christian Starkjohann, all rights reserved.
#     For details of the license see the file doc/License.txt.
# This Revision: $Id: run_checks,v 1.2 2002/03/25 14:32:21 cs Exp $

# General Description:
# This script checks out various system features. It creates the header
# file "check.h" and prints out what it finds on stdout. The script
# assumes that it is started from the current directory.

if [ -z "$CC" ]; then
	CC=cc
fi

echo "*** Checking out system features: ***"
echo "/* automatically created by run_checks */" >checks.h

for i in *.c; do
	exe=`echo $i | sed -e 's/[.]c$//'`
	rm -f $exe
	$CC $CFLAGS -o $exe $i $LIBS 2>/dev/null
	have=no
	if [ -x $exe ]; then
		if ./$exe; then
			have=yes
		fi
	fi
	rm -f $exe
	if [ "$exe" = check ]; then
		if [ "$have" = no ]; then
			echo "*** Fatal: can't compile anything"
			rm -f checks.h
			exit
		fi
		continue
	fi
	echo "have $exe: $have"
	macro=HAVE_`echo $exe | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
	if [ "$have" = yes ]; then
		echo "#define $macro 1" >>checks.h
	else
		echo "/* #define $macro 0 */" >>checks.h
	fi
done
