diff --git a/configure b/configure
index 93751ed84eed5da7f3a99d3524d2b9f8b96c2755..b827374cfa7ea014d8578293fbaa0fd0108a7ce4 100755
--- a/configure
+++ b/configure
@@ -13890,6 +13890,10 @@ _ACEOF
 fi
 
 
+if test "x$LIBUUID_LIB" != "x" ; then
+  UUID_INCLUDE="$LIBUUID_INCLUDE"
+  UUID_LIB="$LIBUUID_LIB"
+else
 
 if test "x${PBX_E2FSUUID}" != "x1" -a "${USE_E2FSUUID}" != "no"; then
    pbxlibdir=""
@@ -13986,7 +13990,11 @@ _ACEOF
 fi
 
 
-for ac_func in uuid_generate_random
+  if test "x$E2FSUUID_LIB" != "x" ; then
+    UUID_INCLUDE="$E2FSUUID_INCLUDE"
+    UUID_LIB="$E2FSUUID_LIB"
+  else
+    for ac_func in uuid_generate_random
 do :
   ac_fn_c_check_func "$LINENO" "uuid_generate_random" "ac_cv_func_uuid_generate_random"
 if test "x$ac_cv_func_uuid_generate_random" = xyes; then :
@@ -13999,18 +14007,13 @@ else
 fi
 done
 
-
-if test "x$LIBUUID_LIB" != "x" ; then
-  UUID_INCLUDE="$LIBUUID_INCLUDE"
-  UUID_LIB="$LIBUUID_LIB"
-elif test "x$E2FSUUID_LIB" != "x" ; then
-  UUID_INCLUDE="$E2FSUUID_INCLUDE"
-  UUID_LIB="$E2FSUUID_LIB"
-elif test "x$SYSUUID" != "x" ; then
-  UUID_INCLUDE=""
-  UUID_LIB=""
-else
-  as_fn_error $? "*** uuid support not found (this typically means the uuid development package is missing)" "$LINENO" 5
+    if test "x$SYSUUID" != "x" ; then
+      UUID_INCLUDE=""
+      UUID_LIB=""
+    else
+      as_fn_error $? "*** uuid support not found (this typically means the uuid development package is missing)" "$LINENO" 5
+    fi
+  fi
 fi
 
 
diff --git a/configure.ac b/configure.ac
index 47d26e298dd6b620d70b7dcca33f6730eeb79fb0..1895c41850d934b89634ce594e26867783601a79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -638,20 +638,23 @@ AC_SUBST(EDITLINE_LIB)
 #  * -le2fs-uuid on OpenBSD
 #  * in libsystem on OS X
 AST_EXT_LIB_CHECK([LIBUUID], [uuid], [uuid_generate_random], [uuid/uuid.h], [])
-AST_EXT_LIB_CHECK([E2FSUUID], [e2fs-uuid], [uuid_generate_random], [uuid/uuid.h], [])
-AC_CHECK_FUNCS([uuid_generate_random], [SYSUUID=true], [SYSUUID=""])
-
 if test "x$LIBUUID_LIB" != "x" ; then
   UUID_INCLUDE="$LIBUUID_INCLUDE"
   UUID_LIB="$LIBUUID_LIB"
-elif test "x$E2FSUUID_LIB" != "x" ; then
-  UUID_INCLUDE="$E2FSUUID_INCLUDE"
-  UUID_LIB="$E2FSUUID_LIB"
-elif test "x$SYSUUID" != "x" ; then
-  UUID_INCLUDE=""
-  UUID_LIB=""
 else
-  AC_MSG_ERROR([*** uuid support not found (this typically means the uuid development package is missing)])
+  AST_EXT_LIB_CHECK([E2FSUUID], [e2fs-uuid], [uuid_generate_random], [uuid/uuid.h], [])
+  if test "x$E2FSUUID_LIB" != "x" ; then
+    UUID_INCLUDE="$E2FSUUID_INCLUDE"
+    UUID_LIB="$E2FSUUID_LIB"
+  else
+    AC_CHECK_FUNCS([uuid_generate_random], [SYSUUID=true], [SYSUUID=""])
+    if test "x$SYSUUID" != "x" ; then
+      UUID_INCLUDE=""
+      UUID_LIB=""
+    else
+      AC_MSG_ERROR([*** uuid support not found (this typically means the uuid development package is missing)])
+    fi
+  fi
 fi
 AC_SUBST(UUID_INCLUDE)
 AC_SUBST(UUID_LIB)