#!/bin/sh

SM=yes
XCONFIG=$1/qmake.conf
VERBOSE=$2


# debuggery

if [ "$VERBOSE" = "yes" ]
then
    echo "Session Management auto-detection..."
fi


# check for headers

if [ "$SM" = "yes" ]
then
    INC="X11/SM/SM.h"
    XDIRS=`sed -n -e '/^QMAKE_INCDIR_X11[	]*=/ { s/[^=]*=[	 ]*//; s/-I/ /g; p; }' $XCONFIG`
    INCDIRS="$XDIRS /usr/include /include"
    F=
    for INCDIR in $INCDIRS
    do
	if [ -f $INCDIR/$INC ]
	then
	    F=yes
	    if [ "$VERBOSE" = "yes" ]
	    then
		echo "  Found $INC in $INCDIR"
	    fi
	    break
	fi
    done
    if [ -z "$F" ]
    then
	SM=no
	if [ "$VERBOSE" = "yes" ]
	then
	    echo "  Could not find $INC anywhere in $INCDIRS"
	fi
    fi
fi


# done

if [ "$SM" != "yes" ]
then
    if [ "$VERBOSE" = "yes" ]
    then
	echo "Session Management disabled."
    fi
    exit 0
else
    if [ "$VERBOSE" = "yes" ]
    then
	echo "Session Management enabled."
    fi
    exit 1
fi
