summaryrefslogtreecommitdiff
path: root/scripts/build-info.sh
blob: 3c8b1fb850eef044b36b11593d9c0ab13bbc14e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

CC=$1

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

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"
echo "#define BUILD_COMMIT \"$build_commit\""
echo "#define BUILD_COMPILER \"$build_compiler\""
echo "#define BUILD_TARGET \"$build_target\""
echo
echo "#endif // BUILD_INFO_H"