#compdef pkg-config

local arguments packages curcontext="$curcontext" state line ret=1
declare -A opt_args

arguments=(
      "--modversion[print the version information of a given package]"
      "--atleast-pkgconfig-version=[require given version of pkg-config]:minimum version"
      "(- *)"{--help,-\?}"[display a help message]"
      "(- *)--usage[display brief usage message]"
      "--print-errors[cause errors to be printed]"
      "--silence-errors[prevent the printing of errors]"
      "--errors-to-stdout[print errors to stdout rather than stderr]"
      "--cflags[print the preprocessor and compiler flags]"
      "--cflags-only-I[output -I flags only]"
      "--cflags-only-other[output cflags not covered by the cflags-only-I option]"
      "--debug[show verbose debug information]"
      "--libs[print the link flags]"
      "--libs-only-L[print the -L and -R parts of \"--libs\"]"
      "--libs-only-l[print the -l part of \"--libs\"]"
      "--libs-only-other[output other libs]"
      "--list-all[list all known packages]"
      "--variable=[return the value of the specified variable]:variable"
      "--define-variable=[set the global value for a variable]:name value pair"
      "--uninstalled[return success if any \"-uninstalled\" packages are being used]"
      "--exists[test whether the package exists or not]"
      "--atleast-version=[test whether the version is at least that of the specified value]:least value"
      "--exact-version=[test whether the version is exactly that of the specified value]:exact value"
      "--max-version=[test whether the version is no greater than some specific value]:max version"
#      "--msvc-syntax[output linker flags in a form compatible with MSVC++ (Windows only)]"
#      "--dont-define-prefix[disables automatic overiding of the variable \"prefix\" (Windows only)]"
#      "--prefix-variable=[set the name of the variable \"prefix\" (Windows only)]:prefix value"
      "*: :->packages"
)

_arguments -C $arguments && ret=0

if [[ -n $state ]] ; then
  packages=( ${${(f)"$(_call_program packages pkg-config --list-all)"}%% *} )
  _wanted packages expl 'package' compadd -a - packages && ret=0
fi

return ret
