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