tar.m4 4.4 KB

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