[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patches] Cross-getconf
- To: patches@xxxxxxxxxx
- Subject: [patches] Cross-getconf
- From: Maxim Kuvyrkov <maxim@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 May 2008 17:17:53 +0400
Hello,
The attached patch adds installation of <sysroot>/usr/libexec/posix/*
files when cross-compiling EGLIBC, thus moving result of cross-build one
step closer to that of native build.
The patch adds a new utility cross-getconf that is a stripped down
version of native getconf. Cross-getconf only handles cases that occur
during cross-compilation of EGLIBC, when invoked with any other
arguments it will fail with an error message.
Any comments?
OK for trunk and 2.8 branch?
--
Maxim Kuvyrkov
CodeSourcery Inc.
2008-05-27 Maxim Kuvyrkov <maxim@xxxxxxxxxxxxxxxx>
Cross-getconf.
* posix/confstr.c (confstr): Move code for case
_CS_V6_WIDTH_RESTRICTED_ENVS to ...
* posix/confstr.inc: New file.
* posix/cross-getconf.c: New utility to mimic getconf for the
purposes of cross-compiling EGLIBC.
* posix/Makefile: Build cross-getconf and use it when cross-building
EGLIBC.
Index: posix/confstr.c
===================================================================
--- posix/confstr.c (revision 6253)
+++ posix/confstr.c (working copy)
@@ -47,66 +47,9 @@ confstr (name, buf, len)
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. */
- {
- char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
-
- 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;
- }
+ /* eglibc: We share code in confstr.inc with cross-getconf.c. */
+#include "confstr.inc"
+ /* eglibc: end. */
break;
case _CS_XBS5_ILP32_OFF32_CFLAGS:
Index: posix/confstr.inc
===================================================================
--- posix/confstr.inc (revision 0)
+++ posix/confstr.inc (revision 0)
@@ -0,0 +1,82 @@
+/* Copyright (C) 2008
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* eglibc: The following piece of code was extracted from
+ confstr.c to share it with cross-getconf.c. */
+
+ /* 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. */
+ {
+ char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
+
+ 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;
+ }
Index: posix/cross-getconf.c
===================================================================
--- posix/cross-getconf.c (revision 0)
+++ posix/cross-getconf.c (revision 0)
@@ -0,0 +1,76 @@
+/* Copyright (C) 2008 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, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "cross-getconf.h"
+
+/* The following macros should be defined in cross-getconf.h
+ for code in confstr.inc to properly work. */
+#ifndef _POSIX_V6_ILP32_OFF32
+# error "_POSIX_V6_ILP32_OFF32 is undefined"
+#endif
+#ifndef _POSIX_V6_ILP32_OFFBIG
+# error "_POSIX_V6_ILP32_OFFBIG is undefined"
+#endif
+#ifndef _POSIX_V6_LP64_OFF64
+# error "_POSIX_V6_LP64_OFF64 is undefined"
+#endif
+#ifndef _POSIX_V6_LPBIG_OFFBIG
+# error "_POSIX_V6_LPBIG_OFFBIG is undefined"
+#endif
+
+/* 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 EGLIBC. */
+
+void
+cross_getconf (void)
+{
+ const char *string = "";
+ size_t string_len = 1;
+
+#include "confstr.inc"
+
+ printf ("%.*s\n", (int) string_len, string);
+}
+
+int
+main (int argc, char *argv[])
+{
+ const char *getconf_dir;
+
+ if (argc != 2 || strcmp (argv[1], "_POSIX_V6_WIDTH_RESTRICTED_ENVS") != 0)
+ {
+ fprintf (stderr,
+ "%s: the only supported argument value is "
+ "_POSIX_V6_WIDTH_RESTRICTED_ENVS", 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;
+ }
+
+ cross_getconf ();
+ return 0;
+}
Index: posix/Makefile
===================================================================
--- posix/Makefile (revision 6253)
+++ posix/Makefile (working copy)
@@ -325,11 +325,32 @@ $(inst_libexecdir)/getconf: $(inst_bindi
mv -f $@/$$spec.new $@/$$spec; \
done < $(objpfx)getconf.speclist
-$(objpfx)getconf.speclist: $(objpfx)getconf
+# eglibc: If we are cross-compiling, build cross-getconf utility and use it
+# instead of getconf.
+
+# We moved a piece of confstr.c to confstr.inc to share the later with
+# cross-getconf.c.
+confstr.c: confstr.inc
+
ifeq (no,$(cross-compiling))
- LC_ALL=C GETCONF_DIR=/dev/null \
- $(run-program-prefix) $< _POSIX_V6_WIDTH_RESTRICTED_ENVS > $@.new
+getconf-dep = $(objpfx)getconf
+getconf-cmd = $(run-program-prefix) $(objpfx)getconf
else
- > $@.new
+getconf-dep = $(objpfx)cross-getconf
+getconf-cmd = $(objpfx)cross-getconf
+
+# Get configuration defines for cross-getconf by preprocessing confstr.c.
+cross-getconf.h: confstr.c
+ $(compile.c) -E -dM -o - | grep "define _POSIX_V6_ILP32_OFF32\|define _POSIX_V6_ILP32_OFFBIG\|define _POSIX_V6_LP64_OFF64\|define _POSIX_V6_LPBIG_OFFBIG" > cross-getconf.h
+
+cross-getconf-CFLAGS = -O
+
+$(objpfx)cross-getconf: cross-getconf.c cross-getconf.h
+ $(native-compile)
endif
+
+$(objpfx)getconf.speclist: $(getconf-dep)
+ LC_ALL=C GETCONF_DIR=/dev/null \
+ $(getconf-cmd) _POSIX_V6_WIDTH_RESTRICTED_ENVS > $@.new
mv -f $@.new $@
+# eglibc: end.