922cbcbcd5653907d765c02be3ab1285883fb48c
[xfstests-dev.git] / m4 / package_gdbmdev.m4
1 AC_DEFUN([AC_PACKAGE_WANT_GDBM],
2   [
3     have_db=
4     AC_CHECK_HEADER(gdbm-ndbm.h,
5       [
6         have_db=true
7         AC_DEFINE(HAVE_GDBM_NDBM_H, [1],
8                   [Define to 1 if you have the <gdbm-ndbm.h> header file.])
9       ])
10
11     if test -z "$have_db"; then
12       dnl gdbm-ndbm.h and gdbm/ndbm.h map to the same autoconf internal
13       dnl variable.  We need to clear it or this test will be skipped
14       dnl and the cached result from first test will be used.
15       AS_UNSET([ac_cv_header_gdbm_ndbm_h])
16       AC_CHECK_HEADER(gdbm/ndbm.h,
17         [
18           have_db=true
19           AC_DEFINE(HAVE_GDBM_NDBM_H_, [1],
20                     [Define to 1 if you have the <gdbm/ndbm.h> header file.])
21         ])
22     fi
23
24     if test -z "$have_db"; then
25       AC_CHECK_HEADER(gdbm.h,
26         [
27           have_db=true
28           gdbm_ndbm_=true
29         ], [
30           have_db=false
31           gdbm_ndbm_=false
32         ])
33       AC_CHECK_HEADER(ndbm.h,
34         [
35           ndbm_=true
36         ], [
37           ndbm_=false
38         ])
39         if test $gdbm_ndbm_ = true; then
40           if test $ndbm_ = true; then
41             AC_DEFINE(HAVE_GDBM_H, [1],
42                       [Define to 1 if you have both <gdbm.h> and <ndbm.h> header files.])
43           fi
44         fi
45     fi
46
47     if test "$have_db" = true; then
48       found=false
49       AC_CHECK_LIB(gdbm, dbm_open, found=true, found=false)
50       AC_CHECK_LIB(gdbm, dbm_fetch,, found=false)
51       AC_CHECK_LIB(gdbm, dbm_store,, found=false)
52       AC_CHECK_LIB(gdbm, dbm_close,, found=false)
53
54       if test "$found" = true; then
55         libgdbm="-lgdbm"
56       else
57         AC_CHECK_LIB(gdbm_compat, dbm_open, found=true, found=false, -lgdbm)
58         AC_CHECK_LIB(gdbm_compat, dbm_fetch,, found=false, -lgdbm)
59         AC_CHECK_LIB(gdbm_compat, dbm_store,, found=false, -lgdbm)
60         AC_CHECK_LIB(gdbm_compat, dbm_close,, found="no", -lgdbm)
61
62         if test "$found" = "true"; then
63           libgdbm="-lgdbm_compat -lgdbm"
64         fi
65       fi
66     fi
67
68     AC_SUBST(libgdbm)
69     AC_SUBST(have_db)
70   ])
71