1# -*- Autoconf -*- 2# This file is part of the aMule Project. 3# 4# Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5# 6# Any parts of this program derived from the xMule, lMule or eMule project, 7# or contributed by third-party developers are copyrighted by their 8# respective authors. 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 2 of the License, or 13# (at your option) any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program; if not, write to the Free Software 22# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 23# 24 25dnl ---------------------------------------------------- 26dnl MULE_CHECK_ZLIB([MIN_ZLIB_VERSION = 1.1.4], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 27dnl 28dnl check if zlib is on the system and is at least MIN_ZLIB_VERSION 29dnl 30dnl Add support for --with-zlib command-line parameter. 31dnl PREFIX may be a directory prefix where zlib is installed, e.g. /usr/local 32dnl or may be one of the following special keywords: 33dnl sys - use system zlib 34dnl 35dnl Will set the output variables: 36dnl ZLIB_CPPFLAGS 37dnl ZLIB_LDFLAGS 38dnl ZLIB_LIBS 39dnl ---------------------------------------------------- 40AC_DEFUN([MULE_CHECK_ZLIB], 41[dnl 42m4_define([MIN_ZLIB_VERSION], [m4_ifval([$1], [$1], [1.1.4])])dnl 43m4_define([zver_max], [m4_bregexp(MIN_ZLIB_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\1])])dnl 44m4_define([zver_mid], [m4_bregexp(MIN_ZLIB_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\2])])dnl 45m4_define([zver_min], [m4_bregexp(MIN_ZLIB_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\3])])dnl 46 47 AC_ARG_WITH([zlib], AS_HELP_STRING([--with-zlib=PREFIX], [use zlib in PREFIX])) 48 49 case "${with_zlib:-yes}" in 50 no) 51 $3 52 ;; 53 yes | sys) 54 ;; 55 *) 56 zlib_prefix="$with_zlib" 57 esac 58 59 MULE_BACKUP([CPPFLAGS]) 60 MULE_BACKUP([LDFLAGS]) 61 MULE_BACKUP([LIBS]) 62 AS_IF([test -n "$zlib_prefix"], 63 [ 64 ZLIB_CPPFLAGS="-I$zlib_prefix/include" 65 ZLIB_LDFLAGS="-L$zlib_prefix/lib" 66 MULE_APPEND([CPPFLAGS], [$ZLIB_CPPFLAGS]) 67 MULE_APPEND([LDFLAGS], [$ZLIB_LDFLAGS]) 68 ], [ 69 ZLIB_CPPFLAGS= 70 ZLIB_LDFLAGS= 71 ]) 72 ZLIB_LIBS="-lz" 73 MULE_PREPEND([LIBS], [$ZLIB_LIBS]) 74 75 AC_MSG_CHECKING([for zlib >= $1]) 76 AC_RUN_IFELSE([ 77 AC_LANG_PROGRAM([[ 78 #include <zlib.h> 79 #include <stdio.h> 80 ]], [dnl Do not use double-quoting here! 81 const char *zver = zlibVersion(); 82 FILE *f=fopen("conftestval", "w"); 83 if (!f) return 1; 84 fprintf(f, "%s", 85 zver[[0]] > 'zver_max' || 86 (zver[[0]] == 'zver_max' && 87 (zver[[2]] > 'zver_mid' || 88 (zver[[2]] == 'zver_mid' && 89 zver[[4]] >= 'zver_min'))) ? "yes" : "no"); 90 fclose(f); 91 f=fopen("conftestver", "w"); 92 if (f) { 93 fprintf(f, "%s", ZLIB_VERSION); 94 fclose(f); 95 } 96 ]) 97 ], [ 98 AS_IF([test -f conftestval], [result=`cat conftestval`], [result=no]) 99 AS_IF([test ${result:-no} = yes], 100 [ 101 AS_IF([test -f conftestver], 102 [ 103 ZLIB_VERSION=`cat conftestver` 104 z_version=" (version $ZLIB_VERSION)" 105 ], [z_version=]) 106 ]) 107 AC_MSG_RESULT([$result$z_version]) 108 ], [ 109 result=no 110 AC_MSG_RESULT([$result]) 111 ], [ 112 result=no 113 z_version= 114 AC_LINK_IFELSE([ 115 AC_LANG_PROGRAM([[ 116 #include <zlib.h> 117 #include <stdio.h> 118 ]], [[ 119 printf("\nZLIB_VERSION_START" ZLIB_VERSION "ZLIB_VERSION_END\n\n"); 120 zlibVersion(); 121 ]]) 122 ], [ 123 ZLIB_VERSION=`grep -a '^ZLIB_VERSION_START.*ZLIB_VERSION_END$' conftest$ac_exeext | sed 's/^ZLIB_VERSION_START\(.*\)ZLIB_VERSION_END$/\1/'` 124 cross_zver_max="`echo $ZLIB_VERSION | cut -d. -f1`" 125 cross_zver_mid="`echo $ZLIB_VERSION | cut -d. -f2`" 126 cross_zver_min="`echo $ZLIB_VERSION | cut -d. -f3`" 127 MULE_IF([test "$cross_zver_max" -gt "zver_max"], [result=yes], 128 [test "$cross_zver_max" -eq "zver_max"], [ 129 MULE_IF([test "$cross_zver_mid" -gt "zver_mid"], [result=yes], 130 [test "$cross_zver_mid" -eq "zver_mid"], 131 [MULE_IF([test "$cross_zver_min" -ge "zver_min"], [result=yes])]) 132 ]) 133 AS_IF([test ${result:-no} = yes], [z_version=" (version $ZLIB_VERSION)"]) 134 ]) 135 AC_MSG_RESULT([$result$z_version]) 136 ]) 137 138 MULE_RESTORE([CPPFLAGS]) 139 MULE_RESTORE([LDFLAGS]) 140 MULE_RESTORE([LIBS]) 141 142 AS_IF([test ${result:-no} = no], [ 143 ZLIB_CPPFLAGS= 144 ZLIB_LDFLAGS= 145 ZLIB_LIBS= 146 $3 147 ], [$2]) 148 149AC_SUBST([ZLIB_CPPFLAGS])dnl 150AC_SUBST([ZLIB_LDFLAGS])dnl 151AC_SUBST([ZLIB_LIBS])dnl 152m4_undefine([zver_max])dnl 153m4_undefine([zver_mid])dnl 154m4_undefine([zver_min])dnl 155m4_undefine([MIN_ZLIB_VERSION])dnl 156]) 157