dpkg-buildpackage.sh 7.6 KB

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