dpkg-buildpackage.sh 7.2 KB

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