diff mbox

[ndctl] ndctl: rework release collateral

Message ID 20160209203808.3440.45296.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams Feb. 9, 2016, 8:38 p.m. UTC
Prompted by a request to have the spec file reference the github tarball
URL, rework spec file generation:

1/ Use noinst_SCRIPTS to do the token replacements in ndctl.spec.in
using sed, kill contrib/genspec and kill the %lname and %dname variables

2/ Use the LIBNDCTL_CURRENT variable to name the sles library package

3/ Unify the git snapshot naming with github archive naming.  Split git-version
off from git-version-gen as a helper for make-git-snapshot.sh.

4/ Specify --disable-silent-rules to configure

Reported-by: Ralf Corsepius <rc040203@freenet.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Documentation/Makefile.am    |    2 ++
 Makefile.am                  |   17 +++++++++++++
 contrib/Makefile             |   39 -------------------------------
 contrib/genspec.c            |   53 ------------------------------------------
 contrib/rpmbuild.sh          |    4 ---
 git-version                  |   16 ++++---------
 git-version-gen              |   35 ++--------------------------
 make-git-snapshot.sh         |   16 +++----------
 ndctl.spec.in                |   35 ++++++++++++----------------
 rpmbuild.sh                  |    5 ++++
 sles/header                  |    0 
 11 files changed, 51 insertions(+), 171 deletions(-)
 delete mode 100644 contrib/Makefile
 delete mode 100644 contrib/genspec.c
 delete mode 100755 contrib/rpmbuild.sh
 copy git-version-gen => git-version (73%)
 rename contrib/make-git-snapshot.sh => make-git-snapshot.sh (55%)
 rename contrib/ndctl.spec.in => ndctl.spec.in (74%)
 create mode 100755 rpmbuild.sh
 rename contrib/sles/header => sles/header (100%)

diff --git a/contrib/sles/header b/sles/header
similarity index 100%
rename from contrib/sles/header
rename to sles/header
diff mbox

Patch

diff --git a/Documentation/Makefile.am b/Documentation/Makefile.am
index a168cec100c8..3b3336918516 100644
--- a/Documentation/Makefile.am
+++ b/Documentation/Makefile.am
@@ -8,6 +8,8 @@  man1_MANS = \
 	ndctl-create-namespace.1 \
 	ndctl-list.1
 
+CLEANFILES = $(man1_MANS)
+
 XML_DEPS = \
 	$(top_srcdir)/version.m4 \
 	Makefile \
diff --git a/Makefile.am b/Makefile.am
index 1c6a4b07f8f1..61dce040131c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,23 @@  LIBNDCTL_CURRENT=6
 LIBNDCTL_REVISION=0
 LIBNDCTL_AGE=0
 
+noinst_SCRIPTS = rhel/ndctl.spec sles/ndctl.spec
+CLEANFILES += $(noinst_SCRIPTS)
+
+do_rhel_subst = sed -e 's,VERSION,$(VERSION),g' \
+            -e 's,DNAME,ndctl-devel,g' \
+            -e 's,LNAME,libndctl,g'
+
+do_sles_subst = sed -e 's,VERSION,$(VERSION),g' \
+            -e 's,DNAME,libndctl-devel,g' \
+            -e 's,LNAME,libndctl$(LIBNDCTL_CURRENT),g'
+
+rhel/ndctl.spec: ndctl.spec.in Makefile.am
+	$(AM_V_GEN)$(MKDIR_P) rhel; $(do_rhel_subst) < $< > $@
+
+sles/ndctl.spec: ndctl.spec.in Makefile.am
+	$(AM_V_GEN)$(MKDIR_P) sles; cat sles/header $< | $(do_sles_subst) > $@
+
 pkginclude_HEADERS = lib/ndctl/libndctl.h
 lib_LTLIBRARIES = lib/libndctl.la
 
