enter: Save and restore the terminal settings.
[micoforia.git] / version-gen.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-only
3
4 package="$1"
5 version_file="$2"
6
7 ver='unnamed_version'
8 # First try git, then gitweb, then default.
9 if [ -e '.git' -o -e '../.git' ]; then
10 git_ver=$(git describe --abbrev=4 HEAD 2>/dev/null)
11 [ -z "$git_ver" ] && git_ver="$ver"
12 # update stat information in index to match working tree
13 git update-index -q --refresh > /dev/null
14 # if there are differences (exit code 1), the working tree is dirty
15 git diff-index --quiet HEAD || git_ver=$git_ver-dirty
16 ver=$git_ver
17 elif [ "${PWD%%-*}" = $package- ]; then
18 ver=${PWD##*/$package-}
19 fi
20 ver=${ver#v}
21
22 echo "$ver"
23 [ -z "${version_file}" ] && exit 0
24 # update version file if necessary
25 content="const char *${package}_version(void) {return \"$ver\";};"
26 [ -r "$version_file" ] && echo "$content" | cmp -s - $version_file && exit 0
27 echo "$content" > $version_file