1# ===========================================================================
2#       http://www.gnu.org/software/autoconf-archive/ax_check_zlib.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_CHECK_ZLIB()
8#
9# DESCRIPTION
10#
11#   This macro searches for an installed zlib library. If nothing was
12#   specified when calling configure, it searches first in /usr/local and
13#   then in /usr. If the --with-zlib=DIR is specified, it will try to find
14#   it in DIR/include/zlib.h and DIR/lib/libz.a. If --without-zlib is
15#   specified, the library is not searched at all.
16#
17#   If either the header file (zlib.h) or the library (libz) is not found,
18#   the configuration exits on error, asking for a valid zlib installation
19#   directory or --without-zlib.
20#
21#   The macro defines the symbol HAVE_LIBZ if the library is found. You
22#   should use autoheader to include a definition for this symbol in a
23#   config.h file. Sample usage in a C/C++ source is as follows:
24#
25#     #ifdef HAVE_LIBZ
26#     #include <zlib.h>
27#     #endif /* HAVE_LIBZ */
28#
29# LICENSE
30#
31#   Copyright (c) 2008 Loic Dachary <loic@senga.org>
32#
33#   This program is free software; you can redistribute it and/or modify it
34#   under the terms of the GNU General Public License as published by the
35#   Free Software Foundation; either version 2 of the License, or (at your
36#   option) any later version.
37#
38#   This program is distributed in the hope that it will be useful, but
39#   WITHOUT ANY WARRANTY; without even the implied warranty of
40#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
41#   Public License for more details.
42#
43#   You should have received a copy of the GNU General Public License along
44#   with this program. If not, see <http://www.gnu.org/licenses/>.
45#
46#   As a special exception, the respective Autoconf Macro's copyright owner
47#   gives unlimited permission to copy, distribute and modify the configure
48#   scripts that are the output of Autoconf when processing the Macro. You
49#   need not follow the terms of the GNU General Public License when using
50#   or distributing such scripts, even though portions of the text of the
51#   Macro appear in them. The GNU General Public License (GPL) does govern
52#   all other use of the material that constitutes the Autoconf Macro.
53#
54#   This special exception to the GPL applies to versions of the Autoconf
55#   Macro released by the Autoconf Archive. When you make and distribute a
56#   modified version of the Autoconf Macro, you may extend this special
57#   exception to the GPL to apply to your modified version as well.
58
59#serial 7
60
61AU_ALIAS([CHECK_ZLIB], [AX_CHECK_ZLIB])
62AC_DEFUN([AX_CHECK_ZLIB],
63#
64# Handle user hints
65#
66[AC_MSG_CHECKING(if zlib is wanted)
67AC_ARG_WITH(zlib,
68[  --with-zlib=DIR root directory path of zlib installation [defaults to
69                    /usr/local or /usr if not found in /usr/local]
70  --without-zlib to disable zlib usage completely],
71[if test "$withval" != no ; then
72  AC_MSG_RESULT(yes)
73  if test -d "$withval"
74  then
75    ZLIB_HOME="$withval"
76  else
77    AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
78  fi
79else
80  AC_MSG_RESULT(no)
81fi],
82[AC_MSG_RESULT(yes)])
83
84ZLIB_HOME=/usr/local
85if test ! -f "${ZLIB_HOME}/include/zlib.h"
86then
87        ZLIB_HOME=/usr
88fi
89
90#
91# Locate zlib, if wanted
92#
93if test -n "${ZLIB_HOME}"
94then
95        ZLIB_OLD_LDFLAGS=$LDFLAGS
96        ZLIB_OLD_CPPFLAGS=$LDFLAGS
97        LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
98        CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
99        AC_LANG_SAVE
100        AC_LANG_C
101        AC_CHECK_LIB(z, inflateEnd, [zlib_cv_libz=yes], [zlib_cv_libz=no])
102        AC_CHECK_HEADER(zlib.h, [zlib_cv_zlib_h=yes], [zlib_cv_zlib_h=no])
103        AC_LANG_RESTORE
104        if test "$zlib_cv_libz" = "yes" -a "$zlib_cv_zlib_h" = "yes"
105        then
106                #
107                # If both library and header were found, use them
108                #
109                AC_CHECK_LIB(z, inflateEnd)
110                AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
111                AC_MSG_RESULT(ok)
112				ZLIB="-lz"
113				AC_SUBST(ZLIB)
114        else
115                #
116                # If either header or library was not found, revert and bomb
117                #
118                AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
119                LDFLAGS="$ZLIB_OLD_LDFLAGS"
120                CPPFLAGS="$ZLIB_OLD_CPPFLAGS"
121                AC_MSG_RESULT(failed)
122                AC_MSG_ERROR(either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib)
123        fi
124fi
125
126])
127