This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Generate /usr/libexec/getconf files when cross-compiling


This patch fixes one of the remaining differences between native and
cross builds of glibc by generating /usr/libexec/getconf/ files when
cross-compiling.

These files are links to the getconf program for the purpose of
getconf returning compilation / linking options to use when building
programs for a different environment than that for which getconf
itself was built.  The idea is that a system may have, for example,
both 32-bit and 64-bit copies of glibc installed; one provides an
ILP32 environment and the other provides an LP64 environment, but
/usr/bin/getconf can only come from one of the copies of glibc.  If a
user runs getconf to determine options relating to the other
environment, getconf then execs a copy from /usr/libexec/getconf that
was installed by the other copy of glibc (and the sysconf function,
similarly, checks that directory to determine what environments are
supported; see sysdeps/posix/sysconf.c:__sysconf_check_spec).

The process for installing these links to getconf requires the
makefiles to determine the set of environments supported by this
particular copy of glibc.  To do so, posix/Makefile runs the newly
built getconf program with appropriate arguments such as
_POSIX_V7_WIDTH_RESTRICTED_ENVS to print the list of supported
environments - with GETCONF_DIR=/dev/null set to ensure that only the
present glibc is considered and links previously installed in
/usr/libexec/getconf are not examined.

To work with cross-compilation, running a program built with the new
glibc is no longer an option.  The relevant code ultimately depends on
the values of various macros from bits/environments.h.  This patch
arranges for the correct settings of those macros to be determined
through preprocessing confstr.c, put in a generated cross-getconf.h
file, and used in building a cross-getconf program that uses the
relevant part of confstr.c, extracted into a new source file to be
shared between both getconf and cross-getconf/

Tested x86_64.

2012-11-14  Maxim Kuvyrkov  <maxim@codesourcery.com>
	    Joseph Myers  <joseph@codesourcery.com>

	* posix/confstr.inc: New file.  Split out of ...
	* posix/confstr.c (confstr): ... here.
	* posix/cross-getconf.c: New file.
	* posix/Makefile (getconf-envs): New variable.
	(getconf-egrep): Likewise.
	($(objpfx)cross-getconf.h): New target.
	(cross-getconf-CFLAGS): New variable.
	($(objpfx)cross-getconf): New target.
	($(objpfx)getconf.speclist): Do not condition main definition on
	[$(cross-compiling) = no].  Remove dummy definition.  Use
	$(objpfx)cross-getconf instead of $(objpfx)getconf.

diff --git a/posix/Makefile b/posix/Makefile
index 80fbf20..d7ef1e4 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -298,15 +298,31 @@ $(inst_libexecdir)/getconf: $(inst_bindir)/getconf \
 	  mv -f $@/$$spec.new $@/$$spec; \
 	done < $(objpfx)getconf.speclist
 
-$(objpfx)getconf.speclist: $(objpfx)getconf
-ifeq (no,$(cross-compiling))
+getconf-envs := _POSIX_V7_ILP32_OFF32 _POSIX_V7_ILP32_OFFBIG \
+		_POSIX_V7_LP64_OFF64 _POSIX_V7_LPBIG_OFFBIG \
+		_POSIX_V6_ILP32_OFF32 _POSIX_V6_ILP32_OFFBIG \
+		_POSIX_V6_LP64_OFF64 _POSIX_V6_LPBIG_OFFBIG \
+		_XBS5_ILP32_OFF32 _XBS5_ILP32_OFFBIG \
+		_XBS5_LP64_OFF64 _XBS5_LPBIG_OFFBIG
+
+getconf-egrep := $(subst $(empty) ,|,$(strip $(getconf-envs)))
+
+# Get configuration defines for cross-getconf by preprocessing confstr.c.
+$(objpfx)cross-getconf.h: confstr.c confstr.inc
+	$(compile.c) -E -dM -o - \
+	    | egrep "define ($(getconf-egrep))" > $@.new
+	mv -f $@.new $@
+
+cross-getconf-CFLAGS = -O -I$(objpfx)
+
+$(objpfx)cross-getconf: cross-getconf.c $(objpfx)cross-getconf.h
+	$(native-compile)
+
+$(objpfx)getconf.speclist: $(objpfx)cross-getconf
 	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _POSIX_V7_WIDTH_RESTRICTED_ENVS > $@.new
+	$< _POSIX_V7_WIDTH_RESTRICTED_ENVS > $@.new
 	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _POSIX_V6_WIDTH_RESTRICTED_ENVS >> $@.new
+	$< _POSIX_V6_WIDTH_RESTRICTED_ENVS >> $@.new
 	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _XBS5_WIDTH_RESTRICTED_ENVS >> $@.new
-else
-	> $@.new
-endif
+	$< _XBS5_WIDTH_RESTRICTED_ENVS >> $@.new
 	mv -f $@.new $@
diff --git a/posix/confstr.c b/posix/confstr.c
index cad6561..9f5eae7 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -48,182 +48,7 @@ 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,
-	 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.  */
-      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;
-      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.
-
-	 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;
-
-    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.
-
-	 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;
-	}
-#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 "confstr.inc"
 
     case _CS_XBS5_ILP32_OFF32_CFLAGS:
     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
