about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-11-17 01:49:19 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-11-17 01:49:19 +0000
commit531f1ae0a79b9c3a91654750b11d25b256d7215f (patch)
tree7c038bf7253a09342f858a9a002fc62b74cfd735
parenta93f9cbc27a00f1bfe64b5ced19b8fde3bdbb1ea (diff)
downloadglibc-531f1ae0a79b9c3a91654750b11d25b256d7215f.tar.gz
glibc-531f1ae0a79b9c3a91654750b11d25b256d7215f.tar.xz
glibc-531f1ae0a79b9c3a91654750b11d25b256d7215f.zip
Generate /usr/libexec/getconf files when cross-compiling.
-rw-r--r--ChangeLog24
-rw-r--r--posix/Makefile14
-rw-r--r--posix/confstr.c201
-rw-r--r--posix/getconf-speclist.c42
-rw-r--r--posix/posix-envs.def151
-rw-r--r--sysdeps/posix/sysconf.c95
6 files changed, 279 insertions, 248 deletions
diff --git a/ChangeLog b/ChangeLog
index 48112a9ba5..53bfab37fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2012-11-17  Joseph Myers  <joseph@codesourcery.com>
+
+	* posix/getconf-speclist.c: New file.
+	* posix/posix-envs.def: Likewise.
+	* posix/confstr.c (START_ENV_GROUP): New macro.
+	(END_ENV_GROUP): Likewise.
+	(KNOWN_ABSENT_ENVIRONMENT): Likewise.
+	(KNOWN_PRESENT_ENV_STRING): Likewise.
+	(KNOWN_PRESENT_ENVIRONMENT): Likewise.
+	(UNKNOWN_ENVIRONMENT): Likewise.
+	(confstr): Include posix-envs.def instead of handling
+	_CS_V7_WIDTH_RESTRICTED_ENVS, _CS_V6_WIDTH_RESTRICTED_ENVS and
+	_CS_V5_WIDTH_RESTRICTED_ENVS directly here.
+	* sysdeps/posix/sysconf.c (START_ENV_GROUP): New macro.
+	(END_ENV_GROUP): Likewise.
+	(KNOWN_ABSENT_ENVIRONMENT): Likewise.
+	(KNOWN_PRESENT_ENVIRONMENT): Likewise.
+	(UNKNOWN_ENVIRONMENT): Likewise.
+	(__sysconf): Include posix-envs.def instead of handling associated
+	cases directly here.
+	* posix/Makefile ($(objpfx)getconf.speclist): Generate by
+	preprocessing getconf-speclist.c rather than running getconf or
+	generating empty file.
+
 2012-11-16  Pino Toscano  <toscano.pino@tiscali.it>
 
 	* scripts/check-local-headers.sh: Ignore 'mach' headers.
diff --git a/posix/Makefile b/posix/Makefile
index 80fbf20321..5e0e886f83 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -298,15 +298,7 @@ $(inst_libexecdir)/getconf: $(inst_bindir)/getconf \
 	  mv -f $@/$$spec.new $@/$$spec; \
 	done < $(objpfx)getconf.speclist
 
-$(objpfx)getconf.speclist: $(objpfx)getconf
-ifeq (no,$(cross-compiling))
-	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _POSIX_V7_WIDTH_RESTRICTED_ENVS > $@.new
-	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _POSIX_V6_WIDTH_RESTRICTED_ENVS >> $@.new
-	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _XBS5_WIDTH_RESTRICTED_ENVS >> $@.new
-else
-	> $@.new
-endif
+$(objpfx)getconf.speclist: getconf-speclist.c posix-envs.def
+	$(compile.c) -E -o - \
+	    | sed -n -e '/@@@PRESENT_/s/@@@PRESENT_//p' > $@.new
 	mv -f $@.new $@
diff --git a/posix/confstr.c b/posix/confstr.c
index cad65615ad..7d86d60bc1 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -48,182 +48,53 @@ confstr (name, buf, len)
       }
       break;
 
