dpkg-buildpackage.sh 5.9 KB

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