This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Backport #30919; remove \n; add $run
[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
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
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
8?RCS: that same Artistic Licence; a copy of which may be found at the root
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:
0f00356b 21?MAKE:byteorder: cat Myread Oldconfig Loc Compile rm run \
1273bb5e 22 usecrosscompile 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
JH
33?C: If the compiler supports cross-compiling or multiple-architecture
34?C: binaries (eg. on NeXT systems), use compiler-defined macros to
35?C: determine the byte order.
36?C: On NeXT 3.2 (and greater), you can build "Fat" Multiple Architecture
37?C: Binaries (MAB) on either big endian or little endian machines.
38?C: The endian-ness is available at compile-time. This only matters
39?C: for perl, where the config.h can be generated and installed on
40?C: one system, and used by a different architecture to build an
41?C: extension. Older versions of NeXT that might not have
42?C: defined either *_ENDIAN__ were all on Motorola 680x0 series,
43?C: so the default case (for NeXT) is big endian to catch them.
44?C: This might matter for NeXT 3.0.
45?C:.
0f00356b 46?H:?%<:#if defined(USE_CROSS_COMPILE) || defined(MULTIARCH)
26327fd3 47?H:?%<:# ifdef __LITTLE_ENDIAN__
6b4048d7 48?H:?%<:# if LONGSIZE == 4
26327fd3
JH
49?H:?%<:# define BYTEORDER 0x1234
50?H:?%<:# else
6b4048d7 51?H:?%<:# if LONGSIZE == 8
26327fd3
JH
52?H:?%<:# define BYTEORDER 0x12345678
53?H:?%<:# endif
54?H:?%<:# endif
55?H:?%<:# else
56?H:?%<:# ifdef __BIG_ENDIAN__
6b4048d7 57?H:?%<:# if LONGSIZE == 4
26327fd3
JH
58?H:?%<:# define BYTEORDER 0x4321
59?H:?%<:# else
6b4048d7 60?H:?%<:# if LONGSIZE == 8
26327fd3
JH
61?H:?%<:# define BYTEORDER 0x87654321
62?H:?%<:# endif
63?H:?%<:# endif
64?H:?%<:# endif
65?H:?%<:# endif
66?H:?%<:# if !defined(BYTEORDER) && (defined(NeXT) || defined(__NeXT__))
67?H:?%<:# define BYTEORDER 0x4321
68?H:?%<:# endif
69?H:?%<:#else
70?H:?%<:#define BYTEORDER 0x$byteorder /* large digits for MSB */
71?H:?%<:#endif /* NeXT */
959f3c4c 72?H:.
959f3c4c 73?T:xxx_prompt
a1780b95 74: check for ordering of bytes in a UV
959f3c4c 75echo " "
0f00356b 76case "$usecrosscompile$multiarch" in
959f3c4c
JH
77*$define*)
78 $cat <<EOM
79You seem to be either cross-compiling or doing a multiarchitecture build,
80skipping the byteorder check.
81
82EOM
0f00356b 83 byteorder='ffff'
959f3c4c
JH
84 ;;
85*)
86 case "$byteorder" in
87 '')
88 $cat <<'EOM'
89In the following, larger digits indicate more significance. A big-endian
90machine like a Pyramid or a Motorola 680?0 chip will come out to 4321. A
91little-endian machine like a Vax or an Intel 80?86 chip would be 1234. Other
9a9edc35
JH
92machines may have weird orders like 3412. A Cray will report 87654321,
93an Alpha will report 12345678. If the test program works the default is
94probably right.
959f3c4c
JH
95I'm now running the test program...
96EOM
a1780b95 97 $cat >try.c <<EOCP
959f3c4c 98#include <stdio.h>
1273bb5e
JH
99#$i_stdlib I_STDLIB
100#ifdef I_STDLIB
101#include <stdlib.h>
102#endif
a1780b95
JH
103#include <sys/types.h>
104typedef $uvtype UV;
959f3c4c
JH
105int main()
106{
107 int i;
108 union {
a1780b95
JH
109 UV l;
110 char c[$uvsize];
959f3c4c
JH
111 } u;
112
a1780b95 113 if ($uvsize > 4)
992b29ec 114 u.l = (((UV)0x08070605) << 32) | (UV)0x04030201;
959f3c4c 115 else
992b29ec 116 u.l = (UV)0x04030201;
a1780b95 117 for (i = 0; i < $uvsize; i++)
959f3c4c
JH
118 printf("%c", u.c[i]+'0');
119 printf("\n");
120 exit(0);
121}
122EOCP
123 xxx_prompt=y
124 set try
914abcdc 125 if eval $compile && $run ./try > /dev/null; then
0f00356b 126 dflt=`$run ./try`
959f3c4c
JH
127 case "$dflt" in
128 [1-4][1-4][1-4][1-4]|12345678|87654321)
129 echo "(The test program ran ok.)"
130 echo "byteorder=$dflt"
131 xxx_prompt=n
132 ;;
133 ????|????????) echo "(The test program ran ok.)" ;;
134 *) echo "(The test program didn't run right for some reason.)" ;;
135 esac
136 else
137 dflt='4321'
138 cat <<'EOM'
139(I can't seem to compile the test program. Guessing big-endian...)
140EOM
141 fi
142 case "$xxx_prompt" in
143 y)
a1780b95 144 rp="What is the order of bytes in $uvtype?"
959f3c4c
JH
145 . ./myread
146 byteorder="$ans"
147 ;;
148 *) byteorder=$dflt
149 ;;
150 esac
151 ;;
152 esac
153 $rm -f try.c try
154 ;;
155esac
156
157