]> git.ipfire.org Git - thirdparty/pdns.git/blame - build-aux/gen-version
Merge pull request #3520 from janeczku/rec-stats-loglevel
[thirdparty/pdns.git] / build-aux / gen-version
CommitLineData
a4e9add5
PL
1#!/bin/sh
2VERSION="unknown"
3
d529cb25
PL
4DIRTY=""
5git status | grep -q clean || DIRTY='.dirty'
6
7# Special environment variable to signal that we are building a release, as this
8# has condequenses for the version number.
9if [ "${IS_RELEASE}" = "YES" ]; then
10 TAG="$(git describe --tags --exact-match 2> /dev/null | cut -d- -f 2-)"
11 if [ -n "${TAG}" ]; then
12 # We're on a tag
539b284d 13 echo "${TAG}${DIRTY}" | tee .version
d529cb25
PL
14 exit 0
15 fi
16 echo 'This is not a tag, either tag this commit or do not set $IS_RELEASE' >&2
17 exit 1
18fi
19
20#
21# Generate the version number based on the branch
22#
a4e9add5
PL
23if [ ! -z "$(git rev-parse --abbrev-ref HEAD 2> /dev/null)" ]; then
24 if $(git rev-parse --abbrev-ref HEAD | grep -q 'rel/'); then
25 REL_TYPE="$(git rev-parse --abbrev-ref HEAD | cut -d/ -f 2 | cut -d- -f 1)"
26 VERSION="$(git describe --match=${REL_TYPE}-* --dirty=.dirty | cut -d- -f 2-)"
27 else
28 GIT_VERSION=$(git show --no-patch --format=format:%h HEAD)
29 BRANCH=".$(git rev-parse --abbrev-ref HEAD | perl -p -e 's/-//g;')"
30 [ "${BRANCH}" = ".master" ] && BRANCH=''
a4e9add5
PL
31 VERSION="0.0${BRANCH}.${PDNS_BUILD_NUMBER}g${GIT_VERSION}${DIRTY}"
32 fi
33 echo "$VERSION" > .version
34elif [ -f .version ]; then
35 VERSION="$(cat .version)"
36fi
37
27f25e0d 38printf $VERSION