diff --git a/share/configure.ac b/share/configure.ac
index 1ea8d54d0ee906608bb404a4eaa5e4d11a9210e9..76c6d96578205c9c288bc39cc01be0f1334789d9 100644
--- a/share/configure.ac
+++ b/share/configure.ac
@@ -212,6 +212,73 @@ m4_define([configure_library],
   ])
 ])
 
+# 1st param: uppercase name of the ocamlfind package
+# 2nd param: actual name of the ocamlfind package (often lowercase)
+# 3rd param: warning to display if problem
+m4_define([configure_pkg],
+[
+m4_ifdef(HAS_OCAML_$1,,
+  [
+  define([VAR],[OCAML_$1])
+  define([require],[$REQUIRE_OCAML_$1])
+  define([use],[$USE_OCAML_$1])
+  define([msg],[$3])
+  define([has],[HAS_OCAML_$1])
+
+   has=
+  AC_MSG_CHECKING(for OCaml package $2)
+  VAR=$(ocamlfind query $2 -format %v 2>/dev/null)
+  if test -z "$VAR" ; then
+    AC_MSG_RESULT(not found via ocamlfind.)
+    has=no
+  else
+    AC_MSG_RESULT(found.)
+    has=yes
+  fi
+  m4_divert_push(frama_c_configure_tool)
+  if test -n "require" -o -n "use" -o "$force_check" = "yes"; then
+    if test "$has" = "no"; then
+      AC_MSG_WARN([msg])
+      reason="$2 missing"
+      for p in require; do
+        up=`upper "$p"`
+        ep=ENABLE_$up
+        eval enable_p=\$$ep
+        if test "$enable_p" != "no"; then
+          fp=FORCE_`upper "$p"`
+          if eval test "\$$fp" = "yes"; then
+            AC_MSG_ERROR([$p requested but $reason.])
+          fi
+          eval $ep="no\ \(see\ warning\ about\ $2\)"
+          AC_MSG_WARN([$p disabled because $reason.])
+          eval INFO_$up=\", $reason\"
+        fi
+      done
+      for p in use; do
+        up=`upper "$p"`
+        ep=ENABLE_$up
+        eval eep="\$$ep"
+        if test "`echo $eep | sed -e 's/ .*//' `" != "no"; then
+          eval $ep="partial\ \(see\ warning\ about\ $2\)"
+          AC_MSG_WARN([$p partially enabled because $reason.])
+          eval INFO_$up=\", $reason\"
+        fi
+      done
+    else
+        VAR=$1
+    fi
+  fi
+  m4_divert_pop(frama_c_configure_tool)
+  AC_SUBST(VAR)
+  AC_SUBST(has)
+  undefine([VAR])
+  undefine([require])
+  undefine([use])
+  undefine([msg])
+  undefine([has])
+])
+])
+
 # 1st param: uppercase name of the program
 # 2nd param: program which must exist. See comment on configure_library()
 # on how to deal with multiple choices for a given program.
@@ -280,6 +347,7 @@ AC_CHECK_PROG(has,$file,yes,no)
 ])
 ])
 
+
 EXTERNAL_PLUGINS=
 
 define([plugin_require_external],
@@ -296,6 +364,20 @@ define([plugin_use_external],
         m4_undefine([USE])
         m4_undefine([UPORIG])])
 
+define([plugin_require_pkg],
+       [m4_define([UPORIG],[OCAML_]tovarname($2))
+        m4_define([REQUIRE],[REQUIRE_]UPORIG)
+        REQUIRE=$REQUIRE" "$1
+        m4_undefine([REQUIRE])
+        m4_undefine([UPORIG])])
+
+define([plugin_use_pkg],
+       [m4_define([UPORIG],[OCAML_]tovarname($2))
+        m4_define([USE],[USE_]UPORIG)
+        USE=$USE" "$1
+        m4_undefine([USE])
+        m4_undefine([UPORIG])])
+
 define([plugin_require],
        [m4_define([UPTARGET],tovarname($1))
         m4_define([UPORIG],tovarname($2))