#compdef make-kpkg

local curcontext="$curcontext" state line
typeset -A opt_args

_arguments -C \
   '--help[display help message]' \
   '--revision[change Debian revision number]:number:' \
   '--append-to-version[specify additional kernel sub-version]:suffix:' \
   '--added-modules[specify add-on modules]:module list:->addedmodules' \
   '--added-patches[specify additional patches]:patches list' \
   '--arch[specify architecture for cross-compilation]:architecture' \
   '--cross-compile[specify target string]:target' \
   '--subarch[specify subarchitecture]:subarchitecture:' \
   '--arch-in-name[include architecture in kernel image name]' \
   '--pgpsign[sign changes file]:name' \
   '--config[specify configuration target]:target:(oldconfig config menuconfig xconfig old menu x)' \
   '--targets[list known targets]' \
   '--noexec[pass -n option to make]' \
   '--verbose[show top level make commands]' \
   '--initrd[create image suitable for initrd]' \
   '(--bzimage)--zimage[make zImage instead of bzImage]' \
   '(--zimage)--bzimage[make bzImage instead of zImage]' \
   '--mkimage[command that produces an initrd image given a directory]:command:' \
   '--rootcmd[specify command for gaining root access]:root command:(sudo fakeroot)' \
   '--stem:package name stem:(kernel linux)' \
   '--us[unsigned source]' \
   '--uc[unsigned changelog]' \
   '*:target:(( \
        clean\:"clean the kernel source directory" \
        buildpackage\:"runs the targets clean and binary" \
        binary\:"all kernel packages" \
        binary-indep\:"arch independent packages" \
        binary-arch\:"arch dependent packages" \
        kernel-source\:"package of the kernel sources" \
        kernel-headers\:"package of the header files included in the kernel" \
        kernel-manual\:"package of the manual pages included in the kernel" \
        kernel-doc\:"package of the documentation included in the kernel" \
        kernel-image\:"package of the kernel image" \
        build\:"compiles the kernel" \
        modules\:"build all add-on modules" \
        modules-config\:"configure all add-on modules" \
        modules-image\:"build all add-on modules, but without source and diff files" \
        modules-clean\:"clean add-on modules" \
        configure\:"configure the kernel" \
        debian\:"creates the debian/ directory" \
        libc-kheaders\:"create the kernel headers package needed by libc" \
    ))' && return

case "$state" in
  (addedmodules)
    compset -P '*,'
    _alternative \
      'moddirs:module dirs:_files -/ -S ,' \
      'modules:loc module dirs:_files -/ -W ${MODULE_LOC:-/usr/src/modules} -S ,'
  ;;
esac
