1a1d25298Schristos#!/usr/bin/env bash 2*56bb7041Schristos# Copyright (C) 1990-2020 Free Software Foundation 3a1d25298Schristos# 4a1d25298Schristos# This file is free software; you can redistribute it and/or modify 5a1d25298Schristos# it under the terms of the GNU General Public License as published by 6a1d25298Schristos# the Free Software Foundation; either version 3 of the License, or 7a1d25298Schristos# (at your option) any later version. 8a1d25298Schristos# 9a1d25298Schristos# This program is distributed in the hope that it will be useful, 10a1d25298Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 11a1d25298Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a1d25298Schristos# GNU General Public License for more details. 13a1d25298Schristos# 14a1d25298Schristos# You should have received a copy of the GNU General Public License 15a1d25298Schristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 16a1d25298Schristos# 17a1d25298Schristos 18a1d25298Schristos# This script creates release packages for gdb, binutils, and other 19a1d25298Schristos# packages which live in src. It used to be implemented as the src-release 20a1d25298Schristos# Makefile and prior to that was part of the top level Makefile, but that 21a1d25298Schristos# turned out to be very messy and hard to maintain. 22a1d25298Schristos 23a1d25298Schristosset -e 24a1d25298Schristos 25a1d25298SchristosBZIPPROG=bzip2 26a1d25298SchristosGZIPPROG=gzip 273aed4a8bSchristosLZIPPROG=lzip 28a1d25298SchristosXZPROG=xz 29a1d25298SchristosMD5PROG=md5sum 30a1d25298SchristosMAKE=make 31a1d25298SchristosCC=gcc 32a1d25298SchristosCXX=g++ 33a1d25298Schristos 34a1d25298Schristos# Default to avoid splitting info files by setting the threshold high. 35a1d25298SchristosMAKEINFOFLAGS=--split-size=5000000 36a1d25298Schristos 37a1d25298Schristos# 38a1d25298Schristos# Support for building net releases 39a1d25298Schristos 403aed4a8bSchristos# Files in root used in any net release. 413aed4a8bSchristosDEVO_SUPPORT="ar-lib ChangeLog compile config config-ml.in config.guess \ 423aed4a8bSchristos config.rpath config.sub configure configure.ac COPYING COPYING.LIB \ 433aed4a8bSchristos COPYING3 COPYING3.LIB depcomp install-sh libtool.m4 ltgcc.m4 \ 443aed4a8bSchristos ltmain.sh ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 \ 453aed4a8bSchristos MAINTAINERS Makefile.def Makefile.in Makefile.tpl missing mkdep \ 463aed4a8bSchristos mkinstalldirs move-if-change README README-maintainer-mode \ 473aed4a8bSchristos src-release.sh symlink-tree test-driver ylwrap" 48a1d25298Schristos 49a1d25298Schristos# Files in devo/etc used in any net release. 50a1d25298SchristosETC_SUPPORT="Makefile.in configure configure.in standards.texi \ 51a1d25298Schristos make-stds.texi standards.info* configure.texi configure.info* \ 52a1d25298Schristos ChangeLog configbuild.* configdev.* fdl.texi texi2pod.pl gnu-oids.texi" 53a1d25298Schristos 54a1d25298Schristos# Get the version number of a given tool 55a1d25298Schristosgetver() 56a1d25298Schristos{ 57a1d25298Schristos tool=$1 58a1d25298Schristos if grep 'AC_INIT.*BFD_VERSION' $tool/configure.ac >/dev/null 2>&1; then 59a1d25298Schristos bfd/configure --version | sed -n -e '1s,.* ,,p' 60a1d25298Schristos elif test -f $tool/common/create-version.sh; then 61a1d25298Schristos $tool/common/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp 62d0317114Schristos cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//' 63a1d25298Schristos rm -f VER.tmp 64*56bb7041Schristos elif test $tool = "gdb"; then 65*56bb7041Schristos ./gdbsupport/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp 66*56bb7041Schristos cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//' 67*56bb7041Schristos rm -f VER.tmp 68a1d25298Schristos elif test -f $tool/version.in; then 69*56bb7041Schristos head -n 1 $tool/version.in 70a1d25298Schristos else 71a1d25298Schristos echo VERSION 72a1d25298Schristos fi 73a1d25298Schristos} 74a1d25298Schristos 75a1d25298Schristos# Setup build directory for building release tarball 76a1d25298Schristosdo_proto_toplev() 77a1d25298Schristos{ 78a1d25298Schristos package=$1 79a1d25298Schristos ver=$2 80a1d25298Schristos tool=$3 81a1d25298Schristos support_files=$4 823aed4a8bSchristos 833aed4a8bSchristos echo "==> Cleaning sources." 843aed4a8bSchristos find \( -name "*.orig" -o -name "*.rej" -o -name "*~" -o -name ".#*" -o -name "*~$bkpat" \) -exec rm {} \; 853aed4a8bSchristos 86a1d25298Schristos echo "==> Making $package-$ver/" 87a1d25298Schristos # Take out texinfo from a few places. 88a1d25298Schristos sed -e '/^all\.normal: /s/\all-texinfo //' \ 89a1d25298Schristos -e '/^ install-texinfo /d' \ 90a1d25298Schristos <Makefile.in >tmp 91a1d25298Schristos mv -f tmp Makefile.in 923aed4a8bSchristos # configure. --enable-gold is needed to ensure .c/.h from .y are 933aed4a8bSchristos # built in the gold dir. The disables speed the build a little. 943aed4a8bSchristos enables= 953aed4a8bSchristos disables= 96*56bb7041Schristos for dir in binutils gas gdb gold gprof ld libctf libdecnumber readline sim; do 973aed4a8bSchristos case " $tool $support_files " in 983aed4a8bSchristos *" $dir "*) enables="$enables --enable-$dir" ;; 993aed4a8bSchristos *) disables="$disables --disable-$dir" ;; 1003aed4a8bSchristos esac 1013aed4a8bSchristos done 1023aed4a8bSchristos echo "==> configure --target=i386-pc-linux-gnu $disables $enables" 1033aed4a8bSchristos ./configure --target=i386-pc-linux-gnu $disables $enables 104a1d25298Schristos $MAKE configure-host configure-target \ 105a1d25298Schristos ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \ 106a1d25298Schristos CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX" 107a1d25298Schristos # Make links, and run "make diststuff" or "make info" when needed. 108a1d25298Schristos rm -rf proto-toplev 109a1d25298Schristos mkdir proto-toplev 110a1d25298Schristos dirs="$DEVO_SUPPORT $support_files $tool" 111a1d25298Schristos for d in $dirs ; do 112a1d25298Schristos if [ -d $d ]; then 113a1d25298Schristos if [ ! -f $d/Makefile ] ; then 114a1d25298Schristos true 115a1d25298Schristos elif grep '^diststuff:' $d/Makefile >/dev/null ; then 116a1d25298Schristos (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" diststuff) \ 117a1d25298Schristos || exit 1 118a1d25298Schristos elif grep '^info:' $d/Makefile >/dev/null ; then 119a1d25298Schristos (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) \ 120a1d25298Schristos || exit 1 121a1d25298Schristos fi 122a1d25298Schristos if [ -d $d/proto-$d.dir ]; then 123a1d25298Schristos ln -s ../$d/proto-$d.dir proto-toplev/$d 124a1d25298Schristos else 125a1d25298Schristos ln -s ../$d proto-toplev/$d 126a1d25298Schristos fi 127a1d25298Schristos else 128a1d25298Schristos if (echo x$d | grep / >/dev/null); then 129a1d25298Schristos mkdir -p proto-toplev/`dirname $d` 130a1d25298Schristos x=`dirname $d` 131a1d25298Schristos ln -s ../`echo $x/ | sed -e 's,[^/]*/,../,g'`$d proto-toplev/$d 132a1d25298Schristos else 133a1d25298Schristos ln -s ../$d proto-toplev/$d 134a1d25298Schristos fi 135a1d25298Schristos fi 136a1d25298Schristos done 137a1d25298Schristos (cd etc; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) 138a1d25298Schristos $MAKE distclean 139a1d25298Schristos mkdir proto-toplev/etc 140a1d25298Schristos (cd proto-toplev/etc; 141a1d25298Schristos for i in $ETC_SUPPORT; do 142a1d25298Schristos ln -s ../../etc/$i . 143a1d25298Schristos done) 144a1d25298Schristos # 145a1d25298Schristos # Take out texinfo from configurable dirs 146a1d25298Schristos rm proto-toplev/configure.ac 147a1d25298Schristos sed -e '/^host_tools=/s/texinfo //' \ 148a1d25298Schristos <configure.ac >proto-toplev/configure.ac 149a1d25298Schristos # 150a1d25298Schristos mkdir proto-toplev/texinfo 151a1d25298Schristos ln -s ../../texinfo/texinfo.tex proto-toplev/texinfo/ 152a1d25298Schristos if test -r texinfo/util/tex3patch ; then 153a1d25298Schristos mkdir proto-toplev/texinfo/util && \ 154a1d25298Schristos ln -s ../../../texinfo/util/tex3patch proto-toplev/texinfo/util 155a1d25298Schristos else 156a1d25298Schristos true 157a1d25298Schristos fi 158a1d25298Schristos chmod -R og=u . || chmod og=u `find . -print` 159a1d25298Schristos # 160a1d25298Schristos # Create .gmo files from .po files. 161a1d25298Schristos for f in `find . -name '*.po' -type f -print`; do 162a1d25298Schristos msgfmt -o `echo $f | sed -e 's/\.po$/.gmo/'` $f 163a1d25298Schristos done 164a1d25298Schristos # 165a1d25298Schristos rm -f $package-$ver 166a1d25298Schristos ln -s proto-toplev $package-$ver 167a1d25298Schristos} 168a1d25298Schristos 169a1d25298SchristosCVS_NAMES='-name CVS -o -name .cvsignore' 170a1d25298Schristos 171a1d25298Schristos# Add an md5sum to the built tarball 172a1d25298Schristosdo_md5sum() 173a1d25298Schristos{ 174a1d25298Schristos echo "==> Adding md5 checksum to top-level directory" 175a1d25298Schristos (cd proto-toplev && find * -follow \( $CVS_NAMES \) -prune \ 176a1d25298Schristos -o -type f -print \ 177a1d25298Schristos | xargs $MD5PROG > ../md5.new) 178a1d25298Schristos rm -f proto-toplev/md5.sum 179a1d25298Schristos mv md5.new proto-toplev/md5.sum 180a1d25298Schristos} 181a1d25298Schristos 182a1d25298Schristos# Build the release tarball 183a1d25298Schristosdo_tar() 184a1d25298Schristos{ 185a1d25298Schristos package=$1 186a1d25298Schristos ver=$2 187a1d25298Schristos echo "==> Making $package-$ver.tar" 188a1d25298Schristos rm -f $package-$ver.tar 189a1d25298Schristos find $package-$ver -follow \( $CVS_NAMES \) -prune \ 190a1d25298Schristos -o -type f -print \ 191a1d25298Schristos | tar cTfh - $package-$ver.tar 192a1d25298Schristos} 193a1d25298Schristos 194a1d25298Schristos# Compress the output with bzip2 195a1d25298Schristosdo_bz2() 196a1d25298Schristos{ 197a1d25298Schristos package=$1 198a1d25298Schristos ver=$2 199a1d25298Schristos echo "==> Bzipping $package-$ver.tar.bz2" 200a1d25298Schristos rm -f $package-$ver.tar.bz2 201a1d25298Schristos $BZIPPROG -k -v -9 $package-$ver.tar 202a1d25298Schristos} 203a1d25298Schristos 204a1d25298Schristos# Compress the output with gzip 205a1d25298Schristosdo_gz() 206a1d25298Schristos{ 207a1d25298Schristos package=$1 208a1d25298Schristos ver=$2 209a1d25298Schristos echo "==> Gzipping $package-$ver.tar.gz" 210a1d25298Schristos rm -f $package-$ver.tar.gz 211a1d25298Schristos $GZIPPROG -k -v -9 $package-$ver.tar 212a1d25298Schristos} 213a1d25298Schristos 2143aed4a8bSchristos# Compress the output with lzip 2153aed4a8bSchristosdo_lz() 2163aed4a8bSchristos{ 2173aed4a8bSchristos package=$1 2183aed4a8bSchristos ver=$2 2193aed4a8bSchristos echo "==> Lzipping $package-$ver.tar.lz" 2203aed4a8bSchristos rm -f $package-$ver.tar.lz 2213aed4a8bSchristos $LZIPPROG -k -v -9 $package-$ver.tar 2223aed4a8bSchristos} 2233aed4a8bSchristos 224a1d25298Schristos# Compress the output with xz 225a1d25298Schristosdo_xz() 226a1d25298Schristos{ 227a1d25298Schristos package=$1 228a1d25298Schristos ver=$2 229a1d25298Schristos echo "==> Xzipping $package-$ver.tar.xz" 230a1d25298Schristos rm -f $package-$ver.tar.xz 231a1d25298Schristos $XZPROG -k -v -9 $package-$ver.tar 232a1d25298Schristos} 233a1d25298Schristos 234a1d25298Schristos# Compress the output with all selected compresion methods 235a1d25298Schristosdo_compress() 236a1d25298Schristos{ 237a1d25298Schristos package=$1 238a1d25298Schristos ver=$2 239a1d25298Schristos compressors=$3 240a1d25298Schristos for comp in $compressors; do 241a1d25298Schristos case $comp in 242a1d25298Schristos bz2) 243a1d25298Schristos do_bz2 $package $ver;; 244a1d25298Schristos gz) 245a1d25298Schristos do_gz $package $ver;; 2463aed4a8bSchristos lz) 2473aed4a8bSchristos do_lz $package $ver;; 248a1d25298Schristos xz) 249a1d25298Schristos do_xz $package $ver;; 250a1d25298Schristos *) 251a1d25298Schristos echo "Unknown compression method: $comp" && exit 1;; 252a1d25298Schristos esac 253a1d25298Schristos done 254a1d25298Schristos} 255a1d25298Schristos 256a1d25298Schristos# Add djunpack.bat the tarball 257a1d25298Schristosdo_djunpack() 258a1d25298Schristos{ 259a1d25298Schristos package=$1 260a1d25298Schristos ver=$2 261a1d25298Schristos echo "==> Adding updated djunpack.bat to top-level directory" 262a1d25298Schristos echo - 's /gdb-[0-9\.]*/$package-'"$ver"'/' 263a1d25298Schristos sed < djunpack.bat > djunpack.new \ 264a1d25298Schristos -e 's/gdb-[0-9][0-9\.]*/$package-'"$ver"'/' 265a1d25298Schristos rm -f proto-toplev/djunpack.bat 266a1d25298Schristos mv djunpack.new proto-toplev/djunpack.bat 267a1d25298Schristos} 268a1d25298Schristos 269a1d25298Schristos# Create a release package, tar it and compress it 270a1d25298Schristostar_compress() 271a1d25298Schristos{ 272a1d25298Schristos package=$1 273a1d25298Schristos tool=$2 274a1d25298Schristos support_files=$3 275a1d25298Schristos compressors=$4 276a1d25298Schristos verdir=${5:-$tool} 277a1d25298Schristos ver=$(getver $verdir) 278a1d25298Schristos do_proto_toplev $package $ver $tool "$support_files" 279a1d25298Schristos do_md5sum 280a1d25298Schristos do_tar $package $ver 281a1d25298Schristos do_compress $package $ver "$compressors" 282a1d25298Schristos} 283a1d25298Schristos 284a1d25298Schristos# Create a gdb release package, tar it and compress it 285a1d25298Schristosgdb_tar_compress() 286a1d25298Schristos{ 287a1d25298Schristos package=$1 288a1d25298Schristos tool=$2 289a1d25298Schristos support_files=$3 290a1d25298Schristos compressors=$4 291a1d25298Schristos ver=$(getver $tool) 292a1d25298Schristos do_proto_toplev $package $ver $tool "$support_files" 293a1d25298Schristos do_md5sum 294a1d25298Schristos do_djunpack $package $ver 295a1d25298Schristos do_tar $package $ver 296a1d25298Schristos do_compress $package $ver "$compressors" 297a1d25298Schristos} 298a1d25298Schristos 299a1d25298Schristos# The FSF "binutils" release includes gprof and ld. 300*56bb7041SchristosBINUTILS_SUPPORT_DIRS="bfd gas include libiberty libctf opcodes ld elfcpp gold gprof intl setup.com makefile.vms cpu zlib" 301a1d25298Schristosbinutils_release() 302a1d25298Schristos{ 303a1d25298Schristos compressors=$1 304a1d25298Schristos package=binutils 305a1d25298Schristos tool=binutils 306a1d25298Schristos tar_compress $package $tool "$BINUTILS_SUPPORT_DIRS" "$compressors" 307a1d25298Schristos} 308a1d25298Schristos 309a1d25298SchristosGAS_SUPPORT_DIRS="bfd include libiberty opcodes intl setup.com makefile.vms zlib" 310a1d25298Schristosgas_release() 311a1d25298Schristos{ 312a1d25298Schristos compressors=$1 313a1d25298Schristos package=gas 314a1d25298Schristos tool=gas 315a1d25298Schristos tar_compress $package $tool "$GAS_SUPPORT_DIRS" "$compressors" 316a1d25298Schristos} 317a1d25298Schristos 318*56bb7041SchristosGDB_SUPPORT_DIRS="bfd include libiberty libctf opcodes readline sim intl libdecnumber cpu zlib contrib gnulib gdbsupport gdbserver" 319a1d25298Schristosgdb_release() 320a1d25298Schristos{ 321a1d25298Schristos compressors=$1 322a1d25298Schristos package=gdb 323a1d25298Schristos tool=gdb 324a1d25298Schristos gdb_tar_compress $package $tool "$GDB_SUPPORT_DIRS" "$compressors" 325a1d25298Schristos} 326a1d25298Schristos 327a1d25298Schristos# Corresponding to the CVS "sim" module. 328a1d25298SchristosSIM_SUPPORT_DIRS="bfd opcodes libiberty include intl gdb/version.in gdb/common/create-version.sh makefile.vms zlib" 329a1d25298Schristossim_release() 330a1d25298Schristos{ 331a1d25298Schristos compressors=$1 332a1d25298Schristos package=sim 333a1d25298Schristos tool=sim 334a1d25298Schristos tar_compress $package $tool "$SIM_SUPPORT_DIRS" "$compressors" gdb 335a1d25298Schristos} 336a1d25298Schristos 337a1d25298Schristosusage() 338a1d25298Schristos{ 339a1d25298Schristos echo "src-release.sh <options> <release>" 340a1d25298Schristos echo "options:" 341a1d25298Schristos echo " -b: Compress with bzip2" 342a1d25298Schristos echo " -g: Compress with gzip" 3433aed4a8bSchristos echo " -l: Compress with lzip" 344a1d25298Schristos echo " -x: Compress with xz" 345a1d25298Schristos exit 1 346a1d25298Schristos} 347a1d25298Schristos 348a1d25298Schristosbuild_release() 349a1d25298Schristos{ 350a1d25298Schristos release=$1 351a1d25298Schristos compressors=$2 352a1d25298Schristos case $release in 353a1d25298Schristos binutils) 354a1d25298Schristos binutils_release "$compressors";; 355a1d25298Schristos gas) 356a1d25298Schristos gas_release "$compressors";; 357a1d25298Schristos gdb) 358a1d25298Schristos gdb_release "$compressors";; 359a1d25298Schristos sim) 360a1d25298Schristos sim_release "$compressors";; 361a1d25298Schristos *) 362a1d25298Schristos echo "Unknown release name: $release" && usage;; 363a1d25298Schristos esac 364a1d25298Schristos} 365a1d25298Schristos 366a1d25298Schristoscompressors="" 367a1d25298Schristos 3683aed4a8bSchristoswhile getopts ":bglx" opt; do 369a1d25298Schristos case $opt in 370a1d25298Schristos b) 371a1d25298Schristos compressors="$compressors bz2";; 372a1d25298Schristos g) 373a1d25298Schristos compressors="$compressors gz";; 3743aed4a8bSchristos l) 3753aed4a8bSchristos compressors="$compressors lz";; 376a1d25298Schristos x) 377a1d25298Schristos compressors="$compressors xz";; 378a1d25298Schristos \?) 379a1d25298Schristos echo "Invalid option: -$OPTARG" && usage;; 380a1d25298Schristos esac 381a1d25298Schristosdone 382a1d25298Schristosshift $((OPTIND -1)) 383a1d25298Schristosrelease=$1 384a1d25298Schristos 385a1d25298Schristosbuild_release $release "$compressors" 386