Skip to content

Commit 4c3b80d

Browse files
committed
scripts: Add script to build QEMU
This commit adds a script to build QEMU outside Poky for non-Linux hosts. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent b4cc537 commit 4c3b80d

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

scripts/build_qemu.sh

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#/usr/bin/env bash
2+
3+
set -e
4+
5+
usage()
6+
{
7+
echo "Usage: $(basename $0) host source output"
8+
}
9+
10+
# Validate and parse arguments
11+
if [ "$1" == "" ]; then
12+
usage
13+
echo
14+
echo "host must be specified."
15+
exit 1
16+
elif [ "$2" == "" ]; then
17+
usage
18+
echo
19+
echo "source must be specified."
20+
exit 1
21+
elif [ "$3" == "" ]; then
22+
usage
23+
echo
24+
echo "output must be specified."
25+
exit 1
26+
fi
27+
28+
BUILD_HOST="$1"
29+
BUILD_SOURCE="$2"
30+
BUILD_OUTPUT="$3"
31+
32+
# Set build parameters
33+
QEMU_TARGETS=" \
34+
aarch64-softmmu \
35+
arm-softmmu \
36+
i386-softmmu \
37+
mips-softmmu \
38+
mipsel-softmmu \
39+
or1k-softmmu \
40+
riscv32-softmmu \
41+
riscv64-softmmu \
42+
rx-softmmu \
43+
sparc-softmmu \
44+
x86_64-softmmu \
45+
xtensa-softmmu \
46+
"
47+
48+
QEMU_FLAGS=" \
49+
--disable-attr \
50+
--disable-cap-ng \
51+
--disable-curl \
52+
--disable-curses \
53+
--disable-debug-info \
54+
--disable-dmg
55+
--disable-docs \
56+
--disable-glusterfs \
57+
--disable-gnutls \
58+
--disable-gtk \
59+
--disable-guest-agent \
60+
--disable-iconv \
61+
--disable-kvm \
62+
--disable-libiscsi \
63+
--disable-libnfs \
64+
--disable-libssh \
65+
--disable-libusb \
66+
--disable-linux-aio \
67+
--disable-nettle \
68+
--disable-numa \
69+
--disable-parallels \
70+
--disable-replication \
71+
--disable-sdl \
72+
--disable-seccomp \
73+
--disable-selinux \
74+
--disable-tpm \
75+
--disable-usb-redir \
76+
--disable-virtfs \
77+
--disable-xen \
78+
--enable-gcrypt \
79+
--enable-png \
80+
--enable-vnc \
81+
--enable-vnc-jpeg \
82+
"
83+
84+
if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
85+
BUILD_PREFIX="${BUILD_OUTPUT}/qemu"
86+
87+
# Set MinGW-w64 cross toolchain prefix
88+
QEMU_FLAGS+="--cross-prefix=x86_64-w64-mingw32-"
89+
90+
# Specify statically linked libraries. Only small runtime libraries are
91+
# statically linked for now to reduce the overall QEMU binary size.
92+
export LDFLAGS=" \
93+
-l:libssp.a \
94+
-l:libwinpthread.a \
95+
"
96+
elif [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
97+
BUILD_PREFIX="${BUILD_OUTPUT}/opt/qemu"
98+
99+
case ${BUILD_HOST} in
100+
macos-aarch64)
101+
HOMEBREW_PREFIX="/opt/homebrew"
102+
;;
103+
macos-x86_64)
104+
HOMEBREW_PREFIX="/usr/local"
105+
;;
106+
esac
107+
108+
# Ensure that arch-specific Homebrew environment is configured
109+
eval $(${HOMEBREW_PREFIX}/bin/brew shellenv)
110+
111+
# Specify statically linked libraries and their dependencies
112+
export LDFLAGS=" \
113+
${HOMEBREW_PREFIX}/lib/libgcrypt.a \
114+
${HOMEBREW_PREFIX}/lib/libgio-2.0.a \
115+
${HOMEBREW_PREFIX}/lib/libglib-2.0.a \
116+
${HOMEBREW_PREFIX}/lib/libgmodule-2.0.a \
117+
${HOMEBREW_PREFIX}/lib/libgmp.a \
118+
${HOMEBREW_PREFIX}/lib/libgobject-2.0.a \
119+
${HOMEBREW_PREFIX}/lib/libgpg-error.a \
120+
${HOMEBREW_PREFIX}/lib/libintl.a \
121+
${HOMEBREW_PREFIX}/lib/libjpeg.a \
122+
${HOMEBREW_PREFIX}/lib/libpcre2-8.a \
123+
${HOMEBREW_PREFIX}/lib/libpixman-1.a \
124+
${HOMEBREW_PREFIX}/lib/libpng.a \
125+
${HOMEBREW_PREFIX}/lib/libzstd.a \
126+
${HOMEBREW_PREFIX}/opt/libffi/lib/libffi.a \
127+
-framework AppKit \
128+
-framework CoreServices \
129+
-framework Foundation \
130+
-liconv \
131+
-lresolv \
132+
-lz \
133+
"
134+
else
135+
echo "ERROR: Invalid build host '${BUILD_HOST}'"
136+
exit 1
137+
fi
138+
139+
# Configure QEMU
140+
${BUILD_SOURCE}/configure \
141+
${QEMU_FLAGS} \
142+
--target-list="${QEMU_TARGETS}" \
143+
--prefix="${BUILD_PREFIX}"
144+
145+
# Build QEMU
146+
make -j
147+
148+
# Install QEMU
149+
make install
150+
151+
# Copy required dynamic-link libraries for Windows
152+
if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
153+
QEMU_WIN_LIBS=" \
154+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libgcrypt-20.dll \
155+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libgpg-error-0.dll \
156+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libiconv-2.dll \
157+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libintl-8.dll \
158+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libjpeg-8.dll \
159+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libpixman-1-0.dll \
160+
"
161+
162+
for l in ${QEMU_WIN_LIBS}; do
163+
cp -f ${l} ${BUILD_PREFIX}
164+
done
165+
fi
166+
167+
# Symlink QEMU executables for macOS
168+
if [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
169+
mkdir -p ${BUILD_OUTPUT}/usr/bin
170+
pushd ${BUILD_OUTPUT}/usr/bin
171+
172+
ln -sf ../../opt/qemu/bin/qemu-edid qemu-edid
173+
ln -sf ../../opt/qemu/bin/qemu-img qemu-img
174+
ln -sf ../../opt/qemu/bin/qemu-io qemu-io
175+
ln -sf ../../opt/qemu/bin/qemu-nbd qemu-nbd
176+
ln -sf ../../opt/qemu/bin/qemu-storage-daemon qemu-storage-daemon
177+
ln -sf ../../opt/qemu/bin/qemu-system-aarch64 qemu-system-aarch64
178+
ln -sf ../../opt/qemu/bin/qemu-system-arm qemu-system-arm
179+
ln -sf ../../opt/qemu/bin/qemu-system-i386 qemu-system-i386
180+
ln -sf ../../opt/qemu/bin/qemu-system-mips qemu-system-mips
181+
ln -sf ../../opt/qemu/bin/qemu-system-mipsel qemu-system-mipsel
182+
ln -sf ../../opt/qemu/bin/qemu-system-or1k qemu-system-or1k
183+
ln -sf ../../opt/qemu/bin/qemu-system-riscv32 qemu-system-riscv32
184+
ln -sf ../../opt/qemu/bin/qemu-system-riscv64 qemu-system-riscv64
185+
ln -sf ../../opt/qemu/bin/qemu-system-rx qemu-system-rx
186+
ln -sf ../../opt/qemu/bin/qemu-system-sparc qemu-system-sparc
187+
ln -sf ../../opt/qemu/bin/qemu-system-x86_64 qemu-system-x86_64
188+
ln -sf ../../opt/qemu/bin/qemu-system-xtensa qemu-system-xtensa
189+
190+
popd
191+
fi

0 commit comments

Comments
 (0)