dpkg-buildpackage.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. -sgpg the sign-command is called like GPG
  14. -spgp the sign-command is called like PGP
  15. -us unsigned source
  16. -uc unsigned changes
  17. -a<arch> architecture field of the changes _file_name_
  18. -b binary-only, do not build source } also passed to
  19. -B binary-only, no arch-indep files } dpkg-genchanges
  20. -v<version> changes since version <version> }
  21. -m<maint> maintainer for release is <maint> } only passed
  22. -C<descfile> changes are described in <descfile> } to dpkg-
  23. -si (default) src includes orig for rev. 0 or 1 } genchanges
  24. -sa uploaded src always includes orig }
  25. -sd uploaded src is diff and .dsc only }
  26. -nc do not clean source tree (implies -b)
  27. -tc clean source tree when finished
  28. -h print this message
  29. END
  30. }
  31. rootcommand=''
  32. signcommand=pgp # Default command for signing
  33. warnpgp='no' # Display a warning to encourage switching to gpg?
  34. if [ ! -e $HOME/.gnupg/secring.gpg ] ; then
  35. warnpgp=yes
  36. fi
  37. if [ -e $HOME/.gnupg/secring.gpg -a ! -e $HOME/.pgp/secring.pgp ] ; then
  38. signcommand=gpg
  39. fi
  40. if [ -e $HOME/.pgp/secring.pgp -a ! -e $HOME/.gnupg/secring.gpg ] ; then
  41. signcommand=pgp
  42. fi
  43. signinterface=$signcommand
  44. signsource='withecho signfile'
  45. signchanges='withecho signfile'
  46. cleansource=false
  47. binarytarget=binary
  48. sourcestyle=''
  49. version=''
  50. since=''
  51. maint=''
  52. desc=''
  53. noclean=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"; warnpgp='' ;;
  61. -sgpg) signinterface=gpg ;;
  62. -spgp) signinterface=pgp ;;
  63. -us) signsource=: ; warnpgp='' ;;
  64. -uc) signchanges=: ; warnpgp='' ;;
  65. -a*) opt_a=1; arch="$value" ;;
  66. -si) sourcestyle=-si ;;
  67. -sa) sourcestyle=-sa ;;
  68. -sd) sourcestyle=-sd ;;
  69. -tc) cleansource=true ;;
  70. -nc) noclean=true; binaryonly=-b ;;
  71. -b) binaryonly=-b ;;
  72. -B) binaryonly=-B; binarytarget=binary-arch ;;
  73. -v*) since="$value" ;;
  74. -m*) maint="$value" ;;
  75. -C*) descfile="$value" ;;
  76. *) echo >&2 "$progname: unknown option or argument $1"
  77. usageversion; exit 2 ;;
  78. esac
  79. shift
  80. done
  81. if test "X$warnpgp" = "Xyes" ; then
  82. echo >&2 <<EOWARN
  83. The Debian project will switch to using GPG (the GNU Privacy Guard) instead
  84. of PGP for signing packages. You might want to make preparations. Check out
  85. the gnupg and debian-keyring packages.
  86. EOWARN
  87. fi
  88. mustsetvar () {
  89. if [ "x$2" = x ]; then
  90. echo >&2 "$progname: unable to determine $3" ; \
  91. exit 1
  92. else
  93. echo "$progname: $3 is $2" ; \
  94. eval "$1=\"\$2\""
  95. fi
  96. }
  97. curd="`pwd`"
  98. dirn="`basename \"$curd\"`"
  99. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  100. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  101. if [ -n "$maint" ]; then maintainer="$maint";
  102. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  103. test "${opt_a}" \
  104. || mustsetvar arch "`dpkg --print-architecture`" "build architecture"
  105. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  106. pv="${package}_${sversion}"
  107. pva="${package}_${sversion}${arch:+_${arch}}"
  108. signfile () {
  109. if test $signinterface = gpg ; then
  110. # --textmode doesn't seem to work; we use perl to filter ^M;
  111. # this doesn't affect the actual signature.
  112. (cat "../$1" ; echo "") | \
  113. $signcommand --local-user "$maintainer" --clearsign --armor \
  114. --textmode --output - - | \
  115. perl -n -p -e 's/\r$//' > "../$1.asc"
  116. else
  117. $signcommand -u "$maintainer" +clearsig=on -fast <"../$1" \
  118. >"../$1.asc"
  119. fi
  120. echo
  121. mv -- "../$1.asc" "../$1"
  122. }
  123. withecho () {
  124. echo " $@" >&2
  125. "$@"
  126. }
  127. set -- $binaryonly $sourcestyle
  128. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  129. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  130. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  131. if [ x$noclean != xtrue ]; then
  132. withecho $rootcommand debian/rules clean
  133. fi
  134. if [ x$binaryonly = x ]; then
  135. cd ..; withecho dpkg-source -b "$dirn"; cd "$dirn"
  136. fi
  137. withecho debian/rules build
  138. withecho $rootcommand debian/rules $binarytarget
  139. if [ x$binaryonly = x ]; then
  140. $signsource "$pv.dsc"
  141. fi
  142. chg=../"$pva.changes"
  143. withecho dpkg-genchanges "$@" >"$chg"
  144. fileomitted () {
  145. set +e
  146. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  147. fir=$?
  148. set -e
  149. return $fir
  150. }
  151. if fileomitted '\.dsc'; then
  152. srcmsg='no source included in upload'
  153. elif fileomitted '\.diff\.gz'; then
  154. srcmsg='Debian-specific package; upload is full source'
  155. elif fileomitted '\.orig\.tar\.gz'; then
  156. srcmsg='diff-only upload (original source NOT included)'
  157. else
  158. srcmsg='full upload (original source is included)'
  159. fi
  160. $signchanges "$pva.changes"
  161. if $cleansource; then
  162. withecho $rootcommand debian/rules clean
  163. fi
  164. echo "dpkg-buildpackage: $srcmsg"