This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / byteorder.U
1 ?RCS: $Id: byteorder.U 1 2006-08-24 12:32:52Z rmanfredi $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.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:
21 ?MAKE:byteorder: cat Myread Oldconfig Loc +cc +ccflags rm
22 ?MAKE:  -pick add $@ %<
23 ?S:byteorder:
24 ?S:     This variable holds the byte order. In the following, larger digits
25 ?S:     indicate more significance.  The variable byteorder is either 4321
26 ?S:     on a big-endian machine, or 1234 on a little-endian, or 87654321
27 ?S:     on a Cray ... or 3412 with weird order !
28 ?S:.
29 ?C:BYTEORDER:
30 ?C:     This symbol hold the hexadecimal constant defined in byteorder,
31 ?C:     i.e. 0x1234 or 0x4321, etc...
32 ?C:.
33 ?H:#define BYTEORDER 0x$byteorder       /* large digits for MSB */
34 ?H:.
35 ?T:xxx_prompt
36 ?F:!try
37 : check for ordering of bytes in a long
38 case "$byteorder" in
39 '')
40         $cat <<'EOM'
41   
42 In the following, larger digits indicate more significance.  A big-endian
43 machine like a Pyramid or a Motorola 680?0 chip will come out to 4321. A
44 little-endian machine like a Vax or an Intel 80?86 chip would be 1234. Other
45 machines may have weird orders like 3412.  A Cray will report 87654321. If
46 the test program works the default is probably right.
47 I'm now running the test program...
48 EOM
49         $cat >try.c <<'EOCP'
50 #include <stdio.h>
51 int main()
52 {
53         int i;
54         union {
55                 unsigned long l;
56                 char c[sizeof(long)];
57         } u;
58
59         if (sizeof(long) > 4)
60                 u.l = (0x08070605L << 32) | 0x04030201L;
61         else
62                 u.l = 0x04030201L;
63         for (i = 0; i < sizeof(long); i++)
64                 printf("%c", u.c[i]+'0');
65         printf("\n");
66         exit(0);
67 }
68 EOCP
69         xxx_prompt=y
70         if $cc $ccflags -o try try.c >/dev/null 2>&1 && ./try > /dev/null; then
71                 dflt=`./try`
72                 case "$dflt" in
73                 [1-4][1-4][1-4][1-4]|12345678|87654321)
74                         echo "(The test program ran ok.)"
75                         echo "byteorder=$dflt"
76                         xxx_prompt=n
77                         ;;
78                 ????|????????) echo "(The test program ran ok.)" ;;
79                 *) echo "(The test program didn't run right for some reason.)" ;;
80                 esac
81         else
82                 dflt='4321'
83                 cat <<'EOM'
84 (I can't seem to compile the test program.  Guessing big-endian...)
85 EOM
86         fi
87         case "$xxx_prompt" in
88         y)
89                 rp="What is the order of bytes in a long?"
90                 . ./myread
91                 byteorder="$ans"
92                 ;;
93         *)      byteorder=$dflt
94                 ;;
95         esac
96         ;;
97 esac
98 $rm -f try.c try
99