PageRenderTime 37ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/m4/ax_check_zlib.m4

http://github.com/mozy/mordor
m4 | 149 lines | 64 code | 5 blank | 80 comment | 0 complexity | fddf46115319cde6000d0c17a7eb7c23 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_check_zlib.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_ZLIB([action-if-found], [action-if-not-found])
  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. # shell commands 'action-if-not-found' is run. If 'action-if-not-found' is
  19. # not specified, the configuration exits on error, asking for a valid zlib
  20. # installation directory or --without-zlib.
  21. #
  22. # If both header file and library are found, shell commands
  23. # 'action-if-found' is run. If 'action-if-found' is not specified, the
  24. # default action appends '-I${ZLIB_HOME}/include' to CPFLAGS, appends
  25. # '-L$ZLIB_HOME}/lib' to LDFLAGS, prepends '-lz' to LIBS, and calls
  26. # AC_DEFINE(HAVE_LIBZ). You should use autoheader to include a definition
  27. # for this symbol in a config.h file. Sample usage in a C/C++ source is as
  28. # follows:
  29. #
  30. # #ifdef HAVE_LIBZ
  31. # #include <zlib.h>
  32. # #endif /* HAVE_LIBZ */
  33. #
  34. # LICENSE
  35. #
  36. # Copyright (c) 2008 Loic Dachary <loic@senga.org>
  37. # Copyright (c) 2010 Bastien Chevreux <bach@chevreux.org>
  38. #
  39. # This program is free software; you can redistribute it and/or modify it
  40. # under the terms of the GNU General Public License as published by the
  41. # Free Software Foundation; either version 2 of the License, or (at your
  42. # option) any later version.
  43. #
  44. # This program is distributed in the hope that it will be useful, but
  45. # WITHOUT ANY WARRANTY; without even the implied warranty of
  46. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  47. # Public License for more details.
  48. #
  49. # You should have received a copy of the GNU General Public License along
  50. # with this program. If not, see <http://www.gnu.org/licenses/>.
  51. #
  52. # As a special exception, the respective Autoconf Macro's copyright owner
  53. # gives unlimited permission to copy, distribute and modify the configure
  54. # scripts that are the output of Autoconf when processing the Macro. You
  55. # need not follow the terms of the GNU General Public License when using
  56. # or distributing such scripts, even though portions of the text of the
  57. # Macro appear in them. The GNU General Public License (GPL) does govern
  58. # all other use of the material that constitutes the Autoconf Macro.
  59. #
  60. # This special exception to the GPL applies to versions of the Autoconf
  61. # Macro released by the Autoconf Archive. When you make and distribute a
  62. # modified version of the Autoconf Macro, you may extend this special
  63. # exception to the GPL to apply to your modified version as well.
  64. #serial 14
  65. AU_ALIAS([CHECK_ZLIB], [AX_CHECK_ZLIB])
  66. AC_DEFUN([AX_CHECK_ZLIB],
  67. #
  68. # Handle user hints
  69. #
  70. [AC_MSG_CHECKING(if zlib is wanted)
  71. zlib_places="/usr/local /usr /opt/local /sw"
  72. AC_ARG_WITH([zlib],
  73. [ --with-zlib=DIR root directory path of zlib installation @<:@defaults to
  74. /usr/local or /usr if not found in /usr/local@:>@
  75. --without-zlib to disable zlib usage completely],
  76. [if test "$withval" != no ; then
  77. AC_MSG_RESULT(yes)
  78. if test -d "$withval"
  79. then
  80. zlib_places="$withval $zlib_places"
  81. else
  82. AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
  83. fi
  84. else
  85. zlib_places=
  86. AC_MSG_RESULT(no)
  87. fi],
  88. [AC_MSG_RESULT(yes)])
  89. #
  90. # Locate zlib, if wanted
  91. #
  92. if test -n "${zlib_places}"
  93. then
  94. # check the user supplied or any other more or less 'standard' place:
  95. # Most UNIX systems : /usr/local and /usr
  96. # MacPorts / Fink on OSX : /opt/local respectively /sw
  97. for ZLIB_HOME in ${zlib_places} ; do
  98. if test -f "${ZLIB_HOME}/include/zlib.h"; then break; fi
  99. ZLIB_HOME=""
  100. done
  101. ZLIB_OLD_LDFLAGS=$LDFLAGS
  102. ZLIB_OLD_CPPFLAGS=$CPPFLAGS
  103. if test -n "${ZLIB_HOME}"; then
  104. LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
  105. CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
  106. fi
  107. AC_LANG_SAVE
  108. AC_LANG_C
  109. AC_CHECK_LIB([z], [inflateEnd], [zlib_cv_libz=yes], [zlib_cv_libz=no])
  110. AC_CHECK_HEADER([zlib.h], [zlib_cv_zlib_h=yes], [zlib_cv_zlib_h=no])
  111. AC_LANG_RESTORE
  112. if test "$zlib_cv_libz" = "yes" && test "$zlib_cv_zlib_h" = "yes"
  113. then
  114. #
  115. # If both library and header were found, action-if-found
  116. #
  117. m4_ifblank([$1],[
  118. CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
  119. LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
  120. LIBS="-lz $LIBS"
  121. AC_DEFINE([HAVE_LIBZ], [1],
  122. [Define to 1 if you have `z' library (-lz)])
  123. ],[
  124. # Restore variables
  125. LDFLAGS="$ZLIB_OLD_LDFLAGS"
  126. CPPFLAGS="$ZLIB_OLD_CPPFLAGS"
  127. $1
  128. ])
  129. else
  130. #
  131. # If either header or library was not found, action-if-not-found
  132. #
  133. m4_default([$2],[
  134. AC_MSG_ERROR([either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib])
  135. ])
  136. fi
  137. fi
  138. ])
  139. dnl If needed, define the m4_ifblank macros from autoconf 2.64
  140. dnl This allows us to run with earlier Autoconfs as well.
  141. ifdef([m4_ifblank],[],[
  142. m4_define([m4_ifblank],
  143. [m4_if(m4_translit([[$1]], [ ][ ][
  144. ]), [], [$2], [$3])])])