#!/bin/sh
#    Copyright (C) 1999, 2002 Free Software Foundation, Inc.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# General.
prefix="/usr"
exec_prefix="${prefix}"
thread_module=""
version="1.1.43"
gpg_error_libs="-L/usr/lib -lgpg-error"
gpg_error_cflags="-I/usr/include"

# LIBS values.
libs="-lgcrypt"
libs_pthread="-lgcrypt-pthread -lpthread"
libs_pth="-lgcrypt-pth"

# CFLAGS values.
cflags=""
cflags_pthread=""
cflags_pth=""

# Misc information.
symmetric_ciphers="arcfour blowfish cast5 des aes twofish serpent"
asymmetric_ciphers="dsa elgamal rsa"
digests="crc md4 md5 rmd160 sha1 sha256 sha512 tiger"
thread_modules=" pthread"

# State variables.
exec_prefix_set=no
echo_libs=no
echo_cflags=no
echo_prefix=no
echo_algorithms=no
echo_exec_prefix=no
echo_version=no

# Prints usage information.
usage()
{
    cat <<EOF
Usage: $0 [OPTIONS]
Options:
	[--thread={${thread_modules}}]
	[--prefix[=DIR]]
	[--exec-prefix[=DIR]]
	[--version]
	[--libs]
	[--cflags]
	[--algorithms]
EOF
    exit $1
}

if test $# -eq 0; then
    # Nothing to do.
    usage 1 1>&2
fi

while test $# -gt 0; do
    case "$1" in
	# Set up `optarg'.
	--*=*)
	    optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
	    ;;
	*)
	    optarg=""
	    ;;
    esac

    case $1 in
	--thread=*)
	    for thread_mod in $thread_modules; do
		if test "$thread_mod" = "$optarg"; then
		    thread_module="$optarg";
		fi
	    done
	    if test "x$thread_module" = "x"; then
		usage 1 1>&2
	    fi
	    ;;
	--prefix=*)
	    prefix=$optarg
	    if test $exec_prefix_set = no ; then
		exec_prefix=$optarg
	    fi
	    ;;
	--prefix)
	    echo_prefix=yes
	    ;;
	--exec-prefix=*)
	    exec_prefix=$optarg
	    exec_prefix_set=yes
	    ;;
	--exec-prefix)
	    echo_exec_prefix=yes
	    ;;
	--version)
	    echo_version=yes
	    ;;
	--cflags)
	    echo_cflags=yes
	    ;;
	--libs)
	    echo_libs=yes
	    ;;
	--algorithms)
	    echo_algorithms=yes
	    ;;
	*)
	    usage 1 1>&2
	    ;;
    esac
    shift
done

if test "$echo_prefix" = "yes"; then
    echo $prefix
fi

if test "$echo_exec_prefix" = "yes"; then
    echo $exec_prefix
fi

if test "$echo_cflags" = "yes"; then
    includes=""
    cflags_final="$cflags"

    # Set up `includes'.
    if test "${prefix}/include" != "/usr/include" ; then
	includes="-I${prefix}/include"
	for i in $cflags ; do
	    if test "$i" = "-I${prefix}/include" ; then
		includes=""
	    fi
	done
    fi

    # Set up `cflags_final'.
    case "$thread_module" in
	pthread)
	    cflags_final=$cflags_pthread
	    ;;
	pth)
	    cflags_final=$cflags_pth
	    ;;
    esac

    echo "$includes" "$cflags_final"
fi

if test "$echo_libs" = "yes"; then
    libdirs=""
    libs_final="$libs"

    # Set up `libdirs'.
    if test "${exec_prefix}/lib" != "/usr/lib" ; then
	libdirs="-L${exec_prefix}/lib"
	for i in $libs ; do
	    if test "$i" = "-L${exec_prefix}/lib" ; then
		libdirs=""
	    fi
	done
    fi

    # Set up `libs_final'.
    case "$thread_module" in
	pthread)
	    libs_final=$libs_pthread
	    ;;
	pth)
	    libs_final=$libs_pth
	    ;;
    esac

    echo $libdirs $libs_final
fi

if test "$echo_version" = "yes"; then
    echo $version
fi

if test "$echo_algorithms" = "yes"; then
    echo "Symmetric cipher algorithms: $ciphers"
    echo "Public-key cipher algorithms: $pubkey_ciphers"
    echo "Message digest algorithms: $digests"
fi
