src-release.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #!/usr/bin/env bash
  2. # Copyright (C) 1990-2020 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. LZIPPROG=lzip
  25. XZPROG=xz
  26. SHA256PROG=sha256sum
  27. MAKE=make
  28. CC=gcc
  29. CXX=g++
  30. # Default to avoid splitting info files by setting the threshold high.
  31. MAKEINFOFLAGS=--split-size=5000000
  32. #
  33. # Support for building net releases
  34. # Files in root used in any net release.
  35. DEVO_SUPPORT="ar-lib ChangeLog compile config config-ml.in config.guess \
  36. config.rpath config.sub configure configure.ac COPYING COPYING.LIB \
  37. COPYING3 COPYING3.LIB depcomp install-sh libtool.m4 ltgcc.m4 \
  38. ltmain.sh ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 \
  39. MAINTAINERS Makefile.def Makefile.in Makefile.tpl missing mkdep \
  40. mkinstalldirs move-if-change README README-maintainer-mode \
  41. src-release.sh symlink-tree test-driver ylwrap"
  42. # Files in devo/etc used in any net release.
  43. ETC_SUPPORT="Makefile.in configure configure.in standards.texi \
  44. make-stds.texi standards.info* configure.texi configure.info* \
  45. ChangeLog configbuild.* configdev.* fdl.texi texi2pod.pl gnu-oids.texi"
  46. # Get the version number of a given tool
  47. getver()
  48. {
  49. tool=$1
  50. if grep 'AC_INIT.*BFD_VERSION' $tool/configure.ac >/dev/null 2>&1; then
  51. bfd/configure --version | sed -n -e '1s,.* ,,p'
  52. elif test -f $tool/common/create-version.sh; then
  53. $tool/common/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
  54. cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
  55. rm -f VER.tmp
  56. elif test $tool = "gdb"; then
  57. ./gdbsupport/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
  58. cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
  59. rm -f VER.tmp
  60. elif test -f $tool/version.in; then
  61. head -n 1 $tool/version.in
  62. else
  63. echo VERSION
  64. fi
  65. }
  66. # Setup build directory for building release tarball
  67. do_proto_toplev()
  68. {
  69. package=$1
  70. ver=$2
  71. tool=$3
  72. support_files=$4
  73. echo "==> Cleaning sources."
  74. find \( -name "*.orig" -o -name "*.rej" -o -name "*~" -o -name ".#*" -o -name "*~$bkpat" \) -exec rm {} \;
  75. echo "==> Making $package-$ver/"
  76. # Take out texinfo from a few places.
  77. sed -e '/^all\.normal: /s/\all-texinfo //' \
  78. -e '/^ install-texinfo /d' \
  79. <Makefile.in >tmp
  80. mv -f tmp Makefile.in
  81. # configure. --enable-gold is needed to ensure .c/.h from .y are
  82. # built in the gold dir. The disables speed the build a little.
  83. enables=
  84. disables=
  85. for dir in binutils gas gdb gold gprof gprofng ld libctf libdecnumber readline sim; do
  86. case " $tool $support_files " in
  87. *" $dir "*) enables="$enables --enable-$dir" ;;
  88. *) disables="$disables --disable-$dir" ;;
  89. esac
  90. done
  91. echo "==> configure --target=i386-pc-linux-gnu $disables $enables"
  92. ./configure --target=i386-pc-linux-gnu $disables $enables
  93. $MAKE configure-host configure-target \
  94. ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
  95. CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
  96. # Make links, and run "make diststuff" or "make info" when needed.
  97. rm -rf proto-toplev
  98. mkdir proto-toplev
  99. dirs="$DEVO_SUPPORT $support_files $tool"
  100. for d in $dirs ; do
  101. if [ -d $d ]; then
  102. if [ ! -f $d/Makefile ] ; then
  103. true
  104. elif grep '^diststuff:' $d/Makefile >/dev/null ; then
  105. (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" diststuff) \
  106. || exit 1
  107. elif grep '^info:' $d/Makefile >/dev/null ; then
  108. (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) \
  109. || exit 1
  110. fi
  111. if [ -d $d/proto-$d.dir ]; then
  112. ln -s ../$d/proto-$d.dir proto-toplev/$d
  113. else
  114. ln -s ../$d proto-toplev/$d
  115. fi
  116. else
  117. if (echo x$d | grep / >/dev/null); then
  118. mkdir -p proto-toplev/`dirname $d`
  119. x=`dirname $d`
  120. ln -s ../`echo $x/ | sed -e 's,[^/]*/,../,g'`$d proto-toplev/$d
  121. else
  122. ln -s ../$d proto-toplev/$d
  123. fi
  124. fi
  125. done
  126. (cd etc; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info)
  127. $MAKE distclean
  128. mkdir proto-toplev/etc
  129. (cd proto-toplev/etc;
  130. for i in $ETC_SUPPORT; do
  131. ln -s ../../etc/$i .
  132. done)
  133. #
  134. # Take out texinfo from configurable dirs
  135. rm proto-toplev/configure.ac
  136. sed -e '/^host_tools=/s/texinfo //' \
  137. <configure.ac >proto-toplev/configure.ac
  138. #
  139. mkdir proto-toplev/texinfo
  140. ln -s ../../texinfo/texinfo.tex proto-toplev/texinfo/
  141. if test -r texinfo/util/tex3patch ; then
  142. mkdir proto-toplev/texinfo/util && \
  143. ln -s ../../../texinfo/util/tex3patch proto-toplev/texinfo/util
  144. fi
  145. chmod -R og=u . || chmod og=u `find . -print`
  146. #
  147. # Create .gmo files from .po files.
  148. for f in `find . -name '*.po' -type f -print`; do
  149. msgfmt -o `echo $f | sed -e 's/\.po$/.gmo/'` $f
  150. done
  151. #
  152. rm -f $package-$ver
  153. ln -s proto-toplev $package-$ver
  154. }
  155. CVS_NAMES='-name CVS -o -name .cvsignore'
  156. # Add a sha256sum to the built tarball
  157. do_sha256sum()
  158. {
  159. echo "==> Adding sha256 checksum to top-level directory"
  160. (cd proto-toplev && find * -follow \( $CVS_NAMES \) -prune \
  161. -o -type f -print \
  162. | xargs $SHA256PROG > ../sha256.new)
  163. rm -f proto-toplev/sha256.sum
  164. mv sha256.new proto-toplev/sha256.sum
  165. }
  166. # Build the release tarball
  167. do_tar()
  168. {
  169. package=$1
  170. ver=$2
  171. echo "==> Making $package-$ver.tar"
  172. rm -f $package-$ver.tar
  173. find $package-$ver -follow \( $CVS_NAMES \) -prune \
  174. -o -type f -print \
  175. | tar cTfh - $package-$ver.tar
  176. }
  177. # Compress the output with bzip2
  178. do_bz2()
  179. {
  180. package=$1
  181. ver=$2
  182. echo "==> Bzipping $package-$ver.tar.bz2"
  183. rm -f $package-$ver.tar.bz2
  184. $BZIPPROG -k -v -9 $package-$ver.tar
  185. }
  186. # Compress the output with gzip
  187. do_gz()
  188. {
  189. package=$1
  190. ver=$2
  191. echo "==> Gzipping $package-$ver.tar.gz"
  192. rm -f $package-$ver.tar.gz
  193. $GZIPPROG -k -v -9 $package-$ver.tar
  194. }
  195. # Compress the output with lzip
  196. do_lz()
  197. {
  198. package=$1
  199. ver=$2
  200. echo "==> Lzipping $package-$ver.tar.lz"
  201. rm -f $package-$ver.tar.lz
  202. $LZIPPROG -k -v -9 $package-$ver.tar
  203. }
  204. # Compress the output with xz
  205. do_xz()
  206. {
  207. package=$1
  208. ver=$2
  209. echo "==> Xzipping $package-$ver.tar.xz"
  210. rm -f $package-$ver.tar.xz
  211. $XZPROG -k -v -9 $package-$ver.tar
  212. }
  213. # Compress the output with all selected compresion methods
  214. do_compress()
  215. {
  216. package=$1
  217. ver=$2
  218. compressors=$3
  219. for comp in $compressors; do
  220. case $comp in
  221. bz2)
  222. do_bz2 $package $ver;;
  223. gz)
  224. do_gz $package $ver;;
  225. lz)
  226. do_lz $package $ver;;
  227. xz)
  228. do_xz $package $ver;;
  229. *)
  230. echo "Unknown compression method: $comp" && exit 1;;
  231. esac
  232. done
  233. }
  234. # Add djunpack.bat the tarball
  235. do_djunpack()
  236. {
  237. package=$1
  238. ver=$2
  239. echo "==> Adding updated djunpack.bat to top-level directory"
  240. echo - 's /gdb-[0-9\.]*/$package-'"$ver"'/'
  241. sed < djunpack.bat > djunpack.new \
  242. -e 's/gdb-[0-9][0-9\.]*/$package-'"$ver"'/'
  243. rm -f proto-toplev/djunpack.bat
  244. mv djunpack.new proto-toplev/djunpack.bat
  245. }
  246. # Create a release package, tar it and compress it
  247. tar_compress()
  248. {
  249. package=$1
  250. tool=$2
  251. support_files=$3
  252. compressors=$4
  253. verdir=${5:-$tool}
  254. ver=$(getver $verdir)
  255. do_proto_toplev $package $ver $tool "$support_files"
  256. do_sha256sum
  257. do_tar $package $ver
  258. do_compress $package $ver "$compressors"
  259. }
  260. # Create a gdb release package, tar it and compress it
  261. gdb_tar_compress()
  262. {
  263. package=$1
  264. tool=$2
  265. support_files=$3
  266. compressors=$4
  267. ver=$(getver $tool)
  268. do_proto_toplev $package $ver $tool "$support_files"
  269. do_sha256sum
  270. do_djunpack $package $ver
  271. do_tar $package $ver
  272. do_compress $package $ver "$compressors"
  273. }
  274. # The FSF "binutils" release includes gprof and ld.
  275. BINUTILS_SUPPORT_DIRS="bfd gas include libiberty libctf opcodes ld elfcpp gold gprof gprofng intl setup.com makefile.vms cpu zlib"
  276. binutils_release()
  277. {
  278. compressors=$1
  279. package=binutils
  280. tool=binutils
  281. tar_compress $package $tool "$BINUTILS_SUPPORT_DIRS" "$compressors"
  282. }
  283. GAS_SUPPORT_DIRS="bfd include libiberty opcodes intl setup.com makefile.vms zlib"
  284. gas_release()
  285. {
  286. compressors=$1
  287. package=gas
  288. tool=gas
  289. tar_compress $package $tool "$GAS_SUPPORT_DIRS" "$compressors"
  290. }
  291. GDB_SUPPORT_DIRS="bfd include libiberty libctf opcodes readline sim intl libdecnumber cpu zlib contrib gnulib gdbsupport gdbserver libbacktrace"
  292. gdb_release()
  293. {
  294. compressors=$1
  295. package=gdb
  296. tool=gdb
  297. gdb_tar_compress $package $tool "$GDB_SUPPORT_DIRS" "$compressors"
  298. }
  299. # Corresponding to the CVS "sim" module.
  300. SIM_SUPPORT_DIRS="bfd opcodes libiberty include intl gdb/version.in gdb/common/create-version.sh makefile.vms zlib"
  301. sim_release()
  302. {
  303. compressors=$1
  304. package=sim
  305. tool=sim
  306. tar_compress $package $tool "$SIM_SUPPORT_DIRS" "$compressors" gdb
  307. }
  308. usage()
  309. {
  310. echo "src-release.sh <options> <release>"
  311. echo "options:"
  312. echo " -b: Compress with bzip2"
  313. echo " -g: Compress with gzip"
  314. echo " -l: Compress with lzip"
  315. echo " -x: Compress with xz"
  316. exit 1
  317. }
  318. build_release()
  319. {
  320. release=$1
  321. compressors=$2
  322. case $release in
  323. binutils)
  324. binutils_release "$compressors";;
  325. gas)
  326. gas_release "$compressors";;
  327. gdb)
  328. gdb_release "$compressors";;
  329. sim)
  330. sim_release "$compressors";;
  331. *)
  332. echo "Unknown release name: $release" && usage;;
  333. esac
  334. }
  335. compressors=""
  336. while getopts ":bglx" opt; do
  337. case $opt in
  338. b)
  339. compressors="$compressors bz2";;
  340. g)
  341. compressors="$compressors gz";;
  342. l)
  343. compressors="$compressors lz";;
  344. x)
  345. compressors="$compressors xz";;
  346. \?)
  347. echo "Invalid option: -$OPTARG" && usage;;
  348. esac
  349. done
  350. shift $((OPTIND -1))
  351. release=$1
  352. build_release $release "$compressors"