* m4/tar.m4 (_AM_PROG_TAR): Split the definition of $_am_tools
[platform/upstream/automake.git] / m4 / tar.m4
1 # Check how to create a tarball.                            -*- Autoconf -*-
2
3 # Copyright (C) 2004  Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
19
20 # serial 1
21
22
23 # _AM_PROG_TAR(FORMAT)
24 # --------------------
25 # Check how to create a tarball in format FORMAT.
26 # FORMAT should be one of `v7', `ustar', or `pax'.
27 #
28 # Substitute a variable $(am__tar) that is a command
29 # writing to stdout a FORMAT-tarball containing the directory
30 # $tardir.
31 #     tardir=directory && $(am__tar) > result.tar
32 #
33 # Substitute a variable $(am__untar) that extract such
34 # a tarball read from stdin.
35 #     $(am__untar) < result.tar
36 AC_DEFUN([_AM_PROG_TAR],
37 [# Always define AMTAR for backward compatibility.
38 AM_MISSING_PROG([AMTAR], [tar])
39 m4_if([$1], [v7],
40      [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
41      [m4_case([$1], [ustar],, [pax],,
42               [m4_fatal([Unknown tar format])])
43 AC_MSG_CHECKING([how to create a $1 tar archive])
44 # Loop over all known methods to create a tar archive until one works.
45 _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
46 _am_tools=${am_cv_prog_tar_$1-$_am_tools}
47 # Do not fold the above two line into one, because Tru64 sh and
48 # Solaris sh will not grok spaces in the rhs of `-'.
49 for _am_tool in $_am_tools
50 do
51   case $_am_tool in
52   gnutar)
53     for _am_tar in tar gnutar gtar;
54     do
55       AM_RUN_LOG([$_am_tar --version]) && break
56     done
57     am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
58     am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
59     am__untar="$_am_tar -xf -"
60     ;;
61   plaintar)
62     # Must skip GNU tar: if it does not support --format= it doesn't create
63     # ustar tarball either.
64     (tar --version) >/dev/null 2>&1 && continue
65     am__tar='tar chf - "$$tardir"'
66     am__tar_='tar chf - "$tardir"'
67     am__untar='tar xf -'
68     ;;
69   pax)
70     am__tar='pax -L -x $1 -w "$$tardir"'
71     am__tar_='pax -L -x $1 -w "$tardir"'
72     am__untar='pax -r'
73     ;;
74   cpio)
75     am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
76     am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
77     am__untar='cpio -i -H $1 -d'
78     ;;
79   none)
80     am__tar=false
81     am__tar_=false
82     am__untar=false
83     ;;
84   esac
85
86   # If the value was cached, stop now.  We just wanted to have am__tar
87   # and am__untar set.
88   test -n "${am_cv_prog_tar_$1}" && break
89
90   # tar/untar a dummy directory, and stop if the command works
91   rm -rf conftest.dir
92   mkdir conftest.dir
93   echo GrepMe > conftest.dir/file
94   AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
95   rm -rf conftest.dir
96   if test -s conftest.tar; then
97     AM_RUN_LOG([$am__untar <conftest.tar])
98     grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
99   fi
100 done
101 rm -rf conftest.dir
102
103 AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
104 AC_MSG_RESULT([$am_cv_prog_tar_$1])])
105 AC_SUBST([am__tar])
106 AC_SUBST([am__untar])
107 ]) # _AM_PROG_TAR