dpkg-buildpackage.sh 5.1 KB

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