Some command line options are not GNU/POSIX compliant (3)
[geeqie.git] / version.sh
1 #!/bin/sh
2
3 ## @file
4 ## @brief Generate the Geeqie version number
5 ##
6 ## This script is called from meson.build
7 ##
8 ## If the current branch is "master" a revison number is generated of the form:  
9 ## <n.m>+git<date of last commit>-<last commit hash>  
10 ## where <n.m> is the most recent tag.  
11 ## e.g. 1.7+git20220117-732b6935  
12 ##
13 ## If not on "master" or no .git directory, a revision number extracted
14 ## from the first line of the NEWS file is generated.  
15 ## This situation will occur when compiling from a source .tar.
16 ## or for a release.  
17 ## The first line of NEWS must be of the form:  
18 ## Geeqie <n.m[.p]>
19 ##
20
21 if [ -d .git ] && [ -x "$(command -v git)" ]
22 then
23         branch=$(git rev-parse --abbrev-ref HEAD)
24
25         if [ "$branch" = "master" ]
26         then
27                 IFS='.'
28                 # shellcheck disable=SC2046
29                 set -- $(git tag --list v[1-9]* | tail -n 1 | tr -d 'v')
30
31                 major_version=$1
32                 minor_version=$2
33 #               patch_version=$3  # not used on master branch
34
35                 printf '%s%s%s%s%s%s%s' "$major_version" "." "$minor_version" "+git" "$(git log --max-count=1 --date=format:"%Y%m%d" --format="%ad")" "-" "$(git rev-parse --quiet --verify --short HEAD)"
36         else
37                 version=$(head -1 NEWS)
38                 # shellcheck disable=SC2086
39                 set -- $version
40                 printf '%s' "$2"
41         fi
42 else
43         version=$(head -1 NEWS)
44         # shellcheck disable=SC2086
45         set -- $version
46         printf '%s' "$2"
47 fi
48