When building clisp on OpenIndiana, I'm encountering this compilation error:
In file included from .../gllib/stdlib.h:51:0, from clisp.c:2167: /usr/include/sys/loadavg.h:47:2: error: unknown type name 'hrtime_t' hrtime_t lg_total; /* used to temporarily hold load totals */ ^~~~~~~~ /usr/include/sys/loadavg.h:48:2: error: unknown type name 'hrtime_t' hrtime_t lg_loads[S_LOADAVG_SZ]; /* table of recorded entries */ ^~~~~~~~ *** Error code 1 The cause is that <sys/loadavg.h>, which gnulib's stdlib.h replacement includes, is not self-contained. Reported at <https://www.illumos.org/issues/9021>. This patch provides a workaround. 2018-02-03 Bruno Haible <br...@clisp.org> stdlib: Fix compilation error on OpenIndiana. * lib/stdlib.in.h: Before including <sys/loadavg.h>, include <sys/time.h>. * m4/stdlib_h.m4 (gl_STDLIB_H): Likewise. * m4/getloadavg.m4 (gl_GETLOADAVG): Likewise. diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index b9701d5..c8a5d0d 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -47,6 +47,9 @@ /* Solaris declares getloadavg() in <sys/loadavg.h>. */ #if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ +/* OpenIndiana has a bug: <sys/time.h> must be included before + <sys/loadavg.h>. */ +# include <sys/time.h> # include <sys/loadavg.h> #endif diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4 index acc2665..7b6a09a 100644 --- a/m4/getloadavg.m4 +++ b/m4/getloadavg.m4 @@ -7,7 +7,7 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -#serial 6 +#serial 7 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. # New applications should use gl_GETLOADAVG instead. @@ -92,6 +92,9 @@ else fi AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0], [[#if HAVE_SYS_LOADAVG_H + /* OpenIndiana has a bug: <sys/time.h> must be included before + <sys/loadavg.h>. */ + # include <sys/time.h> # include <sys/loadavg.h> #endif #include <stdlib.h>]]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index eff6f9e..49dc5d5 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 44 +# stdlib_h.m4 serial 45 dnl Copyright (C) 2007-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,6 +14,9 @@ AC_DEFUN([gl_STDLIB_H], dnl guaranteed by C89. gl_WARN_ON_USE_PREPARE([[#include <stdlib.h> #if HAVE_SYS_LOADAVG_H +/* OpenIndiana has a bug: <sys/time.h> must be included before + <sys/loadavg.h>. */ +# include <sys/time.h> # include <sys/loadavg.h> #endif #if HAVE_RANDOM_H