#!/bin/sh
#
# The Preprocessor:
CPP="gcc -E"
# Compiler (& linker):
[ -z "$CC" ] && CC=gcc

TMPF=/tmp/t$$.c
while [ -f $TMPF ]; do
  TMPF=$TMPF.$$.c
done
trap "rm -f $TMPF" 0 1 2 15

srcdir="`dirname $0`/.."  # Root of tcharge source

cd $srcdir

set -x
echo " Looking for..."
echo "----------------"
##
echo "Xlib...(header files)"
cat > $TMPF <<EOF
#include <X11/Xlib.h>
#include <X11/Xutil.h>
EOF
if ! $CPP $TMPF >/dev/null; then
  echo "X11/Xlib.h and X11/Xutil.h not available"
fi

##
echo "Xlib...(library)"
cat > $TMPF <<EOF
void main() {}
EOF
if ! $CC -lX11 $TMPF >/dev/null; then
  echo "Library libX11 not available"
fi


#### Xlibs: directory #####
P_set=`cat $srcdir/Makefile | tr "=" " " | awk '/^XLIB/{ print $2; exit; }'`
if [ -f $P_set/libX11 ]; then
  echo "XLIB_DIR in Makefile is OK"
else
  P="/usr/X11R6/lib " # should be a longer list
  echo "Find out the Path of the X-libraries..."
  for p in $P; do
    if [ -f $p/Xlib.h ]; then
      echo "In Makefile edit: XLIB_DIR=$p"
      break
    fi
  done
fi

###########################
if ! make -n germany >/dev/null; then
  echo "The Makefile is corrupted; find out the error!"
fi