]> git.donarmstrong.com Git - fastq-tools.git/blob - m4/ax_check_zlib.m4
Much simpler faster code for parsing fastq files.
[fastq-tools.git] / m4 / ax_check_zlib.m4
1 # ===========================================================================
2 #       http://www.gnu.org/software/autoconf-archive/ax_check_zlib.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_CHECK_ZLIB()
8 #
9 # DESCRIPTION
10 #
11 #   This macro searches for an installed zlib library. If nothing was
12 #   specified when calling configure, it searches first in /usr/local and
13 #   then in /usr, /opt/local and /sw. If the --with-zlib=DIR is specified,
14 #   it will try to find it in DIR/include/zlib.h and DIR/lib/libz.a. If
15 #   --without-zlib is specified, the library is not searched at all.
16 #
17 #   If either the header file (zlib.h) or the library (libz) is not found,
18 #   the configuration exits on error, asking for a valid zlib installation
19 #   directory or --without-zlib.
20 #
21 #   The macro defines the symbol HAVE_LIBZ if the library is found. You
22 #   should use autoheader to include a definition for this symbol in a
23 #   config.h file. Sample usage in a C/C++ source is as follows:
24 #
25 #     #ifdef HAVE_LIBZ
26 #     #include <zlib.h>
27 #     #endif /* HAVE_LIBZ */
28 #
29 # LICENSE
30 #
31 #   Copyright (c) 2008 Loic Dachary <loic@senga.org>
32 #   Copyright (c) 2010 Bastien Chevreux <bach@chevreux.org>
33 #
34 #   This program is free software; you can redistribute it and/or modify it
35 #   under the terms of the GNU General Public License as published by the
36 #   Free Software Foundation; either version 2 of the License, or (at your
37 #   option) any later version.
38 #
39 #   This program is distributed in the hope that it will be useful, but
40 #   WITHOUT ANY WARRANTY; without even the implied warranty of
41 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
42 #   Public License for more details.
43 #
44 #   You should have received a copy of the GNU General Public License along
45 #   with this program. If not, see <http://www.gnu.org/licenses/>.
46 #
47 #   As a special exception, the respective Autoconf Macro's copyright owner
48 #   gives unlimited permission to copy, distribute and modify the configure
49 #   scripts that are the output of Autoconf when processing the Macro. You
50 #   need not follow the terms of the GNU General Public License when using
51 #   or distributing such scripts, even though portions of the text of the
52 #   Macro appear in them. The GNU General Public License (GPL) does govern
53 #   all other use of the material that constitutes the Autoconf Macro.
54 #
55 #   This special exception to the GPL applies to versions of the Autoconf
56 #   Macro released by the Autoconf Archive. When you make and distribute a
57 #   modified version of the Autoconf Macro, you may extend this special
58 #   exception to the GPL to apply to your modified version as well.
59
60 #serial 8
61
62 AU_ALIAS([CHECK_ZLIB], [AX_CHECK_ZLIB])
63 AC_DEFUN([AX_CHECK_ZLIB],
64 #
65 # Handle user hints
66 #
67 [AC_MSG_CHECKING(if zlib is wanted)
68 AC_ARG_WITH(zlib,
69 [  --with-zlib=DIR root directory path of zlib installation [defaults to
70                     /usr/local or /usr if not found in /usr/local]
71   --without-zlib to disable zlib usage completely],
72 [if test "$withval" != no ; then
73   zlib_places="/usr/local /usr /opt/local /sw"
74   AC_MSG_RESULT(yes)
75   if test -d "$withval"
76   then
77     zlib_places="$withval $zlib_places"
78   else
79     AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
80   fi
81 else
82   AC_MSG_RESULT(no)
83 fi],
84 [AC_MSG_RESULT(yes)])
85
86 #
87 # Locate zlib, if wanted
88 #
89 if test -n "${zlib_places}"
90 then
91         # check the user supplied or any other more or less 'standard' place:
92         #   Most UNIX systems      : /usr/local and /usr
93         #   MacPorts / Fink on OSX : /opt/local respectively /sw
94         for ZLIB_HOME in ${zlib_places} ; do
95           if test -f "${ZLIB_HOME}/include/zlib.h"; then break; fi
96           ZLIB_HOME=""
97         done
98
99         # if zlib.h was nowhere to be found, give a notice and bail out
100         if test ! -n "${ZLIB_HOME}"; then
101           AC_MSG_ERROR(No zlib.h in any include directory of ${zlib_places}: either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib)
102         fi
103
104         ZLIB_OLD_LDFLAGS=$LDFLAGS
105         ZLIB_OLD_CPPFLAGS=$LDFLAGS
106         LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
107         CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
108         AC_LANG_SAVE
109         AC_LANG_C
110         AC_CHECK_LIB(z, inflateEnd, [zlib_cv_libz=yes], [zlib_cv_libz=no])
111         AC_CHECK_HEADER(zlib.h, [zlib_cv_zlib_h=yes], [zlib_cv_zlib_h=no])
112         AC_LANG_RESTORE
113         if test "$zlib_cv_libz" = "yes" -a "$zlib_cv_zlib_h" = "yes"
114         then
115                 #
116                 # If both library and header were found, use them
117                 #
118                 AC_CHECK_LIB(z, inflateEnd)
119                 AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
120                 AC_MSG_RESULT(ok)
121         else
122                 #
123                 # If either header or library was not found, revert and bomb
124                 #
125                 AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
126                 LDFLAGS="$ZLIB_OLD_LDFLAGS"
127                 CPPFLAGS="$ZLIB_OLD_CPPFLAGS"
128                 AC_MSG_RESULT(failed)
129                 AC_MSG_ERROR(either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib)
130         fi
131 fi
132
133 ])