#!/bin/sh

export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1

env_cc=$(printenv CC)

case $env_cc in
    "gcc")
        # build architecture == system architecture
        pkg-config $@
        ;;
    "gcc"*)
        # gcc -m32 or -m64
        system=${env_cc#"gcc "}

        if [ "$system" = "-m32" ]; then
            i686-linux-gnu-pkg-config $@
        elif [ "$system" = "-m64" ]; then
            pkg-config $@
        fi
        ;;
    *"-gcc")
        # GCC cross-compiler
        system=${env_cc%-gcc}
        $system-pkg-config $@
        ;;
    "clang")
        # build architecture == system architecture
        pkg-config $@
        ;;
    "clang"*)
        # clang -m32 or -m64
        system=${env_cc#"clang "}

        if [ "$system" = "-m32" ]; then
            i686-linux-gnu-pkg-config $@
        elif [ "$system" = "-m64" ]; then
            pkg-config $@
        fi
        ;;
    *)
        # build architecture == system architecture
        pkg-config $@
esac
