xref: /netbsd-src/external/gpl3/gdb/dist/src-release.sh (revision 0abee31d555bf0ef1d0bc65ae85e77a1c3d690b8)
1212397c6Schristos#!/usr/bin/env bash
28dffb485Schristos#   Copyright (C) 1990-2020 Free Software Foundation
3212397c6Schristos#
4212397c6Schristos# This file is free software; you can redistribute it and/or modify
5212397c6Schristos# it under the terms of the GNU General Public License as published by
6212397c6Schristos# the Free Software Foundation; either version 3 of the License, or
7212397c6Schristos# (at your option) any later version.
8212397c6Schristos#
9212397c6Schristos# This program is distributed in the hope that it will be useful,
10212397c6Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
11212397c6Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12212397c6Schristos# GNU General Public License for more details.
13212397c6Schristos#
14212397c6Schristos# You should have received a copy of the GNU General Public License
15212397c6Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16212397c6Schristos#
17212397c6Schristos
18212397c6Schristos# This script creates release packages for gdb, binutils, and other
19212397c6Schristos# packages which live in src.  It used to be implemented as the src-release
20212397c6Schristos# Makefile and prior to that was part of the top level Makefile, but that
21212397c6Schristos# turned out to be very messy and hard to maintain.
22212397c6Schristos
23212397c6Schristosset -e
24212397c6Schristos
25212397c6SchristosBZIPPROG=bzip2
26212397c6SchristosGZIPPROG=gzip
274559860eSchristosLZIPPROG=lzip
28212397c6SchristosXZPROG=xz
294b169a6bSchristosSHA256PROG=sha256sum
30212397c6SchristosMAKE=make
31212397c6SchristosCC=gcc
32212397c6SchristosCXX=g++
334b169a6bSchristosrelease_date=
34212397c6Schristos
35212397c6Schristos# Default to avoid splitting info files by setting the threshold high.
36212397c6SchristosMAKEINFOFLAGS=--split-size=5000000
37212397c6Schristos
38212397c6Schristos#
39212397c6Schristos# Support for building net releases
40212397c6Schristos
414559860eSchristos# Files in root used in any net release.
424559860eSchristosDEVO_SUPPORT="ar-lib ChangeLog compile config config-ml.in config.guess \
434559860eSchristos	config.rpath config.sub configure configure.ac COPYING COPYING.LIB \
444559860eSchristos	COPYING3 COPYING3.LIB depcomp install-sh libtool.m4 ltgcc.m4 \
454559860eSchristos	ltmain.sh ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 \
464559860eSchristos	MAINTAINERS Makefile.def Makefile.in Makefile.tpl missing mkdep \
474559860eSchristos	mkinstalldirs move-if-change README README-maintainer-mode \
48*0abee31dSchristos	SECURITY.txt src-release.sh symlink-tree test-driver ylwrap \
49*0abee31dSchristos        multilib.am"
50212397c6Schristos
51212397c6Schristos# Files in devo/etc used in any net release.
52*0abee31dSchristosETC_SUPPORT="ChangeLog Makefile.am Makefile.in aclocal.m4 add-log.el \
53*0abee31dSchristos	add-log.vi configbuild.* configdev.* configure configure.ac \
54*0abee31dSchristos	configure.in configure.info* configure.texi fdl.texi gnu-oids.texi \
55*0abee31dSchristos	make-stds.texi standards.info* standards.texi texi2pod.pl \
56*0abee31dSchristos	update-copyright.py"
57212397c6Schristos
58212397c6Schristos# Get the version number of a given tool
59212397c6Schristosgetver()
60212397c6Schristos{
61212397c6Schristos    tool=$1
62212397c6Schristos    if grep 'AC_INIT.*BFD_VERSION' $tool/configure.ac >/dev/null 2>&1; then
63212397c6Schristos	bfd/configure --version | sed -n -e '1s,.* ,,p'
64212397c6Schristos    elif test -f $tool/common/create-version.sh; then
65212397c6Schristos	$tool/common/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
66ba340e45Schristos	cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
67212397c6Schristos        rm -f VER.tmp
688dffb485Schristos    elif test $tool = "gdb"; then
698dffb485Schristos	./gdbsupport/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
708dffb485Schristos	cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
718dffb485Schristos        rm -f VER.tmp
72212397c6Schristos    elif test -f $tool/version.in; then
738dffb485Schristos	head -n 1 $tool/version.in
74212397c6Schristos    else
75212397c6Schristos	echo VERSION
76212397c6Schristos    fi
77212397c6Schristos}
78212397c6Schristos
79212397c6Schristos# Setup build directory for building release tarball
80212397c6Schristosdo_proto_toplev()
81212397c6Schristos{
82212397c6Schristos    package=$1
83212397c6Schristos    ver=$2
84212397c6Schristos    tool=$3
85212397c6Schristos    support_files=$4
864559860eSchristos
874559860eSchristos    echo "==> Cleaning sources."
884559860eSchristos    find \( -name "*.orig" -o  -name "*.rej" -o -name "*~" -o -name ".#*" -o -name "*~$bkpat" \) -exec rm {} \;
894559860eSchristos
90212397c6Schristos    echo "==> Making $package-$ver/"
91212397c6Schristos    # Take out texinfo from a few places.
92212397c6Schristos    sed -e '/^all\.normal: /s/\all-texinfo //' \
93212397c6Schristos	-e '/^	install-texinfo /d' \
94212397c6Schristos	<Makefile.in >tmp
95212397c6Schristos    mv -f tmp Makefile.in
964559860eSchristos    # configure.  --enable-gold is needed to ensure .c/.h from .y are
974559860eSchristos    # built in the gold dir.  The disables speed the build a little.
984559860eSchristos    enables=
994559860eSchristos    disables=
1004b169a6bSchristos    for dir in binutils gas gdb gold gprof gprofng libsframe ld libctf libdecnumber readline sim; do
1014559860eSchristos	case " $tool $support_files " in
1024559860eSchristos	    *" $dir "*) enables="$enables --enable-$dir" ;;
1034559860eSchristos	    *) disables="$disables --disable-$dir" ;;
1044559860eSchristos	esac
1054559860eSchristos    done
1064559860eSchristos    echo "==> configure --target=i386-pc-linux-gnu $disables $enables"
1074559860eSchristos    ./configure --target=i386-pc-linux-gnu $disables $enables
108212397c6Schristos    $MAKE configure-host configure-target \
109212397c6Schristos	ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
110212397c6Schristos	CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
111212397c6Schristos    # Make links, and run "make diststuff" or "make info" when needed.
112212397c6Schristos    rm -rf proto-toplev
113212397c6Schristos    mkdir proto-toplev
114212397c6Schristos    dirs="$DEVO_SUPPORT $support_files $tool"
115212397c6Schristos    for d in $dirs ; do
116212397c6Schristos	if [ -d $d ]; then
117212397c6Schristos	    if [ ! -f $d/Makefile ] ; then
118212397c6Schristos		true
119212397c6Schristos	    elif grep '^diststuff:' $d/Makefile >/dev/null ; then
120212397c6Schristos		(cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" diststuff) \
121212397c6Schristos		    || exit 1
122212397c6Schristos	    elif grep '^info:' $d/Makefile >/dev/null ; then
123212397c6Schristos		(cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) \
124212397c6Schristos		    || exit 1
125212397c6Schristos	    fi
126212397c6Schristos	    if [ -d $d/proto-$d.dir ]; then
127212397c6Schristos		ln -s ../$d/proto-$d.dir proto-toplev/$d
128212397c6Schristos	    else
129212397c6Schristos		ln -s ../$d proto-toplev/$d
130212397c6Schristos	    fi
131212397c6Schristos	else
132212397c6Schristos	    if (echo x$d | grep / >/dev/null); then
133212397c6Schristos		mkdir -p proto-toplev/`dirname $d`
134212397c6Schristos		x=`dirname $d`
135212397c6Schristos		ln -s ../`echo $x/ | sed -e 's,[^/]*/,../,g'`$d proto-toplev/$d
136212397c6Schristos	    else
137212397c6Schristos		ln -s ../$d proto-toplev/$d
138212397c6Schristos	    fi
139212397c6Schristos	fi
140212397c6Schristos    done
141212397c6Schristos    (cd etc; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info)
142212397c6Schristos    $MAKE distclean
143212397c6Schristos    mkdir proto-toplev/etc
144212397c6Schristos    (cd proto-toplev/etc;
145212397c6Schristos	for i in $ETC_SUPPORT; do
146212397c6Schristos	    ln -s ../../etc/$i .
147212397c6Schristos	done)
148212397c6Schristos    #
149212397c6Schristos    # Take out texinfo from configurable dirs
150212397c6Schristos    rm proto-toplev/configure.ac
151212397c6Schristos    sed -e '/^host_tools=/s/texinfo //' \
152212397c6Schristos	<configure.ac >proto-toplev/configure.ac
153212397c6Schristos    #
154212397c6Schristos    mkdir proto-toplev/texinfo
155212397c6Schristos    ln -s ../../texinfo/texinfo.tex proto-toplev/texinfo/
156212397c6Schristos    if test -r texinfo/util/tex3patch ; then
157212397c6Schristos	mkdir proto-toplev/texinfo/util && \
158212397c6Schristos	    ln -s ../../../texinfo/util/tex3patch proto-toplev/texinfo/util
159212397c6Schristos    fi
160212397c6Schristos    chmod -R og=u . || chmod og=u `find . -print`
161212397c6Schristos    #
162212397c6Schristos    # Create .gmo files from .po files.
163212397c6Schristos    for f in `find . -name '*.po' -type f -print`; do
164212397c6Schristos	msgfmt -o `echo $f | sed -e 's/\.po$/.gmo/'` $f
165212397c6Schristos    done
166212397c6Schristos    #
167212397c6Schristos    rm -f $package-$ver
168212397c6Schristos    ln -s proto-toplev $package-$ver
169212397c6Schristos}
170212397c6Schristos
171212397c6SchristosCVS_NAMES='-name CVS -o -name .cvsignore'
172212397c6Schristos
1734b169a6bSchristos# Add a sha256sum to the built tarball
1744b169a6bSchristosdo_sha256sum()
175212397c6Schristos{
1764b169a6bSchristos    echo "==> Adding sha256 checksum to top-level directory"
177212397c6Schristos    (cd proto-toplev && find * -follow \( $CVS_NAMES \) -prune \
178212397c6Schristos	-o -type f -print \
1794b169a6bSchristos	| xargs $SHA256PROG > ../sha256.new)
1804b169a6bSchristos    rm -f proto-toplev/sha256.sum
1814b169a6bSchristos    mv sha256.new proto-toplev/sha256.sum
182212397c6Schristos}
183212397c6Schristos
184212397c6Schristos# Build the release tarball
185212397c6Schristosdo_tar()
186212397c6Schristos{
187212397c6Schristos    package=$1
188212397c6Schristos    ver=$2
189212397c6Schristos    echo "==> Making $package-$ver.tar"
190212397c6Schristos    rm -f $package-$ver.tar
1914b169a6bSchristos    if test x$release_date == "x" ; then
1924b169a6bSchristos       find $package-$ver -follow \( $CVS_NAMES \) -prune -o -type f -print \
193212397c6Schristos	   | tar cTfh - $package-$ver.tar
1944b169a6bSchristos    else
1954b169a6bSchristos	# Attempt to create a consistent, reproducible tarball using the
1964b169a6bSchristos	# specified date.
1974b169a6bSchristos	find $package-$ver -follow \( $CVS_NAMES \) -prune -o -type f -print \
1984b169a6bSchristos	    | LC_ALL=C sort \
1994b169a6bSchristos	    | tar cTfh - $package-$ver.tar \
2004b169a6bSchristos		  --mtime=$release_date --group=0 --owner=0
2014b169a6bSchristos    fi
202212397c6Schristos}
203212397c6Schristos
204212397c6Schristos# Compress the output with bzip2
205212397c6Schristosdo_bz2()
206212397c6Schristos{
207212397c6Schristos    package=$1
208212397c6Schristos    ver=$2
209212397c6Schristos    echo "==> Bzipping $package-$ver.tar.bz2"
210212397c6Schristos    rm -f $package-$ver.tar.bz2
211212397c6Schristos    $BZIPPROG -k -v -9 $package-$ver.tar
212212397c6Schristos}
213212397c6Schristos
214212397c6Schristos# Compress the output with gzip
215212397c6Schristosdo_gz()
216212397c6Schristos{
217212397c6Schristos    package=$1
218212397c6Schristos    ver=$2
219212397c6Schristos    echo "==> Gzipping $package-$ver.tar.gz"
220212397c6Schristos    rm -f $package-$ver.tar.gz
221212397c6Schristos    $GZIPPROG -k -v -9 $package-$ver.tar
222212397c6Schristos}
223212397c6Schristos
2244559860eSchristos# Compress the output with lzip
2254559860eSchristosdo_lz()
2264559860eSchristos{
2274559860eSchristos    package=$1
2284559860eSchristos    ver=$2
2294559860eSchristos    echo "==> Lzipping $package-$ver.tar.lz"
2304559860eSchristos    rm -f $package-$ver.tar.lz
2314559860eSchristos    $LZIPPROG -k -v -9 $package-$ver.tar
2324559860eSchristos}
2334559860eSchristos
234212397c6Schristos# Compress the output with xz
235212397c6Schristosdo_xz()
236212397c6Schristos{
237212397c6Schristos    package=$1
238212397c6Schristos    ver=$2
239212397c6Schristos    echo "==> Xzipping $package-$ver.tar.xz"
240212397c6Schristos    rm -f $package-$ver.tar.xz
241212397c6Schristos    $XZPROG -k -v -9 $package-$ver.tar
242212397c6Schristos}
243212397c6Schristos
244212397c6Schristos# Compress the output with all selected compresion methods
245212397c6Schristosdo_compress()
246212397c6Schristos{
247212397c6Schristos    package=$1
248212397c6Schristos    ver=$2
249212397c6Schristos    compressors=$3
250212397c6Schristos    for comp in $compressors; do
251212397c6Schristos	case $comp in
252212397c6Schristos	    bz2)
253212397c6Schristos		do_bz2 $package $ver;;
254212397c6Schristos	    gz)
255212397c6Schristos		do_gz $package $ver;;
2564559860eSchristos	    lz)
2574559860eSchristos		do_lz $package $ver;;
258212397c6Schristos	    xz)
259212397c6Schristos		do_xz $package $ver;;
260212397c6Schristos	    *)
261212397c6Schristos		echo "Unknown compression method: $comp" && exit 1;;
262212397c6Schristos	esac
263212397c6Schristos    done
264212397c6Schristos}
265212397c6Schristos
266212397c6Schristos# Add djunpack.bat the tarball
267212397c6Schristosdo_djunpack()
268212397c6Schristos{
269212397c6Schristos    package=$1
270212397c6Schristos    ver=$2
271212397c6Schristos    echo "==> Adding updated djunpack.bat to top-level directory"
272212397c6Schristos    echo - 's /gdb-[0-9\.]*/$package-'"$ver"'/'
273212397c6Schristos    sed < djunpack.bat > djunpack.new \
274212397c6Schristos	-e 's/gdb-[0-9][0-9\.]*/$package-'"$ver"'/'
275212397c6Schristos    rm -f proto-toplev/djunpack.bat
276212397c6Schristos    mv djunpack.new proto-toplev/djunpack.bat
277212397c6Schristos}
278212397c6Schristos
279212397c6Schristos# Create a release package, tar it and compress it
280212397c6Schristostar_compress()
281212397c6Schristos{
282212397c6Schristos    package=$1
283212397c6Schristos    tool=$2
284212397c6Schristos    support_files=$3
285212397c6Schristos    compressors=$4
286212397c6Schristos    verdir=${5:-$tool}
287212397c6Schristos    ver=$(getver $verdir)
288212397c6Schristos    do_proto_toplev $package $ver $tool "$support_files"
2894b169a6bSchristos    do_sha256sum
290212397c6Schristos    do_tar $package $ver
291212397c6Schristos    do_compress $package $ver "$compressors"
292212397c6Schristos}
293212397c6Schristos
294212397c6Schristos# Create a gdb release package, tar it and compress it
295212397c6Schristosgdb_tar_compress()
296212397c6Schristos{
297212397c6Schristos    package=$1
298212397c6Schristos    tool=$2
299212397c6Schristos    support_files=$3
300212397c6Schristos    compressors=$4
301212397c6Schristos    ver=$(getver $tool)
302212397c6Schristos    do_proto_toplev $package $ver $tool "$support_files"
3034b169a6bSchristos    do_sha256sum
304212397c6Schristos    do_djunpack $package $ver
305212397c6Schristos    do_tar $package $ver
306212397c6Schristos    do_compress $package $ver "$compressors"
307212397c6Schristos}
308212397c6Schristos
309212397c6Schristos# The FSF "binutils" release includes gprof and ld.
310*0abee31dSchristosBINUTILS_SUPPORT_DIRS="libsframe bfd gas include libiberty libctf opcodes ld elfcpp gold gprof gprofng setup.com makefile.vms cpu zlib"
311212397c6Schristosbinutils_release()
312212397c6Schristos{
313212397c6Schristos    compressors=$1
314212397c6Schristos    package=binutils
315212397c6Schristos    tool=binutils
316212397c6Schristos    tar_compress $package $tool "$BINUTILS_SUPPORT_DIRS" "$compressors"
317212397c6Schristos}
318212397c6Schristos
319*0abee31dSchristosGAS_SUPPORT_DIRS="bfd include libiberty opcodes setup.com makefile.vms zlib"
320212397c6Schristosgas_release()
321212397c6Schristos{
322212397c6Schristos    compressors=$1
323212397c6Schristos    package=gas
324212397c6Schristos    tool=gas
325212397c6Schristos    tar_compress $package $tool "$GAS_SUPPORT_DIRS" "$compressors"
326212397c6Schristos}
327212397c6Schristos
328*0abee31dSchristosGDB_SUPPORT_DIRS="libsframe bfd include libiberty libctf opcodes readline sim libdecnumber cpu zlib contrib gnulib gdbsupport gdbserver libbacktrace"
329212397c6Schristosgdb_release()
330212397c6Schristos{
331212397c6Schristos    compressors=$1
332212397c6Schristos    package=gdb
333212397c6Schristos    tool=gdb
334212397c6Schristos    gdb_tar_compress $package $tool "$GDB_SUPPORT_DIRS" "$compressors"
335212397c6Schristos}
336212397c6Schristos
337212397c6Schristos# Corresponding to the CVS "sim" module.
338*0abee31dSchristosSIM_SUPPORT_DIRS="libsframe bfd opcodes libiberty libctf/swap.h include gdb/version.in gdb/common/create-version.sh makefile.vms zlib gnulib"
339212397c6Schristossim_release()
340212397c6Schristos{
341212397c6Schristos    compressors=$1
342212397c6Schristos    package=sim
343212397c6Schristos    tool=sim
344212397c6Schristos    tar_compress $package $tool "$SIM_SUPPORT_DIRS" "$compressors" gdb
345212397c6Schristos}
346212397c6Schristos
347212397c6Schristosusage()
348212397c6Schristos{
349212397c6Schristos    echo "src-release.sh <options> <release>"
350212397c6Schristos    echo "options:"
351212397c6Schristos    echo "  -b: Compress with bzip2"
352212397c6Schristos    echo "  -g: Compress with gzip"
3534559860eSchristos    echo "  -l: Compress with lzip"
354212397c6Schristos    echo "  -x: Compress with xz"
3554b169a6bSchristos    echo "  -r <date>: Create a reproducible tarball using <date> as the mtime"
356212397c6Schristos    exit 1
357212397c6Schristos}
358212397c6Schristos
359212397c6Schristosbuild_release()
360212397c6Schristos{
361212397c6Schristos    release=$1
362212397c6Schristos    compressors=$2
363212397c6Schristos    case $release in
364212397c6Schristos	binutils)
365212397c6Schristos	    binutils_release "$compressors";;
366212397c6Schristos	gas)
367212397c6Schristos	    gas_release "$compressors";;
368212397c6Schristos	gdb)
369212397c6Schristos	    gdb_release "$compressors";;
370212397c6Schristos	sim)
371212397c6Schristos	    sim_release "$compressors";;
372212397c6Schristos	*)
373212397c6Schristos	    echo "Unknown release name: $release" && usage;;
374212397c6Schristos    esac
375212397c6Schristos}
376212397c6Schristos
377212397c6Schristoscompressors=""
378212397c6Schristos
3794b169a6bSchristoswhile getopts ":bglr:x" opt; do
380212397c6Schristos    case $opt in
381212397c6Schristos	b)
382212397c6Schristos	    compressors="$compressors bz2";;
383212397c6Schristos	g)
384212397c6Schristos	    compressors="$compressors gz";;
3854559860eSchristos	l)
3864559860eSchristos	    compressors="$compressors lz";;
3874b169a6bSchristos	r)
3884b169a6bSchristos	    release_date=$OPTARG;;
389212397c6Schristos	x)
390212397c6Schristos	    compressors="$compressors xz";;
391212397c6Schristos	\?)
392212397c6Schristos	    echo "Invalid option: -$OPTARG" && usage;;
393212397c6Schristos  esac
394212397c6Schristosdone
395212397c6Schristosshift $((OPTIND -1))
396212397c6Schristosrelease=$1
397212397c6Schristos
398212397c6Schristosbuild_release $release "$compressors"
399