blob: ca8ea657b1108c80c549eaa3dd4e69104d50bb84 (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
#!/bin/sh

# Writes a "CGIT_VERSION = ..." line into the output file, which the build
# then includes. Run it from the project root, as gen-version.sh <fallback>
# [output], so that git describe reports cgit rather than the bundled git
# submodule. The output file defaults to VERSION.

version=$1
output=${2:-VERSION}

# Prefer what git describe reports, but only at the top of the cgit working
# tree, and keep the fallback when it has nothing to say, as in a shallow or
# tagless clone.
if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git'
then
	described=$(git describe --abbrev=4 HEAD 2>/dev/null)
	test -n "$described" && version=$described
fi

new="CGIT_VERSION = $version"
old=$(cat "$output" 2>/dev/null)

# Leaving the file untouched when nothing changed keeps make from rebuilding
# everything that depends on it.
test "$old" = "$new" && exit 0

echo "$new" > "$output"
cat "$output"