dpkg-buildpackage.sh 7.7 KB

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