| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | source_dir=$(cygpath -u "$1") |
| 5 | build_dir=$(cygpath -u "$2") |
| 6 | output_dir=$(cygpath -u "$3") |
| 7 | patch_dir=$(cygpath -u "$4") |
| 8 | |
| 9 | for patch_file in "$patch_dir"/*.patch; do |
| 10 | patch -d "$source_dir" -p1 < "$patch_file" |
| 11 | done |
| 12 | mkdir -p "$build_dir" "$output_dir" |
| 13 | cd "$build_dir" |
| 14 | "$source_dir/configure" --target-list=x86_64-softmmu --without-default-features \ |
| 15 | --prefix=C:/CageQemu --bindir=. --datadir=share --with-suffix= \ |
| 16 | --extra-cflags=-D_WIN32_WINNT=0x0A00 \ |
| 17 | --enable-whpx --enable-tcg --enable-pixman --enable-slirp --enable-tools \ |
| 18 | --disable-docs --disable-guest-agent --disable-werror \ |
| 19 | --disable-debug-info |
| 20 | ninja -j 6 qemu-system-x86_64.exe qemu-img.exe |
| 21 | cp qemu-system-x86_64.exe qemu-img.exe "$output_dir/" |
| 22 | strip "$output_dir"/*.exe |
| 23 | |
| 24 | |
| 25 | |
| 26 | pending=("$output_dir"/*.exe) |
| 27 | packages=() |
| 28 | while ((${#pending[@]})); do |
| 29 | binary=${pending[0]} |
| 30 | pending=("${pending[@]:1}") |
| 31 | while read -r dll; do |
| 32 | if [[ -f "$MINGW_PREFIX/bin/$dll" && ! -f "$output_dir/$dll" ]]; then |
| 33 | cp "$MINGW_PREFIX/bin/$dll" "$output_dir/$dll" |
| 34 | packages+=("$(pacman -Qqo "$MINGW_PREFIX/bin/$dll")") |
| 35 | pending+=("$output_dir/$dll") |
| 36 | fi |
| 37 | done < <(objdump -p "$binary" | awk '/DLL Name:/ {print $3}') |
| 38 | done |
| 39 | pacman -Q > "$output_dir/build-packages.txt" |
| 40 | |
| 41 | |
| 42 | for package in "${packages[@]}"; do |
| 43 | read -r name version < <(pacman -Q "$package") |
| 44 | base=$(awk '/^%BASE%$/ {getline; print; exit}' "/var/lib/pacman/local/$name-$version/desc") |
| 45 | [[ -n "$base" ]] || { echo "Source package identity missing for $package" >&2; exit 1; } |
| 46 | printf '%s %s\n' "$base" "$version" |
| 47 | done | sort -u > "$output_dir/build-source-packages.txt" |