summaryrefslogtreecommitdiff
path: root/m4/acx_with_external_zlib.m4
blob: 11a5af34d4a4202b893b0e707989cc73d27bb580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Allow the builder to specify an external ZLIB rather than the version
# distributed with CVS.

# Copyright (c) 2003
#		Anthon Pang <apang@telux.net>,
#               Derek R. Price, Ximbiot <http://ximbiot.com>,
#               and the Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# ACX_WITH_EXTERNAL_ZLIB
# -------------------
# Determine which ZLIB to use.
AC_DEFUN([ACX_WITH_EXTERNAL_ZLIB],[
#
# Use --with-zlib to build with a zlib other than the version distributed
# with CVS.
#
# defaults to the included snapshot of zlib
#
AC_ARG_WITH([external-zlib],
            AC_HELP_STRING([--with-external-zlib],
                           [Use the specified ZLIB library (defaults to
                            the version distributed with the CVS source)]),
            [with_external_zlib=$withval],
            [with_external_zlib=no])

#
# Try to locate a ZLIB installation if no location was specified, assuming
# external ZLIB was enabled.
# 
if test -n "$acx_zlib_cv_external_zlib"; then
  # Granted, this is a slightly ugly way to print this info, but the
  # AC_CHECK_HEADER used in the search for a ZLIB installation makes using
  # AC_CACHE_CHECK worse
  AC_MSG_CHECKING([for external ZLIB])
else :; fi
AC_CACHE_VAL([acx_zlib_cv_external_zlib], [
  #
  # --with but no location specified
  # assume zlib.h locates our install.
  #
  acx_zlib_save_CPPFLAGS=$CPPFLAGS
  for acx_zlib_cv_external_zlib in yes /usr/local no; do
    if test x$acx_zlib_cv_external_zlib = xno; then
      break
    fi
    if test x$acx_zlib_cv_external_zlib = xyes; then
      AC_MSG_CHECKING([for external ZLIB])
      AC_MSG_RESULT([])
    else
      CPPFLAGS="$acx_zlib_save_CPPFLAGS -I$acx_zlib_cv_external_zlib/include"
      AC_MSG_CHECKING([for external ZLIB in $acx_zlib_cv_external_zlib])
      AC_MSG_RESULT([])
    fi
    unset ac_cv_header_zlib_h
    AC_CHECK_HEADERS([zlib.h])
    if test "$ac_cv_header_zlib_h" = yes; then
      break
    fi
  done
  CPPFLAGS=$acx_zlib_save_CPPFLAGS
AC_MSG_CHECKING([for external ZLIB])
])dnl
AC_MSG_RESULT([$acx_zlib_cv_external_zlib])


#
# Output a pretty message naming our selected ZLIB "external" or "package"
# so that any warnings printed by the version check make more sense.
#
AC_MSG_CHECKING([selected ZLIB])
if test "x$with_external_zlib" = xno; then
  AC_MSG_RESULT([package])
else
  AC_MSG_RESULT([external])
fi


#
# Verify that the ZLIB we aren't using isn't newer than the one we are.
#
if test "x$acx_zlib_cv_external_zlib" != xno; then
  LOCAL_ZLIB_VERSION=`sed -n '/^#define ZLIB_VERSION ".*"$/{
                              s/^#define ZLIB_VERSION "\(.*\)"$/\1/;
                              p;}' <$srcdir/zlib/zlib.h 2>&AS_MESSAGE_LOG_FD`
  ACX_EXTRACT_HEADER_DEFN([ZLIB_VERSION], [zlib.h])
  ZLIB_VERSION=`echo "$ZLIB_VERSION" |sed 's/"//g'`
  ASX_VERSION_COMPARE([$LOCAL_ZLIB_VERSION], [$ZLIB_VERSION],
    [if test "x$with_external_zlib" = xno; then
       AC_MSG_WARN(
         [Found external ZLIB with a more recent version than the
           package version ($ZLIB_VERSION > $LOCAL_ZLIB_VERSION).  configure with the
           --with-external-zlib option to select the more recent version.])
     fi],
    [],
    [if test "x$with_external_zlib" != xno; then
       AC_MSG_WARN(
         [Package ZLIB is more recent than requested external version
           ($LOCAL_ZLIB_VERSION > $ZLIB_VERSION).  configure with the --without-external-zlib
           option to select the more recent version.])
     fi])
fi


# Now set with_external_zlib to our discovered value or the user specified
# value, as appropriate.
if test x$with_external_zlib = xyes; then
  with_external_zlib=$acx_zlib_cv_external_zlib
fi
# $with_external_zlib could still be "no"


#
# Set up ZLIB includes for later use.
#
if test x$with_external_zlib != xyes \
   && test x$with_external_zlib != no; then
  if test -z "$CPPFLAGS"; then
    CPPFLAGS="-I$with_external_zlib/include"
  else
    CPPFLAGS="$CPPFLAGS -I$with_external_zlib/include"
  fi
  if test -z "$LDFLAGS"; then
    LDFLAGS="-L$with_external_zlib/lib"
  else
    LDFLAGS="$LDFLAGS -L$with_external_zlib/lib"
  fi
fi

ZLIB_CPPFLAGS=
ZLIB_LIBS=
ZLIB_SUBDIRS=
if test x$with_external_zlib = xno; then
  # We need ZLIB_CPPFLAGS so that later executions of cpp from configure
  # don't try to interpret $(top_srcdir)
  ZLIB_CPPFLAGS='-I$(top_srcdir)/zlib'
  ZLIB_LIBS='$(top_builddir)/zlib/libz.a'
  # ZLIB_SUBDIRS is only used in the top level Makefiles.
  ZLIB_SUBDIRS=zlib
else
  # We know what to do now, so set up the CPPFLAGS, LDFLAGS, and LIBS for later
  # use.
  if test -z "$LIBS"; then
    LIBS=-lz
  else
    LIBS="$LIBS -lz"
  fi

  #
  # Verify external installed zlib works
  #
  # Ideally, we would also check that the version is newer
  #
  AC_MSG_CHECKING([that ZLIB library works])
  AC_TRY_LINK([#include <zlib.h>],
              [int i = Z_OK; const char *version = zlibVersion();],
              [AC_MSG_RESULT([yes])],
              [AC_MSG_RESULT([no])
               AC_MSG_ERROR([ZLIB failed to link])])
fi

dnl Subst for the local case
AC_SUBST(ZLIB_SUBDIRS)dnl
AC_SUBST(ZLIB_CPPFLAGS)dnl
AC_SUBST(ZLIB_LIBS)dnl
])