dpkg-buildpackage.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. -ap add pause before starting signature process
  30. -h print this message
  31. -i[<regex>] ignore diffs of files matching regex } only passed
  32. to dpkg-source
  33. END
  34. }
  35. rootcommand=''
  36. if [ -e $HOME/.gnupg/secring.gpg ] ; then
  37. signcommand=gpg
  38. else
  39. signcommand=pgp
  40. fi
  41. signsource='withecho signfile'
  42. signchanges='withecho signfile'
  43. cleansource=false
  44. binarytarget=binary
  45. sourcestyle=''
  46. version=''
  47. since=''
  48. maint=''
  49. desc=''
  50. noclean=false
  51. usepause=false
  52. while [ $# != 0 ]
  53. do
  54. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  55. case "$1" in
  56. -h) usageversion; exit 0 ;;
  57. -r*) rootcommand="$value" ;;
  58. -p*) signcommand="$value" ;;
  59. -k*) signkey="$value" ;;
  60. -sgpg) forcesigninterface=gpg ;;
  61. -spgp) forcesigninterface=pgp ;;
  62. -us) signsource=: ;;
  63. -uc) signchanges=: ;;
  64. -ap) usepause="true";;
  65. -a*) opt_a=1; arch="$value" ;;
  66. -si) sourcestyle=-si ;;
  67. -sa) sourcestyle=-sa ;;
  68. -sd) sourcestyle=-sd ;;
  69. -i*) diffignore=$1;;
  70. -tc) cleansource=true ;;
  71. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  72. -nc) noclean=true; binaryonly=-b ;;
  73. -b) binaryonly=-b ;;
  74. -B) binaryonly=-B; binarytarget=binary-arch ;;
  75. -v*) since="$value" ;;
  76. -m*) maint="$value" ;;
  77. -C*) descfile="$value" ;;
  78. *) echo >&2 "$progname: unknown option or argument $1"
  79. usageversion; exit 2 ;;
  80. esac
  81. shift
  82. done
  83. if test -n "$forcesigninterface" ; then
  84. signinterface=$forcesigninterface
  85. else
  86. signinterface=$signcommand
  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. command -v dpkg-architecture > /dev/null 2>&1 && eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  104. archlist=`dpkg-architecture -a${arch} -t${targetgnusystem} -f 2> /dev/null`
  105. test "${opt_a}" \
  106. || arch=`dpkg-architecture -a${arch} -t${targetgnusystem} -qDEB_HOST_ARCH 2> /dev/null` && test "${arch}" \
  107. || mustsetvar arch "`dpkg --print-architecture`" "build architecture"
  108. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  109. pv="${package}_${sversion}"
  110. pva="${package}_${sversion}${arch:+_${arch}}"
  111. signfile () {
  112. if test "$signinterface" = "gpg" ; then
  113. (cat "../$1" ; echo "") | \
  114. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  115. --textmode > "../$1.asc"
  116. else
  117. $signcommand -u "${signkey:-$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 $archlist
  133. fi
  134. if [ x$binaryonly = x ]; then
  135. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  136. fi
  137. withecho debian/rules build $archlist
  138. withecho $rootcommand debian/rules $binarytarget $archlist
  139. if [ "$usepause" = "true" ] && [ x$binaryonly = x -o x$signchanges != x ] ; then
  140. echo Press the return key to start signing process
  141. read dummy_stuff
  142. fi
  143. if [ x$binaryonly = x ]; then
  144. $signsource "$pv.dsc"
  145. fi
  146. chg=../"$pva.changes"
  147. withecho dpkg-genchanges "$@" >"$chg"
  148. fileomitted () {
  149. set +e
  150. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  151. fir=$?
  152. set -e
  153. return $fir
  154. }
  155. if fileomitted '\.dsc'; then
  156. srcmsg='no source included in upload'
  157. elif fileomitted '\.diff\.gz'; then
  158. srcmsg='Debian-specific package; upload is full source'
  159. elif fileomitted '\.orig\.tar\.gz'; then
  160. srcmsg='diff-only upload (original source NOT included)'
  161. else
  162. srcmsg='full upload (original source is included)'
  163. fi
  164. $signchanges "$pva.changes"
  165. if $cleansource; then
  166. withecho $rootcommand debian/rules clean $archlist
  167. fi
  168. echo "dpkg-buildpackage: $srcmsg"