#!/bin/sh -e

for patch in *.patch; do
    patch -p1 < "$patch"
done

# This is required for linux-headers 5.10
# If you encounter build failures using a later kernel,
# comment out this line:
sed -i 's/#include <sys\/sysinfo.h>//' linux-user/syscall.c

# Remove bash dependency
sed -i 's/env bash/env sh/g' Makefile

# Build qemu-system* binaries dynamically linked
./configure \
    --prefix=/usr \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --disable-debug-info \
    --disable-gtk \
    --disable-docs \
    --enable-sdl \
    --enable-kvm \
    --enable-pie \
    --enable-curses \
    --disable-user \
    --disable-linux-user \
    --enable-system

make
make DESTDIR="$1" PREFIX=/usr install
make clean

# Build qemu Linux user binaries statically linked.
./configure \
    --prefix=/usr \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --disable-debug-info \
    --disable-gtk \
    --disable-docs \
    --disable-user \
    --enable-linux-user \
    --disable-system \
    --static

make
make DESTDIR="$1" PREFIX=/usr install
