dpkg-buildpackage.sh 7.8 KB

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