[PATCH] scripts: allow building QEMU from sources

14 views
Skip to first unread message

Waldemar Kozaczuk

unread,
Feb 7, 2021, 10:12:30 PM2/7/21
to osv...@googlegroups.com, Waldemar Kozaczuk
Add new script download_and_build_qemu.sh that allows building QEMU from
sources. It installs all necessary packages to build QEMU from sources,
downloads QEMU sources and builds both x86_64 and aarch64 versions of
it.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
scripts/download_and_build_qemu.sh | 61 ++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100755 scripts/download_and_build_qemu.sh

diff --git a/scripts/download_and_build_qemu.sh b/scripts/download_and_build_qemu.sh
new file mode 100755
index 00000000..711882ec
--- /dev/null
+++ b/scripts/download_and_build_qemu.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 Waldemar Kozaczuk
+#
+# This work is open source software, licensed under the terms of the
+# BSD license as described in the LICENSE file in the top-level directory.
+#
+
+# This scripts installs all necessary packages to build QEMU from sources,
+# downloads QEMU sources and builds both x86_64 and aarch64 versions of it
+#
+# Usage:
+# ./scripts/download_and_build_qemu.sh <QEMU_VERSION>
+#
+
+#Install tools
+USER_ID=$(id -u)
+LINUX_DIST_ID=$(python3 -c "import distro; print(distro.id())")
+
+case ${LINUX_DIST_ID} in
+ fedora|centos)
+ PACKAGES="ninja-build cmake3 glib2-devel libfdt-devel pixman-devel zlib-devel libaio-devel libcap-devel libiscsi-devel"
+ if [[ "${LINUX_DIST_ID}" == "fedora" ]]; then
+ PACKAGE_MANAGER=dnf
+ else
+ PACKAGE_MANAGER=yum
+ fi ;;
+ ubuntu)
+ PACKAGES="ninja-build cmake libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libaio-dev libcap-dev libnfs-dev libiscsi-dev"
+ PACKAGE_MANAGER="apt-get" ;;
+ *)
+ echo "Unsupported distribution!" && exit 1
+esac
+
+if [[ "${USER_ID}" == "0" ]]; then
+ echo "Installing all necessary packages!" && ${PACKAGE_MANAGER} -y install ${PACKAGES}
+else
+ echo "Needs super user access to install all necessary packages!" && sudo ${PACKAGE_MANAGER} -y install ${PACKAGES}
+fi
+
+#Download and build qemu
+QEMU_VERSION=$1
+QEMU_VERSION=${QEMU_VERSION:-v5.2.0}
+
+OSV_ROOT=$(dirname $(readlink -e $0))/..
+BUILD_DIR=${OSV_ROOT}/build/downloaded_packages
+
+mkdir -p ${BUILD_DIR}
+pushd ${BUILD_DIR}
+
+if [[ ! -d qemu ]]; then
+ git clone --depth 1 --branch ${QEMU_VERSION} git://git.qemu.org/qemu.git
+fi
+cd qemu
+mkdir -p build && cd build
+
+../configure --target-list=x86_64-softmmu,aarch64-softmmu
+make -j$(nproc)
+popd
+
+echo "Built QEMU at ${BUILD_DIR}/qemu/build/qemu-system-x86_64 and ${BUILD_DIR}/qemu/build/qemu-system-aarch64"
--
2.29.2

Nadav Har'El

unread,
Feb 8, 2021, 5:44:22 AM2/8/21
to Waldemar Kozaczuk, Osv Dev
I guess that's ok, but personally I prefer something simpler, like using "test -f /etc/redhat-release" or "test -f /etc/fedora-release" to check if this is a redhat-like system (including Fedora) and specifically fedora.

+
+case ${LINUX_DIST_ID} in
+  fedora|centos)
+    PACKAGES="ninja-build cmake3 glib2-devel libfdt-devel pixman-devel zlib-devel libaio-devel libcap-devel libiscsi-devel"
+    if [[ "${LINUX_DIST_ID}" == "fedora" ]]; then
+      PACKAGE_MANAGER=dnf
+    else
+      PACKAGE_MANAGER=yum
+    fi ;;
+  ubuntu)
+    PACKAGES="ninja-build cmake libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libaio-dev libcap-dev libnfs-dev libiscsi-dev"
+    PACKAGE_MANAGER="apt-get" ;;
+  *)
+    echo "Unsupported distribution!" && exit 1
+esac
+
+if [[ "${USER_ID}" == "0" ]]; then
+  echo "Installing all necessary packages!" && ${PACKAGE_MANAGER} -y install ${PACKAGES}

