File: check-bigendian.sh

package info (click to toggle)
skyeye 1.2.5-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,236 kB
  • ctags: 19,345
  • sloc: ansic: 90,379; sh: 5,188; python: 707; cpp: 417; makefile: 322; exp: 38
file content (62 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
#
# Written by Anthony Lee 2007.03
#

case $CC in
	*gcc*)
		;;
	*)
		# other compiler, should be checked manually.
		printf "IGNORE\n"
		exit 0
		;;
esac

SRC="
static unsigned int data[] = {0x42696745, 0x6e646961, 0x6e537973};

int main(int argc, char **argv)
{
	unsigned int v = 0x12345678;
	unsigned char *s = (unsigned char*)&v;

	exit((s[0] == 0x12 && s[1] == 0x34 && s[2] == 0x56 && s[3] == 0x78) ? 0 : 1);
}"

PROG="check-bigendian"
OBJECT="${BINARY_DIR}${PROG}.o"
TARGET="${BINARY_DIR}${PROG}${SUFFIX}"

if ! ( echo "$SRC" | $CC -o "$OBJECT" -c -x c - > /dev/null 2>&1 ); then
	printf "FAILED (compiling object)"
	exit 1
fi

if test "x$CROSS_COMPILE" = "x"; then
	if ! ( $CC -o "$TARGET" "$OBJECT" > /dev/null 2>&1 ); then
		rm -f "$OBJECT"
		printf "FAILED (compiling program)"
		exit 1
	fi

	if ! ( "$TARGET" > /dev/null 2>&1 ); then
		rm -f "$OBJECT"
		rm -f "$TARGET"
		printf "no\n"
		exit 1
	fi
elif ! ( grep "BigEndianSys" "$OBJECT" > /dev/null 2>&1 ); then
	rm -f "$OBJECT"
	rm -f "$TARGET"
	printf "no\n"
	exit 1
fi

rm -f "$OBJECT"
rm -f "$TARGET"

printf "yes\n"

exit 0