1 dnl @synopsis AX_LIB_ZLIB([MINIMUM-VERSION])
3 dnl Test for the libz library of a particular version (or newer).
5 dnl If no path to the installed zlib is given, the macro will first try
6 dnl using no -I or -L flags, then searches under /usr, /usr/local, /opt,
8 dnl If these all fail, it will try the $ZLIB_ROOT environment variable.
11 dnl AC_SUBST(ZLIB_CPPFLAGS)
12 dnl AC_SUBST(ZLIB_LDFLAGS)
13 dnl AC_SUBST(ZLIB_LIBS)
15 dnl And (if zlib is found):
16 dnl AC_DEFINE(HAVE_ZLIB)
18 dnl It also leaves the shell variables "success" and "ax_have_zlib"
19 dnl set to "yes" or "no".
21 dnl NOTE: This macro does not currently work for cross-compiling,
22 dnl but it can be easily modified to allow it. (grep "cross").
24 dnl @category InstalledPackages
26 dnl @author David Reiss <dreiss@facebook.com>
27 dnl @version 2007-09-12
28 dnl @license AllPermissive
30 dnl Input: ax_zlib_path, WANT_ZLIB_VERSION
31 dnl Output: success=yes/no
32 AC_DEFUN([AX_LIB_ZLIB_DO_CHECK],
35 CPPFLAGS_SAVED="$CPPFLAGS"
36 LDFLAGS_SAVED="$LDFLAGS"
38 LD_LIBRARY_PATH_SAVED="$LD_LIBRARY_PATH"
40 # Set our flags if we are checking a specific directory.
41 if test -n "$ax_zlib_path" ; then
42 ZLIB_CPPFLAGS="-I$ax_zlib_path/include"
43 ZLIB_LDFLAGS="-L$ax_zlib_path/lib"
44 LD_LIBRARY_PATH="$ax_zlib_path/lib:$LD_LIBRARY_PATH"
50 # Required flag for zlib.
53 # Prepare the environment for compilation.
54 CPPFLAGS="$CPPFLAGS $ZLIB_CPPFLAGS"
55 LDFLAGS="$LDFLAGS $ZLIB_LDFLAGS"
56 LIBS="$LIBS $ZLIB_LIBS"
60 export LD_LIBRARY_PATH
64 # Compile, link, and run the program. This checks:
65 # - zlib.h is available for including.
66 # - zlibVersion() is available for linking.
67 # - ZLIB_VERNUM is greater than or equal to the desired version.
68 # - ZLIB_VERSION (defined in zlib.h) matches zlibVersion()
69 # (defined in the library).
71 dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling.
72 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
74 #if ZLIB_VERNUM >= 0x$WANT_ZLIB_VERSION
76 # error zlib is too old
79 const char* lib_version = zlibVersion();
80 const char* hdr_version = ZLIB_VERSION;
82 if (*lib_version != *hdr_version) {
83 /* If this happens, your zlib header doesn't match your zlib */
84 /* library. That is really bad. */
87 if (*lib_version == '\0') {
100 CPPFLAGS="$CPPFLAGS_SAVED"
101 LDFLAGS="$LDFLAGS_SAVED"
103 LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED"
107 AC_DEFUN([AX_LIB_ZLIB],
110 dnl Allow search path to be overridden on the command line.
112 AS_HELP_STRING([--with-zlib@<:@=DIR@:>@], [use zlib (default is yes) - it is possible to specify an alternate root directory for zlib]),
114 if test "$withval" = "xno"; then
116 elif test "$withval" = "xyes"; then
121 ax_zlib_path="$withval"
124 [want_zlib="yes" ; ax_zlib_path="" ])
127 if test "$want_zlib" = "yes"; then
128 # Parse out the version.
129 zlib_version_req=ifelse([$1], ,1.2.3,$1)
130 zlib_version_req_major=`expr $zlib_version_req : '\([[0-9]]*\)'`
131 zlib_version_req_minor=`expr $zlib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
132 zlib_version_req_patch=`expr $zlib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
133 if test -z "$zlib_version_req_patch" ; then
134 zlib_version_req_patch="0"
136 WANT_ZLIB_VERSION=`expr $zlib_version_req_major \* 1000 \+ $zlib_version_req_minor \* 100 \+ $zlib_version_req_patch \* 10`
138 AC_MSG_CHECKING(for zlib >= $zlib_version_req)
141 if test -n "$ax_zlib_path"; then
144 for ax_zlib_path in "" /usr /usr/local /opt /opt/zlib "$ZLIB_ROOT" ; do
146 if test "$success" = "yes"; then
152 if test "$success" != "yes" ; then
159 AC_DEFINE(HAVE_ZLIB,,[define if zlib is available])
162 ax_have_zlib="$success"
164 AC_SUBST(ZLIB_CPPFLAGS)
165 AC_SUBST(ZLIB_LDFLAGS)