?RCS: $Id: byteorder.U,v 3.0.1.2 1997/02/28 15:24:55 ram Exp $ ?RCS: ?RCS: Copyright (c) 1991-1993, Raphael Manfredi ?RCS: ?RCS: You may redistribute only under the terms of the Artistic Licence, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of ?RCS: that same Artistic Licence; a copy of which may be found at the root ?RCS: of the source tree for dist 3.0. ?RCS: ?RCS: $Log: byteorder.U,v $ ?RCS: Revision 3.0.1.2 1997/02/28 15:24:55 ram ?RCS: patch61: no longer ask the user if the test runs ok ?RCS: ?RCS: Revision 3.0.1.1 1994/10/29 16:02:58 ram ?RCS: patch36: added ?F: line for metalint file checking ?RCS: ?RCS: Revision 3.0 1993/08/18 12:05:28 ram ?RCS: Baseline for dist 3.0 netwide release. ?RCS: ?MAKE:byteorder: cat Myread Oldconfig Loc Compile rm run \ usecrosscompile multiarch uvtype uvsize i_stdlib ?MAKE: -pick add $@ %< ?S:byteorder: ?S: This variable holds the byte order in a UV. In the following, ?S: larger digits indicate more significance. The variable byteorder ?S: is either 4321 on a big-endian machine, or 1234 on a little-endian, ?S: or 87654321 on a Cray ... or 3412 with weird order ! ?S:. ?C:BYTEORDER: ?C: This symbol holds the hexadecimal constant defined in byteorder, ?C: in a UV, i.e. 0x1234 or 0x4321 or 0x12345678, etc... ?C: If the compiler supports cross-compiling or multiple-architecture ?C: binaries (eg. on NeXT systems), use compiler-defined macros to ?C: determine the byte order. ?C: On NeXT 3.2 (and greater), you can build "Fat" Multiple Architecture ?C: Binaries (MAB) on either big endian or little endian machines. ?C: The endian-ness is available at compile-time. This only matters ?C: for perl, where the config.h can be generated and installed on ?C: one system, and used by a different architecture to build an ?C: extension. Older versions of NeXT that might not have ?C: defined either *_ENDIAN__ were all on Motorola 680x0 series, ?C: so the default case (for NeXT) is big endian to catch them. ?C: This might matter for NeXT 3.0. ?C:. ?H:?%<:#if defined(USE_CROSS_COMPILE) || defined(MULTIARCH) ?H:?%<:# ifdef __LITTLE_ENDIAN__ ?H:?%<:# if LONGSIZE == 4 ?H:?%<:# define BYTEORDER 0x1234 ?H:?%<:# else ?H:?%<:# if LONGSIZE == 8 ?H:?%<:# define BYTEORDER 0x12345678 ?H:?%<:# endif ?H:?%<:# endif ?H:?%<:# else ?H:?%<:# ifdef __BIG_ENDIAN__ ?H:?%<:# if LONGSIZE == 4 ?H:?%<:# define BYTEORDER 0x4321 ?H:?%<:# else ?H:?%<:# if LONGSIZE == 8 ?H:?%<:# define BYTEORDER 0x87654321 ?H:?%<:# endif ?H:?%<:# endif ?H:?%<:# endif ?H:?%<:# endif ?H:?%<:# if !defined(BYTEORDER) && (defined(NeXT) || defined(__NeXT__)) ?H:?%<:# define BYTEORDER 0x4321 ?H:?%<:# endif ?H:?%<:#else ?H:?%<:#define BYTEORDER 0x$byteorder /* large digits for MSB */ ?H:?%<:#endif /* NeXT */ ?H:. ?T:xxx_prompt : check for ordering of bytes in a UV echo " " case "$usecrosscompile$multiarch" in *$define*) $cat <try.c < #$i_stdlib I_STDLIB #ifdef I_STDLIB #include #endif #include typedef $uvtype UV; int main() { int i; union { UV l; char c[$uvsize]; } u; if ($uvsize > 4) u.l = (((UV)0x08070605) << 32) | (UV)0x04030201; else u.l = (UV)0x04030201; for (i = 0; i < $uvsize; i++) printf("%c", u.c[i]+'0'); printf("\n"); exit(0); } EOCP xxx_prompt=y set try if eval $compile && $run ./try > /dev/null; then dflt=`$run ./try` case "$dflt" in [1-4][1-4][1-4][1-4]|12345678|87654321) echo "(The test program ran ok.)" echo "byteorder=$dflt" xxx_prompt=n ;; ????|????????) echo "(The test program ran ok.)" ;; *) echo "(The test program didn't run right for some reason.)" ;; esac else dflt='4321' cat <<'EOM' (I can't seem to compile the test program. Guessing big-endian...) EOM fi case "$xxx_prompt" in y) rp="What is the order of bytes in $uvtype?" . ./myread byteorder="$ans" ;; *) byteorder=$dflt ;; esac ;; esac $rm -f try.c try ;; esac