diff --git a/contrib/Makefile b/contrib/Makefile
deleted file mode 100644
index 766e186d0389..000000000000
--- a/contrib/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@ 
-CC=gcc
-CFLAGS=-c -Wall
-LDFLAGS=
-SRCS=genspec.c
-OBJS=$(SRCS:.c=.o)
-PROG=genspec
-SPEC_IN=ndctl.spec.in
-RHEL_SPEC=rhel/$(SPEC_IN:.in=)
-SLES_SPEC=sles/$(SPEC_IN:.in=)
-SLES_IN=sles/header
-COMMIT_ID=git log --pretty=format:"%h" -n 1
-
-all: $(RHEL_SPEC) $(SLES_SPEC)
-
-$(RHEL_SPEC) : $(SPEC_IN) $(PROG)
-	@mkdir -p rhel
-	cat $(SPEC_IN) | $(dir $(PROG))$(PROG) `$(COMMIT_ID)` rhel > $@
-
-$(SLES_SPEC) : $(SLES_IN) $(SPEC_IN) $(PROG)
-	@mkdir -p sles
-	cat $(SLES_IN) $(SPEC_IN) | $(dir $(PROG))$(PROG) `$(COMMIT_ID)` sles > $@
-
-$(PROG) : $(OBJS) Makefile
-	$(CC) $(LDFLAGS) $(OBJS) -o $@
-
-.c.o:
-	$(CC) $(CFLAGS) $< -o $@
-
-clean:
-	rm $(OBJS) $(PROG) $(RHEL_SPEC) $(SLES_SPEC)
-	@rmdir rhel sles
-
-depend: .depend
-
-.depend: $(SRCS)
-	rm -f $@ > /dev/null 2>&1
-	$(CC) $(CFLAGS) -MM $^ -MF $@
-
-include .depend
diff --git a/contrib/genspec.c b/contrib/genspec.c
deleted file mode 100644
index 829f648f0a2f..000000000000
--- a/contrib/genspec.c
+++ /dev/null
@@ -1,53 +0,0 @@ 
-#include <stdio.h>
-#include <string.h>
-#include "../config.h"
-
-static char *lname[] = {
-	"ndctl-libs", "libndctl3",
-};
-
-static char *dname[] = {
-	"ndctl-devel", "libndctl-devel",
-};
-
-static int license[] = {
-	1, 0,
-};
-
-int main(int argc, char **argv)
-{
-	const char *commit = argv[1];
-	char buf[1024];
-	int os;
-
-	if (argc != 3) {
-		fprintf(stderr, "commit id and OS must be specified\n");
-		return 1;
-	}
-
-	if (strcmp(argv[2], "rhel") == 0)
-		os = 0;
-	else if (strcmp(argv[2], "sles") == 0)
-		os = 1;
-	else
-		return 1;
-
-	while (fgets(buf, sizeof(buf), stdin)) {
-		if (strncmp("Version:", buf, 8) == 0)
-			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)
-			fprintf(stdout, "%%define lname %s\n", lname[os]);
-		else if (strncmp("%define dname", buf, 12) == 0)
-			fprintf(stdout, "%%define dname %s\n", dname[os]);
-		else if (strncmp("%license", buf, 8) == 0 && !license[os])
-			fprintf(stdout, "%%doc %s", &buf[8]);
-		else if (strncmp("echo \"\" > version", buf, 17) == 0)
-			fprintf(stdout, "echo \"%s\" > version\n", VERSION);
-		else
-			fprintf(stdout, "%s", buf);
-	}
-
-	return 0;
-}
diff --git a/contrib/rpmbuild.sh b/contrib/rpmbuild.sh
deleted file mode 100755
index 97def14bd965..000000000000
--- a/contrib/rpmbuild.sh
+++ /dev/null
@@ -1,4 +0,0 @@ 
-#!/bin/bash
-$(dirname $0)/make-git-snapshot.sh
-make -C $(dirname $0)
-rpmbuild -bb $(dirname $0)/rhel/ndctl.spec
diff --git a/git-version-gen b/git-version
similarity index 73%
copy from git-version-gen
copy to git-version
index 9cd2ebf1407a..3b5217752924 100755
--- a/git-version-gen
+++ b/git-version
@@ -9,7 +9,6 @@  dirty() {
 	fi
 }
 
-GVF=version.m4
 DEF_VER=v50
 
 LF='
@@ -34,14 +33,9 @@  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
+#drop leading 'v' out of the version so its a pure number
+if [ ${VN:0:1} = v ]; then
+	VN=${VN:1}
 fi
-test "$VN" = "$VC" || {
-	echo >&2 "GIT_VERSION = $VN"
-	echo "m4_define([GIT_VERSION], [$VN])" >$GVF
-	exit 0
-}
+
+echo $VN
diff --git a/git-version-gen b/git-version-gen
index 9cd2ebf1407a..e913a3674eef 100755
--- a/git-version-gen
+++ b/git-version-gen
@@ -1,38 +1,6 @@ 
 #!/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=v50
-
-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)
@@ -40,6 +8,9 @@  if test -r $GVF; then
 else
 	VC=unset
 fi
