Merge branch 'maint'
[platform/upstream/automake.git] / m4 / tar.m4
1 # Check how to create a tarball.                            -*- Autoconf -*-
2
3 # Copyright (C) 2004-2012 Free Software Foundation, Inc.
4 #
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
8
9 # serial 3
10
11 # _AM_PROG_TAR(FORMAT)
12 # --------------------
13 # Check how to create a tarball in format FORMAT.
14 # FORMAT should be one of 'v7', 'ustar', or 'pax'.
15 #
16 # Substitute a variable $(am__tar) that is a command
17 # writing to stdout a FORMAT-tarball containing the directory
18 # $tardir.
19 #     tardir=directory && $(am__tar) > result.tar
20 #
21 # Substitute a variable $(am__untar) that extract such
22 # a tarball read from stdin.
23 #     $(am__untar) < result.tar
24 AC_DEFUN([_AM_PROG_TAR],
25 [# Always define AMTAR for backward compatibility.  Yes, it's still used
26 # in the wild :-(  We should find a proper way to deprecate it ...
27 AC_SUBST([AMTAR], ['$${TAR-tar}'])
28 m4_if([$1], [v7],
29      [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
30      [m4_case([$1], [ustar],, [pax],,
31               [m4_fatal([Unknown tar format])])
32 AC_MSG_CHECKING([how to create a $1 tar archive])
33 # Loop over all known methods to create a tar archive until one works.
34 _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
35 _am_tools=${am_cv_prog_tar_$1-$_am_tools}
36 # Do not fold the above two line into one, because Tru64 sh and
37 # Solaris sh will not grok spaces in the rhs of '-'.
38 for _am_tool in $_am_tools
39 do
40   case $_am_tool in
41   gnutar)
42     for _am_tar in tar gnutar gtar;
43     do
44       AM_RUN_LOG([$_am_tar --version]) && break
45     done
46     am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
47     am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
48     am__untar="$_am_tar -xf -"
49     ;;
50   plaintar)
51     # Must skip GNU tar: if it does not support --format= it doesn't create
52     # ustar tarball either.
53     (tar --version) >/dev/null 2>&1 && continue
54     am__tar='tar chf - "$$tardir"'
55     am__tar_='tar chf - "$tardir"'
56     am__untar='tar xf -'
57     ;;
58   pax)
59     am__tar='pax -L -x $1 -w "$$tardir"'
60     am__tar_='pax -L -x $1 -w "$tardir"'
61     am__untar='pax -r'
62     ;;
63   cpio)
64     am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
65     am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
66     am__untar='cpio -i -H $1 -d'
67     ;;
68   none)
69     am__tar=false
70     am__tar_=false
71     am__untar=false
72     ;;
73   esac
74
75   # If the value was cached, stop now.  We just wanted to have am__tar
76   # and am__untar set.
77   test -n "${am_cv_prog_tar_$1}" && break
78
79   # tar/untar a dummy directory, and stop if the command works
80   rm -rf conftest.dir
81   mkdir conftest.dir
82   echo GrepMe > conftest.dir/file
83   AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
84   rm -rf conftest.dir
85   if test -s conftest.tar; then
86     AM_RUN_LOG([$am__untar <conftest.tar])
87     grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
88   fi
89 done
90 rm -rf conftest.dir
91
92 AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
93 AC_MSG_RESULT([$am_cv_prog_tar_$1])])
94 AC_SUBST([am__tar])
95 AC_SUBST([am__untar])
96 ]) # _AM_PROG_TAR