xscreensaver_prefixes="$exec_prefix $prefix /usr /usr/local /opt/local /usr/X11R6 /usr/X11R6 /opt/kde /opt/kde3 /usr/kde /usr/local/kde /usr/local/xscreensaver /usr/openwin/lib/xscreensaver"

old_IFS=$IFS
IFS=:
for path in $PATH; do 
   case $path in
      */bin)
	path=`echo $path | sed -e 's,/bin$,,'`
	xscreensaver_prefixes="$path $xscreensaver_prefixes"
        ;;
   esac
done
IFS=$old_IFS

KDE_FIND_PATH(lib/xscreensaver/flame, XSCREENSAVER, 
        [ $xscreensaver_prefixes ],
        [
    	    KDE_FIND_PATH(bin/xscreensaver-hacks/flame, XSCREENSAVER, 
  	      [ $xscreensaver_prefixes ],
	      [
    	          KDE_FIND_PATH(hacks/flame, XSCREENSAVER, 
  	          [ $xscreensaver_prefixes ],
	          [
		    XSCREENSAVER=NO
	          ])
	      ])
        ])

XSCREENSAVER_HACKS_DIR=

if test "$XSCREENSAVER" != "NO"; then
     XSCREENSAVER_HACKS_DIR=`echo $XSCREENSAVER | sed -e 's,/flame$,,'`
     AC_DEFINE_UNQUOTED(XSCREENSAVER_HACKS_DIR, "$XSCREENSAVER_HACKS_DIR", [Defines where xscreensaver stores its graphic hacks])

     AC_MSG_CHECKING([for flame.xml])
     AC_FIND_FILE(lib/xscreensaver/config/flame.xml, [ $xscreensaver_prefixes ], XSCREENSAVER_CONFIG)
     if test "$XSCREENSAVER_CONFIG" = NO; then
	AC_FIND_FILE(lib/X11/xscreensaver/config/flame.xml, [ $xscreensaver_prefixes ],
		XSCREENSAVER_CONFIG)
        if test "$XSCREENSAVER_CONFIG" = NO; then
		AC_FIND_FILE(share/control-center/screensavers/flame.xml,
			[ $xscreensaver_prefixes ], XSCREENSAVER_CONFIG)
		if test "$XSCREENSAVER_CONFIG" != NO; then
                    XSCREENSAVER_CONFIG="$XSCREENSAVER_CONFIG/share/control-center/screensavers/"
		else
		    AC_FIND_FILE(share/xscreensaver/config/flame.xml,
			         [ $xscreensaver_prefixes ], XSCREENSAVER_CONFIG)
		    if test "$XSCREENSAVER_CONFIG" != NO; then
			XSCREENSAVER_CONFIG="$XSCREENSAVER_CONFIG/share/xscreensaver/config/flame.xml"
		    else
			AC_FIND_FILE(config/control-center-2.0/flame.xml,
			         [ $xscreensaver_prefixes ], XSCREENSAVER_CONFIG)
		        if test "$XSCREENSAVER_CONFIG" != NO; then
			     XSCREENSAVER_CONFIG="$XSCREENSAVER_CONFIG/config/control-center-2.0/flame.xml"
		        fi
		    fi
		fi
	else
	     XSCREENSAVER_CONFIG="$XSCREENSAVER_CONFIG/lib/X11/xscreensaver/config"
        fi
     else
	XSCREENSAVER_CONFIG="$XSCREENSAVER_CONFIG/lib/xscreensaver/config"
     fi
     AC_MSG_RESULT([$XSCREENSAVER_CONFIG])
     AC_DEFINE_UNQUOTED(XSCREENSAVER_CONFIG_DIR, "$XSCREENSAVER_CONFIG", 
	[Defines where xscreensaver stores it's config files])
fi

AM_CONDITIONAL(include_XSCREENSAVER, test "$XSCREENSAVER" != "NO")
AC_SUBST(XSCREENSAVER_HACKS_DIR)

