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 5b880f6e06e08cc771f3cdd81e1981f5627bd0b2..7c8659852ac1633fe7eaa64c1fa64071951da13c 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 e7da9f6cc7a7d3774eca40ec3abb6d375ba1cf03..b8e72d6086ae8ddeb68affe35b82c68a05f3f1c4 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11597
+#define LIBUSB_NANO 11598