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 @version 2007-09-12
27 dnl @license AllPermissive
29 dnl Copyright (C) 2009 David Reiss
30 dnl Copying and distribution of this file, with or without modification,
31 dnl are permitted in any medium without royalty provided the copyright
32 dnl notice and this notice are preserved.
34 dnl Input: ax_zlib_path, WANT_ZLIB_VERSION
35 dnl Output: success=yes/no
36 AC_DEFUN([AX_LIB_ZLIB_DO_CHECK],
39 CPPFLAGS_SAVED="$CPPFLAGS"
40 LDFLAGS_SAVED="$LDFLAGS"
42 LD_LIBRARY_PATH_SAVED="$LD_LIBRARY_PATH"
44 # Set our flags if we are checking a specific directory.
45 if test -n "$ax_zlib_path" ; then
46 ZLIB_CPPFLAGS="-I$ax_zlib_path/include"
47 ZLIB_LDFLAGS="-L$ax_zlib_path/lib"
48 LD_LIBRARY_PATH="$ax_zlib_path/lib:$LD_LIBRARY_PATH"
54 # Required flag for zlib.
57 # Prepare the environment for compilation.
58 CPPFLAGS="$CPPFLAGS $ZLIB_CPPFLAGS"
59 LDFLAGS="$LDFLAGS $ZLIB_LDFLAGS"
60 LIBS="$LIBS $ZLIB_LIBS"
64 export LD_LIBRARY_PATH
68 # Compile, link, and run the program. This checks:
69 # - zlib.h is available for including.
70 # - zlibVersion() is available for linking.
71 # - ZLIB_VERNUM is greater than or equal to the desired version.
72 # - ZLIB_VERSION (defined in zlib.h) matches zlibVersion()
73 # (defined in the library).
75 dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling.
76 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
78 #if ZLIB_VERNUM >= 0x$WANT_ZLIB_VERSION
80 # error zlib is too old
83 const char* lib_version = zlibVersion();
84 const char* hdr_version = ZLIB_VERSION;
86 if (*lib_version != *hdr_version) {
87 /* If this happens, your zlib header doesn't match your zlib */
88 /* library. That is really bad. */
91 if (*lib_version == '\0') {
104 CPPFLAGS="$CPPFLAGS_SAVED"
105 LDFLAGS="$LDFLAGS_SAVED"
107 LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED"
111 AC_DEFUN([AX_LIB_ZLIB],
114 dnl Allow search path to be overridden on the command line.
116 AS_HELP_STRING([--with-zlib@<:@=DIR@:>@], [use zlib (default is yes) - it is possible to specify an alternate root directory for zlib]),
118 if test "x$withval" = "xno"; then
120 elif test "x$withval" = "xyes"; then
125 ax_zlib_path="$withval"
128 [want_zlib="yes" ; ax_zlib_path="" ])
131 if test "$want_zlib" = "yes"; then
132 # Parse out the version.
133 zlib_version_req=ifelse([$1], ,1.2.3,$1)
134 zlib_version_req_major=`expr $zlib_version_req : '\([[0-9]]*\)'`
135 zlib_version_req_minor=`expr $zlib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
136 zlib_version_req_patch=`expr $zlib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
137 if test -z "$zlib_version_req_patch" ; then
138 zlib_version_req_patch="0"
140 WANT_ZLIB_VERSION=`expr $zlib_version_req_major \* 1000 \+ $zlib_version_req_minor \* 100 \+ $zlib_version_req_patch \* 10`
142 AC_MSG_CHECKING(for zlib >= $zlib_version_req)
145 if test -n "$ax_zlib_path"; then
148 for ax_zlib_path in "" /usr /usr/local /opt /opt/zlib "$ZLIB_ROOT" ; do
150 if test "$success" = "yes"; then
156 if test "$success" != "yes" ; then
163 AC_DEFINE(HAVE_ZLIB,,[define if zlib is available])
166 ax_have_zlib="$success"
168 AC_SUBST(ZLIB_CPPFLAGS)
169 AC_SUBST(ZLIB_LDFLAGS)