Reputation: 6478
I am preparing a new version of my BSD Make scripts and need to check if the tar
command on the system supports the -J
option for compression with xz
.
What is the correct way of doing this in autoconf
? It does not seem that AC_CHECK_PROG
allows to test a program with options.
In my case, a valid test could be tar -cJf /dev/null /dev/null
, so I came up with the test
define([CHECK_TAR_OPTION], dnl
[printf 'checking whether tar -$1 works...']
[if tar c$1f /dev/null /dev/null >&- 2>&-;then $2=yes; else $2=no; fi]
[printf '%s\n' "$$2"])dnl
In my code
CHECK_TAR_OPTION(z,USE_GZIP)
will then set USE_GZIP to yes if tar -z
works or to no otherwise.
I have some experience with M4 programming but not in relation with autoconf
so I would appreciate a more idiosyncratic solution.
Upvotes: 0
Views: 202
Reputation: 16315
Your approach seems to me the wrong way around. You can always:
tar c /dev/null | <compression command> > foo.tar.<compression extension>
no matter what tar
supports, which is pretty easy to do with AC_CHECK_PROG
or whatever. What seems to be important to you is what tar
can extract, which you aren't testing. This code walks through your compression methods and should select one based on the ability to round trip data through tar
.
compressor_test ()
{
AS_CASE(["$1"], [*xz], [tflag="J"], [*bzip2], [tflag="j"], [*gzip], [tflag="z"], [tflag=""])
tar c /dev/null > /dev/null 2>&1 | "$1" | tar "tv${tflag}" > /dev/null 2>&1
test $? -eq 0
}
AC_CACHE_CHECK([for a suitable tar compressor], [ac_cv_path_COMPRESSOR],
[AC_PATH_PROGS_FEATURE_CHECK([COMPRESSOR], [xz bzip2 gzip cat],
[[compressor_test $ac_path_COMPRESSOR \
&& ac_cv_path_COMPRESSOR=$ac_path_COMPRESSOR ac_path_COMPRESSOR_found=:]])])
AC_SUBST([COMPRESSOR], [$ac_cv_path_COMPRESSOR])
Upvotes: 3