+
+VN=$(./git-version)
+
 test "$VN" = "$VC" || {
 	echo >&2 "GIT_VERSION = $VN"
 	echo "m4_define([GIT_VERSION], [$VN])" >$GVF
diff --git a/contrib/make-git-snapshot.sh b/make-git-snapshot.sh
similarity index 55%
rename from contrib/make-git-snapshot.sh
rename to make-git-snapshot.sh
index e031223c740f..2825ac4321cd 100755
--- a/contrib/make-git-snapshot.sh
+++ b/make-git-snapshot.sh
@@ -14,16 +14,8 @@  trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
-pushd "$WORKDIR" > /dev/null
-git branch to-archive $HEAD
-read COMMIT_SHORTID COMMIT_TITLE <<EOGIT
-$(git log to-archive^..to-archive --pretty='format:%h %s')
-EOGIT
-popd > /dev/null
+VERSION=$(./git-version)
+DIRNAME="ndctl-${VERSION}"
+git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"v${VERSION}.tar.gz"
 
-echo "Making git snapshot using commit: $COMMIT_SHORTID $COMMIT_TITLE"
-
-DIRNAME="$NAME-git$COMMIT_SHORTID"
-git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" to-archive | xz -9 > $OUTDIR/"$DIRNAME.tar.xz"
-
-echo "Written $OUTDIR/$DIRNAME.tar.xz"
+echo "Written $OUTDIR/v${VERSION}.tar.gz"
diff --git a/contrib/ndctl.spec.in b/ndctl.spec.in
similarity index 74%
rename from contrib/ndctl.spec.in
rename to ndctl.spec.in
index da0c9cee947a..e24b31cc54f0 100644
--- a/contrib/ndctl.spec.in
+++ b/ndctl.spec.in
@@ -1,16 +1,11 @@ 
-%global gitcommit
-%define lname
-%define dname
-
 Name:           ndctl
-Version:
+Version:	VERSION
 Release:        1%{?dist}
 Summary:	Manage "libnvdimm" subsystem devices (Non-volatile Memory)
 License:        GPLv2
 Group:          Hardware/Other
 Url:            https://github.com/pmem/ndctl
-# Snapshot tarball can be created using: ./make-git-shapshot.sh [gitcommit]
-Source0:        %{name}-git%{gitcommit}.tar.xz
+Source0:        https://github.com/pmem/ndctl/archive/v%{version}.tar.gz
 
 BuildRequires:  autoconf
 BuildRequires:  asciidoc
@@ -26,36 +21,36 @@  BuildRequires:  pkgconfig(json-c)
 %description
 Utility library for managing the "libnvdimm" subsystem.  The "libnvdimm"
 subsystem defines a kernel device model and control message interface for
-platform NVDIMM resources like those defined by the ACPI 6.0 NFIT (NVDIMM
+platform NVDIMM resources like those defined by the ACPI 6+ NFIT (NVDIMM
 Firmware Interface Table).
 
 
-%package -n %dname
+%package -n DNAME
 Summary:        Development files for libndctl
 License:        LGPLv2
 Group:          Development/Libraries/Other
-Requires:       %{lname}%{?_isa} = %{version}-%{release}
+Requires:       LNAME%{?_isa} = %{version}-%{release}
 
-%description -n %dname
+%description -n DNAME
 The %{name}-devel package contains libraries and header files for
 developing applications that use %{name}.
 
 
-%package -n %lname
+%package -n LNAME
 Summary:        Management library for "libnvdimm" subsystem devices (Non-volatile Memory)
 License:        LGPLv2
 Group:          System/Libraries
 
-%description -n %lname
+%description -n LNAME
 Libraries for %{name}.
 
 %prep
-%setup -q %{?gitcommit:-n %{name}-git%{gitcommit}}
+%setup -q v%{version}
 
 %build
-echo "" > version
+echo "VERSION" > version
 ./autogen.sh
-%configure --disable-static --enable-local
+%configure --disable-static --enable-local --disable-silent-rules
 make %{?_smp_mflags}
 
 %install
@@ -65,9 +60,9 @@  find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
 %check
 make check
 
-%post -n %lname -p /sbin/ldconfig
+%post -n LNAME -p /sbin/ldconfig
 
-%postun -n %lname -p /sbin/ldconfig
+%postun -n LNAME -p /sbin/ldconfig
 
 %files
 %defattr(-,root,root)
@@ -75,13 +70,13 @@  make check
 %{_bindir}/ndctl
 %{_mandir}/man1/*
 
-%files -n %lname
+%files -n LNAME
 %defattr(-,root,root)
 %doc README.md
 %license COPYING licenses/BSD-MIT licenses/CC0
 %{_libdir}/libndctl.so.*
 
-%files -n %dname
+%files -n DNAME
 %defattr(-,root,root)
 %license COPYING
 %{_includedir}/ndctl/
diff --git a/rpmbuild.sh b/rpmbuild.sh
new file mode 100755
index 000000000000..4535b4654409
--- /dev/null
+++ b/rpmbuild.sh
@@ -0,0 +1,5 @@ 
+#!/bin/bash
+pushd $(dirname $0) >/dev/null
+./make-git-snapshot.sh
+popd > /dev/null
+rpmbuild -ba $(dirname $0)/rhel/ndctl.spec