#!/bin/bash

usage() {
    cat <<EOF
${2:+$2

}Usage: xml2-config <OPTION...>

Options:
  --prefix              print libxml prefix
  --prefix=DIR          change libxml prefix
  --libs                print library linking information
  --dynamic             skip libraries only necessary for static linking
  --cflags              print pre-processor and compiler flags
  --modules             module support enabled
  --help                display this help and exit
  --version             output version information
EOF
    exit $1
}

if (( $# < 1 )); then
    usage 1 "Need at least one option."
fi

pc_args=()
libs=0
libflag=--static

for arg; do
    case $arg in
        --prefix) pc_args+=(--variable=prefix) ;;
        --prefix=*) pc_args+=(--define-variable=prefix="${arg#*=}") ;;
        --libs) libs=1 ;;
        --dynamic) libflag=--shared ;;
        --cflags) pc_args+=(--cflags) ;;
        --modules) pc_args+=(--variable=modules) ;;
        --help) usage 0 ;;
        --version) pc_args+=(--modversion) ;;
        *) usage 1 "Unknown option: ${arg@Q}" ;;
    esac
done

if (( libs )); then
    pc_args+=(--libs $libflag)
fi

exec ${PKG_CONFIG:-pkg-config} "${pc_args[@]}" libxml-2.0
