From a067fb27c2843d27f767b691763a5ee5dc200d4d Mon Sep 17 00:00:00 2001 From: AaronMatthewBrown Date: Thu, 10 Dec 2009 14:20:48 +0000 Subject: [PATCH] Modify auto* scripts to handle the different uuid libraries/headers. --- configure.ac | 31 +++++++++++++++++++++++++++++-- src/Makefile.am | 4 ++-- src/config.h.in | 12 ++++++++++++ src/uuid.c | 17 +++++++++++++---- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index ba1e9ce..625ee73 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,7 @@ AC_PROG_RANLIB AC_PROG_LN_S AC_PROG_LIBTOOL + # Sets a conditional makefile variable so that certain Makefile tasks will be # performed only on linux (currently, add -luuid to LD_FLAGS) AM_CONDITIONAL(LINUX, [case $host_os in linux*) true;; *) false;; esac]) @@ -28,8 +29,34 @@ AM_CONDITIONAL(LINUX, [case $host_os in linux*) true;; *) false;; esac]) AC_HEADER_STDC # Check for uuid.h and a valid libuuid -AC_CHECK_HEADER(uuid/uuid.h, ,AC_MSG_ERROR([uuid/uuid.h is not available])) -AC_CHECK_LIB(uuid, uuid_generate, ,AC_MSG_ERROR([libuuid is not available])) +AC_CHECK_FUNC(uuid_create) +if test "${ac_cv_func_uuid_create}" = yes ; then + AC_DEFINE(HAVE_UUID_CREATE, [], "specifies if the uuid_create function defined") + use_uuid_library="no" +else + AC_CHECK_FUNC(uuid_generate) + if test "${ac_cv_func_uuid_generate}" = yes ; then + AC_DEFINE(HAVE_UUID_GENERATE, [], "specifies if the uuid_generate function defined") + use_uuid_library="no" + else + AC_CHECK_LIB(uuid, uuid_generate, , + AC_MSG_ERROR([libuuid is not available])) + AC_DEFINE(HAVE_UUID_GENERATE, [], "specifies if the uuid_generate function defined") + use_uuid_library="yes" + fi +fi + +AM_CONDITIONAL(USE_UUID_LIBRARY, test "${use_uuid_library}" = yes) + +AC_CHECK_HEADER(uuid.h) +if test "${ac_cv_header_uuid_h}" = yes ; then + AC_DEFINE(HAVE_UUID_H, [], "specifies if the uuid.h header exists") +else + AC_CHECK_HEADER(uuid/uuid.h) + if test "${ac_cv_header_uuid_uuid_h}" = yes ; then + AC_DEFINE(HAVE_UUID_UUID_H, [], "specifies if the uuid/uuid.h header exists") + fi +fi # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git a/src/Makefile.am b/src/Makefile.am index d2a10fe..ad6204c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,7 +37,7 @@ iperf3_CFLAGS = -g -Wall iperf3_LDADD = libiperf.a # Linux installs require the uuid library explicitly linked in -if LINUX +if USE_UUID_LIBRARY iperf3_LDFLAGS = -luuid else iperf3_LDFLAGS = @@ -73,7 +73,7 @@ iperf3_profile_CFLAGS = -pg -Wall iperf3_profile_LDADD = libiperf.a # Linux installs require the uuid library explicitly linked in -if LINUX +if USE_UUID_LIBRARY iperf3_profile_LDFLAGS = -luuid else iperf3_profile_LDFLAGS = diff --git a/src/config.h.in b/src/config.h.in index 9e9fa68..e764d3d 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -33,6 +33,18 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* "specifies if the uuid_create function defined" */ +#undef HAVE_UUID_CREATE + +/* "specifies if the uuid_generate function defined" */ +#undef HAVE_UUID_GENERATE + +/* "specifies if the uuid.h header exists" */ +#undef HAVE_UUID_H + +/* "specifies if the uuid/uuid.h header exists" */ +#undef HAVE_UUID_UUID_H + /* Name of package */ #undef PACKAGE diff --git a/src/uuid.c b/src/uuid.c index e75b542..6f62eae 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -1,12 +1,19 @@ +#include "config.h" + #include #include #include -#if defined(__FreeBSD__) + +#if defined(HAVE_UUID_H) +#warning DOING SOMETHING #include -#else +#elif defined(HAVE_UUID_UUID_H) #include +#else +#error No uuid header file specified #endif + /* XXX: this code is not portable: not all versions of linux install libuuidgen by default * if not installed, may need to do something like this: @@ -21,13 +28,15 @@ get_uuid(char *temp) char *s; uuid_t uu; -#if defined(__FreeBSD__) +#if defined(HAVE_UUID_CREATE) uuid_create(&uu, NULL); uuid_to_string(&uu, &s, 0); -#else +#elif defined(HAVE_UUID_GENERATE) s = (char *) malloc(37); uuid_generate(uu); uuid_unparse(uu, s); +#else +#error No uuid function specified #endif memcpy(temp, s, 37); }