#!/usr/bin/sh
# vdr-config - print VDR's build settings from vdr.pc
#
# vdr-config --version | --list | --VARIABLE...
#
#   --version   VDR's version
#   --list      the names of the variables
#   --VARIABLE  the value of one, e.g. --apiversion, --libdir, --cxxflags
#
# Prints one line per option, in the order given.

usage() { sed -ne '4,10s/^# \{0,1\}//p' "$0" ; }

[ $# -gt 0 ] || { usage >&2 ; exit 1 ; }
vars=$(pkg-config vdr --print-variables) || exit 1

for opt ; do
    case $opt in
        --help|-h) usage ;;
        --version) pkg-config vdr --modversion ;;
        --list)    printf '%s\n' "$vars" | sort ;;
        --?*)
            if printf '%s\n' "$vars" | grep -qxF -- "${opt#--}" ; then
                pkg-config vdr --variable="${opt#--}"
            else
                echo "vdr-config: unknown option '$opt'" >&2
                exit 1
            fi
            ;;
        *) echo "vdr-config: unknown option '$opt'" >&2 ; exit 1 ;;
    esac
done