-    case _CS_V7_WIDTH_RESTRICTED_ENVS:
-      /* We have to return a newline-separated list of named of
-	 programming environements in which the widths of blksize_t,
+      /* For _CS_V7_WIDTH_RESTRICTED_ENVS, _CS_V6_WIDTH_RESTRICTED_ENVS
+	 and _CS_V5_WIDTH_RESTRICTED_ENVS:
+
+	 We have to return a newline-separated list of names of
+	 programming environments in which the widths of blksize_t,
 	 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
 	 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
 	 wint_t types are no greater than the width of type long.
 
-	 Currently this means all environment which the system allows.  */
+	 Currently this means all environments that the system allows.  */
+
+#define START_ENV_GROUP(VERSION)		\
+    case _CS_##VERSION##_WIDTH_RESTRICTED_ENVS:	\
       string_len = 0;
-#ifndef _POSIX_V7_ILP32_OFF32
-      if (__sysconf (_SC_V7_ILP32_OFF32) > 0)
-#endif
-#if !defined _POSIX_V7_ILP32_OFF32 || _POSIX_V7_ILP32_OFF32 > 0
-	{
-	  memcpy (restenvs + string_len, "POSIX_V7_ILP32_OFF32",
-		  sizeof "POSIX_V7_ILP32_OFF32" - 1);
-	  string_len += sizeof "POSIX_V7_ILP32_OFF32" - 1;
-	}
-#endif
-#ifndef _POSIX_V7_ILP32_OFFBIG
-      if (__sysconf (_SC_V7_ILP32_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V7_ILP32_OFFBIG || _POSIX_V7_ILP32_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V7_ILP32_OFFBIG",
-		  sizeof "POSIX_V7_ILP32_OFFBIG" - 1);
-	  string_len += sizeof "POSIX_V7_ILP32_OFFBIG" - 1;
-	}
-#endif
-#ifndef _POSIX_V7_LP64_OFF64
-      if (__sysconf (_SC_V7_LP64_OFF64) > 0)
-#endif
-#if !defined _POSIX_V7_LP64_OFF64 || _POSIX_V7_LP64_OFF64 > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V7_LP64_OFF64",
-		  sizeof "POSIX_V7_LP64_OFF64" - 1);
-	  string_len += sizeof "POSIX_V7_LP64_OFF64" - 1;
-	}
-#endif
-#ifndef _POSIX_V7_LPBIG_OFFBIG
-      if (__sysconf (_SC_V7_LPBIG_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V7_LPBIG_OFFBIG || _POSIX_V7_LPBIG_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V7_LPBIG_OFFBIG",
-		  sizeof "POSIX_V7_LPBIG_OFFBIG" - 1);
-	  string_len += sizeof "POSIX_V7_LPBIG_OFFBIG" - 1;
-	}
-#endif
-      restenvs[string_len++] = '\0';
-      string = restenvs;
+
+#define END_ENV_GROUP(VERSION)			\
+      restenvs[string_len++] = '\0';		\
+      string = restenvs;			\
       break;
 
-    case _CS_V6_WIDTH_RESTRICTED_ENVS:
-      /* We have to return a newline-separated list of named of
-	 programming environements in which the widths of blksize_t,
-	 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
-	 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
-	 wint_t types are no greater than the width of type long.
+#define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+      /* Empty.  */
 
-	 Currently this means all environment which the system allows.  */
-      string_len = 0;
-#ifndef _POSIX_V6_ILP32_OFF32
-      if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
-#endif
-#if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
-	{
-	  memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFF32",
-		  sizeof "POSIX_V6_ILP32_OFF32" - 1);
-	  string_len += sizeof "POSIX_V6_ILP32_OFF32" - 1;
-	}
-#endif
-#ifndef _POSIX_V6_ILP32_OFFBIG
-      if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFFBIG",
-		  sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
-	  string_len += sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
-	}
-#endif
-#ifndef _POSIX_V6_LP64_OFF64
-      if (__sysconf (_SC_V6_LP64_OFF64) > 0)
-#endif
-#if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V6_LP64_OFF64",
-		  sizeof "POSIX_V6_LP64_OFF64" - 1);
-	  string_len += sizeof "POSIX_V6_LP64_OFF64" - 1;
-	}
-#endif
-#ifndef _POSIX_V6_LPBIG_OFFBIG
-      if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "POSIX_V6_LPBIG_OFFBIG",
-		  sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
-	  string_len += sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
-	}
-#endif
-      restenvs[string_len++] = '\0';
-      string = restenvs;
-      break;
+#define KNOWN_PRESENT_ENV_STRING(STR)		\
+      if (string_len > 0)			\
+	restenvs[string_len++] = '\n';		\
+      memcpy (restenvs + string_len, STR,	\
+	      sizeof STR - 1);			\
+      string_len += sizeof STR - 1;
 
