#!/bin/sh


if [ -n "$1" -a "$1" = "--help" ] ; then
	echo "Usage : $0\n Auto-configure and make MinilibX"
	exit
fi


conf_inc=NO

for inc in \
    /usr/X11/include          \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11R4/include        \
                              \
    /usr/include/X11          \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
    /usr/include/X11R4        \
                              \
    /usr/local/X11/include    \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
    /usr/local/X11R4/include  \
                              \
    /usr/local/include/X11    \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
    /usr/local/include/X11R4  \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
                              \
    /usr/include              \
    /usr/local/include        \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
                              \
    /usr/openwin/include      \
    /usr/openwin/share/include
 do
	if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
		conf_inc=$inc
		break
	fi
 done


if [ "$conf_inc" = "NO" ]; then
	echo "Can't find a suitable X11 include directory."
	exit
else
	echo "X11 include dir : $conf_inc"
fi

if [ -z "$HOSTTYPE" ]; then
    conf_ht=`uname -s`
else
    conf_ht=$HOSTTYPE
fi

if [ -z "$conf_ht" ]; then
    conf_docp=""
else
    conf_docp="do_cp"
    echo "lib_$conf_ht generation"
fi


/bin/echo "INC=$conf_inc" > Makefile.gen
/bin/echo "HT=$conf_ht" >> Makefile.gen
/bin/echo "DOCP=$conf_docp" >> Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen

/bin/echo "INC=$conf_inc" > test/Makefile.gen
/bin/echo "HT=$conf_ht" >> test/Makefile.gen
/bin/echo "DOCP=$conf_docp" >> test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen


if [ -n "$1" -a "$1" = "clean" ] ; then
    echo "Now make it clean."
    make -f Makefile.gen clean
    (cd test ; make -f Makefile.gen clean)
    exit
fi

echo "Now make it."
make -f Makefile.gen all
(cd test ; make -f Makefile.gen all )
