@@ -23,6 +23,12 @@ AM_LDFLAGS = \
-Wl,--gc-sections \
-Wl,--as-needed
+BUILT_SOURCES = $(top_srcdir)/version.m4
+$(top_srcdir)/version.m4: FORCE
+ $(AM_V_GEN)$(top_srcdir)/git-version-gen
+
+FORCE:
+
SED_PROCESS = \
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \
-e 's,@VERSION\@,$(VERSION),g' \
@@ -6,6 +6,7 @@ if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
echo "Activated pre-commit hook."
fi
+$(dirname $0)/git-version-gen
autoreconf --install --symlink
libdir() {
@@ -1,6 +1,7 @@
AC_PREREQ(2.60)
+m4_include([version.m4])
AC_INIT([ndctl],
- [41],
+ GIT_VERSION,
[linux-nvdimm@lists.01.org],
[ndctl],
[https://github.com/pmem/ndctl])
@@ -34,7 +34,7 @@ int main(int argc, char **argv)
while (fgets(buf, sizeof(buf), stdin)) {
if (strncmp("Version:", buf, 8) == 0)
- fprintf(stdout, "Version: %s\n", VERSION);
+ fprintf(stdout, "Version: %s\n", &VERSION[1]);
else if (strncmp("%global gitcommit", buf, 17) == 0)
fprintf(stdout, "%%global gitcommit %s\n", commit);
else if (strncmp("%define lname", buf, 12) == 0)
@@ -43,6 +43,8 @@ int main(int argc, char **argv)
fprintf(stdout, "%%define dname %s\n", dname[os]);
else if (strncmp("%license", buf, 8) == 0 && !license[os])
/* skip */;
+ else if (strncmp("echo \"\" > version", buf, 17) == 0)
+ fprintf(stdout, "echo \"%s\" > version\n", VERSION);
else
fprintf(stdout, "%s", buf);
}
@@ -4,7 +4,7 @@
Name: ndctl
Version:
-Release: 1%{?gitcommit:.git%{gitcommit}}%{?dist}
+Release: 1%{?dist}
Summary: Manage "libnvdimm" subsystem devices (Non-volatile Memory)
License: GPL-2.0
URL: https://github.com/pmem/ndctl
@@ -52,11 +52,9 @@ Libraries for %{name}
%prep
%setup -q %{?gitcommit:-n %{name}-git%{gitcommit}}
-
%build
-%if %{defined gitcommit}
- ./autogen.sh
-%endif
+echo "" > version
+./autogen.sh
%configure --disable-static
make %{?_smp_mflags}
new file mode 100755
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+dirty() {
+ git update-index -q --refresh
+ if test -z "$(git diff-index --name-only HEAD --)"; then
+ echo "$1"
+ else
+ echo "${1}.dirty"
+ fi
+}
+
+GVF=version.m4
+DEF_VER=v41
+
+LF='
+'
+
+# First see if there is a version file (included in release tarballs),
+# then try git-describe, then default.
+if test -f version; then
+ VN=$(cat version) || VN="$DEF_VER"
+elif test -d ${GIT_DIR:-.git} -o -f .git &&
+ VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) &&
+ case "$VN" in
+ *$LF*) (exit 1) ;;
+ v[0-9]*)
+ VN="$(dirty $VN)"
+ esac; then
+ VN=$(echo "$VN" | sed -e 's/-/./g');
+else
+ read COMMIT COMMIT_SUBJECT <<EOF
+ $(git log --oneline --abbrev=8 -n1 HEAD)
+EOF
+ VN="$(dirty ${DEF_VER}.git$COMMIT)"
+fi
+
+if test -r $GVF; then
+ VC=$(sed -e 's/m4_define(\[GIT_VERSION], \[//' <$GVF)
+ VC=$(echo $VC | sed -e 's/\])//')
+else
+ VC=unset
+fi
+test "$VN" = "$VC" || {
+ echo >&2 "GIT_VERSION = $VN"
+ echo "m4_define([GIT_VERSION], [$VN])" >$GVF
+ exit 0
+}
@@ -22,9 +22,7 @@ struct cmd_struct {
static int cmd_version(int argc, const char **argv)
{
- static const char ndctl_version_string[] = "ndctl " VERSION;
-
- printf("%s\n", ndctl_version_string);
+ printf("%s\n", VERSION);
return 0;
}
Arrange for "VERSION" in config.h to append the HEAD git commit when the build is not being done on a released tag. This also appends ".dirty" when the build was done while local changes were pending in the tree. When a released tag is present the VERSION string collapses to just the base version number. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- Makefile.am | 6 ++++++ autogen.sh | 1 + configure.ac | 3 ++- contrib/genspec.c | 4 +++- contrib/ndctl.spec.in | 8 +++----- git-version-gen | 47 +++++++++++++++++++++++++++++++++++++++++++++++ ndctl.c | 4 +--- 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100755 git-version-gen