Subject: Re: cross-building from macos x
To: None <tech-toolchain@NetBSD.org>
From: Kurt J. Lidl <lidl@pix.net>
List: tech-toolchain
Date: 08/07/2007 16:10:49
On Mon, Aug 06, 2007 at 10:09:19PM +0200, Alan Barrett wrote:
> On Mon, 06 Aug 2007, Joerg Sonnenberger wrote:
> > On Mon, Aug 06, 2007 at 12:16:51PM -0400, Kurt Lidl wrote:
> > > http://mail-index.netbsd.org/netbsd-bugs/2007/07/29/0002.html
> > 
> > It should only include the minimal version from the #else case.
> > It doesn't have to be fast, so just providing the default version in C
> > is good enough.
> 
> I agree.  I will do some testing and then commit a fix along those
> lines, unless somebody else beats me to it.

The following patch (derived from the original one) progresses
beyond the very early failure that I saw before.  Hopefully this
qualifies as "the minimal version", and can be commited.  Thanks!

-Kurt

Index: tools/compat/configure.ac
===================================================================
RCS file: /cvsroot/src/tools/compat/configure.ac,v
retrieving revision 1.60
diff -u -r1.60 configure.ac
--- tools/compat/configure.ac	9 Oct 2006 14:59:05 -0000	1.60
+++ tools/compat/configure.ac	6 Aug 2007 19:22:53 -0000
@@ -142,6 +142,8 @@
 
 AC_CHECK_DECLS([bswap16, bswap32, bswap64],,, [#include <machine/bswap.h>])
 
+AC_CHECK_DECLS([be16enc, le16enc, be16dec, le16dec, be32enc, le32enc, be32dec, le32dec, be64enc, le64enc, be64dec, le64dec],,, [#include <sys/endian.h>])
+
 AC_CHECK_DECLS([fstatvfs],,, [#include <sys/statvfs.h>])
 
 AC_CHECK_DECLS([setgroupent, setpassent],,, [
Index: tools/compat/compat_defs.h
===================================================================
RCS file: /cvsroot/src/tools/compat/compat_defs.h,v
retrieving revision 1.57
diff -u -r1.57 compat_defs.h
--- tools/compat/compat_defs.h	12 Oct 2006 16:19:06 -0000	1.57
+++ tools/compat/compat_defs.h	6 Aug 2007 19:22:53 -0000
@@ -642,6 +642,136 @@
 #define le64toh(x)	htole64(x)
 #endif
 
+#if !HAVE_DECL_BE16ENC
+static __inline void __unused
+be16enc(void *buf, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	p[0] = (uint8_t)(((unsigned)u >> 8) & 0xff);
+	p[1] = (uint8_t)(u & 0xff);
+}
+#endif
+
+#if !HAVE_DECL_LE16ENC
+static __inline void __unused
+le16enc(void *buf, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	p[0] = (uint8_t)(u & 0xff);
+	p[1] = (uint8_t)(((unsigned)u >> 8) & 0xff);
+}
+#endif
+
+#if !HAVE_DECL_BE16DEC
+static __inline uint16_t __unused
+be16dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return (uint16_t)((p[0] << 8) | p[1]);
+}
+#endif
+
+#if !HAVE_DECL_LE16DEC
+static __inline uint16_t __unused
+le16dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return (uint16_t)((p[1] << 8) | p[0]);
+}
+#endif
+
+#if !HAVE_DECL_BE32ENC
+static __inline void __unused
+be32enc(void *buf, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	p[0] = (uint8_t)((u >> 24) & 0xff);
+	p[1] = (uint8_t)((u >> 16) & 0xff);
+	p[2] = (uint8_t)((u >> 8) & 0xff);
+	p[3] = (uint8_t)(u & 0xff);
+}
+#endif
+
+#if !HAVE_DECL_LE32ENC
+static __inline void __unused
+le32enc(void *buf, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	p[0] = (uint8_t)(u & 0xff);
+	p[1] = (uint8_t)((u >> 8) & 0xff);
+	p[2] = (uint8_t)((u >> 16) & 0xff);
+	p[3] = (uint8_t)((u >> 24) & 0xff);
+}
+#endif
+
+#if !HAVE_DECL_BE32DEC
+static __inline uint32_t __unused
+be32dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+#endif
+
+#if !HAVE_DECL_LE32DEC
+static __inline uint32_t __unused
+le32dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+#endif
+
+#if !HAVE_DECL_BE64ENC
+static __inline void __unused
+be64enc(void *buf, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	be32enc(p, (uint32_t)(u >> 32));
+	be32enc(p + 4, (uint32_t)(u & 0xffffffffULL));
+}
+#endif
+
+#if !HAVE_DECL_LE64ENC
+static __inline void __unused
+le64enc(void *buf, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)buf;
+
+	le32enc(p, (uint32_t)(u & 0xffffffffULL));
+	le32enc(p + 4, (uint32_t)(u >> 32));
+}
+#endif
+
+#if !HAVE_DECL_BE64DEC
+static __inline uint64_t __unused
+be64dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+#endif
+
+#if !HAVE_DECL_LE64DEC
+static __inline uint64_t __unused
+le64dec(const void *buf)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+
+	return (le32dec(p) | ((uint64_t)le32dec(p + 4) << 32));
+}
+#endif
+
 /* <sys/mman.h> */
 
 #ifndef MAP_FILE