src-release.sh 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/usr/bin/env bash
  2. # Copyright (C) 1990-2014 Free Software Foundation
  3. #
  4. # This file is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # This script creates release packages for gdb, binutils, and other
  18. # packages which live in src. It used to be implemented as the src-release
  19. # Makefile and prior to that was part of the top level Makefile, but that
  20. # turned out to be very messy and hard to maintain.
  21. set -e
  22. BZIPPROG=bzip2
  23. GZIPPROG=gzip
  24. XZPROG=xz
  25. MD5PROG=md5sum
  26. MAKE=make
  27. CC=gcc
  28. CXX=g++
  29. # Default to avoid splitting info files by setting the threshold high.
  30. MAKEINFOFLAGS=--split-size=5000000
  31. #
  32. # Support for building net releases
  33. # Files in devo used in any net release.
  34. DEVO_SUPPORT="README Makefile.in configure configure.ac \
  35. config.guess config.sub config move-if-change \
  36. COPYING COPYING.LIB install-sh config-ml.in symlink-tree \
  37. mkinstalldirs ltmain.sh missing ylwrap \
  38. libtool.m4 ltsugar.m4 ltversion.m4 ltoptions.m4 \
  39. Makefile.def Makefile.tpl src-release.sh config.rpath \
  40. ChangeLog MAINTAINERS README-maintainer-mode \
  41. lt~obsolete.m4 ltgcc.m4 depcomp mkdep compile \
  42. COPYING3 COPYING3.LIB"
  43. # Files in devo/etc used in any net release.
  44. ETC_SUPPORT="Makefile.in configure configure.in standards.texi \
  45. make-stds.texi standards.info* configure.texi configure.info* \
  46. ChangeLog configbuild.* configdev.* fdl.texi texi2pod.pl gnu-oids.texi"
  47. # Get the version number of a given tool
  48. getver()
  49. {
  50. tool=$1
  51. if grep 'AC_INIT.*BFD_VERSION' $tool/configure.ac >/dev/null 2>&1; then
  52. bfd/configure --version | sed -n -e '1s,.* ,,p'
  53. elif test -f $tool/common/create-version.sh; then
  54. $tool/common/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
  55. cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
  56. rm -f VER.tmp
  57. elif test -f $tool/version.in; then
  58. head -1 $tool/version.in
  59. else
  60. echo VERSION
  61. fi
  62. }
  63. # Setup build directory for building release tarball
  64. do_proto_toplev()
  65. {
  66. package=$1
  67. ver=$2
  68. tool=$3
  69. support_files=$4
  70. echo "==> Making $package-$ver/"
  71. # Take out texinfo from a few places.
  72. sed -e '/^all\.normal: /s/\all-texinfo //' \
  73. -e '/^ install-texinfo /d' \
  74. <Makefile.in >tmp
  75. mv -f tmp Makefile.in
  76. #
  77. ./configure --target=i386-pc-linux-gnu
  78. $MAKE configure-host configure-target \
  79. ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
  80. CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
  81. # Make links, and run "make diststuff" or "make info" when needed.
  82. rm -rf proto-toplev
  83. mkdir proto-toplev
  84. dirs="$DEVO_SUPPORT $support_files $tool"
  85. for d in $dirs ; do
  86. if [ -d $d ]; then
  87. if [ ! -f $d/Makefile ] ; then
  88. true
  89. elif grep '^diststuff:' $d/Makefile >/dev/null ; then
  90. (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" diststuff) \
  91. || exit 1
  92. elif grep '^info:' $d/Makefile >/dev/null ; then
  93. (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) \
  94. || exit 1
  95. fi
  96. if [ -d $d/proto-$d.dir ]; then
  97. ln -s ../$d/proto-$d.dir proto-toplev/$d
  98. else
  99. ln -s ../$d proto-toplev/$d
  100. fi
  101. else
  102. if (echo x$d | grep / >/dev/null); then
  103. mkdir -p proto-toplev/`dirname $d`
  104. x=`dirname $d`
  105. ln -s ../`echo $x/ | sed -e 's,[^/]*/,../,g'`$d proto-toplev/$d
  106. else
  107. ln -s ../$d proto-toplev/$d
  108. fi
  109. fi
  110. done
  111. (cd etc; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info)
  112. $MAKE distclean
  113. mkdir proto-toplev/etc
  114. (cd proto-toplev/etc;
  115. for i in $ETC_SUPPORT; do
  116. ln -s ../../etc/$i .
  117. done)
  118. #
  119. # Take out texinfo from configurable dirs
  120. rm proto-toplev/configure.ac
  121. sed -e '/^host_tools=/s/texinfo //' \
  122. <configure.ac >proto-toplev/configure.ac
  123. #
  124. mkdir proto-toplev/texinfo
  125. ln -s ../../texinfo/texinfo.tex proto-toplev/texinfo/
  126. if test -r texinfo/util/tex3patch ; then
  127. mkdir proto-toplev/texinfo/util && \
  128. ln -s ../../../texinfo/util/tex3patch proto-toplev/texinfo/util
  129. else
  130. true
  131. fi
  132. chmod -R og=u . || chmod og=u `find . -print`
  133. #
  134. # Create .gmo files from .po files.
  135. for f in `find . -name '*.po' -type f -print`; do
  136. msgfmt -o `echo $f | sed -e 's/\.po$/.gmo/'` $f
  137. done
  138. #
  139. rm -f $package-$ver
  140. ln -s proto-toplev $package-$ver
  141. }
  142. CVS_NAMES='-name CVS -o -name .cvsignore'
  143. # Add an md5sum to the built tarball
  144. do_md5sum()
  145. {
  146. echo "==> Adding md5 checksum to top-level directory"
  147. (cd proto-toplev && find * -follow \( $CVS_NAMES \) -prune \
  148. -o -type f -print \
  149. | xargs $MD5PROG > ../md5.new)
  150. rm -f proto-toplev/md5.sum
  151. mv md5.new proto-toplev/md5.sum
  152. }
  153. # Build the release tarball
  154. do_tar()
  155. {
  156. package=$1
  157. ver=$2
  158. echo "==> Making $package-$ver.tar"
  159. rm -f $package-$ver.tar
  160. find $package-$ver -follow \( $CVS_NAMES \) -prune \
  161. -o -type f -print \
  162. | tar cTfh - $package-$ver.tar
  163. }
  164. # Compress the output with bzip2
  165. do_bz2()
  166. {
  167. package=$1
  168. ver=$2
  169. echo "==> Bzipping $package-$ver.tar.bz2"
  170. rm -f $package-$ver.tar.bz2
  171. $BZIPPROG -k -v -9 $package-$ver.tar
  172. }
  173. # Compress the output with gzip
  174. do_gz()
  175. {
  176. package=$1
  177. ver=$2
  178. echo "==> Gzipping $package-$ver.tar.gz"
  179. rm -f $package-$ver.tar.gz
  180. $GZIPPROG -k -v -9 $package-$ver.tar
  181. }
  182. # Compress the output with xz
  183. do_xz()
  184. {
  185. package=$1
  186. ver=$2
  187. echo "==> Xzipping $package-$ver.tar.xz"
  188. rm -f $package-$ver.tar.xz
  189. $XZPROG -k -v -9 $package-$ver.tar
  190. }
  191. # Compress the output with all selected compresion methods
  192. do_compress()
  193. {
  194. package=$1
  195. ver=$2
  196. compressors=$3
  197. for comp in $compressors; do
  198. case $comp in
  199. bz2)
  200. do_bz2 $package $ver;;
  201. gz)
  202. do_gz $package $ver;;
  203. xz)
  204. do_xz $package $ver;;
  205. *)
  206. echo "Unknown compression method: $comp" && exit 1;;
  207. esac
  208. done
  209. }
  210. # Add djunpack.bat the tarball
  211. do_djunpack()
  212. {
  213. package=$1
  214. ver=$2
  215. echo "==> Adding updated djunpack.bat to top-level directory"
  216. echo - 's /gdb-[0-9\.]*/$package-'"$ver"'/'
  217. sed < djunpack.bat > djunpack.new \
  218. -e 's/gdb-[0-9][0-9\.]*/$package-'"$ver"'/'
  219. rm -f proto-toplev/djunpack.bat
  220. mv djunpack.new proto-toplev/djunpack.bat
  221. }
  222. # Create a release package, tar it and compress it
  223. tar_compress()
  224. {
  225. package=$1
  226. tool=$2
  227. support_files=$3
  228. compressors=$4
  229. verdir=${5:-$tool}
  230. ver=$(getver $verdir)
  231. do_proto_toplev $package $ver $tool "$support_files"
  232. do_md5sum
  233. do_tar $package $ver
  234. do_compress $package $ver "$compressors"
  235. }
  236. # Create a gdb release package, tar it and compress it
  237. gdb_tar_compress()
  238. {
  239. package=$1
  240. tool=$2
  241. support_files=$3
  242. compressors=$4
  243. ver=$(getver $tool)
  244. do_proto_toplev $package $ver $tool "$support_files"
  245. do_md5sum
  246. do_djunpack $package $ver
  247. do_tar $package $ver
  248. do_compress $package $ver "$compressors"
  249. }
  250. # The FSF "binutils" release includes gprof and ld.
  251. BINUTILS_SUPPORT_DIRS="bfd gas include libiberty opcodes ld elfcpp gold gprof intl setup.com makefile.vms cpu zlib"
  252. binutils_release()
  253. {
  254. compressors=$1
  255. package=binutils
  256. tool=binutils
  257. tar_compress $package $tool "$BINUTILS_SUPPORT_DIRS" "$compressors"
  258. }
  259. GAS_SUPPORT_DIRS="bfd include libiberty opcodes intl setup.com makefile.vms zlib"
  260. gas_release()
  261. {
  262. compressors=$1
  263. package=gas
  264. tool=gas
  265. tar_compress $package $tool "$GAS_SUPPORT_DIRS" "$compressors"
  266. }
  267. GDB_SUPPORT_DIRS="bfd include libiberty opcodes readline sim intl libdecnumber cpu zlib"
  268. gdb_release()
  269. {
  270. compressors=$1
  271. package=gdb
  272. tool=gdb
  273. gdb_tar_compress $package $tool "$GDB_SUPPORT_DIRS" "$compressors"
  274. }
  275. # Corresponding to the CVS "sim" module.
  276. SIM_SUPPORT_DIRS="bfd opcodes libiberty include intl gdb/version.in gdb/common/create-version.sh makefile.vms zlib"
  277. sim_release()
  278. {
  279. compressors=$1
  280. package=sim
  281. tool=sim
  282. tar_compress $package $tool "$SIM_SUPPORT_DIRS" "$compressors" gdb
  283. }
  284. usage()
  285. {
  286. echo "src-release.sh <options> <release>"
  287. echo "options:"
  288. echo " -b: Compress with bzip2"
  289. echo " -g: Compress with gzip"
  290. echo " -x: Compress with xz"
  291. exit 1
  292. }
  293. build_release()
  294. {
  295. release=$1
  296. compressors=$2
  297. case $release in
  298. binutils)
  299. binutils_release "$compressors";;
  300. gas)
  301. gas_release "$compressors";;
  302. gdb)
  303. gdb_release "$compressors";;
  304. sim)
  305. sim_release "$compressors";;
  306. *)
  307. echo "Unknown release name: $release" && usage;;
  308. esac
  309. }
  310. compressors=""
  311. while getopts ":gbx" opt; do
  312. case $opt in
  313. b)
  314. compressors="$compressors bz2";;
  315. g)
  316. compressors="$compressors gz";;
  317. x)
  318. compressors="$compressors xz";;
  319. \?)
  320. echo "Invalid option: -$OPTARG" && usage;;
  321. esac
  322. done
  323. shift $((OPTIND -1))
  324. release=$1
  325. build_release $release "$compressors"