Skip to content

Commit c209ce0

Browse files
lsgunthKelvin Cao
authored andcommitted
Add retrieving version information from git
1 parent b12df66 commit c209ce0

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ __pycache__
1313
cscope.out
1414
tags
1515
*.o.d
16+
version.h

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ install: modules_install
1717

1818
.PHONY: install
1919

20+
version.h: FORCE $(OBJDIR)
21+
@$(SHELL_PATH) ./VERSION-GEN
22+
23+
modules: | version.h
24+
2025
%::
2126
$(MAKE) -C $(KERNEL_SOURCES) M=$$PWD $@
2227

@@ -33,5 +38,7 @@ pahole: pahole64 pahole32
3338
echo "!!Arches don't match!!"
3439

3540
clean::
36-
rm -f pahole32 pahole64 pahole*.txt
41+
rm -f pahole32 pahole64 pahole*.txt version.h
3742
$(MAKE) -C $(KERNEL_SOURCES) M=$$PWD $@
43+
44+
.PHONY: FORCE

VERSION-GEN

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

ntb_hw_switchtec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#include <linux/interrupt.h>
2121
#include <linux/ntb.h>
2222

23+
#include "version.h"
2324
MODULE_DESCRIPTION("Microsemi Switchtec(tm) NTB Driver");
24-
MODULE_VERSION("0.1");
25+
MODULE_VERSION(VERSION);
2526
MODULE_LICENSE("GPL");
2627
MODULE_AUTHOR("Microsemi Corporation");
2728

switchtec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#include <linux/poll.h>
2424
#include <linux/wait.h>
2525

26+
#include "version.h"
2627
MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver");
27-
MODULE_VERSION("0.1");
28+
MODULE_VERSION(VERSION);
2829
MODULE_LICENSE("GPL");
2930
MODULE_AUTHOR("Microsemi Corporation");
3031

0 commit comments

Comments
 (0)