dpkg-buildpackage.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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.
  8. Copyright (C) 1996 Ian Jackson.
  9. Copyright (C) 2000 Wichert Akkerman
  10. This is free software; see the GNU General Public Licence version 2
  11. or later for copying conditions. There is NO warranty.
  12. Usage: dpkg-buildpackage [options]
  13. Options: -r<gain-root-command>
  14. -p<sign-command>
  15. -k<keyid> the key to use for signing
  16. -sgpg the sign-command is called like GPG
  17. -spgp the sign-command is called like PGP
  18. -sdebsign the sign-command works like debsign
  19. -us unsigned source
  20. -uc unsigned changes
  21. -a<arch> Debian architecture we build for
  22. -b binary-only, do not build source } also passed to
  23. -B binary-only, no arch-indep files } dpkg-genchanges
  24. -S source only, no binary files }
  25. -v<version> changes since version <version> }
  26. -m<maint> maintainer for package is <maint> }
  27. -e<maint> maintainer for release is <maint> } only passed
  28. -C<descfile> changes are described in <descfile> } to dpkg-
  29. -si (default) src includes orig for rev. 0 or 1 } genchanges
  30. -sa uploaded src always includes orig }
  31. -sd uploaded src is diff and .dsc only }
  32. -nc do not clean source tree (implies -b)
  33. -tc clean source tree when finished
  34. -ap add pause before starting signature process
  35. -h print this message
  36. -i[<regex>] ignore diffs of files matching regex } only passed
  37. to dpkg-source
  38. END
  39. }
  40. rootcommand=''
  41. signcommand=""
  42. if [ -e $GNUPGHOME/secring.pgp -o -e $HOME/.gnupg/secring.gpg ] && \
  43. command -v gpg > /dev/null 2>&1; then
  44. signcommand=gpg
  45. elif command -v pgp > /dev/null 2>&1 ; then
  46. signcommand=pgp
  47. fi
  48. signsource='withecho signfile'
  49. signchanges='withecho signfile'
  50. cleansource=false
  51. binarytarget=binary
  52. sourcestyle=''
  53. version=''
  54. since=''
  55. maint=''
  56. desc=''
  57. noclean=false
  58. usepause=false
  59. while [ $# != 0 ]
  60. do
  61. value="`echo x\"$1\" | sed -e 's/^x-.//'`"
  62. case "$1" in
  63. -h) usageversion; exit 0 ;;
  64. -r*) rootcommand="$value" ;;
  65. -p*) signcommand="$value" ;;
  66. -k*) signkey="$value" ;;
  67. -sgpg) forcesigninterface=gpg ;;
  68. -spgp) forcesigninterface=pgp ;;
  69. -sdebsign) forcesigninterface=debsign ;;
  70. -us) signsource=: ;;
  71. -uc) signchanges=: ;;
  72. -ap) usepause="true";;
  73. -a*) opt_a=1; targetarch="$value" ;;
  74. -si) sourcestyle=-si ;;
  75. -sa) sourcestyle=-sa ;;
  76. -sd) sourcestyle=-sd ;;
  77. -i*) diffignore=$1;;
  78. -tc) cleansource=true ;;
  79. -t*) targetgnusystem="$value" ;; # Order DOES matter!
  80. -nc) noclean=true; if [ -z "$binaryonly" ]; then binaryonly=-b; fi ;;
  81. -b) binaryonly=-b; [ "$sourceonly" ] && \
  82. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  83. -B) binaryonly=-B; binarytarget=binary-arch; [ "$sourceonly" ] && \
  84. { echo >&2 "$progname: cannot combine $1 and -S" ; exit 2 ; } ;;
  85. -S) sourceonly=-S; [ "$binaryonly" ] && \
  86. { echo >&2 "$progname: cannot combine $binaryonly and $1" ; exit 2 ; } ;;
  87. -v*) since="$value" ;;
  88. -m*) maint="$value" ;;
  89. -e*) changedby="$value" ;;
  90. -C*) descfile="$value" ;;
  91. *) echo >&2 "$progname: unknown option or argument $1"
  92. usageversion; exit 2 ;;
  93. esac
  94. shift
  95. done
  96. if [ -z "$signcommand" ] ; then
  97. signsource=:
  98. signchanges=:
  99. fi
  100. if test -n "$forcesigninterface" ; then
  101. signinterface=$forcesigninterface
  102. else
  103. signinterface=$signcommand
  104. fi
  105. if test "$signinterface" = "debsign"; then
  106. signsource=:
  107. fi
  108. mustsetvar () {
  109. if [ "x$2" = x ]; then
  110. echo >&2 "$progname: unable to determine $3" ; \
  111. exit 1
  112. else
  113. echo "$progname: $3 is $2" ; \
  114. eval "$1=\"\$2\""
  115. fi
  116. }
  117. curd="`pwd`"
  118. dirn="`basename \"$curd\"`"
  119. mustsetvar package "`dpkg-parsechangelog | sed -n 's/^Source: //p'`" "source package"
  120. mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
  121. if [ -n "$maint" ]; then maintainer="$maint";
  122. else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
  123. eval `dpkg-architecture -a${arch} -t${targetgnusystem} -s`
  124. archlist=`dpkg-architecture -a${targetarch} -t${targetgnusystem} -f 2> /dev/null`
  125. if [ x$sourceonly = x ]; then
  126. mustsetvar arch "`dpkg-architecture -a${targetarch} -t${targetgnusystem} -qDEB_HOST_ARCH`" "build architecture"
  127. else
  128. arch=source
  129. fi
  130. sversion=`echo "$version" | perl -pe 's/^\d+://'`
  131. pv="${package}_${sversion}"
  132. pva="${package}_${sversion}${arch:+_${arch}}"
  133. signfile () {
  134. if test "$signinterface" = "gpg" ; then
  135. (cat "../$1" ; echo "") | \
  136. $signcommand --local-user "${signkey:-$maintainer}" --clearsign --armor \
  137. --textmode > "../$1.asc"
  138. elif test "$signinterface" = "debsign"; then
  139. if test x$signkey != x; then
  140. $signcommand -k"$signkey" ../$1
  141. else
  142. $signcommand ../$1
  143. fi
  144. return
  145. else
  146. $signcommand -u "${signkey:-$maintainer}" +clearsig=on -fast <"../$1" \
  147. >"../$1.asc"
  148. fi
  149. echo
  150. mv -- "../$1.asc" "../$1"
  151. }
  152. withecho () {
  153. echo " $@" >&2
  154. "$@"
  155. }
  156. set -- $binaryonly $sourceonly $sourcestyle
  157. if [ -n "$maint" ]; then set -- "$@" "-m$maint" ; fi
  158. if [ -n "$changedby" ]; then set -- "$@" "-e$changedby" ; fi
  159. if [ -n "$since" ]; then set -- "$@" "-v$since" ; fi
  160. if [ -n "$desc" ]; then set -- "$@" "-C$desc" ; fi
  161. if [ x$noclean != xtrue ]; then
  162. withecho $rootcommand debian/rules clean $archlist
  163. fi
  164. if [ x$binaryonly = x ]; then
  165. cd ..; withecho dpkg-source $diffignore -b "$dirn"; cd "$dirn"
  166. fi
  167. if [ x$sourceonly = x ]; then
  168. withecho debian/rules build $archlist
  169. withecho $rootcommand debian/rules $binarytarget $archlist
  170. fi
  171. if [ "$usepause" = "true" ] && [ x$binaryonly = x -o x$signchanges != x ] ; then
  172. echo Press the return key to start signing process
  173. read dummy_stuff
  174. fi
  175. if [ x$binaryonly = x ]; then
  176. $signsource "$pv.dsc"
  177. fi
  178. chg=../"$pva.changes"
  179. withecho dpkg-genchanges "$@" >"$chg"
  180. fileomitted () {
  181. set +e
  182. test -z "`sed -n '/^Files:/,/^[^ ]/ s/'$1'$//p' <$chg`"
  183. fir=$?
  184. set -e
  185. return $fir
  186. }
  187. if fileomitted '\.dsc'; then
  188. srcmsg='no source included in upload'
  189. elif fileomitted '\.diff\.gz'; then
  190. srcmsg='Debian-specific package; upload is full source'
  191. elif fileomitted '\.orig\.tar\.gz'; then
  192. srcmsg='diff-only upload (original source NOT included)'
  193. elif fileomitted '\.deb'; then
  194. srcmsg='source-only upload'
  195. else
  196. srcmsg='full upload (original source is included)'
  197. fi
  198. $signchanges "$pva.changes"
  199. if $cleansource; then
  200. withecho $rootcommand debian/rules clean $archlist
  201. fi
  202. echo "dpkg-buildpackage: $srcmsg"