Check for the presence of _SC_NPROCESSORS_ONLN rather than using it unconditionally with `sysconf', fixing a compilation error:
adaint.c: In function '__gnat_number_of_cpus': adaint.c:2398:26: error: '_SC_NPROCESSORS_ONLN' undeclared (first use in this function) 2398 | cores = (int) sysconf (_SC_NPROCESSORS_ONLN); | ^~~~~~~~~~~~~~~~~~~~ adaint.c:2398:26: note: each undeclared identifier is reported only once for each function it appears in at least with with VAX/NetBSD 1.6.2. Assume _SC_NPROCESSORS_ONLN is a macro and use #ifdef like in other places across GCC sources. gcc/ada/ * adaint.c (__gnat_number_of_cpus): Check for the presence of _SC_NPROCESSORS_ONLN before using it. --- NB we could probably replace the list of OS #ifdefs with just a check for _SC_NPROCESSORS_ONLN, making use of it automagically with any new OS that supports it, as from the length of the list has grown up to I gather the `sysconf' API for this variable has become a semi-established standard now even though not actually listed by the relevant standards. --- gcc/ada/adaint.c | 2 ++ 1 file changed, 2 insertions(+) gcc-netbsd-libada-sc-nprocessors-onln.diff Index: gcc/gcc/ada/adaint.c =================================================================== --- gcc.orig/gcc/ada/adaint.c +++ gcc/gcc/ada/adaint.c @@ -2479,7 +2479,9 @@ __gnat_number_of_cpus (void) #if defined (__linux__) || defined (__sun__) || defined (_AIX) \ || defined (__APPLE__) || defined (__FreeBSD__) || defined (__OpenBSD__) \ || defined (__DragonFly__) || defined (__NetBSD__) +#ifdef _SC_NPROCESSORS_ONLN cores = (int) sysconf (_SC_NPROCESSORS_ONLN); +#endif #elif defined (__QNX__) cores = (int) _syspage_ptr->num_cpu;