diff --git a/posix/confstr.inc b/posix/confstr.inc
new file mode 100644
index 0000000..7675eff
--- /dev/null
+++ b/posix/confstr.inc
@@ -0,0 +1,195 @@
+/* Determine supported programming environments, for getconf and
+   cross-getconf.
+   Copyright (C) 1991-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/>.  */
+
+    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,
+	 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.  */
+      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;
+      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.
+
+	 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;
+
+    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.
+
+	 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;
+	}
+#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;
diff --git a/posix/cross-getconf.c b/posix/cross-getconf.c
new file mode 100644
index 0000000..f4371b2
--- /dev/null
+++ b/posix/cross-getconf.c
@@ -0,0 +1,143 @@
+/* Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Undefine macros that should be defined in cross-getconf.h.  */
+#undef _POSIX_V7_ILP32_OFF32
+#undef _POSIX_V7_ILP32_OFFBIG
+#undef _POSIX_V7_LP64_OFF64
+#undef _POSIX_V7_LPBIG_OFFBIG
+#undef _POSIX_V6_ILP32_OFF32
+#undef _POSIX_V6_ILP32_OFFBIG
+#undef _POSIX_V6_LP64_OFF64
+#undef _POSIX_V6_LPBIG_OFFBIG
+#undef _XBS5_ILP32_OFF32
+#undef _XBS5_ILP32_OFFBIG
+#undef _XBS5_LP64_OFF64
+#undef _XBS5_LPBIG_OFFBIG
+
+#include "cross-getconf.h"
+
+/* Define macros cross-getconf.h doesn't define to (-1).
+   This will prevent using host's __sysconf in confstr.inc.  */
+#ifndef _POSIX_V7_ILP32_OFF32
+# define _POSIX_V7_ILP32_OFF32 (-1)
+#endif
+#ifndef _POSIX_V7_ILP32_OFFBIG
+# define _POSIX_V7_ILP32_OFFBIG (-1)
+#endif
+#ifndef _POSIX_V7_LP64_OFF64
+# define _POSIX_V7_LP64_OFF64 (-1)
+#endif
+#ifndef _POSIX_V7_LPBIG_OFFBIG
+# define _POSIX_V7_LPBIG_OFFBIG (-1)
+#endif
+#ifndef _POSIX_V6_ILP32_OFF32
+# define _POSIX_V6_ILP32_OFF32 (-1)
+#endif
+#ifndef _POSIX_V6_ILP32_OFFBIG
+# define _POSIX_V6_ILP32_OFFBIG (-1)
+#endif
+#ifndef _POSIX_V6_LP64_OFF64
+# define _POSIX_V6_LP64_OFF64 (-1)
+#endif
+#ifndef _POSIX_V6_LPBIG_OFFBIG
+# define _POSIX_V6_LPBIG_OFFBIG (-1)
+#endif
+#ifndef _XBS5_ILP32_OFF32
+# define _XBS5_ILP32_OFF32 (-1)
+#endif
+#ifndef _XBS5_ILP32_OFFBIG
+# define _XBS5_ILP32_OFFBIG (-1)
+#endif
+#ifndef _XBS5_LP64_OFF64
+# define _XBS5_LP64_OFF64 (-1)
+#endif
+#ifndef _XBS5_LPBIG_OFFBIG
+# define _XBS5_LPBIG_OFFBIG (-1)
+#endif
+
+#undef _CS_V5_WIDTH_RESTRICTED_ENVS
+#define _CS_V5_WIDTH_RESTRICTED_ENVS 5
+
+#undef _CS_V6_WIDTH_RESTRICTED_ENVS
+#define _CS_V6_WIDTH_RESTRICTED_ENVS 6
+
+#undef _CS_V7_WIDTH_RESTRICTED_ENVS
+#define _CS_V7_WIDTH_RESTRICTED_ENVS 7
+
+/* Cross-getconf is a very simple program that assumes fixed
+   input and produces fixed output.  It handles only cases
+   that are necessary to cross-compile glibc.  */
+
+void
+cross_getconf (int name)
+{
+  const char *string = "";
+  size_t string_len = 1;
+
+  /* Note that this buffer must be large enough for the longest strings
+     used below.  */
+  char restenvs[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
+
+  switch (name)
+    {
+#include "confstr.inc"
+    }
+
+  printf ("%.*s\n", (int) string_len, string);
+}
+
+int
+main (int argc, char *argv[])
+{
+  const char *getconf_dir;
+
+  if (argc != 2)
+    {
+      fprintf (stderr,
+	       "%s: must be called with exactly one argument\n", argv[0]);
+      return 1;
+    }
+
+  getconf_dir = getenv ("GETCONF_DIR");
+  if (getconf_dir == NULL
+      || strcmp (getconf_dir, "/dev/null") != 0)
+    {
+      fprintf (stderr, "%s: GETCONF_DIR should be /dev/null\n", argv[0]);
+      return 1;
+    }
+
+  if (strcmp (argv[1], "_POSIX_V7_WIDTH_RESTRICTED_ENVS") == 0)
+    cross_getconf (_CS_V7_WIDTH_RESTRICTED_ENVS);
+  else if (strcmp (argv[1], "_POSIX_V6_WIDTH_RESTRICTED_ENVS") == 0)
+    cross_getconf (_CS_V6_WIDTH_RESTRICTED_ENVS);
+  else if (strcmp (argv[1], "_XBS5_WIDTH_RESTRICTED_ENVS") == 0)
+    cross_getconf (_CS_V5_WIDTH_RESTRICTED_ENVS);
+  else
+    {
+      fprintf (stderr,
+	       "%s: the only supported arguments value are "
+	       "_POSIX_V7_WIDTH_RESTRICTED_ENVS, "
+	       "_POSIX_V6_WIDTH_RESTRICTED_ENVS, and "
+	       "_XBS5_WIDTH_RESTRICTED_ENVS\n", argv[0]);
+      return 1;
+    }
+  return 0;
+}

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]