1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/sh
# many parts of this blatantly ripped from GNU Autoconf macros
# Use this for cross-compiling, as we can't run cross-compiled binaries
# on our host.
if test -z "$O" || ! cd "$O"; then
echo '$O= not defined or not a directory' >&2
exit 1
fi
echo '/* architecture-specific settings (auto-detected): */'
# check sizes of various types we care for
# this is slightly slower but much easier to read and follow than the
# bisecting autoconf version
for t in short int long 'long long'; do
> out
for s in 2 4 6 8 12 1 16 24 32 0; do
cat > t.c <<EOF
int main(void)
{
static int x[(long int)(sizeof($t)) == $s ? 1 : -1];
x[0] = 0;
return 0;
}
EOF
echo "trying sizeof($t) == $s" >> out
$CC -o t.o $CFLAGS $CPPFLAGS t.c \
>> out 2>&1 && break
done
if test $s -eq 0; then
echo "Unable to calculate sizeof($t) for cross-compiling" >&2
cat out >&2
exit 1
fi
t=`echo $t | tr a-z A-Z | tr ' ' _`
echo "#define SIZEOF_$t $s"
echo "SIZEOF_$t := $s" >> config_detected.mk
done
# check endian-ness
cat > t.c <<EOF
short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
void _ascii(void)
{
char *s = (char *)ascii_mm;
s = (char *)ascii_ii;
}
short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
void _ebcdic(void)
{
char *s = (char *)ebcdic_mm;
s = (char *)ebcdic_ii;
}
int main(void)
{
_ascii();
_ebcdic();
return 0;
}
EOF
echo "compiling endian test" > out
$CC -o t.o $CFLAGS $CPPFLAGS t.c >> out 2>&1
if grep BIGenDianSyS t.o >/dev/null 2>&1; then
echo "#define WORDS_BIGENDIAN 1"
echo "WORDS_BIGENDIAN := 1" >> config_detected.mk
elif grep LiTTleEnDian t.o >/dev/null 2>&1; then
echo "/* #undef WORDS_BIGENDIAN */"
echo "# WORDS_BIGENDIAN :=" >> config_detected.mk
else
echo "Unable to determine endian-ness for cross compiling" >&2
cat out >&2
exit 1
fi
echo ''
exec rm -f t.o out t.c
|