-    case _CS_V5_WIDTH_RESTRICTED_ENVS:
-      /* We have to return a newline-separated list of named of
-	 programming environements in which the widths of blksize_t,
-	 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
-	 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
-	 wint_t types are no greater than the width of type long.
+#define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+      KNOWN_PRESENT_ENV_STRING (#ENV_PREFIX "_" #SUFFIX)
 
-	 Currently this means all environment which the system allows.  */
-      string_len = 0;
-#ifndef _XBS5_ILP32_OFF32
-      if (__sysconf (_SC_XBS5_ILP32_OFF32) > 0)
-#endif
-#if !defined _XBS5_ILP32_OFF32 || _XBS5_ILP32_OFF32 > 0
-	{
-	  memcpy (restenvs + string_len, "XBS5_ILP32_OFF32",
-		  sizeof "XBS5_ILP32_OFF32" - 1);
-	  string_len += sizeof "XBS5_ILP32_OFF32" - 1;
+#define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)		\
+      if (__sysconf (_SC_##SC_PREFIX##_##SUFFIX) > 0)			\
+	{								\
+	  KNOWN_PRESENT_ENVIRONMENT (SC_PREFIX, ENV_PREFIX, SUFFIX)	\
 	}
-#endif
-#ifndef _XBS5_ILP32_OFFBIG
-      if (__sysconf (_SC_XBS5_ILP32_OFFBIG) > 0)
-#endif
-#if !defined _XBS5_ILP32_OFFBIG || _XBS5_ILP32_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "XBS5_ILP32_OFFBIG",
-		  sizeof "XBS5_ILP32_OFFBIG" - 1);
-	  string_len += sizeof "XBS5_ILP32_OFFBIG" - 1;
-	}
-#endif
-#ifndef _XBS5_LP64_OFF64
-      if (__sysconf (_SC_XBS5_LP64_OFF64) > 0)
-#endif
-#if !defined _XBS5_LP64_OFF64 || _XBS5_LP64_OFF64 > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "XBS5_LP64_OFF64",
-		  sizeof "XBS5_LP64_OFF64" - 1);
-	  string_len += sizeof "XBS5_LP64_OFF64" - 1;
-	}
-#endif
-#ifndef _XBS5_LPBIG_OFFBIG
-      if (__sysconf (_SC_XBS5_LPBIG_OFFBIG) > 0)
-#endif
-#if !defined _XBS5_LPBIG_OFFBIG || _XBS5_LPBIG_OFFBIG > 0
-	{
-	  if (string_len)
-	    restenvs[string_len++] = '\n';
-	  memcpy (restenvs + string_len, "XBS5_LPBIG_OFFBIG",
-		  sizeof "XBS5_LPBIG_OFFBIG" - 1);
-	  string_len += sizeof "XBS5_LPBIG_OFFBIG" - 1;
-	}
-#endif
-      restenvs[string_len++] = '\0';
-      string = restenvs;
-      break;
+
+#include "posix-envs.def"
+
+#undef START_ENV_GROUP
+#undef END_ENV_GROUP
+#undef KNOWN_ABSENT_ENVIRONMENT
+#undef KNOWN_PRESENT_ENV_STRING
+#undef KNOWN_PRESENT_ENVIRONMENT
+#undef UNKNOWN_ENVIRONMENT
 
     case _CS_XBS5_ILP32_OFF32_CFLAGS:
     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
