#!/bin/sh
set -e

HIPERISO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
GUI_DIR="$HIPERISO_ROOT/src/gui/QT"
BUILD_DIR="$GUI_DIR/build_output"
PAYLOAD="$HIPERISO_ROOT/build/payload"

cd "$GUI_DIR"
mkdir -p "$BUILD_DIR"

qmake Hiperiso2Disk.pro -o "$BUILD_DIR/Makefile"
make -j"$(nproc)" -C "$BUILD_DIR" 2>&1 | tail -20

strip "$BUILD_DIR/Hiperiso2Disk"

mkdir -p "$PAYLOAD/tool/x86_64"
cp "$BUILD_DIR/Hiperiso2Disk" "$PAYLOAD/tool/x86_64/Hiperiso2Disk.qt5"
chmod +x "$PAYLOAD/tool/x86_64/Hiperiso2Disk.qt5"

echo "=== Hiperiso2Disk.qt5 ==="
ls -lh "$PAYLOAD/tool/x86_64/Hiperiso2Disk.qt5"
