dpkg-buildpackage.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #!/bin/sh
  2. set -e
  3. version="1.10.10"; # This line modified by Makefile
  4. progname="`basename \"$0\"`"
  5. usageversion () {
  6. cat >&2 <<END
  7. Debian dpkg-buildpackage $version.
  8. Copyright (C) 1996 Ian Jackson.
  9. Copyright (C) 2000 Wichert Akkerman
  10. This is free software; see the GNU General Public Licence version 2
  11. or later for copying conditions. There is NO warranty.
  12. Usage: dpkg-buildpackage [options]
  13. Options: -r<gain-root-command>
  14. -p<sign-command>
  15. -d do not check build dependencies and conflicts
  16. -D check build dependencies and conflicts
  17. -k<keyid> the key to use for signing
  18. -sgpg the sign-command is called like GPG
  19. -spgp the sign-command is called like PGP
  20. -us unsigned source
  21. -uc unsigned changes
  22. -a<arch> Debian architecture we build for (implies -d)
  23. -b binary-only, do not build source } also passed to
  24. -B binary-only, no arch-indep files } dpkg-genchanges
  25. -S source only, no binary files }
  26. -t<system> set GNU system type } passed to dpkg-architecture
  27. -v<version> changes since version <version> }
  28. -m<maint> maintainer for package is <maint> }
  29. -e<maint> maintainer for release is <maint> } only passed
  30. -C<descfile> changes are described in <descfile> } to dpkg-
  31. -si (default) src includes orig for rev. 0 or 1 } genchanges
  32. -sa uploaded src always includes orig }
  33. -sd uploaded src is diff and .dsc only }
  34. -sn force Debian native source format } only passed
  35. -s[sAkurKUR] see dpkg-source for explanation } to dpkg-source
  36. -nc do not clean source tree (implies -b)
  37. -tc clean source tree when finished
  38. -ap add pause before starting signature process
  39. -h print this message
  40. -W Turn certain errors into warnings. } passed to
  41. -E When -W is turned on, -E turned it off. } dpkg-source
  42. -i[<regex>] ignore diffs of files matching regex } only passed
  43. -I<filename> filter out files when building tarballs } to dpkg-source
  44. END
  45. }
  46. rootcommand=''
  47. signcommand=""
  48. if (( [ -n "$GNUPGHOME" ] && [ -e "$GNUPGHOME" ] ) || [ -e "$HOME/.gnupg" ] ) && \
  49. command -v gpg > /dev/null 2>&1; then
  50. signcommand=gpg
  51. elif command -v pgp > /dev/null 2>&1 ; then
  52. signcommand=pgp
  53. fi
  54. signsource='withecho signfile'
  55. signchanges='withecho signfile'
  56. cleansource=false
  57. checkbuilddep=true
  58. checkbuilddep_args=''
  59. binarytarget=binary
  60. sourcestyle=''
  61. version=''
  62. since=''
  63. maint=''
  64. desc=''
  65. noclean=false
  66. usepause=false
  67. warnable_error=0
  68. passopts=''
  69. while [ $# != 0 ]
  70. do
  71. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  72. case "$1" in
  73. -h) usageversion; exit 0 ;;
  74. -r*) rootcommand="$value" ;;
  75. -p*) signcommand="$value" ;;
  76. -k*) signkey="$value" ;;
  77. -d) checkbuilddep=false ;;
  78. -D) checkbuilddep=true ;;
  79. -sgpg) forcesigninterface=gpg ;;
  80. -spgp) forcesigninterface=pgp ;;
  81. -us) signsource=: ;;
  82. -uc) signchanges=: ;;
  83. -ap) usepause="true";;
  84. -a*) targetarch="$value"; checkbuilddep=false ;;
  85. -si) sourcestyle=-si ;;
  86. -sa) sourcestyle=-sa ;;
  87. -sd) sourcestyle=-sd ;;
  88. -s[nsAkurKUR]) passopts="$passopts $1";; # passed to dpkg-source
  89. -i*) diffignore=$1;;
  90. -I*) tarignore="$tarignore $1";;
  91. -tc) cleansource=true ;;
  92. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  93. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  94. -b) binaryonly=-b; [ "$sourceonly" ] && \
  95. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  96. -B) binaryonly=-B; checkbuilddep_args=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  97. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  98. -S) sourceonly=-S; checkbuilddep=false; [ "$binaryonly" ] && \
  99. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  100. -v*) since="$value" ;;
  101. -m*) maint="$value" ;;
  102. -e*) changedby="$value" ;;
  103. -C*) desc="$value" ;;
  104. -W) warnable_error=1; passopts="$passopts -W";;
  105. -E) warnable_error=0; passopts="$passopts -E";;
  106. *) echo >&2 "$progname: unknown option or argument $1"
  107. usageversion; exit 2 ;;
  108. esac
  109. shift
  110. done
  111. if [ -z "$signcommand" ] ; then
  112. signsource=:
  113. signchanges=:
  114. fi
  115. if test -n "$forcesigninterface" ; then
  116. signinterface=$forcesigninterface
  117. if [ "$signinterface" != "gpg" ] && [ "$signinterface" != "pgp" ] ; then
  118. echo >&2 "$progname: invalid sign interface specified"
  119. exit 1
  120. fi
  121. else
  122. signinterface=$signcommand
  123. fi
  124. mustsetvar () {
  125. if [ "x$2" = x ]; then
  126. echo >&2 "$progname: unable to determine $3" ; \
  127. exit 1
  128. else
  129. echo "$progname: $3 $2" ; \
  130. eval "$1=\"\$2\""
  131. fi
  132. }
  133. curd="`pwd`"
  134. dirn="`basename \"$curd\"`"
  135. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package is"
  136. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version is"
  137. if [ -n "$changedby" ]; then maintainer="$changedby";
  138. elif [ -n "$maint" ]; then maintainer="$maint";
  139. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source changed by"; fi
  140. eval `dpkg-architecture -a${targetarch} -t${targetgnusystem} -s -f`
  141. if [ x$sourceonly = x ]; then
  142. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "host architecture"
  143. else
  144. arch=source
  145. fi
  146. mustsetvar sversion "`echo \"$version\" | perl -pe 's/^\d+://'`" "source version without epoch"
  147. pv="${package}_${sversion}"
  148. pva="${package}_${sversion}_${arch}"
  149. signfile () {
  150. if test "$signinterface" = "gpg" ; then
  151. (cat "../$1" ; echo "") | \
  152. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  153. --textmode > "../$1.asc"
  154. else
  155. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  156. >"../$1.asc"
  157. fi
  158. status=$?
  159. if [ $status -eq 0 ]; then
  160. mv -- "../$1.asc" "../$1"
  161. else
  162. /bin/rm -f "../$1.asc"
  163. fi
  164. echo
  165. return $status
  166. }
  167. withecho () {
  168. echo " $@" >&2
  169. "$@"
  170. }
  171. if [ "$checkbuilddep" = "true" ]; then
  172. if ! dpkg-checkbuilddeps $checkbuilddep_args; then
  173. echo >&2 "$progname: Build dependencies/conflicts unsatisfied; aborting."
  174. echo >&2 "$progname: (Use -d flag to override.)"
  175. exit 3
  176. fi
  177. fi
  178. set -- $binaryonly $sourceonly $sourcestyle
  179. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  180. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  181. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  182. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  183. if [ x$noclean != xtrue ]; then
  184. withecho $rootcommand debian/rules clean
  185. fi
  186. if [ x$binaryonly = x ]; then
  187. cd ..; withecho dpkg-source $passopts $diffignore $tarignore -b "$dirn"; cd "$dirn"
  188. fi
  189. if [ x$sourceonly = x ]; then
  190. withecho debian/rules build
  191. withecho $rootcommand debian/rules $binarytarget
  192. fi
  193. if [ "$usepause" = "true" ] && \
  194. ( [ "$signchanges" != ":" ] || ( [ -z "$binaryonly" ] && [ "$signsource" != ":" ] ) ) ; then
  195. echo Press the return key to start signing process
  196. read dummy_stuff
  197. fi
  198. signerrors=
  199. if [ x$binaryonly = x ]; then
  200. if ! $signsource "$pv.dsc"; then
  201. signerrors="(WARNING: Failed to sign .dsc and .changes file)"
  202. signchanges=:
  203. fi
  204. fi
  205. chg=../"$pva.changes"
  206. withecho dpkg-genchanges "$@" >"$chg"
  207. fileomitted () {
  208. set +e
  209. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  210. fir=$?
  211. set -e
  212. return $fir
  213. }
  214. if fileomitted '\.deb'; then
  215. # source only upload
  216. if fileomitted '\.diff\.gz'; then
  217. srcmsg='source only upload: Debian-native package'
  218. elif fileomitted '\.orig\.tar\.gz'; then
  219. srcmsg='source only, diff-only upload (original source NOT included)'
  220. else
  221. srcmsg='source only upload (original source is included)'
  222. fi
  223. else
  224. srcmsg='full upload (original source is included)'
  225. if fileomitted '\.dsc'; then
  226. srcmsg='binary only upload (no source included)'
  227. elif fileomitted '\.diff\.gz'; then
  228. srcmsg='full upload; Debian-native package (full source is included)'
  229. elif fileomitted '\.orig\.tar\.gz'; then
  230. srcmsg='binary and diff upload (original source NOT included)'
  231. else
  232. srcmsg='full upload (original source is included)'
  233. fi
  234. fi
  235. if ! $signchanges "$pva.changes"; then
  236. signerrors="(WARNING: Failed to sign .changes file)"
  237. fi
  238. if $cleansource; then
  239. withecho $rootcommand debian/rules clean
  240. fi
  241. echo "dpkg-buildpackage: $srcmsg"
  242. if [ -n "$signerrors" ]; then
  243. echo >&2 $signerrors
  244. exit 1
  245. fi