dpkg-buildpackage.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #!/bin/sh
  2. set -e
  3. version="1.3.0"; # This line modified by Makefile
  4. progname="`basename \"$0\"`"
  5. usageversion () {
  6. cat >&2 <<END
  7. Debian GNU/Linux 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. -k<keyid> the key to use for signing
  16. -sgpg the sign-command is called like GPG
  17. -spgp the sign-command is called like PGP
  18. -sdebsign the sign-command works like debsign
  19. -us unsigned source
  20. -uc unsigned changes
  21. -a<arch> Debian architecture we build for
  22. -b binary-only, do not build source } also passed to
  23. -B binary-only, no arch-indep files } dpkg-genchanges
  24. -S source only, no binary files }
  25. -t<system> set GNU system type } passed to dpkg-architecture
  26. -v<version> changes since version <version> }
  27. -m<maint> maintainer for package is <maint> }
  28. -e<maint> maintainer for release is <maint> } only passed
  29. -C<descfile> changes are described in <descfile> } to dpkg-
  30. -si (default) src includes orig for rev. 0 or 1 } genchanges
  31. -sa uploaded src always includes orig }
  32. -sd uploaded src is diff and .dsc only }
  33. -nc do not clean source tree (implies -b)
  34. -tc clean source tree when finished
  35. -ap add pause before starting signature process
  36. -h print this message
  37. -i[<regex>] ignore diffs of files matching regex } only passed
  38. to dpkg-source
  39. END
  40. }
  41. rootcommand=''
  42. signcommand=""
  43. if [ -e $GNUPGHOME/secring.pgp -o -e $HOME/.gnupg/secring.gpg ] && \
  44. command -v gpg > /dev/null 2>&1; then
  45. signcommand=gpg
  46. elif command -v pgp > /dev/null 2>&1 ; then
  47. signcommand=pgp
  48. fi
  49. signsource='withecho signfile'
  50. signchanges='withecho signfile'
  51. cleansource=false
  52. binarytarget=binary
  53. sourcestyle=''
  54. version=''
  55. since=''
  56. maint=''
  57. desc=''
  58. noclean=false
  59. usepause=false
  60. while [ $# != 0 ]
  61. do
  62. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  63. case "$1" in
  64. -h) usageversion; exit 0 ;;
  65. -r*) rootcommand="$value" ;;
  66. -p*) signcommand="$value" ;;
  67. -k*) signkey="$value" ;;
  68. -sgpg) forcesigninterface=gpg ;;
  69. -spgp) forcesigninterface=pgp ;;
  70. -sdebsign) forcesigninterface=debsign ;;
  71. -us) signsource=: ;;
  72. -uc) signchanges=: ;;
  73. -ap) usepause="true";;
  74. -a*) opt_a=1; targetarch="$value" ;;
  75. -si) sourcestyle=-si ;;
  76. -sa) sourcestyle=-sa ;;
  77. -sd) sourcestyle=-sd ;;
  78. -i*) diffignore=$1;;
  79. -tc) cleansource=true ;;
  80. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  81. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  82. -b) binaryonly=-b; [ "$sourceonly" ] && \
  83. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  84. -B) binaryonly=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  85. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  86. -S) sourceonly=-S; [ "$binaryonly" ] && \
  87. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  88. -v*) since="$value" ;;
  89. -m*) maint="$value" ;;
  90. -e*) changedby="$value" ;;
  91. -C*) descfile="$value" ;;
  92. *) echo >&2 "$progname: unknown option or argument $1"
  93. usageversion; exit 2 ;;
  94. esac
  95. shift
  96. done
  97. if [ -z "$signcommand" ] ; then
  98. signsource=:
  99. signchanges=:
  100. fi
  101. if test -n "$forcesigninterface" ; then
  102. signinterface=$forcesigninterface
  103. else
  104. signinterface=$signcommand
  105. fi
  106. if test "$signinterface" = "debsign"; then
  107. signsource=:
  108. fi
  109. mustsetvar () {
  110. if [ "x$2" = x ]; then
  111. echo >&2 "$progname: unable to determine $3" ; \
  112. exit 1
  113. else
  114. echo "$progname: $3 is $2" ; \
  115. eval "$1=\"\$2\""
  116. fi
  117. }
  118. curd="`pwd`"
  119. dirn="`basename \"$curd\"`"
  120. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  121. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  122. if [ -n "$maint" ]; then maintainer="$maint";
  123. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  124. eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  125. archlist=`dpkg-architecture -a${targetarch} -t${targetgnusystem} -f 2> /dev/null`
  126. if [ x$sourceonly = x ]; then
  127. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "build architecture"
  128. else
  129. arch=source
  130. fi
  131. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  132. pv="${package}_${sversion}"
  133. pva="${package}_${sversion}${arch:+_${arch}}"
  134. signfile () {
  135. if test "$signinterface" = "gpg" ; then
  136. (cat "../$1" ; echo "") | \
  137. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  138. --textmode > "../$1.asc"
  139. elif test "$signinterface" = "debsign"; then
  140. if test x$signkey != x; then
  141. $signcommand -k"$signkey" ../$1
  142. else
  143. $signcommand ../$1
  144. fi
  145. return
  146. else
  147. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  148. >"../$1.asc"
  149. fi
  150. echo
  151. mv -- "../$1.asc" "../$1"
  152. }
  153. withecho () {
  154. echo " $@" >&2
  155. "$@"
  156. }
  157. set -- $binaryonly $sourceonly $sourcestyle
  158. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  159. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  160. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  161. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  162. if [ x$noclean != xtrue ]; then
  163. withecho $rootcommand debian/rules clean $archlist
  164. fi
  165. if [ x$binaryonly = x ]; then
  166. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  167. fi
  168. if [ x$sourceonly = x ]; then
  169. withecho debian/rules build $archlist
  170. withecho $rootcommand debian/rules $binarytarget $archlist
  171. fi
  172. if [ "$usepause" = "true" ] && [ "x$binaryonly" = x -o "x$signchanges" != x ] ; then
  173. echo Press the return key to start signing process
  174. read dummy_stuff
  175. fi
  176. if [ x$binaryonly = x ]; then
  177. $signsource "$pv.dsc"
  178. fi
  179. chg=../"$pva.changes"
  180. withecho dpkg-genchanges "$@" >"$chg"
  181. fileomitted () {
  182. set +e
  183. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  184. fir=$?
  185. set -e
  186. return $fir
  187. }
  188. if fileomitted '\.dsc'; then
  189. srcmsg='no source included in upload'
  190. elif fileomitted '\.diff\.gz'; then
  191. srcmsg='Debian-specific package; upload is full source'
  192. elif fileomitted '\.orig\.tar\.gz'; then
  193. srcmsg='diff-only upload (original source NOT included)'
  194. elif fileomitted '\.deb'; then
  195. srcmsg='source-only upload'
  196. else
  197. srcmsg='full upload (original source is included)'
  198. fi
  199. $signchanges "$pva.changes"
  200. if $cleansource; then
  201. withecho $rootcommand debian/rules clean $archlist
  202. fi
  203. echo "dpkg-buildpackage: $srcmsg"