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