dpkg-buildpackage.sh 8.3 KB

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