Automatic date update in version.in
[binutils-gdb.git] / src-release.sh
blob169135856a250fb7f98d42f9b9a154e3d37cf909
1 #!/usr/bin/env bash
2 # Copyright (C) 1990-2020 Free Software Foundation
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.
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/>.
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.
23 set -e
25 BZIPPROG=bzip2
26 GZIPPROG=gzip
27 LZIPPROG=lzip
28 XZPROG=xz
29 SHA256PROG=sha256sum
30 MAKE=make
31 CC=gcc
32 CXX=g++
33 release_date=
35 # Default to avoid splitting info files by setting the threshold high.
36 MAKEINFOFLAGS=--split-size=5000000
39 # Support for building net releases
41 # Files in root used in any net release.
42 DEVO_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 SECURITY.txt src-release.sh symlink-tree test-driver ylwrap \
49 multilib.am"
51 # Files in devo/etc used in any net release.
52 ETC_SUPPORT="Makefile.in configure configure.in standards.texi \
53 make-stds.texi standards.info* configure.texi configure.info* \
54 ChangeLog configbuild.* configdev.* fdl.texi texi2pod.pl gnu-oids.texi"
56 # Get the version number of a given tool
57 getver()
59 tool=$1
60 if grep 'AC_INIT.*BFD_VERSION' $tool/configure.ac >/dev/null 2>&1; then
61 bfd/configure --version | sed -n -e '1s,.* ,,p'
62 elif test -f $tool/common/create-version.sh; then
63 $tool/common/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
64 cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
65 rm -f VER.tmp
66 elif test $tool = "gdb"; then
67 ./gdbsupport/create-version.sh $tool 'dummy-host' 'dummy-target' VER.tmp
68 cat VER.tmp | grep 'version\[\]' | sed 's/.*"\([^"]*\)".*/\1/' | sed 's/-git$//'
69 rm -f VER.tmp
70 elif test -f $tool/version.in; then
71 head -n 1 $tool/version.in
72 else
73 echo VERSION
77 # Setup build directory for building release tarball
78 do_proto_toplev()
80 package=$1
81 ver=$2
82 tool=$3
83 support_files=$4
85 echo "==> Cleaning sources."
86 find \( -name "*.orig" -o -name "*.rej" -o -name "*~" -o -name ".#*" -o -name "*~$bkpat" \) -exec rm {} \;
88 echo "==> Making $package-$ver/"
89 # Take out texinfo from a few places.
90 sed -e '/^all\.normal: /s/\all-texinfo //' \
91 -e '/^ install-texinfo /d' \
92 <Makefile.in >tmp
93 mv -f tmp Makefile.in
94 # configure. --enable-gold is needed to ensure .c/.h from .y are
95 # built in the gold dir. The disables speed the build a little.
96 enables=
97 disables=
98 for dir in binutils gas gdb gold gprof gprofng libsframe ld libctf libdecnumber readline sim; do
99 case " $tool $support_files " in
100 *" $dir "*) enables="$enables --enable-$dir" ;;
101 *) disables="$disables --disable-$dir" ;;
102 esac
103 done
104 echo "==> configure --target=i386-pc-linux-gnu $disables $enables"
105 ./configure --target=i386-pc-linux-gnu $disables $enables
106 $MAKE configure-host configure-target \
107 ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
108 CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
109 # Make links, and run "make diststuff" or "make info" when needed.
110 rm -rf proto-toplev
111 mkdir proto-toplev
112 dirs="$DEVO_SUPPORT $support_files $tool"
113 for d in $dirs ; do
114 if [ -d $d ]; then
115 if [ ! -f $d/Makefile ] ; then
116 true
117 elif grep '^diststuff:' $d/Makefile >/dev/null ; then
118 (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" diststuff) \
119 || exit 1
120 elif grep '^info:' $d/Makefile >/dev/null ; then
121 (cd $d ; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info) \
122 || exit 1
124 if [ -d $d/proto-$d.dir ]; then
125 ln -s ../$d/proto-$d.dir proto-toplev/$d
126 else
127 ln -s ../$d proto-toplev/$d
129 else
130 if (echo x$d | grep / >/dev/null); then
131 mkdir -p proto-toplev/`dirname $d`
132 x=`dirname $d`
133 ln -s ../`echo $x/ | sed -e 's,[^/]*/,../,g'`$d proto-toplev/$d
134 else
135 ln -s ../$d proto-toplev/$d
138 done
139 (cd etc; $MAKE MAKEINFOFLAGS="$MAKEINFOFLAGS" info)
140 $MAKE distclean
141 mkdir proto-toplev/etc
142 (cd proto-toplev/etc;
143 for i in $ETC_SUPPORT; do
144 ln -s ../../etc/$i .
145 done)
147 # Take out texinfo from configurable dirs
148 rm proto-toplev/configure.ac
149 sed -e '/^host_tools=/s/texinfo //' \
150 <configure.ac >proto-toplev/configure.ac
152 mkdir proto-toplev/texinfo
153 ln -s ../../texinfo/texinfo.tex proto-toplev/texinfo/
154 if test -r texinfo/util/tex3patch ; then
155 mkdir proto-toplev/texinfo/util && \
156 ln -s ../../../texinfo/util/tex3patch proto-toplev/texinfo/util
158 chmod -R og=u . || chmod og=u `find . -print`
160 # Create .gmo files from .po files.
161 for f in `find . -name '*.po' -type f -print`; do
162 msgfmt -o `echo $f | sed -e 's/\.po$/.gmo/'` $f
163 done
165 rm -f $package-$ver
166 ln -s proto-toplev $package-$ver
169 CVS_NAMES='-name CVS -o -name .cvsignore'
171 # Add a sha256sum to the built tarball
172 do_sha256sum()
174 echo "==> Adding sha256 checksum to top-level directory"
175 (cd proto-toplev && find * -follow \( $CVS_NAMES \) -prune \
176 -o -type f -print \
177 | xargs $SHA256PROG > ../sha256.new)
178 rm -f proto-toplev/sha256.sum
179 mv sha256.new proto-toplev/sha256.sum
182 # Build the release tarball
183 do_tar()
185 package=$1
186 ver=$2
187 echo "==> Making $package-$ver.tar"
188 rm -f $package-$ver.tar
189 if test x$release_date == "x" ; then
190 find $package-$ver -follow \( $CVS_NAMES \) -prune -o -type f -print \
191 | tar cTfh - $package-$ver.tar
192 else
193 # Attempt to create a consistent, reproducible tarball using the
194 # specified date.
195 find $package-$ver -follow \( $CVS_NAMES \) -prune -o -type f -print \
196 | LC_ALL=C sort \
197 | tar cTfh - $package-$ver.tar \
198 --mtime=$release_date --group=0 --owner=0
202 # Compress the output with bzip2
203 do_bz2()
205 package=$1
206 ver=$2
207 echo "==> Bzipping $package-$ver.tar.bz2"
208 rm -f $package-$ver.tar.bz2
209 $BZIPPROG -k -v -9 $package-$ver.tar
212 # Compress the output with gzip
213 do_gz()
215 package=$1
216 ver=$2
217 echo "==> Gzipping $package-$ver.tar.gz"
218 rm -f $package-$ver.tar.gz
219 $GZIPPROG -k -v -9 $package-$ver.tar
222 # Compress the output with lzip
223 do_lz()
225 package=$1
226 ver=$2
227 echo "==> Lzipping $package-$ver.tar.lz"
228 rm -f $package-$ver.tar.lz
229 $LZIPPROG -k -v -9 $package-$ver.tar
232 # Compress the output with xz
233 do_xz()
235 package=$1
236 ver=$2
237 echo "==> Xzipping $package-$ver.tar.xz"
238 rm -f $package-$ver.tar.xz
239 $XZPROG -k -v -9 $package-$ver.tar
242 # Compress the output with all selected compresion methods
243 do_compress()
245 package=$1
246 ver=$2
247 compressors=$3
248 for comp in $compressors; do
249 case $comp in
250 bz2)
251 do_bz2 $package $ver;;
253 do_gz $package $ver;;
255 do_lz $package $ver;;
257 do_xz $package $ver;;
259 echo "Unknown compression method: $comp" && exit 1;;
260 esac
261 done
264 # Add djunpack.bat the tarball
265 do_djunpack()
267 package=$1
268 ver=$2
269 echo "==> Adding updated djunpack.bat to top-level directory"
270 echo - 's /gdb-[0-9\.]*/$package-'"$ver"'/'
271 sed < djunpack.bat > djunpack.new \
272 -e 's/gdb-[0-9][0-9\.]*/$package-'"$ver"'/'
273 rm -f proto-toplev/djunpack.bat
274 mv djunpack.new proto-toplev/djunpack.bat
277 # Create a release package, tar it and compress it
278 tar_compress()
280 package=$1
281 tool=$2
282 support_files=$3
283 compressors=$4
284 verdir=${5:-$tool}
285 ver=$(getver $verdir)
286 do_proto_toplev $package $ver $tool "$support_files"
287 do_sha256sum
288 do_tar $package $ver
289 do_compress $package $ver "$compressors"
292 # Create a gdb release package, tar it and compress it
293 gdb_tar_compress()
295 package=$1
296 tool=$2
297 support_files=$3
298 compressors=$4
299 ver=$(getver $tool)
300 do_proto_toplev $package $ver $tool "$support_files"
301 do_sha256sum
302 do_djunpack $package $ver
303 do_tar $package $ver
304 do_compress $package $ver "$compressors"
307 # The FSF "binutils" release includes gprof and ld.
308 BINUTILS_SUPPORT_DIRS="libsframe bfd gas include libiberty libctf opcodes ld elfcpp gold gprof gprofng setup.com makefile.vms cpu zlib"
309 binutils_release()
311 compressors=$1
312 package=binutils
313 tool=binutils
314 tar_compress $package $tool "$BINUTILS_SUPPORT_DIRS" "$compressors"
317 GAS_SUPPORT_DIRS="bfd include libiberty opcodes setup.com makefile.vms zlib"
318 gas_release()
320 compressors=$1
321 package=gas
322 tool=gas
323 tar_compress $package $tool "$GAS_SUPPORT_DIRS" "$compressors"
326 GDB_SUPPORT_DIRS="libsframe bfd include libiberty libctf opcodes readline sim libdecnumber cpu zlib contrib gnulib gdbsupport gdbserver libbacktrace"
327 gdb_release()
329 compressors=$1
330 package=gdb
331 tool=gdb
332 gdb_tar_compress $package $tool "$GDB_SUPPORT_DIRS" "$compressors"
335 # Corresponding to the CVS "sim" module.
336 SIM_SUPPORT_DIRS="libsframe bfd opcodes libiberty libctf/swap.h include gdb/version.in gdb/common/create-version.sh makefile.vms zlib gnulib"
337 sim_release()
339 compressors=$1
340 package=sim
341 tool=sim
342 tar_compress $package $tool "$SIM_SUPPORT_DIRS" "$compressors" gdb
345 usage()
347 echo "src-release.sh <options> <release>"
348 echo "options:"
349 echo " -b: Compress with bzip2"
350 echo " -g: Compress with gzip"
351 echo " -l: Compress with lzip"
352 echo " -x: Compress with xz"
353 echo " -r <date>: Create a reproducible tarball using <date> as the mtime"
354 exit 1
357 build_release()
359 release=$1
360 compressors=$2
361 case $release in
362 binutils)
363 binutils_release "$compressors";;
364 gas)
365 gas_release "$compressors";;
366 gdb)
367 gdb_release "$compressors";;
368 sim)
369 sim_release "$compressors";;
371 echo "Unknown release name: $release" && usage;;
372 esac
375 compressors=""
377 while getopts ":bglr:x" opt; do
378 case $opt in
380 compressors="$compressors bz2";;
382 compressors="$compressors gz";;
384 compressors="$compressors lz";;
386 release_date=$OPTARG;;
388 compressors="$compressors xz";;
390 echo "Invalid option: -$OPTARG" && usage;;
391 esac
392 done
393 shift $((OPTIND -1))
394 release=$1
396 build_release $release "$compressors"