1 AC_DEFUN([AC_PATH_ZLIB], [
2	AC_ARG_WITH(zlib,
3                    AC_HELP_STRING([--with-zlib=DIR],
4                                 [search for ZLIB in DIR/include and DIR/lib]),
5                    [for dir in `echo "$withval" | tr : ' '`; do
6    if test -d $dir/include; then
7      ZLIB_CFLAGS="$ZLIB_CFLAGS -I$dir/include"
8    fi
9    if test -d $dir/lib; then
10      ZLIB_LDFLAGS="$ZLIB_LDFLAGS -L$dir/lib"
11    fi
12  done[]])
13
14        AC_ARG_WITH(zlib-includes,
15                    AC_HELP_STRING([--with-zlib-includes=DIR],
16	                           [search for ZLIB includes in DIR]),
17	            [for dir in `echo "$withval" | tr : ' '`; do
18    if test -d $dir; then
19      ZLIB_CFLAGS="$ZLIB_CFLAGS -I$dir"
20    fi
21  done[]])
22
23ac_zlib_saved_CFLAGS="$CFLAGS"
24ac_zlib_saved_LDFLAGS="$LDFLAGS"
25ac_zlib_saved_LIBS="$LIBS"
26CFLAGS="$CFLAGS $ZLIB_CFLAGS"
27LDFLAGS="$LDFLAGS $ZLIB_LDFLAGS"
28ac_have_zlibh=no
29ac_have_zlib=no
30  	touch /tmp/dummy1_zlib.h
31        AC_CHECK_HEADERS([/tmp/dummy1_zlib.h], [ac_have_zlibh=yes], [ac_have_zlibh=no],
32		[#include "zlib.h"])
33	rm /tmp/dummy1_zlib.h
34 	if test $ac_have_zlibh = yes; then
35        	AC_SEARCH_LIBS(gzopen, [z], [ac_have_zlib=yes], [ac_have_zlib=no])
36	fi
37# List of places to try
38testdirs="$HOME/opt/zlib $OBITINSTALL/other"
39for dir in $testdirs; do
40	if test $ac_have_zlib = no; then
41		if  test -f $dir/include/zlib.h; then
42			ZLIB_CFLAGS="-I$dir/include"
43			CPPFLAGS="$ac_zlib_saved_CPPFLAGS $ZLIB_CFLAGS"
44			ZLIB_LDFLAGS="-L$dir/lib"
45			LDFLAGS="$ac_zlib_saved_LDFLAGS $ZLIB_LDFLAGS"
46  			touch /tmp/dummy3_zlib.h
47 		        AC_CHECK_HEADERS([/tmp/dummy3_zlib.h], [ac_have_zlibh=yes], [ac_have_zlibh=no],
48				[#include "zlib.h"])
49			rm /tmp/dummy3_zlib.h
50			if test $ac_have_zlibh = yes; then
51				# Force check
52				ac_cv_search_gzopen="  "
53		        	AC_SEARCH_LIBS(gzopen, [z], [ac_have_zlib=yes], [ac_have_zlib=no])
54			fi
55			if test $ac_have_zlib = yes ; then
56				if test $ac_have_zlibh = yes ; then
57					break;
58				fi
59			fi
60		fi
61	fi
62done[]
63if test $ac_have_zlib = no; then
64	AC_MSG_WARN([cannot find ZLIB library])
65fi
66if test $ac_have_zlibh = no; then
67	AC_MSG_WARN([cannot find ZLIB headers])
68	ac_have_zlib=no
69fi
70if test $ac_have_zlib = yes; then
71	AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if ZLIB is available.])
72fi
73ZLIB_LIBS="$LIBS"
74CFLAGS="$ac_zlib_saved_CFLAGS"
75LDFLAGS="$ac_zlib_saved_LDFLAGS"
76LIBS="$ac_zlib_saved_LIBS"
77	AC_SUBST(ZLIB_CFLAGS)
78	AC_SUBST(ZLIB_LDFLAGS)
79	AC_SUBST(ZLIB_LIBS)
80])
81