blob: e4079ee70b3e7b5b67e98d72f6362673b9fb94a3 (
plain)
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
error_msg()
{
echo $@ >&2
}
host_test()
{
mb_hdrdir=$(pwd)/build
mkdir -p $mb_hdrdir || exit 2
if [ -z "$mb_compiler" ]; then
echo "config error: compiler not set."
exit 2
fi
$mb_compiler -dM -E - < /dev/null > /dev/null && return 0
error_msg "config error: invalid compiler."
exit 2
}
host_endian_h()
{
mb_header='endian.h'
rm -f "$mb_hdrdir"/$mb_header
# portable
printf "#include <$mb_header>" | $mb_compiler $mb_cflags \
-E - > /dev/null 2>/dev/null \
&& return 0
# non-portable
mb_hosthdr=
[ -z $mb_hosthdr ] && printf "#include <sys/$mb_header>" | $mb_compiler $mb_cflags \
-E - > /dev/null 2>/dev/null \
&& mb_hosthdr='sys/'$mb_header
[ -z $mb_hosthdr ] && printf "#include <machine/$mb_header>" | $mb_compiler $mb_cflags \
-E - > /dev/null 2>/dev/null \
&& mb_hosthdr='machine/'$mb_header
if [ -z "$mb_hosthdr" ]; then
error_msg "config error: could not find an alternate <$mb_header>."
exit 2
fi
printf "#include <%s>\\n" $mb_hosthdr > "$mb_hdrdir"/$mb_header || exit 2
}
# one: args
for arg ; do
case "$arg" in
--help) usage
;;
--compiler=*)
mb_compiler=${arg#*=}
;;
--cflags=*)
mb_cflags=${arg#*=}
;;
*)
error_msg ${arg#}: "unsupported config argument."
exit 2
;;
esac
done
# two: test
host_test
# three: headers
host_endian_h
# all done
exit 0
|