I personally prefer not to add the "-y". I think it's a good idea to allow the user, who has no idea that this script is even planning to install anything, say ok if anything needs to be installed.

+else
+  echo "Needs super user access to install all necessary packages!" && sudo ${PACKAGE_MANAGER} -y install ${PACKAGES}
+fi
+
+#Download and build qemu
+QEMU_VERSION=$1
+QEMU_VERSION=${QEMU_VERSION:-v5.2.0}
+
+OSV_ROOT=$(dirname $(readlink -e $0))/..
+BUILD_DIR=${OSV_ROOT}/build/downloaded_packages
+
+mkdir -p ${BUILD_DIR}

Please use double quotes on $BUILD_DIR here an in most lines below. If the current directory's name has a space in it, all this code will break.

+pushd ${BUILD_DIR}
+
+if [[ ! -d qemu ]]; then
+  git clone --depth 1 --branch ${QEMU_VERSION} git://git.qemu.org/qemu.git
+fi
+cd qemu
+mkdir -p build && cd build
+
+../configure --target-list=x86_64-softmmu,aarch64-softmmu
+make -j$(nproc)
+popd
+
+echo "Built QEMU at ${BUILD_DIR}/qemu/build/qemu-system-x86_64 and ${BUILD_DIR}/qemu/build/qemu-system-aarch64"
--
2.29.2

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20210208031209.1266843-1-jwkozaczuk%40gmail.com.

Waldemar Kozaczuk

unread,
Feb 16, 2021, 11:24:57 PM2/16/21
to osv...@googlegroups.com, Waldemar Kozaczuk
Add new script download_and_build_qemu.sh that allows building QEMU from
sources. It installs all necessary packages to build QEMU from sources,
downloads QEMU sources and builds both x86_64 and aarch64 versions of
it.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
scripts/download_and_build_qemu.sh | 61 ++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100755 scripts/download_and_build_qemu.sh

diff --git a/scripts/download_and_build_qemu.sh b/scripts/download_and_build_qemu.sh
new file mode 100755
index 00000000..6104c439
--- /dev/null
+++ b/scripts/download_and_build_qemu.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# Copyright (C) 2021 Waldemar Kozaczuk
+#
+# This work is open source software, licensed under the terms of the
+# BSD license as described in the LICENSE file in the top-level directory.
+#
+
+# This scripts installs all necessary packages to build QEMU from sources,
+# downloads QEMU sources and builds both x86_64 and aarch64 versions of it
+#
+# Usage:
+# ./scripts/download_and_build_qemu.sh <QEMU_VERSION>
+#
+
+#Install tools
+USER_ID=$(id -u)
+LINUX_DIST_ID=$(grep "^ID=" /etc/os-release)
+
+case "${LINUX_DIST_ID}" in
+ *fedora*|*centos*)
+ PACKAGES="ninja-build cmake3 glib2-devel libfdt-devel pixman-devel zlib-devel libaio-devel libcap-devel libiscsi-devel"
+ if [[ "${LINUX_DIST_ID}" == "fedora" ]]; then
+ PACKAGE_MANAGER=dnf
+ else
+ PACKAGE_MANAGER=yum
+ fi ;;
+ *ubuntu*)
+ PACKAGES="ninja-build cmake libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libaio-dev libcap-dev libnfs-dev libiscsi-dev"
+ PACKAGE_MANAGER="apt-get" ;;
+ *)
+ echo "Unsupported distribution!" && exit 1
+esac
+
+if [[ "${USER_ID}" == "0" ]]; then
+ echo "Installing all necessary packages!" && ${PACKAGE_MANAGER} install ${PACKAGES}
+else
+ echo "Needs super user access to install all necessary packages!" && sudo ${PACKAGE_MANAGER} install ${PACKAGES}
+fi
+
+#Download and build qemu
+QEMU_VERSION=$1
+QEMU_VERSION=${QEMU_VERSION:-v5.2.0}
+
+OSV_ROOT=$(dirname $(readlink -e $0))/..
+BUILD_DIR="${OSV_ROOT}"/build/downloaded_packages
+
+mkdir -p "${BUILD_DIR}"

Commit Bot

unread,
Feb 18, 2021, 5:57:19 PM2/18/21
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

scripts: allow building QEMU from sources

Add new script download_and_build_qemu.sh that allows building QEMU from
sources. It installs all necessary packages to build QEMU from sources,
downloads QEMU sources and builds both x86_64 and aarch64 versions of
it.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/scripts/download_and_build_qemu.sh b/scripts/download_and_build_qemu.sh
--- a/scripts/download_and_build_qemu.sh
Reply all
Reply to author
Forward
0 new messages