dpkg-buildpackage.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 package is <maint> }
  24. -e<maint> maintainer for release is <maint> } only passed
  25. -C<descfile> changes are described in <descfile> } to dpkg-
  26. -si (default) src includes orig for rev. 0 or 1 } genchanges
  27. -sa uploaded src always includes orig }
  28. -sd uploaded src is diff and .dsc only }
  29. -nc do not clean source tree (implies -b)
  30. -tc clean source tree when finished
  31. -ap add pause before starting signature process
  32. -h print this message
  33. -i[<regex>] ignore diffs of files matching regex } only passed
  34. to dpkg-source
  35. END
  36. }
  37. rootcommand=''
  38. if [ -e $HOME/.gnupg/secring.gpg ] ; then
  39. signcommand=gpg
  40. else
  41. signcommand=pgp
  42. fi
  43. signsource='withecho signfile'
  44. signchanges='withecho signfile'
  45. cleansource=false
  46. binarytarget=binary
  47. sourcestyle=''
  48. version=''
  49. since=''
  50. maint=''
  51. desc=''
  52. noclean=false
  53. usepause=false
  54. while [ $# != 0 ]
  55. do
  56. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  57. case "$1" in
  58. -h) usageversion; exit 0 ;;
  59. -r*) rootcommand="$value" ;;
  60. -p*) signcommand="$value" ;;
  61. -k*) signkey="$value" ;;
  62. -sgpg) forcesigninterface=gpg ;;
  63. -spgp) forcesigninterface=pgp ;;
  64. -sdebsign) forcesigninterface=debsign ;;
  65. -us) signsource=: ;;
  66. -uc) signchanges=: ;;
  67. -ap) usepause="true";;
  68. -a*) opt_a=1; targetarch="$value" ;;
  69. -si) sourcestyle=-si ;;
  70. -sa) sourcestyle=-sa ;;
  71. -sd) sourcestyle=-sd ;;
  72. -i*) diffignore=$1;;
  73. -tc) cleansource=true ;;
  74. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  75. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  76. -b) binaryonly=-b ;;
  77. -B) binaryonly=-B; binarytarget=binary-arch ;;
  78. -v*) since="$value" ;;
  79. -m*) maint="$value" ;;
  80. -e*) changedby="$value" ;;
  81. -C*) descfile="$value" ;;
  82. *) echo >&2 "$progname: unknown option or argument $1"
  83. usageversion; exit 2 ;;
  84. esac
  85. shift
  86. done
  87. if test -n "$forcesigninterface" ; then
  88. signinterface=$forcesigninterface
  89. else
  90. signinterface=$signcommand
  91. fi
  92. if test "$signinterface" = "debsign"; then
  93. signsource=:
  94. fi
  95. mustsetvar () {
  96. if [ "x$2" = x ]; then
  97. echo >&2 "$progname: unable to determine $3" ; \
  98. exit 1
  99. else
  100. echo "$progname: $3 is $2" ; \
  101. eval "$1=\"\$2\""
  102. fi
  103. }
  104. curd="`pwd`"
  105. dirn="`basename \"$curd\"`"
  106. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  107. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  108. if [ -n "$maint" ]; then maintainer="$maint";
  109. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  110. eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  111. archlist=`dpkg-architecture -a${targetarch} -t${targetgnusystem} -f 2> /dev/null`
  112. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "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 "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  142. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  143. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  144. if [ x$noclean != xtrue ]; then
  145. withecho $rootcommand debian/rules clean $archlist
  146. fi
  147. if [ x$binaryonly = x ]; then
  148. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  149. fi
  150. withecho debian/rules build $archlist
  151. withecho $rootcommand debian/rules $binarytarget $archlist
  152. if [ "$usepause" = "true" ] && [ x$binaryonly = x -o x$signchanges != x ] ; then
  153. echo Press the return key to start signing process
  154. read dummy_stuff
  155. fi
  156. if [ x$binaryonly = x ]; then
  157. $signsource "$pv.dsc"
  158. fi
  159. chg=../"$pva.changes"
  160. withecho dpkg-genchanges "$@" >"$chg"
  161. fileomitted () {
  162. set +e
  163. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  164. fir=$?
  165. set -e
  166. return $fir
  167. }
  168. if fileomitted '\.dsc'; then
  169. srcmsg='no source included in upload'
  170. elif fileomitted '\.diff\.gz'; then
  171. srcmsg='Debian-specific package; upload is full source'
  172. elif fileomitted '\.orig\.tar\.gz'; then
  173. srcmsg='diff-only upload (original source NOT included)'
  174. else
  175. srcmsg='full upload (original source is included)'
  176. fi
  177. $signchanges "$pva.changes"
  178. if $cleansource; then
  179. withecho $rootcommand debian/rules clean $archlist
  180. fi
  181. echo "dpkg-buildpackage: $srcmsg"