1 # Allow the builder to specify an external ZLIB rather than the version
2 # distributed with CVS.
5 # Anthon Pang <apang@telux.net>,
6 # Derek R. Price, Ximbiot <http://ximbiot.com>,
7 # and the Free Software Foundation, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # ACX_WITH_EXTERNAL_ZLIB
26 # Determine which ZLIB to use.
27 AC_DEFUN([ACX_WITH_EXTERNAL_ZLIB],[
29 # Use --with-zlib to build with a zlib other than the version distributed
32 # defaults to the included snapshot of zlib
34 AC_ARG_WITH([external-zlib],
35 AC_HELP_STRING([--with-external-zlib],
36 [Use the specified ZLIB library (defaults to
37 the version distributed with the CVS source)]),
38 [with_external_zlib=$withval],
39 [with_external_zlib=no])
42 # Try to locate a ZLIB installation if no location was specified, assuming
43 # external ZLIB was enabled.
45 if test -n "$acx_zlib_cv_external_zlib"; then
46 # Granted, this is a slightly ugly way to print this info, but the
47 # AC_CHECK_HEADER used in the search for a ZLIB installation makes using
48 # AC_CACHE_CHECK worse
49 AC_MSG_CHECKING([for external ZLIB])
51 AC_CACHE_VAL([acx_zlib_cv_external_zlib], [
53 # --with but no location specified
54 # assume zlib.h locates our install.
56 acx_zlib_save_CPPFLAGS=$CPPFLAGS
57 for acx_zlib_cv_external_zlib in yes /usr/local no; do
58 if test x$acx_zlib_cv_external_zlib = xno; then
61 if test x$acx_zlib_cv_external_zlib = xyes; then
62 AC_MSG_CHECKING([for external ZLIB])
65 CPPFLAGS="$acx_zlib_save_CPPFLAGS -I$acx_zlib_cv_external_zlib/include"
66 AC_MSG_CHECKING([for external ZLIB in $acx_zlib_cv_external_zlib])
69 unset ac_cv_header_zlib_h
70 AC_CHECK_HEADERS([zlib.h])
71 if test "$ac_cv_header_zlib_h" = yes; then
75 CPPFLAGS=$acx_zlib_save_CPPFLAGS
76 AC_MSG_CHECKING([for external ZLIB])
78 AC_MSG_RESULT([$acx_zlib_cv_external_zlib])
82 # Output a pretty message naming our selected ZLIB "external" or "package"
83 # so that any warnings printed by the version check make more sense.
85 AC_MSG_CHECKING([selected ZLIB])
86 if test "x$with_external_zlib" = xno; then
87 AC_MSG_RESULT([package])
89 AC_MSG_RESULT([external])
94 # Verify that the ZLIB we aren't using isn't newer than the one we are.
96 if test "x$acx_zlib_cv_external_zlib" != xno; then
97 LOCAL_ZLIB_VERSION=`sed -n '/^#define ZLIB_VERSION ".*"$/{
98 s/^#define ZLIB_VERSION "\(.*\)"$/\1/;
99 p;}' <$srcdir/zlib/zlib.h 2>&AS_MESSAGE_LOG_FD`
100 ACX_EXTRACT_HEADER_DEFN([ZLIB_VERSION], [zlib.h])
101 ZLIB_VERSION=`echo "$ZLIB_VERSION" |sed 's/"//g'`
102 ASX_VERSION_COMPARE([$LOCAL_ZLIB_VERSION], [$ZLIB_VERSION],
103 [if test "x$with_external_zlib" = xno; then
105 [Found external ZLIB with a more recent version than the
106 package version ($ZLIB_VERSION > $LOCAL_ZLIB_VERSION). configure with the
107 --with-external-zlib option to select the more recent version.])
110 [if test "x$with_external_zlib" != xno; then
112 [Package ZLIB is more recent than requested external version
113 ($LOCAL_ZLIB_VERSION > $ZLIB_VERSION). configure with the --without-external-zlib
114 option to select the more recent version.])
119 # Now set with_external_zlib to our discovered value or the user specified
120 # value, as appropriate.
121 if test x$with_external_zlib = xyes; then
122 with_external_zlib=$acx_zlib_cv_external_zlib
124 # $with_external_zlib could still be "no"
128 # Set up ZLIB includes for later use.
130 if test x$with_external_zlib != xyes \
131 && test x$with_external_zlib != no; then
132 if test -z "$CPPFLAGS"; then
133 CPPFLAGS="-I$with_external_zlib/include"
135 CPPFLAGS="$CPPFLAGS -I$with_external_zlib/include"
137 if test -z "$LDFLAGS"; then
138 LDFLAGS="-L$with_external_zlib/lib"
140 LDFLAGS="$LDFLAGS -L$with_external_zlib/lib"
147 if test x$with_external_zlib = xno; then
148 # We need ZLIB_CPPFLAGS so that later executions of cpp from configure
149 # don't try to interpret $(top_srcdir)
150 ZLIB_CPPFLAGS='-I$(top_srcdir)/zlib'
151 ZLIB_LIBS='$(top_builddir)/zlib/libz.a'
152 # ZLIB_SUBDIRS is only used in the top level Makefiles.
155 # We know what to do now, so set up the CPPFLAGS, LDFLAGS, and LIBS for later
157 if test -z "$LIBS"; then
164 # Verify external installed zlib works
166 # Ideally, we would also check that the version is newer
168 AC_MSG_CHECKING([that ZLIB library works])
169 AC_TRY_LINK([#include <zlib.h>],
170 [int i = Z_OK; const char *version = zlibVersion();],
171 [AC_MSG_RESULT([yes])],
173 AC_MSG_ERROR([ZLIB failed to link])])
176 dnl Subst for the local case
177 AC_SUBST(ZLIB_SUBDIRS)dnl
178 AC_SUBST(ZLIB_CPPFLAGS)dnl
179 AC_SUBST(ZLIB_LIBS)dnl