summaryrefslogtreecommitdiff
path: root/scripts/build-info.sh
diff options
context:
space:
mode:
authorCebtenzzre <cebtenzzre@gmail.com>2023-09-15 16:59:49 -0400
committerGitHub <noreply@github.com>2023-09-15 16:59:49 -0400
commite6616cf0db2b63189fc34d0076f654af9adecdf8 (patch)
tree5a5d518c2e576972ee097297ed1551b66880914b /scripts/build-info.sh
parent3aefaab9e59335ebb07d5205dbc8633efd680e58 (diff)
examples : add compiler version and target to build info (#2998)
Diffstat (limited to 'scripts/build-info.sh')
-rwxr-xr-xscripts/build-info.sh38
1 files changed, 25 insertions, 13 deletions
diff --git a/scripts/build-info.sh b/scripts/build-info.sh
index ed0d6c56..3c8b1fb8 100755
--- a/scripts/build-info.sh
+++ b/scripts/build-info.sh
@@ -1,23 +1,35 @@
#!/bin/sh
-BUILD_NUMBER="0"
-BUILD_COMMIT="unknown"
+CC=$1
-REV_LIST=$(git rev-list --count HEAD)
-if [ $? -eq 0 ]; then
- BUILD_NUMBER=$REV_LIST
+build_number="0"
+build_commit="unknown"
+build_compiler="unknown"
+build_target="unknown"
+
+if out=$(git rev-list --count HEAD); then
+ # git is broken on WSL so we need to strip extra newlines
+ build_number=$(printf '%s' "$out" | tr -d '\n')
+fi
+
+if out=$(git rev-parse --short HEAD); then
+ build_commit=$(printf '%s' "$out" | tr -d '\n')
+fi
+
+if out=$($CC --version | head -1); then
+ build_compiler=$out
fi
-REV_PARSE=$(git rev-parse --short HEAD)
-if [ $? -eq 0 ]; then
- BUILD_COMMIT=$REV_PARSE
+if out=$($CC -dumpmachine); then
+ build_target=$out
fi
echo "#ifndef BUILD_INFO_H"
echo "#define BUILD_INFO_H"
-echo ""
-echo "#define BUILD_NUMBER $BUILD_NUMBER" | tr -d '\n'
-echo ""
-echo "#define BUILD_COMMIT \"$BUILD_COMMIT\"" | tr -d '\n'
-echo ""
+echo
+echo "#define BUILD_NUMBER $build_number"
+echo "#define BUILD_COMMIT \"$build_commit\""
+echo "#define BUILD_COMPILER \"$build_compiler\""
+echo "#define BUILD_TARGET \"$build_target\""
+echo
echo "#endif // BUILD_INFO_H"