#!/usr/bin/env sh # Generates src/core/version.h from CORE_BASE_VERSION pinned in # Makefile + the current short git rev. Called by: # - The project Makefile at parse time via $(shell ...) (gated to # skip read-only goals like clean / print-* / lint). # - jni/Android.mk via $(shell ...) so ndk-build picks it up. # - scripts/c89-lint.sh, scripts/install-hooks.sh's pre-commit, and # the c-cpp.yml msvc-check step (which invokes cl.exe directly). # # Output is gitignored. Re-runs are content-aware: if the new # contents match the existing file, the mtime is left alone so # incremental builds don't needlessly rebuild libretro.o. # # POSIX sh compatible -- no bashisms. set -e ROOT=$(cd "$(dirname "$0")/.." && pwd) OUT="$ROOT/src/core/version.h" # Portable sed extraction that works on both GNU and BSD sed. CORE_BASE_VERSION=$(sed -n 's/^CORE_BASE_VERSION[[:space:]]*:*=[[:space:]]*\(.*\)/\1/p' "$ROOT/Makefile" | head -1) if [ -z "$CORE_BASE_VERSION" ]; then echo "gen-version-h.sh: failed to read CORE_BASE_VERSION from Makefile" >&2 exit 1 fi # Short rev + "-dirty" when tracked files are modified (see build-id.sh). # Content-aware output below keeps incremental builds cheap: the file is # only rewritten when the rev or dirty state actually changes. # The harness build-identity guard compares VJ_EXPECT_BUILD against this # string, so both sides must agree on the dirty suffix. GIT_REV=$("$ROOT/scripts/build-id.sh") mkdir -p "$(dirname "$OUT")" TMP="$OUT.tmp" cat > "$TMP" << EOF /* Auto-generated by scripts/gen-version-h.sh. Do not edit; do not commit. */ #ifndef VJAG_VERSION_H #define VJAG_VERSION_H #define CORE_BASE_VERSION "${CORE_BASE_VERSION}" #define GIT_VERSION " ${GIT_REV}" #ifdef BUILD_TIMESTAMP #define CORE_VERSION CORE_BASE_VERSION GIT_VERSION " " BUILD_TIMESTAMP #else #define CORE_VERSION CORE_BASE_VERSION GIT_VERSION #endif #endif EOF if cmp -s "$TMP" "$OUT" 2>/dev/null; then rm "$TMP" else mv "$TMP" "$OUT" fi