diff --git a/setup.sh b/setup.sh index 49245ec..4020627 100755 --- a/setup.sh +++ b/setup.sh @@ -284,18 +284,27 @@ fi header "Windows Cross-Compile" if $SETUP_WIN; then - win_pkgs="$(get_pkgs win)" - if [[ -n "$win_pkgs" ]]; then - install_pkgs "$win_pkgs" "Windows cross-compile" - fi + # Only touch apt / update-alternatives (which need sudo) when the toolchain is missing. If it is + # already installed, skip them so `./setup.sh --win` can run WITHOUT sudo — important because the + # daemon cross-compile that follows should run as the invoking user. Running the whole setup under + # sudo leaves root-owned build artifacts under external/dragonx, which then break `make clean` on + # a later non-sudo build (stale objects get relinked -> the mingw link failure recurs). + if has_cmd x86_64-w64-mingw32-g++-posix || has_cmd x86_64-w64-mingw32-g++; then + ok "Windows cross-compile toolchain already present — skipping apt install" + else + win_pkgs="$(get_pkgs win)" + if [[ -n "$win_pkgs" ]]; then + install_pkgs "$win_pkgs" "Windows cross-compile" + fi - # Set posix thread model if available - if has_cmd update-alternatives && [[ "$PKG" == "apt" ]]; then - if ! $CHECK_ONLY; then - sudo update-alternatives --set x86_64-w64-mingw32-gcc \ - /usr/bin/x86_64-w64-mingw32-gcc-posix 2>/dev/null || true - sudo update-alternatives --set x86_64-w64-mingw32-g++ \ - /usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true + # Set posix thread model if available + if has_cmd update-alternatives && [[ "$PKG" == "apt" ]]; then + if ! $CHECK_ONLY; then + sudo update-alternatives --set x86_64-w64-mingw32-gcc \ + /usr/bin/x86_64-w64-mingw32-gcc-posix 2>/dev/null || true + sudo update-alternatives --set x86_64-w64-mingw32-g++ \ + /usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true + fi fi fi