This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Missed comment removal from NeXT removal
[metaconfig.git] / U / compline / byteorder.U
CommitLineData
959f3c4c
JH
1?RCS: $Id: byteorder.U,v 3.0.1.2 1997/02/28 15:24:55 ram Exp $
2?RCS:
3?RCS: Copyright (c) 1991-1993, Raphael Manfredi
0065f4af 4?RCS:
65a32477 5?RCS: You may redistribute only under the terms of the Artistic License,
959f3c4c
JH
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
65a32477 8?RCS: that same Artistic License; a copy of which may be found at the root
959f3c4c
JH
9?RCS: of the source tree for dist 3.0.
10?RCS:
11?RCS: $Log: byteorder.U,v $
12?RCS: Revision 3.0.1.2 1997/02/28 15:24:55 ram
13?RCS: patch61: no longer ask the user if the test runs ok
14?RCS:
15?RCS: Revision 3.0.1.1 1994/10/29 16:02:58 ram
16?RCS: patch36: added ?F: line for metalint file checking
17?RCS:
18?RCS: Revision 3.0 1993/08/18 12:05:28 ram
19?RCS: Baseline for dist 3.0 netwide release.
20?RCS:
2cb64bf6 21?MAKE:byteorder: cat Myread Oldconfig Loc Compile rm_try run \
9c11722e 22 multiarch uvtype uvsize i_stdlib
959f3c4c
JH
23?MAKE: -pick add $@ %<
24?S:byteorder:
a1780b95
JH
25?S: This variable holds the byte order in a UV. In the following,
26?S: larger digits indicate more significance. The variable byteorder
27?S: is either 4321 on a big-endian machine, or 1234 on a little-endian,
28?S: or 87654321 on a Cray ... or 3412 with weird order !
959f3c4c
JH
29?S:.
30?C:BYTEORDER:
31?C: This symbol holds the hexadecimal constant defined in byteorder,
a1780b95 32?C: in a UV, i.e. 0x1234 or 0x4321 or 0x12345678, etc...
959f3c4c 33?C: If the compiler supports cross-compiling or multiple-architecture
a02993a8 34?C: binaries, use compiler-defined macros to
959f3c4c 35?C: determine the byte order.
959f3c4c 36?C:.
54e5f844 37?H:?%<:#if defined(MULTIARCH)
26327fd3 38?H:?%<:# ifdef __LITTLE_ENDIAN__
6b4048d7 39?H:?%<:# if LONGSIZE == 4
26327fd3
JH
40?H:?%<:# define BYTEORDER 0x1234
41?H:?%<:# else
6b4048d7 42?H:?%<:# if LONGSIZE == 8
26327fd3
JH
43?H:?%<:# define BYTEORDER 0x12345678
44?H:?%<:# endif
45?H:?%<:# endif
46?H:?%<:# else
47?H:?%<:# ifdef __BIG_ENDIAN__
6b4048d7 48?H:?%<:# if LONGSIZE == 4
26327fd3
JH
49?H:?%<:# define BYTEORDER 0x4321
50?H:?%<:# else
6b4048d7 51?H:?%<:# if LONGSIZE == 8
26327fd3
JH
52?H:?%<:# define BYTEORDER 0x87654321
53?H:?%<:# endif
54?H:?%<:# endif
55?H:?%<:# endif
56?H:?%<:# endif
26327fd3
JH
57?H:?%<:#else
58?H:?%<:#define BYTEORDER 0x$byteorder /* large digits for MSB */
a02993a8 59?H:?%<:#endif
959f3c4c 60?H:.
959f3c4c 61?T:xxx_prompt
0065f4af 62?F:!try
a1780b95 63: check for ordering of bytes in a UV
959f3c4c 64echo " "
9c11722e 65case "$multiarch" in
959f3c4c
JH
66*$define*)
67 $cat <<EOM
9c11722e 68You seem to be doing a multiarchitecture build,
959f3c4c
JH
69skipping the byteorder check.
70
71EOM
0f00356b 72 byteorder='ffff'
959f3c4c
JH
73 ;;
74*)
75 case "$byteorder" in
76 '')
77 $cat <<'EOM'
78In the following, larger digits indicate more significance. A big-endian
79machine like a Pyramid or a Motorola 680?0 chip will come out to 4321. A
80little-endian machine like a Vax or an Intel 80?86 chip would be 1234. Other
9a9edc35
JH
81machines may have weird orders like 3412. A Cray will report 87654321,
82an Alpha will report 12345678. If the test program works the default is
83probably right.
959f3c4c
JH
84I'm now running the test program...
85EOM
a1780b95 86 $cat >try.c <<EOCP
959f3c4c 87#include <stdio.h>
1273bb5e
JH
88#$i_stdlib I_STDLIB
89#ifdef I_STDLIB
90#include <stdlib.h>
91#endif
a1780b95
JH
92#include <sys/types.h>
93typedef $uvtype UV;
959f3c4c
JH
94int main()
95{
96 int i;
97 union {
a1780b95
JH
98 UV l;
99 char c[$uvsize];
959f3c4c
JH
100 } u;
101
a1780b95 102 if ($uvsize > 4)
992b29ec 103 u.l = (((UV)0x08070605) << 32) | (UV)0x04030201;
959f3c4c 104 else
992b29ec 105 u.l = (UV)0x04030201;
a1780b95 106 for (i = 0; i < $uvsize; i++)
959f3c4c
JH
107 printf("%c", u.c[i]+'0');
108 printf("\n");
109 exit(0);
110}
111EOCP
112 xxx_prompt=y
113 set try
914abcdc 114 if eval $compile && $run ./try > /dev/null; then
0f00356b 115 dflt=`$run ./try`
959f3c4c
JH
116 case "$dflt" in
117 [1-4][1-4][1-4][1-4]|12345678|87654321)
118 echo "(The test program ran ok.)"
119 echo "byteorder=$dflt"
120 xxx_prompt=n
121 ;;
122 ????|????????) echo "(The test program ran ok.)" ;;
123 *) echo "(The test program didn't run right for some reason.)" ;;
124 esac
125 else
126 dflt='4321'
127 cat <<'EOM'
128(I can't seem to compile the test program. Guessing big-endian...)
129EOM
130 fi
131 case "$xxx_prompt" in
132 y)
a1780b95 133 rp="What is the order of bytes in $uvtype?"
959f3c4c
JH
134 . ./myread
135 byteorder="$ans"
136 ;;
137 *) byteorder=$dflt
138 ;;
139 esac
140 ;;
141 esac
2cb64bf6 142 $rm_try
959f3c4c
JH
143 ;;
144esac
145