#!/bin/sh

# Querying fvwm installation. Author: Mikhael Goikhman.

PACKAGE="fvwm"
VERSION="2.4.19"
script=`basename $0`

usage()
{
	cat <<EOF
This script is a part of $PACKAGE-$VERSION package.

Usage: $script [OPTIONS]
Options:
	[-h]	[--help] [-?]
	[-v]	[--version] [-V]
	[-i]	[--info]

	[-P]	[--prefix]
	[-E]	[--exec-prefix]
	[-B]	[--bindir]
	[-D]	[--datadir]
	[-L]	[--libexecdir]
	[-S]	[--sysconfdir]
	[-M]	[--mandir]

	[-m]	[--fvwm-moduledir]
	[-d]	[--fvwm-datadir]
	[-I]	[--default-imagepath]
	[-U]	[--default-userdir]

	[-e]	[--fvwm-exe]     print fvwm executable name (in bindir)
	[-s]	[--supports]     list supported features, one per line
	[--supports-<feature>]   return: 0 (yes), 100 (no), 200 (unknown)
EOF
	exit $1
}

if test $# -eq 0; then
	usage 1 1>&2
fi

prefix="/usr/local"
exec_prefix="${prefix}"
bindir="${exec_prefix}/bin"
datadir="${prefix}/share"
libexecdir="${exec_prefix}/libexec"
sysconfdir="/etc"
mandir="/usr/local/man"

fvwm_moduledir="${libexecdir}/fvwm/2.4.19"
fvwm_datadir="${datadir}/fvwm"
fvwm_imagepath="/usr/include/X11/bitmaps:/usr/include/X11/pixmaps"
fvwm_userdir='$HOME/.fvwm'
fvwm_exe='fvwm2'

with_gnomehints=yes
with_gtk=yes
with_gdkimlib=yes
with_gnomelibs=no
with_multibyte=no
with_readline=yes
with_rplay=no
with_shape=yes
with_sm=yes
with_stroke=no
with_xinerama=yes
with_xpm=yes

while test $# -gt 0; do
	case "$1" in
		--help|-help|-h|-\?)
			usage 0 ;;

		--version|-version|-v|-V)
			echo "$VERSION" ;;

		--prefix|-prefix|-P)
			echo "$prefix" ;;

		--exec-prefix|-exec-prefix|-E)
			echo "$exec_prefix" ;;

		--bindir|-bindir|-B)
			echo "$bindir" ;;

		--datadir|-datadir|-D)
			echo "$datadir" ;;

		--libexecdir|-libexecdir|-L)
			echo "$libexecdir" ;;

		--sysconfdir|-sysconfdir|-S)
			echo "$sysconfdir" ;;

		--mandir|-mandir|-M)
			echo "$mandir" ;;

		--fvwm-moduledir|-fvwm-moduledir|-m)
			echo "$fvwm_moduledir" ;;

		--fvwm-datadir|-fvwm-datadir|-d)
			echo "$fvwm_datadir" ;;

		--default-imagepath|-default-imagepath|-I)
			echo "$fvwm_imagepath" ;;

		--default-userdir|-default-userdir|-U)
			echo "$fvwm_userdir" ;;

		--fvwm-exe|-fvwm-exe|-e)
			echo "$fvwm_exe" ;;

		--supports|-supports|-s)
			test "$with_gnomehints" = "yes" && echo "gnome-hints"
			test "$with_gtk"        = "yes" && echo "gtk"
			test "$with_gdkimlib"   = "yes" && echo "gdk-imlib"
			test "$with_gnomelibs"  = "yes" && echo "gnome-libs"
			test "$with_multibyte"  = "yes" && echo "multibyte"
			test "$with_readline"   = "yes" && echo "readline"
			test "$with_rplay"      = "yes" && echo "rplay"
			test "$with_shape"      = "yes" && echo "shape"
			test "$with_sm"         = "yes" && echo "sm"
			test "$with_stroke"     = "yes" && echo "stroke"
			test "$with_xinerama"   = "yes" && echo "xinerama"
			test "$with_xpm"        = "yes" && echo "xpm"
			;;

		--supports-*)
			feature=`echo "$1" | sed 's/^--supports-//'`
			feature=`echo "$feature" | sed 's/[-_]//g'`
			test "$feature" = "gnomewm" && feature="gnomehints"
			with=`eval echo '$'with_"$feature"`
			test "$with" = "yes" && exit 0
			test "$with" = "no"  && exit 100
			exit 200
			;;

		--info|-info|-i)
			echo "Package: $PACKAGE"
			echo "Version: $VERSION"
			echo ""
			echo "Instalation options:"
			echo "	prefix: $prefix"
			echo "	exec-prefix: $exec_prefix"
			echo "	bindir: $bindir"
			echo "	datadir: $datadir"
			echo "	libexecdir: $libexecdir"
			echo "	sysconfdir: $sysconfdir"
			echo "	mandir: $mandir"
			echo ""
			echo "Compiled-in paths:"
			echo "	Module directory: $fvwm_moduledir"
			echo "	Data directory: $fvwm_datadir"
			echo "	Default ImagePath: $fvwm_imagepath"
			echo "	Default UserDir: $fvwm_userdir"
			echo ""
			echo "Support for features:"
			echo "	gnome-hints (window manager hints): $with_gnomehints"
			echo "	gtk (FvwmGtk): $with_gtk"
			echo "	gdk-imlib (in FvwmGtk): $with_gdkimlib"
			echo "	gnome-libs (in FvwmGtk): $with_gnomelibs"
			echo "	multibyte: $with_multibyte"
			echo "	readline: $with_readline"
			echo "	rplay: $with_rplay"
			echo "	shape (shaped windows): $with_shape"
			echo "	sm (session management): $with_sm"
			echo "	stroke: $with_stroke"
			echo "	xinerama: $with_xinerama"
			echo "	xpm: $with_xpm"
			;;

		*)
			echo "$script: unknown parameter [$1]" 1>&2
			exit 1
			;;

	esac
	shift
done

exit 0
