check_bzlib.m4 3.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
dnl @synopsis CHECK_BZLIB()
dnl
dnl This macro searches for an installed bzlib library. If nothing was
dnl specified when calling configure, it searches first in /usr/local
dnl and then in /usr. If the --with-bzlib=DIR is specified, it will try
dnl to find it in DIR/include/bzlib.h and DIR/lib/libbz2.a. If
dnl --without-bzlib is specified, the library is not searched at all.
dnl
dnl If either the header file (bzlib.h) or the library (libbz2) is not
dnl found, the configuration exits on error, asking for a valid bzlib
dnl installation directory or --without-bzlib.
dnl
dnl The macro defines the symbol HAVE_LIBBZ2 if the library is found. You
dnl should use autoheader to include a definition for this symbol in a
dnl config.h file. Sample usage in a C/C++ source is as follows:
dnl
dnl   #ifdef HAVE_LIBBZ2
dnl   #include <bzlib.h>
dnl   #endif /* HAVE_LIBBZ2 */
dnl
dnl @category InstalledPackages
dnl @author Loic Dachary <loic@senga.org>
dnl @version 2004-09-20
dnl @license GPLWithACException

AC_DEFUN([CHECK_BZLIB],
#
# Handle user hints
#
[AC_MSG_CHECKING(if bzlib is wanted)
AC_ARG_WITH(bzlib,
[  --with-bzlib=DIR root directory path of bzlib installation [defaults to
                    /usr/local or /usr if not found in /usr/local]
  --without-bzlib to disable bzlib usage completely],
[if test "$withval" != no ; then
  if test -d "$withval"
  then
    BZLIB_HOME="$withval"
  else
40
    BZLIB_HOME=/usr/local
41 42 43
    AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
  fi
else
44
  DISABLE_BZLIB=1
45 46 47 48 49 50
  AC_MSG_RESULT(no)
fi])

#
# Locate bzlib, if wanted
#
51
if test -z "${DISABLE_BZLIB}" 
52
then
53 54 55 56 57
        if test ! -f "${BZLIB_HOME}/include/bzlib.h"
        then
            BZLIB_HOME=/usr
        fi

58
        AC_MSG_RESULT(yes)
59
        BZLIB_OLD_LDFLAGS=$LDFLAGS
60
        BZLIB_OLD_CPPFLAGS=$CPPFLAGS
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        LDFLAGS="$LDFLAGS -L${BZLIB_HOME}/lib"
        CPPFLAGS="$CPPFLAGS -I${BZLIB_HOME}/include"
        AC_LANG_SAVE
        AC_LANG_C
        AC_CHECK_LIB(bz2, BZ2_bzCompressInit, [bzlib_cv_libbz2=yes], [bzlib_cv_libbz2=no])
        AC_CHECK_HEADER(bzlib.h, [bzlib_cv_bzlib_h=yes], [bzlib_cv_bzlib_h=no])
        AC_LANG_RESTORE
        if test "$bzlib_cv_libbz2" = "yes" -a "$bzlib_cv_bzlib_h" = "yes"
        then
                #
                # If both library and header were found, use them
                #
                AC_CHECK_LIB(bz2, BZ2_bzCompressInit)
                AC_MSG_CHECKING(bzlib in ${BZLIB_HOME})
                AC_MSG_RESULT(ok)
76 77
                LIBBZ2=-lbz2
                AC_SUBST(LIBBZ2)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        else
                #
                # If either header or library was not found, revert and bomb
                #
                AC_MSG_CHECKING(bzlib in ${BZLIB_HOME})
                LDFLAGS="$BZLIB_OLD_LDFLAGS"
                CPPFLAGS="$BZLIB_OLD_CPPFLAGS"
                AC_MSG_RESULT(failed)
# Don't fail; this is optional in Darshan
#                AC_MSG_ERROR(either specify a valid bzlib installation with --with-bzlib=DIR or disable bzlib usage with --without-bzlib)
#                TODO: it would be nice if this showed up at the _end_ of
#                configure...
                AC_MSG_WARN(libbz2 not found; Darshan utilities will use gzip only.)
        fi
fi

])