|
| 1 | +#!/bin/bash |
| 2 | +######################################################################## |
| 3 | +# |
| 4 | +# Copyright 2016 Keith Busch |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +# copy of this software and associated documentation files (the "Software"), |
| 8 | +# to deal in the Software without restriction, including without limitation |
| 9 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +# and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +# Software is furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included |
| 14 | +# in all copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | +# OTHER DEALINGS IN THE SOFTWARE. |
| 23 | +# |
| 24 | +# Forked off of nvme-cli: |
| 25 | +# https://github.com/linux-nvme/nvme-cli/ |
| 26 | +# |
| 27 | +######################################################################## |
| 28 | + |
| 29 | +OBJDIR=${OBJDIR:-.} |
| 30 | +GVF=$OBJDIR/version.h |
| 31 | +DEF_VER=??? |
| 32 | + |
| 33 | +LF=' |
| 34 | +' |
| 35 | + |
| 36 | +# First see if there is a version file (included in release tarballs), |
| 37 | +# then try git-describe, then default. |
| 38 | +if test -f version; then |
| 39 | + VN=$(cat version) || VN="$DEF_VER" |
| 40 | +elif test -d .git -o -f .git; then |
| 41 | + VN=$(git describe --always --tags --match "v[0-9]*" HEAD 2>/dev/null) |
| 42 | + |
| 43 | + git update-index -q --refresh |
| 44 | + test -z "$(git diff-index --name-only HEAD --)" || |
| 45 | + VN="$VN-dirty" |
| 46 | +else |
| 47 | + VN="$DEF_VER" |
| 48 | +fi |
| 49 | + |
| 50 | +VN=$(expr "$VN" : v*'\(.*\)') |
| 51 | +MVN=$(expr "$VN" : v*'\([0-9.]*\)') |
| 52 | + |
| 53 | +VN_RE='^([0-9]+)\.([0-9]+)(.([0-9]+))?(-rc[0-9]+)?(-([0-9]+)-g([A-Za-z0-9]+))?' |
| 54 | +if [[ $VN =~ $VN_RE ]]; then |
| 55 | + MAJOR=${BASH_REMATCH[1]} |
| 56 | + MINOR=${BASH_REMATCH[2]} |
| 57 | + PATCH=${BASH_REMATCH[4]} |
| 58 | + if [[ "$PATCH" -eq "" ]]; then |
| 59 | + PATCH=0 |
| 60 | + fi |
| 61 | + SINCE_TAG=${BASH_REMATCH[7]} |
| 62 | + if [[ "$SINCE_TAG" -eq "" ]]; then |
| 63 | + SINCE_TAG=0 |
| 64 | + fi |
| 65 | +else |
| 66 | + MAJOR=0 |
| 67 | + MINOR=0 |
| 68 | + SINCE_TAG=0 |
| 69 | +fi |
| 70 | + |
| 71 | +if test -r $GVF |
| 72 | +then |
| 73 | + VC=$(head -n1 $GVF | sed -e 's/^#define VERSION //') |
| 74 | + VC="${VC%\"}" |
| 75 | + VC="${VC#\"}" |
| 76 | +else |
| 77 | + VC=unset |
| 78 | +fi |
| 79 | + |
| 80 | +test "$VN" = "$VC" || { |
| 81 | + echo " VER $VN" |
| 82 | + echo "#define VERSION \"$VN\"" >$GVF |
| 83 | +} |
0 commit comments