summaryrefslogtreecommitdiff
path: root/m4/ax_check_bzlib.m4
blob: 8c79c6898572204486570c188f73ee415b471786 (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
AC_DEFUN([AX_CHECK_BZLIB],
#
# Handle user hints
#
[AC_MSG_CHECKING(if bzip2 is wanted)
bzlib_places="/usr/local /usr /opt/local /sw"
AC_ARG_WITH([bzip2],
[  --with-bzip2=DIR         root directory path of bzip2 installation @<:@defaults to
                          /usr/local or /usr if not found in /usr/local@:>@
  --without-bzip2          to disable bzip2 usage completely],
[if test "$withval" != no ; then
  AC_MSG_RESULT(yes)
  if test -d "$withval"
  then
    bzlib_places="$withval $bzlib_places"
  else
    AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
  fi
else
  bzlib_places=
  AC_MSG_RESULT(no)
fi],
[AC_MSG_RESULT(yes)])

#
# Locate bzip2, if wanted
#
if test -n "${bzlib_places}"
then
	# check the user supplied or any other more or less 'standard' place:
	#   Most UNIX systems      : /usr/local and /usr
	#   MacPorts / Fink on OSX : /opt/local respectively /sw
	for bzlib_HOME in ${bzlib_places} ; do
	  if test -f "${bzlib_HOME}/include/bzlib.h"; then break; fi
	  bzlib_HOME=""
	done

  bzlib_OLD_LDFLAGS=$LDFLAGS
  bzlib_OLD_CPPFLAGS=$CPPFLAGS
  if test -n "${bzlib_HOME}"; then
        LDFLAGS="$LDFLAGS -L${bzlib_HOME}/lib"
        CPPFLAGS="$CPPFLAGS -I${bzlib_HOME}/include"
  fi
  AC_LANG_SAVE
  AC_LANG_C
  AC_CHECK_LIB([bz2], [BZ2_bzDecompressInit], [bzlib_cv_libbz2=yes], [bzlib_cv_libbz2=no])
  AC_CHECK_HEADER([bzlib.h], [bzlib_cv_bzlib_h=yes], [bzlib_cv_bzlib_h=no])
  AC_LANG_RESTORE
  if test "$bzlib_cv_libbz2" = "yes" && test "$bzlib_cv_bzlib_h" = "yes"
  then
    #
    # If both library and header were found, action-if-found
    #
    m4_ifblank([$1],[
                CPPFLAGS="$CPPFLAGS -I${bzlib_HOME}/include"
                LDFLAGS="$LDFLAGS -L${bzlib_HOME}/lib"
                LIBS="-lbz2 $LIBS"
                AC_DEFINE([HAVE_BZLIB], [1],
                          [Define to 1 if you have `bz2' library (-lbz2)])
               ],[
                # Restore variables
                LDFLAGS="$bzlib_OLD_LDFLAGS"
                CPPFLAGS="$bzlib_OLD_CPPFLAGS"
                $1
               ])
  else
    #
    # If either header or library was not found, action-if-not-found
    #
    m4_default([$2],[
                AC_MSG_ERROR([either specify a valid bzip2 installation with --with-bzip2=DIR or disable bzip2 usage with --without-bzip2])
                ])
  fi
fi
])