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