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