build: fix <ndbm.h> detection in AC_PACKAGE_WANT_GDBM
[xfstests-dev.git] / m4 / package_gdbmdev.m4
index ae76e340eb5be0124d5125731155d243c86add78..723900fc5337b9bc755896be5699cdaf236c7ee8 100644 (file)
@@ -1,57 +1,53 @@
-AC_DEFUN([AC_PACKAGE_WANT_NDBM],
-  [ AC_CHECK_HEADERS(ndbm.h, [ have_db=true ], [ have_db=false ])
-    found=false
-    libgdbm=""
-
-    if test $have_db = true; then
-      AC_CHECK_LIB(ndbm,dbm_open,found=true,found=false)
-      AC_CHECK_LIB(ndbm,dbm_fetch,,found=false)
-      AC_CHECK_LIB(ndbm,dbm_store,,found=false)
-      AC_CHECK_LIB(ndbm,dbm_close,,found=false)
-
-      if test $found = true; then
-        libgdbm="$ndbm"
-      fi
-    fi
-
-    AC_SUBST(libgdbm)
-    AC_SUBST(have_db)
-  ])
-
 AC_DEFUN([AC_PACKAGE_WANT_GDBM],
-  [ AC_CHECK_HEADER(gdbm-ndbm.h, [ gdbm_ndbm=true; have_db=true ], [ gdbm_ndbm=false; have_db=false ])
-
-    if test $gdbm_ndbm = true; then
-        AC_DEFINE(HAVE_GDBM_NDBM_H, [1], [Define to 1 if you have the <gdbm-ndbm.h> header file.])
-    else
-        AS_UNSET([ac_cv_header_gdbm_ndbm_h])
-        AC_CHECK_HEADER(gdbm/ndbm.h, [ gdbm_ndbm_=true; have_db=true ], [ gdbm_ndbm_=false; have_db=false ])
-        if test $gdbm_ndbm_ = true; then
-            AC_DEFINE(HAVE_GDBM_NDBM_H_, [1], [Define to 1 if you have the <gdbm/ndbm.h> header file.])
-        fi
+  [
+    have_db=
+    AC_CHECK_HEADER(gdbm-ndbm.h,
+      [
+       have_db=true
+        AC_DEFINE(HAVE_GDBM_NDBM_H, [1],
+                 [Define to 1 if you have the <gdbm-ndbm.h> header file.])
+      ])
+
+    if test -z "$have_db"; then
+      dnl gdbm-ndbm.h and gdbm/ndbm.h map to the same autoconf internal
+      dnl variable.  We need to clear it or this test will be skipped
+      dnl and the cached result from first test will be used.
+      AS_UNSET([ac_cv_header_gdbm_ndbm_h])
+      AC_CHECK_HEADER(gdbm/ndbm.h,
+       [
+         have_db=true
+         AC_DEFINE(HAVE_GDBM_NDBM_H_, [1],
+                   [Define to 1 if you have the <gdbm/ndbm.h> header file.])
+       ])
     fi
 
-    found=false
-    libgdbm=""
-
-    if test $have_db = true; then
-      AC_CHECK_LIB(gdbm,dbm_open,found=true,found=false)
-      AC_CHECK_LIB(gdbm,dbm_fetch,,found=false)
-      AC_CHECK_LIB(gdbm,dbm_store,,found=false)
-      AC_CHECK_LIB(gdbm,dbm_close,,found=false)
-
-      if test $found = true; then
-        libgdbm="${libgdbm} -lgdbm"
-      fi
-
-      found="no"
-      AC_CHECK_LIB(gdbm_compat,dbm_open,found=true,found=false)
-      AC_CHECK_LIB(gdbm_compat,dbm_fetch,,found=false)
-      AC_CHECK_LIB(gdbm_compat,dbm_store,,found=false)
-      AC_CHECK_LIB(gdbm_compat,dbm_close,,found="no")
+    if test -z "$have_db"; then
+      AC_CHECK_HEADER(ndbm.h,
+       [
+         have_db=true
+         AC_DEFINE(HAVE_NDBM_H, [1],
+                   [Define to 1 if you have the <ndbm.h> header file.])
+       ])
+    fi
 
-      if test $found = true ; then
-        libgdbm="${libgdbm} -lgdbm_compat"
+    if test "$have_db" = true; then
+      found=false
+      AC_CHECK_LIB(gdbm, dbm_open, found=true, found=false)
+      AC_CHECK_LIB(gdbm, dbm_fetch,, found=false)
+      AC_CHECK_LIB(gdbm, dbm_store,, found=false)
+      AC_CHECK_LIB(gdbm, dbm_close,, found=false)
+
+      if test "$found" = true; then
+        libgdbm="-lgdbm"
+      else
+       AC_CHECK_LIB(gdbm_compat, dbm_open, found=true, found=false, -lgdbm)
+       AC_CHECK_LIB(gdbm_compat, dbm_fetch,, found=false, -lgdbm)
+       AC_CHECK_LIB(gdbm_compat, dbm_store,, found=false, -lgdbm)
+       AC_CHECK_LIB(gdbm_compat, dbm_close,, found="no", -lgdbm)
+
+       if test "$found" = "true"; then
+         libgdbm="-lgdbm_compat -lgdbm"
+       fi
       fi
     fi