-mkdir ${QEMU_INSTALL_DIR}
-mkdir build
-cd build
-../configure --target-list=x86_64-softmmu --prefix=${QEMU_INSTALL_DIR} || exit
-make -j`nproc` || exit 1
-make install || exit 1
+mkdir ${QEMU_INSTALL_DIR} || \
+ { echo "Failed to create ${QEMU_INSTALL_DIR}"; exit 1; }
+
+# Apply additional patches
+if [ $PATCH ]
+then
+ chmod +x ${SCRIPT_DIR}/qemu_patches/${QEMU_VERSION}/*
+ run-parts --verbose --report ${SCRIPT_DIR}/qemu_patches/${QEMU_VERSION}
+fi
+
+# Build
+./configure --target-list=x86_64-softmmu --prefix=${QEMU_INSTALL_DIR} || \
+ { echo "Failed to configure ${QEMU_VERSION}"; exit 1; }
+make -j`nproc` || \
+ { echo "Failed to compile ${QEMU_VERSION}"; exit 1; }
+make install || \
+ { echo "Failed to install ${QEMU_VERSION}"; exit 1; }