#!/bin/sh

# Querying fvwm installation. Author: Mikhael Goikhman.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

PACKAGE="fvwm"
VERSION="2.6.6"
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]
	    	[--datarootdir]
	[-D]	[--datadir]
	[-L]	[--libexecdir]
	[-S]	[--sysconfdir]
	[-M]	[--mandir]
	[-O]    [--localedir]

	[-m]	[--fvwm-moduledir]
	[-d]	[--fvwm-datadir]
	[-p]	[--fvwm-perllibdir]
	[-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"
exec_prefix="/usr"
bindir="${exec_prefix}/bin"
datarootdir="${prefix}/share"
datadir="${datarootdir}"
libexecdir="${exec_prefix}/libexec"
sysconfdir="/etc"
mandir="${datarootdir}/man"
localedir="${datadir}/locale"

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

VERSIONINFO=""
release_date="2016-03-15"

with_bidi=yes
with_gettext=yes
with_gtk=no
with_gdkimlib=no
with_gnomelibs=no
with_iconv=yes
with_perllib=yes
with_png=yes
with_readline=yes
with_rplay=no
with_rsvg=yes
with_shape=yes
with_shm=yes
with_sm=yes
with_stroke=no
with_xcursor=yes
with_xinerama=yes
with_xft=yes
with_xpm=yes
with_xrender=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" ;;

		--datarootdir|-datarootdir)
			echo "$datarootdir" ;;

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

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

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

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

		--localedir|-localedir|-O)
			echo "$localedir" ;;

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

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

		--fvwm-perllibdir|-fvwm-perllibdir|--perllibdir|-perllibdir|-p)
			echo "$fvwm_perllibdir" ;;

		--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_bidi"       = "yes" && echo "bidi"
			test "$with_gettext"    = "yes" && echo "gettext"
			test "$with_gtk"        = "yes" && echo "gtk"
			test "$with_gdkimlib"   = "yes" && echo "gdk-imlib"
			test "$with_gnomelibs"  = "yes" && echo "gnome-libs"
			test "$with_iconv"      = "yes" && echo "iconv"
			test "$with_perllib"    = "yes" && echo "perllib"
			test "$with_png"        = "yes" && echo "png"
			test "$with_readline"   = "yes" && echo "readline"
			test "$with_rplay"      = "yes" && echo "rplay"
			test "$with_rsvg"       = "yes" && echo "rsvg"
			test "$with_shape"      = "yes" && echo "shape"
			test "$with_shm"        = "yes" && echo "shm"
			test "$with_sm"         = "yes" && echo "sm"
			test "$with_stroke"     = "yes" && echo "stroke"
			test "$with_xcursor"    = "yes" && echo "xcursor"
			test "$with_xinerama"   = "yes" && echo "xinerama"
			test "$with_xft"        = "yes" && echo "xft"
			test "$with_xpm"        = "yes" && echo "xpm"
			test "$with_xrender"    = "yes" && echo "xrender"
			;;

		--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$VERSIONINFO"
			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 "	localedir: $localedir"
			echo ""
			echo "Compiled-in paths:"
			echo "	Module directory: $fvwm_moduledir"
			echo "	Data directory: $fvwm_datadir"
			echo "	Perl lib directory: $fvwm_perllibdir"
			echo "	Default ImagePath: $fvwm_imagepath"
			echo "	Default UserDir: $fvwm_userdir"
			echo ""
			echo "Support for features:"
			echo "	bidi (bi-directionality): $with_bidi"
			echo "	gettext (Native Lang Support): $with_gettext"
			echo "	gtk (required for FvwmGtk): $with_gtk"
			echo "	gdk-imlib (in FvwmGtk): $with_gdkimlib"
			echo "	gnome-libs (in FvwmGtk): $with_gnomelibs"
			echo "	perllib (Perl library installed): $with_perllib"
			echo "	iconv (i18n conversions): $with_iconv"
			echo "	png: $with_png"
			echo "	readline: $with_readline"
			echo "	rplay: $with_rplay"
			echo "	shape (shaped windows): $with_shape"
			echo "	shm (shared memory): $with_shm"
			echo "	sm (session management): $with_sm"
			echo "	stroke (mouse gestures): $with_stroke"
			echo "	rsvg (SVG icons and images): $with_rsvg"
			echo "	xcursor (ARGB/animated cursors): $with_xcursor"
			echo "	xinerama (multi-head): $with_xinerama"
			echo "	xft (FreeType anti-alias font): $with_xft"
			echo "	xpm: $with_xpm"
			echo "	xrender (XFree86 Xrender extention): $with_xrender"
			;;

		--is-final|-is-final)
			test "$is_final" = yes && echo yes
			test "$is_final" != yes && echo no
			;;
		*)
			echo >&2 "$script: unknown argument '$1'."
			echo >&2 "Run '$script --help' to get the usage."
			exit 1
			;;

	esac
	shift
done

exit 0