diff --git a/posix/getconf-speclist.c b/posix/getconf-speclist.c
new file mode 100644
index 0000000000..72c5c3de82
--- /dev/null
+++ b/posix/getconf-speclist.c
@@ -0,0 +1,42 @@
+/* List POSIX compilation environments for this libc.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+
+#define START_ENV_GROUP(VERSION)		\
+  /* Empty.  */
+
+#define END_ENV_GROUP(VERSION)			\
+  /* Empty.  */
+
+#define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+  /* Empty.  */
+
+#define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+  @@@PRESENT_##ENV_PREFIX##_##SUFFIX
+
+#define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+  /* Empty.  */
+
+#include "posix-envs.def"
+
+#undef START_ENV_GROUP
+#undef END_ENV_GROUP
+#undef KNOWN_ABSENT_ENVIRONMENT
+#undef KNOWN_PRESENT_ENVIRONMENT
+#undef UNKNOWN_ENVIRONMENT
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
new file mode 100644
index 0000000000..c32ea8acfc
--- /dev/null
+++ b/posix/posix-envs.def
@@ -0,0 +1,151 @@
+/* Handle POSIX compilation environments that may or may not be present.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Before including this file, the including file must have included
+   <bits/environments.h> (generally via <unistd.h>) and must have
+   defined the following macros, exactly one of which will be called
+   for each POSIX environment:
+
+   KNOWN_PRESENT_ENVIRONMENT, for POSIX environments that are known to
+   be supported in this libc.
+
+   KNOWN_ABSENT_ENVIRONMENT, for POSIX environments that are known not
+   to be supported on this system.
+
+   UNKNOWN_ENVIRONMENT, for POSIX environments not supported in this
+   libc but possibly supported by another libc on the same system,
+   that can be selected using the same compiler but different
+   compilation options.
+
+   Each macro has arguments (SC_PREFIX, ENV_PREFIX, SUFFIX).  The
+   corresponding argument to sysconf is _SC_##SC_PREFIX##_##SUFFIX.
+   The environment name, as used with getconf, is
+   ENV_PREFIX##_##SUFFIX, and the corresponding macro is the same with
+   a leading "_".
+
+   In addition, the macros START_ENV_GROUP and END_ENV_GROUP must be
+   defined.  These are called with arguments V5, V6, V7 before and
+   after the relevant groups of environments.  */
+
+START_ENV_GROUP (V7)
+
+#if _POSIX_V7_ILP32_OFF32 > 0
+KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
+#elif defined _POSIX_V7_ILP32_OFF32
+KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
+#else
+UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
+#endif
+
+#if _POSIX_V7_ILP32_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
+#elif defined _POSIX_V7_ILP32_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
+#endif
+
+#if _POSIX_V7_LP64_OFF64 > 0
+KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
+#elif defined _POSIX_V7_LP64_OFF64
+KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
+#else
+UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
+#endif
+
+#if _POSIX_V7_LPBIG_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
+#elif defined _POSIX_V7_LPBIG_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
+#endif
+
+END_ENV_GROUP (V7)
+
+START_ENV_GROUP (V6)
+
+#if _POSIX_V6_ILP32_OFF32 > 0
+KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
+#elif defined _POSIX_V6_ILP32_OFF32
+KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
+#else
+UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
+#endif
+
+#if _POSIX_V6_ILP32_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
+#elif defined _POSIX_V6_ILP32_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
+#endif
+
+#if _POSIX_V6_LP64_OFF64 > 0
+KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
+#elif defined _POSIX_V6_LP64_OFF64
+KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
+#else
+UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
+#endif
+
+#if _POSIX_V6_LPBIG_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
+#elif defined _POSIX_V6_LPBIG_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
+#endif
+
+END_ENV_GROUP (V6)
+
+START_ENV_GROUP (V5)
+
+#if _XBS5_ILP32_OFF32 > 0
+KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
+#elif defined _XBS5_ILP32_OFF32
+KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
+#else
+UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
+#endif
+
+#if _XBS5_ILP32_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
+#elif defined _XBS5_ILP32_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
+#endif
+
+#if _XBS5_LP64_OFF64 > 0
+KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
+#elif defined _XBS5_LP64_OFF64
+KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
+#else
+UNKNOWN_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
+#endif
+
+#if _XBS5_LPBIG_OFFBIG > 0
+KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
+#elif defined _XBS5_LPBIG_OFFBIG
+KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
+#else
+UNKNOWN_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
+#endif
+
+END_ENV_GROUP (V5)
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index bfe28b47ee..99043b7558 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -790,80 +790,31 @@ __sysconf (name)
       return -1;
 #endif
 
