Fix compile errors in FreeBSD and NetBSD.
authorPeng Huang <shawn.p.huang@gmail.com>
Sun, 11 Apr 2010 22:45:50 +0000 (06:45 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sun, 11 Apr 2010 22:45:50 +0000 (06:45 +0800)
configure.ac
src/Util.h

index 22af515..1a0ac62 100644 (file)
@@ -65,9 +65,34 @@ AC_PATH_PROG(SQLITE3, sqlite3)
 # check uuid
 PKG_CHECK_MODULES(UUID, [
     uuid
+],
+[
+    cat >>confdefs.h <<_ACEOF
+#define HAVE_UUID_UUID_H 1
+#define HAVE_UUID_GENERATE 1
+_ACEOF
+],
+[
+    uuid_revert_save_LIBS=$LIBS
+    AC_CHECK_HEADERS(uuid.h uuid/uuid.h sys/uuid.h)
+    AC_SEARCH_LIBS(uuid_create, uuid, [
+        if test "$ac_cv_search_uuid_create" != "none required"; then
+            UUID_LIBS=$ac_cv_search_uuid_create
+        fi
+        AC_CHECK_FUNCS(uuid_create)
+    ],
+    [
+        AC_SEARCH_LIBS(uuid_generate, uuid, [
+            if test "$ac_cv_search_uuid_generate" != "none required"; then
+                UUID_LIBS=$ac_cv_search_uuid_generate
+            fi
+            AC_CHECK_FUNCS(uuid_generate)
+        ])
+    ])
+    LIBS=$uuid_revert_save_LIBS
 ])
 
-# check uuid
+# check sigc
 PKG_CHECK_MODULES(SIGC, [
     sigc++-2.0
 ])
index 4b0dbe7..7bf4cf5 100644 (file)
@@ -1,7 +1,17 @@
 #ifndef __PY_UTIL_H_
 #define __PY_UTIL_H_
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(HAVE_UUID_H)
+#include <uuid.h>
+#elif defined(HAVE_UUID_UUID_H)
 #include <uuid/uuid.h>
+#elif defined(HAVE_SYS_UUID_H)
+#include <sys/uuid.h>
+#endif
 #include <sys/utsname.h>
 #include <stdlib.h>
 #include "String.h"
@@ -12,8 +22,16 @@ class UUID {
 public:
     UUID (void) {
         uuid_t u;
+#if defined(HAVE_UUID_CREATE)
+        gchar* uuid;
+        uuid_create (&u, 0);
+        uuid_to_string (&u, &uuid, 0);
+        g_strlcpy (m_uuid, uuid, sizeof(m_uuid));
+        free(uuid);
+#elif defined(HAVE_UUID_GENERATE)
         uuid_generate (u);
         uuid_unparse (u, m_uuid);
+#endif
     }
 
     operator const gchar * (void) const {