forked from rhdrjones/kvm-unit-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·227 lines (207 loc) · 5.18 KB
/
configure
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env bash
srcdir=$(cd "$(dirname "$0")"; pwd)
prefix=/usr/local
cc=gcc
ld=ld
objcopy=objcopy
objdump=objdump
ar=ar
addr2line=addr2line
arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
host=$arch
cross_prefix=
endian=""
pretty_print_stacks=yes
environ_default=yes
u32_long=
vmm="qemu"
errata_force=0
erratatxt="$srcdir/errata.txt"
usage() {
cat <<-EOF
Usage: $0 [options]
Options include:
--arch=ARCH architecture to compile for ($arch)
--processor=PROCESSOR processor to compile for ($arch)
--vmm=VMM virtual machine monitor to compile for (qemu
or kvmtool, default is qemu) (arm/arm64 only)
--cross-prefix=PREFIX cross compiler prefix
--cc=CC c compiler to use ($cc)
--ld=LD ld linker to use ($ld)
--prefix=PREFIX where to install things ($prefix)
--endian=ENDIAN endianness to compile for (little or big, ppc64 only)
--[enable|disable]-pretty-print-stacks
enable or disable pretty stack printing (enabled by default)
--[enable|disable]-default-environ
enable or disable the generation of a default environ when
no environ is provided by the user (enabled by default)
--erratatxt=FILE specify a file to use instead of errata.txt. Use
'--erratatxt=' to ensure no file is used.
EOF
exit 1
}
while [[ "$1" = -* ]]; do
opt="$1"; shift
arg=
if [[ "$opt" = *=* ]]; then
arg="${opt#*=}"
opt="${opt%%=*}"
fi
case "$opt" in
--prefix)
prefix="$arg"
;;
--arch)
arch="$arg"
;;
--processor)
processor="$arg"
;;
--vmm)
vmm="$arg"
;;
--cross-prefix)
cross_prefix="$arg"
;;
--endian)
endian="$arg"
;;
--cc)
cc="$arg"
;;
--ld)
ld="$arg"
;;
--enable-pretty-print-stacks)
pretty_print_stacks=yes
;;
--disable-pretty-print-stacks)
pretty_print_stacks=no
;;
--enable-default-environ)
environ_default=yes
;;
--disable-default-environ)
environ_default=no
;;
--erratatxt)
erratatxt=
[ "$arg" ] && erratatxt=$(eval realpath "$arg")
;;
--help)
usage
;;
*)
usage
;;
esac
done
if [ "$erratatxt" ] && [ ! -f "$erratatxt" ]; then
echo "erratatxt: $erratatxt does not exist or is not a regular file"
exit 1
fi
arch_name=$arch
[ "$arch" = "aarch64" ] && arch="arm64"
[ "$arch_name" = "arm64" ] && arch_name="aarch64"
[ -z "$processor" ] && processor="$arch"
if [ "$processor" = "arm64" ]; then
processor="cortex-a57"
elif [ "$processor" = "arm" ]; then
processor="cortex-a15"
fi
if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
testdir=x86
elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
testdir=arm
if [ "$vmm" = "qemu" ]; then
arm_uart_early_addr=0x09000000
elif [ "$vmm" = "kvmtool" ]; then
arm_uart_early_addr=0x3f8
errata_force=1
else
echo '--vmm must be one of "qemu" or "kvmtool"!'
usage
fi
elif [ "$arch" = "ppc64" ]; then
testdir=powerpc
firmware="$testdir/boot_rom.bin"
if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then
echo "You must provide endianness (big or little)!"
usage
fi
else
testdir=$arch
fi
if [ ! -d "$srcdir/$testdir" ]; then
echo "$testdir does not exist!"
exit 1
fi
if [ -f "$srcdir/$testdir/run" ]; then
ln -fs "$srcdir/$testdir/run" $testdir-run
fi
# check if uint32_t needs a long format modifier
cat << EOF > lib-test.c
__UINT32_TYPE__
EOF
u32_long=$("$cross_prefix$cc" -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
rm -f lib-test.c
# Are we in a separate build tree? If so, link the Makefile
# and shared stuff so that 'make' and run_tests.sh work.
if test ! -e Makefile; then
echo "linking Makefile..."
ln -s "$srcdir/Makefile" .
echo "linking tests..."
mkdir -p $testdir
ln -sf "$srcdir/$testdir/run" $testdir/
ln -sf "$srcdir/$testdir/unittests.cfg" $testdir/
ln -sf "$srcdir/run_tests.sh"
echo "linking scripts..."
ln -sf "$srcdir/scripts"
fi
# link lib/asm for the architecture
rm -f lib/asm
asm="asm-generic"
if [ -d "$srcdir/lib/$arch/asm" ]; then
asm="$srcdir/lib/$arch/asm"
elif [ -d "$srcdir/lib/$testdir/asm" ]; then
asm="$srcdir/lib/$testdir/asm"
fi
mkdir -p lib
ln -sf "$asm" lib/asm
# create the config
cat <<EOF > config.mak
SRCDIR=$srcdir
PREFIX=$prefix
HOST=$host
ARCH=$arch
ARCH_NAME=$arch_name
PROCESSOR=$processor
CC=$cross_prefix$cc
LD=$cross_prefix$ld
OBJCOPY=$cross_prefix$objcopy
OBJDUMP=$cross_prefix$objdump
AR=$cross_prefix$ar
ADDR2LINE=$cross_prefix$addr2line
TEST_DIR=$testdir
FIRMWARE=$firmware
ENDIAN=$endian
PRETTY_PRINT_STACKS=$pretty_print_stacks
ENVIRON_DEFAULT=$environ_default
ERRATATXT=$erratatxt
U32_LONG_FMT=$u32_long
EOF
cat <<EOF > lib/config.h
#ifndef CONFIG_H
#define CONFIG_H 1
/*
* Generated file. DO NOT MODIFY.
*
*/
EOF
if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
cat <<EOF >> lib/config.h
#define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr}
#define CONFIG_ERRATA_FORCE ${errata_force}
EOF
fi
echo "#endif" >> lib/config.h