-    case _SC_XBS5_ILP32_OFF32:
-#ifdef _XBS5_ILP32_OFF32
-      return _XBS5_ILP32_OFF32;
-#else
-      return __sysconf_check_spec ("ILP32_OFF32");
-#endif
-    case _SC_XBS5_ILP32_OFFBIG:
-#ifdef _XBS5_ILP32_OFFBIG
-      return _XBS5_ILP32_OFFBIG;
-#else
-      return __sysconf_check_spec ("ILP32_OFFBIG");
-#endif
-    case _SC_XBS5_LP64_OFF64:
-#ifdef _XBS5_LP64_OFF64
-      return _XBS5_LP64_OFF64;
-#else
-      return __sysconf_check_spec ("LP64_OFF64");
-#endif
-    case _SC_XBS5_LPBIG_OFFBIG:
-#ifdef _XBS5_LPBIG_OFFBIG
-      return _XBS5_LPBIG_OFFBIG;
-#else
-      return __sysconf_check_spec ("LPBIG_OFFBIG");
-#endif
+#define START_ENV_GROUP(VERSION)		\
+      /* Empty.  */
 
-    case _SC_V6_ILP32_OFF32:
-#ifdef _POSIX_V6_ILP32_OFF32
-      return _POSIX_V6_ILP32_OFF32;
-#else
-      return __sysconf_check_spec ("ILP32_OFF32");
-#endif
-    case _SC_V6_ILP32_OFFBIG:
-#ifdef _POSIX_V6_ILP32_OFFBIG
-      return _POSIX_V6_ILP32_OFFBIG;
-#else
-      return __sysconf_check_spec ("ILP32_OFFBIG");
-#endif
-    case _SC_V6_LP64_OFF64:
-#ifdef _POSIX_V6_LP64_OFF64
-      return _POSIX_V6_LP64_OFF64;
-#else
-      return __sysconf_check_spec ("LP64_OFF64");
-#endif
-    case _SC_V6_LPBIG_OFFBIG:
-#ifdef _POSIX_V6_LPBIG_OFFBIG
-      return _POSIX_V6_LPBIG_OFFBIG;
-#else
-      return __sysconf_check_spec ("LPBIG_OFFBIG");
-#endif
+#define END_ENV_GROUP(VERSION)			\
+      /* Empty.  */
 
-    case _SC_V7_ILP32_OFF32:
-#ifdef _POSIX_V7_ILP32_OFF32
-      return _POSIX_V7_ILP32_OFF32;
-#else
-      return __sysconf_check_spec ("ILP32_OFF32");
-#endif
-    case _SC_V7_ILP32_OFFBIG:
-#ifdef _POSIX_V7_ILP32_OFFBIG
-      return _POSIX_V7_ILP32_OFFBIG;
-#else
-      return __sysconf_check_spec ("ILP32_OFFBIG");
-#endif
-    case _SC_V7_LP64_OFF64:
-#ifdef _POSIX_V7_LP64_OFF64
-      return _POSIX_V7_LP64_OFF64;
-#else
-      return __sysconf_check_spec ("LP64_OFF64");
-#endif
-    case _SC_V7_LPBIG_OFFBIG:
-#ifdef _POSIX_V7_LPBIG_OFFBIG
-      return _POSIX_V7_LPBIG_OFFBIG;
-#else
-      return __sysconf_check_spec ("LPBIG_OFFBIG");
-#endif
+#define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+    case _SC_##SC_PREFIX##_##SUFFIX:				\
+      return _##ENV_PREFIX##_##SUFFIX;
+
+#define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+    case _SC_##SC_PREFIX##_##SUFFIX:					\
+      return _##ENV_PREFIX##_##SUFFIX;
+
+#define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX)	\
+    case _SC_##SC_PREFIX##_##SUFFIX:				\
+      return __sysconf_check_spec (#SUFFIX);
+
+#include <posix/posix-envs.def>
+
+#undef START_ENV_GROUP
+#undef END_ENV_GROUP
+#undef KNOWN_ABSENT_ENVIRONMENT
+#undef KNOWN_PRESENT_ENVIRONMENT
+#undef UNKNOWN_ENVIRONMENT
 
     case _SC_XOPEN_LEGACY:
       return _XOPEN_LEGACY;