tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: host endianness
Well, in summary, you guys are pretty clever.
On Mon, 8 Feb 2010, Izumi Tsutsui wrote:
> With nbtool_config.h like src/sbin/disklabel/bswap.h?
>
> ---
> #include <sys/types.h>
>
> #if HAVE_NBTOOL_CONFIG_H
> #ifndef BYTE_ORDER
> #ifdef WORDS_BIGENDIAN
> #define BYTE_ORDER BIG_ENDIAN
> #else
> #define BYTE_ORDER LITTLE_ENDIAN
> #endif
> #endif
> #endif
>
> #define HOST_BYTE_ORDER BYTE_ORDER
This however, requires modifying the pcc dist for a NetBSD-ism, which I'm
reluctant to do (the native pcc build just uses GNU configure to provide
this definition for each use case)
On Mon, 8 Feb 2010, Christos Zoulas wrote:
> compile and run:
>
> #include <stdio.h>
> union {
> int x;
> char c[4];
> } z = {
> .x = ('4' << 24) | ('3' << 16) | ('2' << 8) | '1'
> };
>
> int
> main(void)
> {
> printf("%4.4s\n", z.c);
> return 0;
> }
which makes some sense but as noted, it does require building and running
a host program in a strange place (that Makefile.inc will be included
several times)
Then, various contributors come up with:
> printf "%s" "C!" | od -t x2 | sed 's/[^1234]*//;s/2143/4321/p;d'
which Alan Barrett doesn't particularly like:
> src/tools/compat already has a configure script that sets BYTE_ORDER,
> and I'd prefer it if we could use that definition, or add another mini C
> program to the configure script, rather than relying on yet another host
> tool.
and I wonder if it would be simpler to use my original idea just extended
with a quick copy/paste from bsd.own.mk to guarantee we know the host
architecture, like so?
Index: bsd.endian.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.endian.mk,v
retrieving revision 1.15
diff -u -r1.15 bsd.endian.mk
--- bsd.endian.mk 9 Jan 2008 11:26:14 -0000 1.15
+++ bsd.endian.mk 10 Feb 2010 09:13:21 -0000
@@ -24,4 +24,31 @@
TARGET_ENDIANNESS= 4321
.endif
+# For _HOST_ARCH, if uname -p fails, or prints "unknown", or prints
+# something that does not look like an identifier, then use uname -m.
+_HOST_ARCH!= uname -p 2>/dev/null
+_HOST_ARCH:= ${HOST_ARCH:tW:C/.*[^-_A-Za-z0-9].*//:S/unknown//}
+.if empty(_HOST_ARCH)
+_HOST_ARCH!= uname -m
+.endif
+
+.if ${_HOST_ARCH} == "alpha" || \
+ ${_HOST_ARCH} == "arm" || \
+ ${_HOST_ARCH} == "i386" || \
+ ${_HOST_ARCH} == "ia64" || \
+ ${_HOST_ARCH} == "vax" || \
+ ${_HOST_ARCH} == "x86_64" || \
+ ${_HOST_ARCH:C/^.*el$/el/} == "el"
+HOST_ENDIANNESS= 1234
+.elif ${_HOST_ARCH} == "hppa" || \
+ ${_HOST_ARCH} == "m68000" || \
+ ${_HOST_ARCH} == "m68k" || \
+ ${_HOST_ARCH} == "powerpc" || \
+ ${_HOST_ARCH} == "powerpc64" || \
+ ${_HOST_ARCH} == "sparc" || \
+ ${_HOST_ARCH} == "sparc64" || \
+ ${_HOST_ARCH:C/^.*eb$/eb/} == "eb"
+HOST_ENDIANNESS= 4321
+.endif
+
.endif # !defined(_BSD_ENDIAN_MK_)
regards,
iain
Home |
Main Index |
Thread Index |
Old Index