XPM_LIB_DIR=/usr/X11/lib
MOTIF_INCLUDE_DIR=/usr/X11/LessTif/Motif2.0/include
MOTIF_LIB_DIR=/usr/X11/LessTif/Motif2.0/lib
X_LIB_DIR=/usr/X11/lib

CFLAGS="-O20" 

LIBS="-lXm -lXt -lXext -lX11 -lXpm -lXxf86vm"


rm -f Makefile

echo "Searching for Motif include files..."
not_found=true
for dir in $MOTIF_INCLUDE_DIR /usr/include /usr/include/X* /usr/include/Motif* \
           /usr/X*/LessTif/Motif*/include /usr/X*/include /usr/local/*/include \
	   /usr/local/include  
do
 if test -r "$dir/Xm/XmAll.h" 
 then
    MOTIF_INCLUDE_DIR=$dir
    echo  "Motif include files found in $MOTIF_INCLUDE_DIR."
    not_found=false
    break
 fi
done

if $not_found 
 then
    echo "Motif include files not found. Configure can't continue."
    echo "Get LessTif from http://www.lesstif.org"
    exit
fi    
     
echo "Searching for Motif library files..."
not_found=true
for dir in $MOTIF_LIB_DIR /usr/lib /lib /usr/lib/Motif* /usr/lib/X* /usr/lib/LessTif \
           /usr/X*/LessTif/Motif*/lib /usr/X*/lib /usr/local/lib  
do
    for ext in "la" "a"; do
        if test -d "$dir" && test -r "$dir/libXm.$ext"; then
	 MOTIF_LIB_DIR=$dir
	 echo  "Motif library files found in $MOTIF_LIB_DIR."
	 not_found=false
	 break 2
	fi
    done	
done

if $not_found 
 then
    echo "Motif library files not found. Configure can't continue."
    echo "Get LessTif from http://www.lesstif.org"
    exit
fi    

echo "Searching for X library files..."
not_found=true
for dir in $X_LIB_DIR /usr/lib /lib /usr/X*/lib  
do
 if test -r "$dir/libXt.so" 
 then
    T_LIB_DIR=$dir
    echo  "X library files found in $X_LIB_DIR."
    not_found=false
    break
 fi
done

if $not_found 
 then
    echo "X library files not found. Configure can't continue."
    exit
fi

echo "Searching for Xpm library files..."
not_found=true
for dir in $XPM_LIB_DIR /usr/lib /lib /usr/lib/Motif* /usr/lib/X* /usr/lib/LessTif \
           /usr/X*/LessTif/Motif*/lib /usr/X*/lib /usr/local/lib /usr/local/lib/*  \
 	   /usr/X*/lib/* /usr/lib/*  
do
    for ext in "sl" "so" "a"; do
        if test -d "$dir" && test -r "$dir/libXpm.$ext"; then
	 XPM_LIB_DIR=$dir
	 echo  "Xpm library files found in $XPM_LIB_DIR."
	 not_found=false
	 break 2
	fi
    done	
done
										    
if $not_found 
 then
    echo "Xpm library files not found. Configure can't continue."
    exit
fi    


echo "all:" > Makefile
echo "	cc -c -o Tab.o Tab.c -I. -O2 -I$MOTIF_INCLUDE_DIR " >> Makefile
echo "	cc -o glukalka modifed.c Tab.o -I$MOTIF_INCLUDE_DIR $CFLAGS -L$MOTIF_LIB_DIR -L$X_LIB_DIR -L$XPM_LIB_DIR $LIBS" >> Makefile
echo >> Makefile
echo "clean:" >> Makefile
echo "	rm -f glukalka" >> Makefile
echo "	rm -f *.o" >> Makefile

echo
echo "Configure completed."
