2
dnl @synopsis ST_LIB_ARCHIVE([ENABLED-DEFAULT])
4
dnl This macro figures out what's necessary to link a program against an
5
dnl instance of the BSD libarchive package by Tim Kientzle.
7
dnl See http://people.freebsd.org/~kientzle/libarchive/ for more info.
9
dnl It exports and substitutes the variables LIBARCHIVE_LIBS, LIBARCHIVE_LDFLAGS,
10
dnl and LIBARCHIVE_CPPFLAGS to appropriate values for the identified instance of
11
dnl libarchive. The values are AC_SUBST'd, so a user could, for example, simply
12
dnl include @LIBARCHIVE_CPPFLAGS@ in the definition of AM_CPPFLAGS in a Makefile.am.
14
dnl ENABLED-DEFAULT is either "yes" or "no" and determines whether the default value
15
dnl is --with-libarchive or --without-libarchive. It is not possible to specify a
16
dnl default directory. More simply, any reasonable choice for a default should just
17
dnl go into the auto-detect list.
19
dnl The macro defines the symbol HAVE_LIBARCHIVE if the library is found. You
20
dnl should use autoheader to include a definition for this symbol in a config.h
21
dnl file. Sample usage in a C/C++ source is as follows:
23
dnl #ifdef HAVE_LIBARCHIVE
24
dnl #include <archive.h>
25
dnl #endif /* HAVE_LIBARCHIVE */
27
dnl @category InstalledPackages
28
dnl @author Andre Stechert <andre@splunk.com>
29
dnl @version 2006-04-20
30
dnl @license GPLWithACException
32
AC_DEFUN([ST_LIB_ARCHIVE],
35
# Handle input from the configurer and blend with the requirements from the maintainer.
36
# We go through the trouble of creating a second set of variables other than the with_foo
37
# variables in order to be sure that error/corner cases have been cleaned up.
39
# After this statement, three trusted variable are defined.
41
# st_lib_archive_ENABLED will be either "yes" or "no". its value determines whether
42
# or not we bother with the rest of the checks and whether or not we export a
45
# st_lib_archive_LOCATION will be either "auto" or "defined". if it is "auto", then
46
# we try a bunch of standard locations. if it is "defined", then we just try the value
47
# provided in st_lib_archive_DIR.
49
# st_lib_archive_DIR will contain the string provided by the user, provided that it's
50
# actually a directory.
52
AC_MSG_CHECKING([if libarchive is wanted])
53
AC_ARG_WITH([libarchive],
54
AS_HELP_STRING([--with-libarchive=DIR], [libarchive installation directory]),
55
[if test "x$with_libarchive" = "xno" ; then
56
st_lib_archive_ENABLED=no
57
elif test "x$with_libarchive" = "xyes" ; then
58
st_lib_archive_ENABLED=yes
59
st_lib_archive_LOCATION=auto
61
st_lib_archive_ENABLED=yes
62
st_lib_archive_LOCATION=defined
63
if test -d "$with_libarchive" ; then
64
st_lib_archive_DIR="$with_libarchive"
66
AC_MSG_ERROR([$with_libarchive is not a directory])
69
[if test "x$1" = "xno" ; then
70
st_lib_archive_ENABLED=no
71
elif test "x$1" = "xyes" ; then
72
st_lib_archive_ENABLED=yes
74
st_lib_archive_ENABLED=yes
77
if test "$st_lib_archive_ENABLED" = "yes" ; then
80
# After this statement, one trusted variable is defined.
82
# st_lib_archive_LIB will be either "lib" or "lib64", depending on whether the configurer
83
# specified 32, 64. The default is "lib".
85
AC_MSG_CHECKING([whether to use lib or lib64])
86
AC_ARG_WITH([libarchive-bits],
87
AS_HELP_STRING([--with-libarchive-bits=32/64], [if 64, look in /lib64 on hybrid systems]),
88
[if test "x$with_libarchive_bits" = "x32" ; then
89
st_lib_archive_LIB=lib
90
elif test "x$with_libarchive_bits" = "x64" ; then
91
st_lib_archive_LIB=lib64
93
AC_MSG_ERROR([the argument must be either 32 or 64])
95
[st_lib_archive_LIB=lib])
96
AC_MSG_RESULT($st_lib_archive_LIB)
98
# Save the environment before verifying libarchive availability
100
st_lib_archive_SAVECPPFLAGS="$CPPFLAGS"
101
st_lib_archive_SAVELDFLAGS="$LDFLAGS"
105
if test "x$st_lib_archive_LOCATION" = "xdefined" ; then
106
CPPFLAGS="-I$st_lib_archive_DIR/include $st_lib_archive_SAVECPPFLAGS"
107
LDFLAGS="-L$st_lib_archive_DIR/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
108
AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
109
AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
110
if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
111
LIBARCHIVE_CPPFLAGS="-I$dir/include"
112
LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
114
AC_MSG_ERROR([could not find libarchive in the requested location])
118
# These are the common install directories for Linux, FreeBSD, Solaris, and Mac.
120
for dir in /usr /usr/local /usr/sfw /opt/csw /opt/local /sw
122
if test -d "$dir" ; then
123
CPPFLAGS="-I$dir/include $st_lib_archive_SAVECPPFLAGS"
124
LDFLAGS="-L$dir/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
125
AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
126
AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
127
if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
128
LIBARCHIVE_CPPFLAGS="-I$dir/include"
129
LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
136
if test "x$st_lib_archive_found_hdr" = "xyes" && test "x$st_lib_archive_found_lib" = "xyes" ; then
137
LIBARCHIVE_LIBS="-larchive"
138
AC_DEFINE([HAVE_LIBARCHIVE], [1], [Defined to 1 if libarchive is available for use.])
139
AC_SUBST(LIBARCHIVE_LIBS)
140
AC_SUBST(LIBARCHIVE_CPPFLAGS)
141
AC_SUBST(LIBARCHIVE_LDFLAGS)
145
# Restore the environment now that we're done.
148
CPPFLAGS="$st_lib_archive_SAVECPPFLAGS"
149
LDFLAGS="$st_lib_archive_SAVELDFLAGS"
153
AM_CONDITIONAL(LIBARCHIVE, test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes")