mirror of
https://codeberg.org/armin/sm-26.git
synced 2026-10-11 17:01:53 +02:00
41 lines
1 KiB
Bash
41 lines
1 KiB
Bash
|
|
#!/bin/sh
|
||
|
|
set -u
|
||
|
|
|
||
|
|
SRC_DIR="$1"
|
||
|
|
OUT_FILE="$2"
|
||
|
|
|
||
|
|
git_ver="unknown"
|
||
|
|
git_branch="unknown"
|
||
|
|
|
||
|
|
if command -v git >/dev/null 2>&1 && [ -d "$SRC_DIR/.git" ]; then
|
||
|
|
ver=$(git -C "$SRC_DIR" describe --always --dirty --tags 2>/dev/null | tr -d '\n\r')
|
||
|
|
if [ $? -eq 0 ] && [ -n "$ver" ]; then
|
||
|
|
git_ver="$ver"
|
||
|
|
fi
|
||
|
|
|
||
|
|
branch=$(git -C "$SRC_DIR" symbolic-ref --short -q HEAD 2>/dev/null | tr -d '\n\r')
|
||
|
|
if [ -z "$branch" ]; then
|
||
|
|
branch="detached"
|
||
|
|
fi
|
||
|
|
git_branch="$branch"
|
||
|
|
fi
|
||
|
|
|
||
|
|
build_time=$(date '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || date '+%Y-%m-%d %H:%M:%S')
|
||
|
|
|
||
|
|
mkdir -p "$(dirname "$OUT_FILE")"
|
||
|
|
TMP="$OUT_FILE.tmp.$$"
|
||
|
|
|
||
|
|
cat > "$TMP" <<EOF
|
||
|
|
#pragma once
|
||
|
|
static constexpr const char* const SM26_GIT_VERSION = "$git_ver";
|
||
|
|
static constexpr const char* const SM26_GIT_BRANCH = "$git_branch";
|
||
|
|
static constexpr const char* const SM26_BUILD_TIME = "$build_time";
|
||
|
|
EOF
|
||
|
|
|
||
|
|
if [ ! -f "$OUT_FILE" ] || ! cmp -s "$TMP" "$OUT_FILE"; then
|
||
|
|
mv "$TMP" "$OUT_FILE"
|
||
|
|
else
|
||
|
|
rm -f "$TMP"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "buildinfo: v$git_ver ($git_branch) @ $build_time"
|