diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ce1b5..dcda8d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `gmake.mk`: stopped relying on the `OS` env var alone (unset under MSYS2), now also detects Windows via `uname -s` (`MINGW*`/`MSYS*`/`UCRT*`/`CLANG*`/`CYGWIN*`), with the native-Windows `cmd.exe` mkdir/rd path reserved for environments without a POSIX shell; fixes MSYS2 builds silently falling through to the Linux `mkdir -p`/`rm -rf` path mismatch - `build.sh`: install/uninstall no longer requires `doas`/`sudo` under MSYS2, where neither exists and `id -u` never reports root - `build.bat`: now builds `release` before `install`, no separate manual build step needed +- `build.sh`: `install`/`uninstall` now only escalate the final install step; other targets (`clean`, etc.) and the release build run as the invoking user, so `build clean install` no longer leaves root-owned `obj/`/`bin/` that break later non-root builds diff --git a/build.sh b/build.sh index 3cb086d..08ba120 100755 --- a/build.sh +++ b/build.sh @@ -34,6 +34,24 @@ for arg in "$@"; do done if [ "$HAS_INSTALL" = "1" ] || [ "$HAS_UNINSTALL" = "1" ]; then + # build as the invoking user; only install/uninstall step runs privileged, + # so obj/ and bin/ never end up root-owned + BUILD_ARGS="" + PRIV_ARGS="" + for arg in "$@"; do + case "$arg" in + install|uninstall) PRIV_ARGS="$PRIV_ARGS $arg" ;; + *) BUILD_ARGS="$BUILD_ARGS $arg" ;; + esac + done + + if [ -n "$BUILD_ARGS" ]; then + make -f "$MK_FILE" $BUILD_ARGS GL_MAJOR=$GL_MAJOR GL_MINOR=$GL_MINOR || exit 1 + fi + if [ "$HAS_INSTALL" = "1" ]; then + make -f "$MK_FILE" release GL_MAJOR=$GL_MAJOR GL_MINOR=$GL_MINOR || exit 1 + fi + if [ "$IS_WIN" = "1" ] || [ "$(id -u)" = "0" ]; then PRIV="" elif command -v doas > /dev/null 2>&1; then @@ -45,7 +63,7 @@ if [ "$HAS_INSTALL" = "1" ] || [ "$HAS_UNINSTALL" = "1" ]; then exit 1 fi - $PRIV make -f "$MK_FILE" "$@" GL_MAJOR=$GL_MAJOR GL_MINOR=$GL_MINOR + $PRIV make -f "$MK_FILE" $PRIV_ARGS GL_MAJOR=$GL_MAJOR GL_MINOR=$GL_MINOR elif [ "$1" = "run" ]; then make -f "$MK_FILE" run GL_MAJOR=$GL_MAJOR GL_MINOR=$GL_MINOR elif [ "$1" = "run_gl" ]; then