#compdef rpmbuild

local -a cmds b_cmds t_cmds options b_options

cmds=(--rebuild --recompile)
b_cmds=(-ba -bb -bp -bc -bi -bl -bs)
t_cmds=(-ta -tb -tp -tc -ti -tl -ts)
options=(--quiet -v -vv --verbose --rcfile --pipe --dbpath -r --root --buildroot --clean --nobuild --nodeps --nodigest --nosignature --macros
	--rmsource --rmspec --short-circuit --sign --target -D --define -E --eval --with --without --debug --bcond --install-build-tree)
b_options=(--clean --nobuild --nodeps --nodigest --nosignature --rmsource --rmspec --short-circuit --sign --target --debug --with --without)

_arguments \
	"($cmds $b_cmds $t_cmds)"{-ba,-ta}'[build binary and source packages]' \
	"($cmds $b_cmds $t_cmds)"{-bb,-tb}'[build a binary package]' \
	"($cmds $b_cmds $t_cmds)"{-bp,-tp}'[execute the "%prep" stage]' \
	"($cmds $b_cmds $t_cmds)"{-bc,-tc}'[do the "%build" stage]' \
	"($cmds $b_cmds $t_cmds)"{-bi,-ti}'[do the "%install" stage]' \
	"($cmds $b_cmds $t_cmds)"{-bl,-tl}'[do a "list check"]' \
	"($cmds $b_cmds $t_cmds)"{-bs,-ts}'[build just the source package]' \
	"($cmds $b_cmds $t_cmds * $b_options $options)"{-\?,--help}'[show help message]' \
	"($cmds $b_cmds $t_cmds * $b_options $options)"--querytags'[display known query tags]' \
	"($cmds $b_cmds $t_cmds * $b_options)"--showrc'[display final rpmrc and macro configuration]' \
	"($cmds $b_cmds $t_cmds * $b_options $options)"--usage'[display brief usage message]' \
	"($cmds $b_cmds $t_cmds * $b_options $options)"--version'[print the version of rpm being used]' \
	"(-v --verbose -vv)"--quiet'[print as little as possible]' \
	"(-v --verbose --quiet)"{-v,--verbose}'[print verbose information]' \
	"(-v --verbose --quiet)"-vv'[print lots of ugly debugging information]' \
	--rcfile'[RC files]:RC files:_files -S\:' \
	--macros'[macros files]:macros files:_files -S\:' \
	--pipe'[command to pipe the output of rpm to]:command' \
	--dbpath'[set database directory]:database directory:_files -/' \
	"(-r --root)"{-r,--root}'[root file system tree]:chroot directory:_files -/' \
	--buildroot'[override the BuildRoot]:BuildRoot directory:_files -/' \
	--clean'[remove the build tree after the packages are made]' \
	--nobuild'[do not execute any build stages (for spec testing purposes]' \
	--nodeps'[do not verify build dependencies]' \
	--nodigest"[don't verify package digest(s)]" \
	--nosignature"[don't verify package signature(s)]" \
	--rmsource'[remove the sources after the build]' \
	--rmspec'[remove the spec file after the build]' \
	--short-circuit'[skip straight to specified stage (-bc, -bi or -bb in PLD Linux]' \
	--sign'[embed a GPG signature]' \
	--target='[set target platform]:arch-vendor-os:' \
	{'*-D','*--define='}'[define MACRO with value EXPR]:MACRO EXPR' \
	{'*-E','*--eval='}'[print macro expansion of EXPR]:EXPR' \
	'*--with[enable configure option for build]:option' \
	'*--without[disable configure option for build]:option' \
	"($cmds $b_cmds $t_cmds * $b_options)"--bcond'[find all --with/--without values]' \
	--debug'[build packages with debug information]' \
	"($cmds $b_cmds $t_cmds * $b_options)"--install-build-tree'[make all needed dirs for building binary rpms]' \
	"(--clean $b_cmds $t_cmds --rebuild)"--recompile'[recompile source package]' \
	"(--clean $b_cmds $t_cmds --recompile)"--rebuild'[rebuild source package]' \
	"*:file:_files -g '(#i)*.(spec|srpm|tgz|tar|tar.gz|tar.bz2)(-.)'" && ret=0
