Jens Geyer | 224b43e | 2019-10-09 00:03:11 +0200 | [diff] [blame^] | 1 | # Check how to create a tarball. -*- Autoconf -*- |
| 2 | |
| 3 | # Copyright (C) 2004-2018 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 | # _AM_PROG_TAR(FORMAT) |
| 10 | # -------------------- |
| 11 | # Check how to create a tarball in format FORMAT. |
| 12 | # FORMAT should be one of 'v7', 'ustar', or 'pax'. |
| 13 | # |
| 14 | # Substitute a variable $(am__tar) that is a command |
| 15 | # writing to stdout a FORMAT-tarball containing the directory |
| 16 | # $tardir. |
| 17 | # tardir=directory && $(am__tar) > result.tar |
| 18 | # |
| 19 | # Substitute a variable $(am__untar) that extract such |
| 20 | # a tarball read from stdin. |
| 21 | # $(am__untar) < result.tar |
| 22 | # |
| 23 | AC_DEFUN([_AM_PROG_TAR], |
| 24 | [# Always define AMTAR for backward compatibility. Yes, it's still used |
| 25 | # in the wild :-( We should find a proper way to deprecate it ... |
| 26 | AC_SUBST([AMTAR], ['$${TAR-tar}']) |
| 27 | |
| 28 | # We'll loop over all known methods to create a tar archive until one works. |
| 29 | _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' |
| 30 | |
| 31 | m4_if([$1], [v7], |
| 32 | [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], |
| 33 | |
| 34 | [m4_case([$1], |
| 35 | [ustar], |
| 36 | [# The POSIX 1988 'ustar' format is defined with fixed-size fields. |
| 37 | # There is notably a 21 bits limit for the UID and the GID. In fact, |
| 38 | # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 |
| 39 | # and bug#13588). |
| 40 | am_max_uid=2097151 # 2^21 - 1 |
| 41 | am_max_gid=$am_max_uid |
| 42 | # The $UID and $GID variables are not portable, so we need to resort |
| 43 | # to the POSIX-mandated id(1) utility. Errors in the 'id' calls |
| 44 | # below are definitely unexpected, so allow the users to see them |
| 45 | # (that is, avoid stderr redirection). |
| 46 | am_uid=`id -u || echo unknown` |
| 47 | am_gid=`id -g || echo unknown` |
| 48 | AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) |
| 49 | if test $am_uid -le $am_max_uid; then |
| 50 | AC_MSG_RESULT([yes]) |
| 51 | else |
| 52 | AC_MSG_RESULT([no]) |
| 53 | _am_tools=none |
| 54 | fi |
| 55 | AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) |
| 56 | if test $am_gid -le $am_max_gid; then |
| 57 | AC_MSG_RESULT([yes]) |
| 58 | else |
| 59 | AC_MSG_RESULT([no]) |
| 60 | _am_tools=none |
| 61 | fi], |
| 62 | |
| 63 | [pax], |
| 64 | [], |
| 65 | |
| 66 | [m4_fatal([Unknown tar format])]) |
| 67 | |
| 68 | AC_MSG_CHECKING([how to create a $1 tar archive]) |
| 69 | |
| 70 | # Go ahead even if we have the value already cached. We do so because we |
| 71 | # need to set the values for the 'am__tar' and 'am__untar' variables. |
| 72 | _am_tools=${am_cv_prog_tar_$1-$_am_tools} |
| 73 | |
| 74 | for _am_tool in $_am_tools; do |
| 75 | case $_am_tool in |
| 76 | gnutar) |
| 77 | for _am_tar in tar gnutar gtar; do |
| 78 | AM_RUN_LOG([$_am_tar --version]) && break |
| 79 | done |
| 80 | am__tar="$_am_tar --hard-dereference --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' |
| 81 | am__tar_="$_am_tar --hard-dereference --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' |
| 82 | am__untar="$_am_tar -xf -" |
| 83 | ;; |
| 84 | plaintar) |
| 85 | # Must skip GNU tar: if it does not support --format= it doesn't create |
| 86 | # ustar tarball either. |
| 87 | (tar --version) >/dev/null 2>&1 && continue |
| 88 | am__tar='tar chf --hard-dereference - "$$tardir"' |
| 89 | am__tar_='tar chf --hard-dereference - "$tardir"' |
| 90 | am__untar='tar xf -' |
| 91 | ;; |
| 92 | pax) |
| 93 | am__tar='pax -L -x $1 -w "$$tardir"' |
| 94 | am__tar_='pax -L -x $1 -w "$tardir"' |
| 95 | am__untar='pax -r' |
| 96 | ;; |
| 97 | cpio) |
| 98 | am__tar='find "$$tardir" -print | cpio -o -H $1 -L' |
| 99 | am__tar_='find "$tardir" -print | cpio -o -H $1 -L' |
| 100 | am__untar='cpio -i -H $1 -d' |
| 101 | ;; |
| 102 | none) |
| 103 | am__tar=false |
| 104 | am__tar_=false |
| 105 | am__untar=false |
| 106 | ;; |
| 107 | esac |
| 108 | |
| 109 | # If the value was cached, stop now. We just wanted to have am__tar |
| 110 | # and am__untar set. |
| 111 | test -n "${am_cv_prog_tar_$1}" && break |
| 112 | |
| 113 | # tar/untar a dummy directory, and stop if the command works. |
| 114 | rm -rf conftest.dir |
| 115 | mkdir conftest.dir |
| 116 | echo GrepMe > conftest.dir/file |
| 117 | AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) |
| 118 | rm -rf conftest.dir |
| 119 | if test -s conftest.tar; then |
| 120 | AM_RUN_LOG([$am__untar <conftest.tar]) |
| 121 | AM_RUN_LOG([cat conftest.dir/file]) |
| 122 | grep GrepMe conftest.dir/file >/dev/null 2>&1 && break |
| 123 | fi |
| 124 | done |
| 125 | rm -rf conftest.dir |
| 126 | |
| 127 | AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) |
| 128 | AC_MSG_RESULT([$am_cv_prog_tar_$1])]) |
| 129 | |
| 130 | AC_SUBST([am__tar]) |
| 131 | AC_SUBST([am__untar]) |
| 132 | ]) # _AM_PROG_TAR |