Home | History | Annotate | Line # | Download | only in m4
      1 # Allow the builder to specify an external ZLIB rather than the version
      2 # distributed with CVS.
      3 
      4 # Copyright (c) 2003
      5 #		Anthon Pang <apang (a] telux.net>,
      6 #               Derek R. Price, Ximbiot <http://ximbiot.com>,
      7 #               and the Free Software Foundation, Inc.
      8 
      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)
     12 # any later version.
     13 
     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.
     18 
     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
     22 # 02111-1307, USA.
     23 
     24 # ACX_WITH_EXTERNAL_ZLIB
     25 # -------------------
     26 # Determine which ZLIB to use.
     27 AC_DEFUN([ACX_WITH_EXTERNAL_ZLIB],[
     28 #
     29 # Use --with-zlib to build with a zlib other than the version distributed
     30 # with CVS.
     31 #
     32 # defaults to the included snapshot of zlib
     33 #
     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])
     40 
     41 #
     42 # Try to locate a ZLIB installation if no location was specified, assuming
     43 # external ZLIB was enabled.
     44 # 
     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])
     50 else :; fi
     51 AC_CACHE_VAL([acx_zlib_cv_external_zlib], [
     52   #
     53   # --with but no location specified
     54   # assume zlib.h locates our install.
     55   #
     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
     59       break
     60     fi
     61     if test x$acx_zlib_cv_external_zlib = xyes; then
     62       AC_MSG_CHECKING([for external ZLIB])
     63       AC_MSG_RESULT([])
     64     else
     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])
     67       AC_MSG_RESULT([])
     68     fi
     69     unset ac_cv_header_zlib_h
     70     AC_CHECK_HEADERS([zlib.h])
     71     if test "$ac_cv_header_zlib_h" = yes; then
     72       break
     73     fi
     74   done
     75   CPPFLAGS=$acx_zlib_save_CPPFLAGS
     76 AC_MSG_CHECKING([for external ZLIB])
     77 ])dnl
     78 AC_MSG_RESULT([$acx_zlib_cv_external_zlib])
     79 
     80 
     81 #
     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.
     84 #
     85 AC_MSG_CHECKING([selected ZLIB])
     86 if test "x$with_external_zlib" = xno; then
     87   AC_MSG_RESULT([package])
     88 else
     89   AC_MSG_RESULT([external])
     90 fi
     91 
     92 
     93 #
     94 # Verify that the ZLIB we aren't using isn't newer than the one we are.
     95 #
     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
    104        AC_MSG_WARN(
    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.])
    108      fi],
    109     [],
    110     [if test "x$with_external_zlib" != xno; then
    111        AC_MSG_WARN(
    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.])
    115      fi])
    116 fi
    117 
    118 
    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
    123 fi
    124 # $with_external_zlib could still be "no"
    125 
    126 
    127 #
    128 # Set up ZLIB includes for later use.
    129 #
    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"
    134   else
    135     CPPFLAGS="$CPPFLAGS -I$with_external_zlib/include"
    136   fi
    137   if test -z "$LDFLAGS"; then
    138     LDFLAGS="-L$with_external_zlib/lib"
    139   else
    140     LDFLAGS="$LDFLAGS -L$with_external_zlib/lib"
    141   fi
    142 fi
    143 
    144 ZLIB_CPPFLAGS=
    145 ZLIB_LIBS=
    146 ZLIB_SUBDIRS=
    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.
    153   ZLIB_SUBDIRS=zlib
    154 else
    155   # We know what to do now, so set up the CPPFLAGS, LDFLAGS, and LIBS for later
    156   # use.
    157   if test -z "$LIBS"; then
    158     LIBS=-lz
    159   else
    160     LIBS="$LIBS -lz"
    161   fi
    162 
    163   #
    164   # Verify external installed zlib works
    165   #
    166   # Ideally, we would also check that the version is newer
    167   #
    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])],
    172               [AC_MSG_RESULT([no])
    173                AC_MSG_ERROR([ZLIB failed to link])])
    174 fi
    175 
    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
    180 ])
    181