configure.ac: Consider Mac OS X target version for clock_gettime()
authorChris Dickens <christopher.a.dickens@gmail.com>
Fri, 15 Jan 2021 20:42:35 +0000 (12:42 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 15 Jan 2021 20:42:35 +0000 (12:42 -0800)
The AC_CHECK_FUNCS() macro checks whether a program compiled on the host
will link against the function, but it does not help when targeting
older systems where that function is not available. Additionally, the
way that autoconf compiles the program ignores any attributes or
preprocessor guards that installed headers might have applied to that
function.

Resolve this by verifying that the OS X target version is 10.12 or newer
before checking for clock_gettime().

Closes #836

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
configure.ac
libusb/version_nano.h

index 5b880f6..7c86598 100644 (file)
@@ -199,17 +199,37 @@ dnl headers not available on all platforms but required on others
 AC_CHECK_HEADERS([sys/time.h])
 
 if test "x$platform" = xposix; then
-       dnl the clock_gettime() function needs certain clock IDs defined
-       AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
+       dnl check availability of clock_gettime()
+       if test "x$backend" = xdarwin; then
+               dnl need to verify that OS X target is 10.12 or later for clock_gettime()
+               AC_MSG_CHECKING([whether OS X target version is 10.12 or later])
+               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+                               #include <AvailabilityMacros.h>
+                               #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
+                               # error "Target OS X version is too old"
+                               #endif
+                       ], [])],
+                       [AC_MSG_RESULT([yes])
+                        osx_10_12_or_later=yes],
+                       [AC_MSG_RESULT([no])
+                        osx_10_12_or_later=])
+               if test "x$osx_10_12_or_later" = xyes; then
+                       AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
+               else
+                       AC_MSG_NOTICE([clock_gettime() is not available on target OS X version])
+               fi
+       else
+               AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [AC_MSG_ERROR([clock_gettime() is required on this platform])])
+       fi
+
        if test "x$have_clock_gettime" = xyes; then
+               dnl the clock_gettime() function needs certain clock IDs defined
                AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
                dnl use the monotonic clock for condition variable timed waits if possible
                AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes])
                if test "x$need_clock_realtime" = xyes; then
                        AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
                fi
-       elif test "x$backend" != xdarwin; then
-               AC_MSG_ERROR([clock_gettime() is required on this platform])
        fi
 fi
 
index e7da9f6..b8e72d6 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11597
+#define LIBUSB_NANO 11598