| ARG UBUNTU_VERSION="UBUNTU_VERSION_build_arg_must_be_set" | |
| FROM ubuntu:$UBUNTU_VERSION AS build | |
| # add deb-src for apt build-dep | |
| RUN sed -e 's/Types: deb/Types: deb deb-src/' -i /etc/apt/sources.list.d/* || true | |
| RUN sed -e 's/# deb-src/deb-src/' -i /etc/apt/sources.list | |
| # archive.canonical.com is not reachable anymore, and cause a long timeout | |
| RUN sed -e '/archive.canonical.com/d' -i /etc/apt/sources.list | |
| # build dependencies | |
| RUN apt update && \ | |
| env DEBIAN_FRONTEND=noninteractive apt install -y git build-essential flex bison | |
| RUN apt update && \ | |
| env DEBIAN_FRONTEND=noninteractive apt build-dep -y --arch-only qemu | |
| ARG QEMU_VERSION | |
| RUN echo "QEMU_VERSION=${QEMU_VERSION:?QEMU_VERSION build arg must be set}" | |
| ARG QEMU_REPO="https://gitlab.com/qemu-project/qemu.git" | |
| RUN cd /tmp && \ | |
| mkdir qemu && cd qemu && git init && \ | |
| git remote add origin "${QEMU_REPO}" && \ | |
| git fetch origin "${QEMU_VERSION}" --depth 1 && \ | |
| git checkout FETCH_HEAD && \ | |
| ./configure --prefix=/opt/qemu --disable-docs --disable-werror && \ | |
| make install -j $(nproc) && \ | |
| strip /opt/qemu/bin/* && \ | |
| rm -rf /tmp/* | |
| # retrieve runtime dependencies (libs) | |
| RUN ldd /opt/qemu/bin/* | grep '=>' | sed -e 's/.*=>//' -e 's/(.*//' | sort -u > /opt/qemu/libs | |
| # store them in /deps/lib | |
| RUN mkdir -p /deps/lib && cp --preserve --dereference $(cat /opt/qemu/libs) /deps/lib | |
| # copy loader (with its original path) | |
| RUN cp --preserve --parents --dereference /lib*/ld-linux* /deps/ | |
| ################################################################################ | |
| FROM scratch | |
| COPY --from=build /deps / | |
| # copy qemu and all associated artifacts (roms, ...) | |
| COPY --from=build /opt/qemu /usr | |
| # build with: | |
| # podman build -f release.docker --build-arg QEMU_VERSION=v11.1.0 --build-arg UBUNTU_VERSION=24.04 -t qemu/v11.1.0 | |
| # run with: | |
| # podman run -it --rm qemu/v11.1.0 qemu-system-aarch64 --version |