dpkg-buildpackage.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. signcommand=""
  39. if [ -e $GNUPGHOME/secring.pgp -o -e $HOME/.gnupg/secring.gpg ] && \
  40. command -v gpg > /dev/null 2>&1; then
  41. signcommand=gpg
  42. elif command -v pgp > /dev/null 2>&1 ; then
  43. signcommand=pgp
  44. fi
  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. usepause=false
  56. while [ $# != 0 ]
  57. do
  58. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  59. case "$1" in
  60. -h) usageversion; exit 0 ;;
  61. -r*) rootcommand="$value" ;;
  62. -p*) signcommand="$value" ;;
  63. -k*) signkey="$value" ;;
  64. -sgpg) forcesigninterface=gpg ;;
  65. -spgp) forcesigninterface=pgp ;;
  66. -sdebsign) forcesigninterface=debsign ;;
  67. -us) signsource=: ;;
  68. -uc) signchanges=: ;;
  69. -ap) usepause="true";;
  70. -a*) opt_a=1; targetarch="$value" ;;
  71. -si) sourcestyle=-si ;;
  72. -sa) sourcestyle=-sa ;;
  73. -sd) sourcestyle=-sd ;;
  74. -i*) diffignore=$1;;
  75. -tc) cleansource=true ;;
  76. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  77. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  78. -b) binaryonly=-b ;;
  79. -B) binaryonly=-B; binarytarget=binary-arch ;;
  80. -v*) since="$value" ;;
  81. -m*) maint="$value" ;;
  82. -e*) changedby="$value" ;;
  83. -C*) descfile="$value" ;;
  84. *) echo >&2 "$progname: unknown option or argument $1"
  85. usageversion; exit 2 ;;
  86. esac
  87. shift
  88. done
  89. if [ -z "$signcommand" ] ; then
  90. signsource=:
  91. signchanges=:
  92. fi
  93. if test -n "$forcesigninterface" ; then
  94. signinterface=$forcesigninterface
  95. else
  96. signinterface=$signcommand
  97. fi
  98. if test "$signinterface" = "debsign"; then
  99. signsource=:
  100. fi
  101. mustsetvar () {
  102. if [ "x$2" = x ]; then
  103. echo >&2 "$progname: unable to determine $3" ; \
  104. exit 1
  105. else
  106. echo "$progname: $3 is $2" ; \
  107. eval "$1=\"\$2\""
  108. fi
  109. }
  110. curd="`pwd`"
  111. dirn="`basename \"$curd\"`"
  112. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  113. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  114. if [ -n "$maint" ]; then maintainer="$maint";
  115. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  116. eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  117. archlist=`dpkg-architecture -a${targetarch} -t${targetgnusystem} -f 2> /dev/null`
  118. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "build architecture"
  119. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  120. pv="${package}_${sversion}"
  121. pva="${package}_${sversion}${arch:+_${arch}}"
  122. signfile () {
  123. if test "$signinterface" = "gpg" ; then
  124. (cat "../$1" ; echo "") | \
  125. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  126. --textmode > "../$1.asc"
  127. elif test "$signinterface" = "debsign"; then
  128. if test x$signkey != x; then
  129. $signcommand -k"$signkey" ../$1
  130. else
  131. $signcommand ../$1
  132. fi
  133. return
  134. else
  135. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  136. >"../$1.asc"
  137. fi
  138. echo
  139. mv -- "../$1.asc" "../$1"
  140. }
  141. withecho () {
  142. echo " $@" >&2
  143. "$@"
  144. }
  145. set -- $binaryonly $sourcestyle
  146. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  147. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  148. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  149. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  150. if [ x$noclean != xtrue ]; then
  151. withecho $rootcommand debian/rules clean $archlist
  152. fi
  153. if [ x$binaryonly = x ]; then
  154. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  155. fi
  156. withecho debian/rules build $archlist
  157. withecho $rootcommand debian/rules $binarytarget $archlist
  158. if [ "$usepause" = "true" ] && [ x$binaryonly = x -o x$signchanges != x ] ; then
  159. echo Press the return key to start signing process
  160. read dummy_stuff
  161. fi
  162. if [ x$binaryonly = x ]; then
  163. $signsource "$pv.dsc"
  164. fi
  165. chg=../"$pva.changes"
  166. withecho dpkg-genchanges "$@" >"$chg"
  167. fileomitted () {
  168. set +e
  169. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  170. fir=$?
  171. set -e
  172. return $fir
  173. }
  174. if fileomitted '\.dsc'; then
  175. srcmsg='no source included in upload'
  176. elif fileomitted '\.diff\.gz'; then
  177. srcmsg='Debian-specific package; upload is full source'
  178. elif fileomitted '\.orig\.tar\.gz'; then
  179. srcmsg='diff-only upload (original source NOT included)'
  180. else
  181. srcmsg='full upload (original source is included)'
  182. fi
  183. $signchanges "$pva.changes"
  184. if $cleansource; then
  185. withecho $rootcommand debian/rules clean $archlist
  186. fi
  187. echo "dpkg-buildpackage: $srcmsg"