dpkg-buildpackage.sh 5.5 KB

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