Merge branch 'maint'
[platform/upstream/automake.git] / t / dist-formats.tap
1 #! /bin/sh
2 # Copyright (C) 2012 Free Software Foundation, Inc.
3 #
4 # This program 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 2, or (at your option)
7 # 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 # Check support for different compression formats used by distribution
18 # archives.
19
20 am_create_testdir=empty
21 . ./defs || Exit 1
22
23 plan_ 70
24
25 # ---------------------------------------------------- #
26 #  Common and/or auxiliary subroutines and variables.  #
27 # ---------------------------------------------------- #
28
29 ocwd=`pwd` || fatal_ "obtaining current working directory"
30
31 TAR='' && unset TAR
32
33 # Create common aclocal.m4 file, for later tests.
34 mkdir setup \
35   && cd setup \
36   && echo 'AC_INIT([x], [0]) AM_INIT_AUTOMAKE' > configure.ac \
37   && $ACLOCAL \
38   && mv aclocal.m4 .. \
39   && cd .. \
40   && rm -rf setup \
41   || fatal_ "creating common aclocal.m4 file"
42
43 # Some make implementations (e.g., HP-UX) don't grok '-j', some require
44 # no space between '-j' and the number of jobs (e.g., older GNU make
45 # versions), and some *do* require a space between '-j' and the number
46 # of jobs (e.g., Solaris dmake).  We need a runtime test to see what
47 # works.
48 for MAKE_j4 in "$MAKE -j4" "$MAKE -j 4" false; do
49   echo all: | $MAKE_j4 -f - && break
50   : For shells with buggy 'set -e'.
51 done
52
53 # Set variables '$compressor' and '$suffix'.
54 setup_vars_for_compression_format ()
55 {
56   suffix=NONE compressor=NONE
57   case $1 in
58     gzip) suffix=tar.gz  compressor=gzip     ;;
59     tarZ) suffix=tar.Z   compressor=compress ;;
60     lzip) suffix=tar.lz  compressor=lzip     ;;
61       xz) suffix=tar.xz  compressor=xz       ;;
62    bzip2) suffix=tar.bz2 compressor=bzip2    ;;
63      zip) suffix=zip     compressor=zip      ;;
64     shar) suffix=shar.gz compressor=shar     ;;
65        *) fatal_ "invalid compression format '$1'";;
66   esac
67 }
68
69 all_compression_formats='gzip tarZ lzip xz bzip2 zip shar'
70
71 all_compressors=`
72   for x in $all_compression_formats; do
73     setup_vars_for_compression_format $x
74     echo $compressor
75   done | tr "$nl" ' '`
76 echo All compressors: $all_compressors
77
78 missing_compressors=`
79   for c in $all_compressors; do
80     case $c in
81       # Assume gzip(1) is available on every reasonable portability target.
82       gzip)
83         continue
84         ;;
85       # On Cygwin, as of 9/2/2012, 'compress' is provided by sharutils
86       # and is just a dummy script that is not able to actually compress
87       # (it can only decompress).  So, check that the 'compress' program
88       # is actually able to compress input.
89       # Note that, at least on GNU/Linux, 'compress' does (and is
90       # documented to) exit with status 2 if the output is larger than
91       # the input after (attempted) compression; so we need to pass it
92       # an input that it can actually reduce in size when compressing.
93       compress)
94         for x in 1 2 3 4 5 6 7 8; do
95           echo aaaaaaaaaaaaaaa
96         done | $c -c >/dev/null && continue
97         : For shells with busted 'set -e'.
98         ;;
99       *)
100         $c --version </dev/null >&2 && continue
101         : For shells with busted 'set -e'.
102         ;;
103     esac
104     echo $c
105   done | tr "$nl" ' '`
106 echo Missing compressors: $missing_compressors
107
108 have_compressor ()
109 {
110   case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac
111 }
112
113 have_all_compressors ()
114 {
115   test -z "$missing_compressors"
116 }
117
118 start_subtest ()
119 {
120   name=$1; shift
121   test -n "$name" || fatal_ "start_subtest: no subtest name given"
122   if test $# -gt 0; then
123     eval "$@" || fatal_ "start_subtest: evaluating assignments"
124   fi
125   ac_opts=`echo $ac_opts | tr ',' ' '`
126   am_opts=`echo $am_opts | tr ',' ' '`
127   mkdir "$name"
128   cd "$name"
129   unindent > configure.ac <<END
130     AC_INIT([$name], [1.0])
131     AM_INIT_AUTOMAKE([$ac_opts])
132     AC_CONFIG_FILES([Makefile])
133     AC_OUTPUT
134 END
135   echo "AUTOMAKE_OPTIONS = $am_opts" > Makefile.am
136   # It is imperative that aclocal.m4 is copied after configure.ac has
137   # been created, to avoid a spurious trigger of the automatic remake
138   # rules for configure & co.
139   cp "$ocwd"/aclocal.m4 \
140      "$am_scriptdir"/missing \
141      "$am_scriptdir"/install-sh \
142      .
143 }
144
145 end_subtest ()
146 {
147   unset name; unset ac_opts; unset am_opts;
148   cd "$ocwd" || fatal_ "couldn't chdir back to '$ocwd'"
149 }
150
151 command_ok_if_have_compressor ()
152 {
153   if have_compressor "$compressor"; then
154     command_ok_ "$@"
155   else
156     skip_ -r "'$compressor' not available" "$1"
157   fi
158 }
159
160 can_compress ()
161 {
162   test $# -eq 2 || fatal_ "can_compress: bad number of arguments"
163   tarname=$1 format=$2
164   setup_vars_for_compression_format "$format"
165
166   command_ok_ "'dist-$format' target always created" $MAKE -n dist-$format
167
168   command_ok_if_have_compressor "'make dist-$format' work by default" \
169     eval '
170       rm -rf *$tarname* \
171         && make dist-$format \
172         && test -f $tarname-1.0.$suffix \
173         && ls -l *$tarname* \
174         && test "`ls *$tarname*`" = $tarname-1.0.$suffix'
175
176   unset suffix compressor format tarname
177 }
178
179 # ---------------------------------------- #
180 #  Defaults layout of the dist-* targets.  #
181 # ---------------------------------------- #
182
183 start_subtest defaults
184
185 command_ok_ "default [automake]"        $AUTOMAKE
186 command_ok_ "default [autoconf]"        $AUTOCONF
187 command_ok_ "default [configure]"       ./configure
188 command_ok_ "default [make distcheck]"  $MAKE distcheck
189
190 command_ok_ "'make dist' only builds *.tar.gz by default" \
191             test "`ls *defaults*`" = defaults-1.0.tar.gz
192
193 rm -rf *defaults*
194
195 for fmt in $all_compression_formats; do
196   can_compress defaults $fmt
197 done
198 unset fmt
199
200 end_subtest
201
202 # ----------------------------------------------------------- #
203 #  Check diagnostic for no-dist-gzip without another dist-*.  #
204 # ----------------------------------------------------------- #
205
206 nogzip_stderr ()
207 {
208   grep "$1:.*no-dist-gzip" stderr \
209     && grep "$1:.* at least one archive format must be enabled" stderr
210 }
211
212 nogzip_automake_failure ()
213 {
214   AUTOMAKE_fails -d "no-dist-gzip ($1) without other formats is an error"
215   command_ok_ "no-dist-gzip ($1) without other formats gives diagnostic" \
216               nogzip_stderr "$2"
217 }
218
219 start_subtest am-nogz-only am_opts=no-dist-gzip ac_opts=
220 nogzip_automake_failure 'am' 'Makefile\.am:1'
221 end_subtest
222
223 start_subtest ac-nogz-only am_opts= ac_opts=no-dist-gzip
224 nogzip_automake_failure 'ac' 'configure\.ac:2'
225 end_subtest
226
227 # ------------------------------------------------- #
228 #  Check use of no-dist-gzip with a dist-* option.  #
229 # ------------------------------------------------- #
230
231 append_to_opt ()
232 {
233   var=$1_opts val=$2
234   eval "$var=\${$var:+\"\$$var,\"}\$val" || fatal_ "evaluating \${$var}"
235   unset var val
236 }
237
238 nogzip ()
239 {
240   test $#,$1,$3,$5 = 6,in,and,in \
241     && case $2,$6 in ac,ac|ac,am|am,ac|am,am) :;; *) false;; esac \
242     || fatal_ "nogzip: invalid usage"
243   format=$4 where_dist_nogzip=$2 where_dist_format=$6
244   shift 6
245
246   am_opts= ac_opts=
247   append_to_opt $where_dist_format dist-$format
248   append_to_opt $where_dist_nogzip no-dist-gzip
249   setup_vars_for_compression_format "$format"
250   # Do these before the am_opts and ac_opts variable can be munged
251   # by 'start_subtest'.
252   desc=
253   test -n "$am_opts" && desc=${desc:+"$desc "}"am=$am_opts"
254   test -n "$ac_opts" && desc=${desc:+"$desc "}"ac=$ac_opts"
255
256   start_subtest nogzip-$format am_opts=$am_opts ac_opts=$ac_opts
257
258   unindent >> Makefile.am <<END
259     check-ark-name:
260         test \$(DIST_ARCHIVES) = \$(distdir).$suffix
261     check-ark-exists:
262         test -f \$(distdir).$suffix
263     check-no-tar-gz:
264         test ! -f \$(distdir).tar.gz
265 END
266
267   command_ok_ "$desc [automake]" $AUTOMAKE
268   command_ok_ "$desc [autoconf]" $AUTOCONF
269   command_ok_ "$desc [configure]" ./configure
270   command_ok_ "$desc [ark-name]" $MAKE check-ark-name
271   command_ok_if_have_compressor "$desc [distcheck]" $MAKE distcheck
272   command_ok_if_have_compressor "$desc [ark-exists]" $MAKE check-ark-exists
273   command_ok_ "$desc [no .tar.gz]"  $MAKE check-no-tar-gz
274
275   unset desc
276
277   end_subtest
278 }
279
280 #      $1 $2  $3   $4     $5  $6
281 nogzip in am  and  bzip2  in  am
282 nogzip in ac  and  xz     in  am
283 nogzip in am  and  lzip   in  ac
284 nogzip in ac  and  tarZ   in  ac
285
286
287 # ----------------------------------------------------------- #
288 #  The 'dist-gzip' target is created also with no-dist-gzip.  #
289 # ----------------------------------------------------------- #
290
291 start_subtest dist-gzip-persistence am_opts=no-dist-gzip,dist-xz
292 command_ok_ "dist-gzip persistence [automake]"  $AUTOMAKE
293 command_ok_ "dist-gzip persistence [autoconf]"  $AUTOCONF
294 command_ok_ "dist-gzip persistence [configure]" ./configure
295 can_compress dist-gzip-persistence gzip
296 end_subtest
297
298
299 # ----------------------- #
300 #  Parallel compression.  #
301 # ----------------------- #
302
303 # We only use formats requiring 'gzip', 'bzip2' and 'compress' programs,
304 # since there are the most likely to be all found on the great majority
305 # of systems.
306
307 start_subtest parallel-compression ac_opts=dist-bzip2 am_opts=dist-tarZ
308
309 desc=gzip+bzip2+tarZ
310 tarname=parallel-compression-1.0
311
312 check_tarball ()
313 {
314   format=$1
315   setup_vars_for_compression_format $format
316   (
317     tarball=$tarname.$suffix \
318       && test -f $tarball \
319       && mkdir check-$format \
320       && cp $tarball check-$format \
321       && cd check-$format \
322       && $compressor -d $tarball \
323       && tar xvf $tarname.tar \
324       && diff ../Makefile.in $tarname/Makefile.in \
325       && cd .. \
326       && rm -rf check-$format
327    )
328 }
329
330 command_ok_ "$desc [automake]" $AUTOMAKE
331
332 skip_reason=
333 have_compressor compress || skip_reason="'compress' not available"
334 have_compressor bzip2 || skip_reason="'bzip2' not available"
335 if test "$MAKE_j4" = false; then
336   test -z "$skip_reason" || skip_reason="$skip_reason and "
337   skip_reason="${skip_reason}make concurrency unavailable"
338 fi
339
340 if test -n "$skip_reason"; then
341   skip_row_ 6 -r "$skip_reason" "$desc"
342 else
343   command_ok_ "$desc [autoconf]" $AUTOCONF
344   command_ok_ "$desc [configure]" ./configure
345   command_ok_ "$desc [make -j4 dist-all]"  $MAKE_j4 dist
346   ls -l # For debugging.
347   command_ok_ "$desc [check .tar.gz tarball]"  check_tarball gzip
348   command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2
349   command_ok_ "$desc [check .tar.Z tarball]"   check_tarball tarZ
350 fi
351
352 unset tarname desc skip_reason
353
354 end_subtest
355
356
357 # --------------------------------------------------------- #
358 #  The various 'dist-*' targets can happily work together.  #
359 # --------------------------------------------------------- #
360
361 start_subtest all-together
362
363 desc='all compressors together'
364 tarname=all-together-1.0
365
366 echo 'AM_INIT_AUTOMAKE([' > am-init.m4
367 echo 'AUTOMAKE_OPTIONS =' > Makefile.am
368
369 # Add half 'dist-*' options to AM_INIT_AUTOMAKE, half to AUTOMAKE_OPTIONS.
370 flip=:
371 for fmt in $all_compression_formats; do
372   test $fmt = gzip && continue
373   if $flip; then
374     echo "  dist-$fmt" >> am-init.m4
375     flip=false
376   else
377     echo "AUTOMAKE_OPTIONS += dist-$fmt" >> Makefil.am
378     flip=:
379   fi
380 done
381 unset flip fmt
382
383 echo '])' >> am-init.m4
384
385 sed 's/AM_INIT_AUTOMAKE.*/m4_include([am-init.m4])/' configure.ac > t
386 mv -f t configure.ac
387
388 # For debugging.
389 cat Makefil.am
390 cat configure.ac
391 cat am-init.m4
392
393 command_ok_ "$desc [aclocal]" $ACLOCAL --force
394 command_ok_ "$desc [automake]" $AUTOMAKE
395 command_ok_ "$desc [autoconf]" $AUTOCONF
396 command_ok_ "$desc [configure]" ./configure
397
398 if have_all_compressors; then
399   command_ok_ "$desc [make distcheck, real]" $MAKE distcheck
400 else
401   skip_ -r "not all compressors available" "$desc [make distcheck, real]"
402 fi
403
404 # We fake existence of all the compressors here, so that we don't have
405 # to require any of them to run the further tests.  This is especially
406 # important since it's very unlikely that a non-developer has all the
407 # compression tools installed on his machine at the same time.
408
409 mkdir bin
410 cd bin
411 cat > check-distdir <<END
412 #!/bin/sh
413 { ls -l '$tarname' && diff Makefile.am '$tarname'/Makefile.am; } >&2 \
414   || { echo "== distdir fail =="; exit 1; }
415 END
416 cat > grep-distdir-error <<'END'
417 #!/bin/sh
418 grep 'distdir fail' && exit 1
419 :
420 END
421 chmod a+x check-distdir grep-distdir-error
422 for prog in tar $all_compressors; do
423   case $prog in
424     tar|shar|zip) cp check-distdir $prog;;
425                *) cp grep-distdir-error $prog;;
426   esac
427 done
428 unset prog
429 ls -l # For debugging.
430 cd ..
431
432 oPATH=$PATH
433 PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
434
435 command_ok_ \
436   "$desc ['make dist-all', stubbed]" \
437   $MAKE dist-all
438
439 subdesc="$desc ['make dist -j4', stubbed]"
440 if test "$MAKE_j4" = false; then
441   skip_ -r "make concurrency unavailable" "$subdesc"
442 else
443   command_ok_ "$subdesc" $MAKE_j4 dist
444 fi
445 unset subdesc
446
447 PATH=$oPATH; export PATH
448
449 end_subtest
450
451 :