| #! /bin/sh |
| # Copyright (C) 2012 Free Software Foundation, Inc. |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2, or (at your option) |
| # any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
| # Check support for different compression formats used by distribution |
| # archives. |
| |
| . ./defs || exit 1 |
| |
| plan_ 18 |
| |
| # -------------------------------------- # |
| # Auxiliary subroutines and variables. # |
| # -------------------------------------- # |
| |
| TAR='' && unset TAR |
| |
| # Set variables '$compressor' and '$suffix'. |
| setup_vars_for_compression_format () |
| { |
| suffix=NONE |
| case $1 in |
| gzip) suffix=tar.gz ;; |
| lzip) suffix=tar.lz ;; |
| xz) suffix=tar.xz ;; |
| bzip2) suffix=tar.bz2 ;; |
| zip) suffix=zip ;; |
| *) fatal_ "invalid compression format '$1'";; |
| esac |
| compressor=$1 |
| } |
| |
| check_tarball () |
| { |
| format=$1 |
| ( |
| setup_vars_for_compression_format $format \ |
| && tarball=$distdir.$suffix \ |
| && test -f $tarball \ |
| && mkdir check-$format \ |
| && cp $tarball check-$format \ |
| && cd check-$format \ |
| && $compressor -d $tarball \ |
| && tar xvf $distdir.tar \ |
| && diff ../Makefile.in $distdir/Makefile.in \ |
| && diff ../aclocal.m4 $distdir/aclocal.m4 \ |
| && diff ../configure $distdir/configure \ |
| && cd .. \ |
| && rm -rf check-$format |
| ) |
| } |
| |
| |
| have_compressor () |
| { |
| test $# -eq 1 || fatal_ "have_compressor(): bad usage" |
| case $1 in |
| # Assume gzip(1) is available on every reasonable portability target. |
| gzip) |
| return 0;; |
| *) |
| case $1 in |
| # Do not use --version, or older versions bzip2 would try to |
| # compress stdin. This would cause binary output in the test |
| # logs, with potential breakage of our testsuite harness. |
| bzip2) o=--help;; |
| # OpenSolaris zip do not support the '--version' option, but |
| # accepts the '-v' one with a similar meaning (if no further |
| # arguments are given). |
| zip) o=-v;; |
| # Assume the other compressors we care about support the |
| # '--version' option. |
| *) o=--version;; |
| esac |
| # Redirect to stderr to avoid polluting the output, in case this |
| # function is used in a command substitution (as it is, below). |
| if $1 $o </dev/null >&2; then |
| return 0 |
| else |
| return 1 |
| fi |
| ;; |
| esac |
| fatal_ "have_compressor(): dead code reached" |
| } |
| |
| all_compression_formats='gzip lzip xz bzip2 zip' |
| |
| all_compressors=$( |
| for x in $all_compression_formats; do |
| setup_vars_for_compression_format $x |
| echo $compressor |
| done | tr "$nl" ' ') |
| echo All compressors: $all_compressors |
| |
| missing_compressors=$( |
| for c in $all_compressors; do |
| have_compressor $c || echo $c |
| done | tr "$nl" ' ') |
| echo Missing compressors: $missing_compressors |
| |
| # Redefine to avoid re-running the already executed checks. |
| have_compressor () |
| { |
| case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac |
| } |
| |
| have_all_compressors () |
| { |
| test -z "$missing_compressors" |
| } |
| |
| clean_dist () |
| { |
| rm -rf *$distdir* |
| } |
| |
| # ------------------------- # |
| # Setup and basic checks. # |
| # ------------------------- # |
| |
| echo AC_OUTPUT >> configure.ac |
| : > Makefile.am |
| |
| $ACLOCAL && $AUTOCONF && $AUTOMAKE -a || fatal_ "autotools failed" |
| ./configure || fatal_ "./configure failed" |
| |
| command_ok_ "make distcheck" $MAKE distcheck |
| |
| command_ok_ "only gzip archive is built by default" \ |
| test "$(ls *$distdir*)" = $distdir.tar.gz |
| |
| |
| # ------------------------------------- # |
| # Test all known formats, separately. # |
| # ------------------------------------- # |
| |
| for format in $all_compression_formats; do |
| setup_vars_for_compression_format "$format" |
| desc="$format distribution format" |
| command_ok_ "$desc [seems accepted]" \ |
| $MAKE -n dist AM_DIST_FORMATS="$format" |
| if have_compressor "$compressor"; then |
| command_ok_ "$desc $format distribution format [works]" \ |
| eval '$MAKE dist AM_DIST_FORMATS="$format" \ |
| && ls -l *$distdir* \ |
| && test -f $distdir.$suffix \ |
| && test "$(echo *$distdir*)" = $distdir.$suffix' |
| else |
| skip_ -r "'$compressor' not available" "$1" |
| fi |
| clean_dist |
| unset desc suffix compressor format |
| done |
| |
| # ----------------------- # |
| # Parallel compression. # |
| # ----------------------- # |
| |
| # We only use formats requiring 'gzip', 'bzip2' and 'xz' programs, |
| # since there are the most likely to be all found on the great |
| # majority of systems. |
| |
| desc='parallel compression' |
| |
| skip_reason= |
| have_compressor xz || skip_reason="'xz' not available" |
| have_compressor bzip2 || skip_reason="'bzip2' not available" |
| |
| if test -n "$skip_reason"; then |
| skip_row_ 6 -r "$skip_reason" "$desc" |
| else |
| command_ok_ "$desc [make -j8 distcheck]" \ |
| $MAKE -j8 distcheck AM_DIST_FORMATS='gzip bzip2 xz' |
| ls -l # For debugging. |
| command_ok_ "$desc [check .tar.gz tarball]" check_tarball gzip |
| command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2 |
| command_ok_ "$desc [check .tar.xz tarball]" check_tarball xz |
| fi |
| |
| clean_dist |
| unset desc skip_reason |
| |
| |
| # ------------------------------- # |
| # Invalid distribution formats. # |
| # ------------------------------- # |
| |
| command_ok_ "invalid distribution formats [exit status]" eval ' |
| ! $MAKE dist AM_DIST_FORMATS="foobar tarZ shar" 2>stderr' |
| |
| cat stderr >&2 # For debugging. |
| |
| command_ok_ "invalid distribution formats [error report]" eval ' |
| sed -e "s/^/ /" -e "s/$/ /" stderr >stderr2 \ |
| && grep "[iI]nvalid distribution format.* foobar " stderr2 \ |
| && grep "[iI]nvalid distribution format.* tarZ " stderr2 \ |
| && grep "[iI]nvalid distribution format.* shar " stderr2' |
| |
| : |