diff mbox

[04/11] ndctl: update genspec to output per-distro flavored spec files

Message ID 20150905013137.28464.90913.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit f343e10fffb8
Headers show

Commit Message

Dan Williams Sept. 5, 2015, 1:31 a.m. UTC
The Red Hat environment prefers:
ndctl, ndctl-libs, ndctl-devel

The SUSE environment prefers:
ndctl, libndctl3, libndctl-devel

SUSE is more strict about the "License:" field.  Finally, SUSE does not
seem to ship a /usr/share/license directory, so suppress "%license" for
SUSE.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 contrib/Makefile      |   19 +++++++++++++------
 contrib/genspec.c     |   36 ++++++++++++++++++++++++++++++++----
 contrib/ndctl.spec.in |   35 +++++++++++++++++++++--------------
 contrib/rpmbuild.sh   |    2 +-
 4 files changed, 67 insertions(+), 25 deletions(-)
diff mbox

Patch

diff --git a/contrib/Makefile b/contrib/Makefile
index e5d786dfd914..958281765b9b 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -5,22 +5,29 @@  SRCS=genspec.c
 OBJS=$(SRCS:.c=.o)
 PROG=genspec
 SPEC_IN=ndctl.spec.in
-SPEC=$(SPEC_IN:.in=)
+RHEL_SPEC=rhel/$(SPEC_IN:.in=)
+SLES_SPEC=sles/$(SPEC_IN:.in=)
 COMMIT_ID=git log --pretty=format:"%h" -n 1
 
-all: $(SPEC)
+all: $(RHEL_SPEC) $(SLES_SPEC)
 
-$(SPEC) : $(SPEC_IN) $(PROG)
-	cat $(SPEC_IN) | $(dir $(PROG))$(PROG) `$(COMMIT_ID)` > $@
+$(RHEL_SPEC) : $(SPEC_IN) $(PROG)
+	@mkdir -p rhel
+	cat $(SPEC_IN) | $(dir $(PROG))$(PROG) `$(COMMIT_ID)` rhel > $@
 
-$(PROG) : $(OBJS)
+$(SLES_SPEC) : $(SPEC_IN) $(PROG)
+	@mkdir -p sles
+	cat $(SPEC_IN) | $(dir $(PROG))$(PROG) `$(COMMIT_ID)` sles > $@
+
+$(PROG) : $(OBJS) Makefile
 	$(CC) $(LDFLAGS) $(OBJS) -o $@
 
 .c.o:
 	$(CC) $(CFLAGS) $< -o $@
 
 clean:
-	rm $(OBJS) $(PROG) $(SPEC)
+	rm $(OBJS) $(PROG) $(RHEL_SPEC) $(SLES_SPEC)
+	@rmdir rhel sles
 
 depend: .depend
 
diff --git a/contrib/genspec.c b/contrib/genspec.c
index 21d16b39ab0d..14f27c4b2224 100644
--- a/contrib/genspec.c
+++ b/contrib/genspec.c
@@ -2,22 +2,50 @@ 
 #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 != 2) {
-		fprintf(stderr, "commit id must be specified\n");
+	if (argc != 3) {
+		fprintf(stderr, "commit id and OS must be specified\n");
 		return 1;
 	}
 
-	while (fgets(buf, sizeof(buf), stdin))
+	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);
 		else if (strncmp("%global gitcommit", buf, 17) == 0)
-			fprintf(stdout, "%%global gitcommit %s\n", argv[1]);
+			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])
+			/* skip */;
 		else
 			fprintf(stdout, "%s", buf);
+	}
 
 	return 0;
 }
diff --git a/contrib/ndctl.spec.in b/contrib/ndctl.spec.in
index cfe111525da4..9e64a44e97c6 100644
--- a/contrib/ndctl.spec.in
+++ b/contrib/ndctl.spec.in
@@ -1,10 +1,12 @@ 
 %global gitcommit
+%define lname
+%define dname
 
 Name:           ndctl
 Version:
 Release:        1%{?gitcommit:.git%{gitcommit}}%{?dist}
 Summary:	Manage "libnvdimm" subsystem devices (Non-volatile Memory)
-License:        GPLv2
+License:        GPL-2.0
 URL:            https://github.com/pmem/ndctl
 
 %if %{defined gitcommit}
@@ -17,6 +19,7 @@  Source0:        https://github.com/pmem/ndctl/archive/%{name}-%{version}.tar.gz
 BuildRequires: libtool
 BuildRequires: autoconf
 BuildRequires: automake
+BuildRequires: pkgconfig
 BuildRequires: pkgconfig(libudev)
 BuildRequires: pkgconfig(uuid)
 BuildRequires: pkgconfig(libkmod)
@@ -28,21 +31,21 @@  platform NVDIMM resources like those defined by the ACPI 6.0 NFIT (NVDIMM
 Firmware Interface Table).
 
 
-%package        devel
-Summary:        Development files for %{name}
-License:        LGPLv2.1 and BSD and MIT
-Requires:       %{name}%{?_isa} = %{version}-%{release}
+%package -n %dname
+Summary:        Development files for libndctl
+License:        LGPL-2.1+
+Requires:       %{lname}%{?_isa} = %{version}-%{release}
 
-%description    devel
+%description -n %dname
 The %{name}-devel package contains libraries and header files for
 developing applications that use %{name}.
 
 
-%package        libs
-Summary:        %{name} libraries
-License:        LGPLv2.1 and BSD and MIT
+%package -n %lname
+Summary:        Management library for "libnvdimm" subsystem devices (Non-volatile Memory)
+License:        LGPL-2.1+
 
-%description    libs
+%description -n %lname
 Libraries for %{name}
 
 
@@ -63,21 +66,25 @@  make %{?_smp_mflags}
 find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
 
 
-%post libs -p /sbin/ldconfig
+%post -n %lname -p /sbin/ldconfig
 
-%postun libs -p /sbin/ldconfig
+%postun -n %lname -p /sbin/ldconfig
 
 %files
 %license licenses/GPLv2 licenses/BSD-MIT licenses/CC0
 %{_bindir}/ndctl
 
-%files libs
+%files -n %lname
 %doc README.md
 %license COPYING licenses/BSD-MIT licenses/CC0
 %{_libdir}/libndctl.so.*
 
-%files devel
+%files -n %dname
 %license COPYING
 %{_includedir}/ndctl/
 %{_libdir}/libndctl.so
 %{_libdir}/pkgconfig/libndctl.pc
+
+%changelog
+* Mon Aug 03 2015 dan.j.williams@intel.com
+- Initial rpm release
diff --git a/contrib/rpmbuild.sh b/contrib/rpmbuild.sh
index 8926bdefb86b..97def14bd965 100755
--- a/contrib/rpmbuild.sh
+++ b/contrib/rpmbuild.sh
@@ -1,4 +1,4 @@ 
 #!/bin/bash
 $(dirname $0)/make-git-snapshot.sh
 make -C $(dirname $0)
-rpmbuild -bb $(dirname $0)/ndctl.spec
+rpmbuild -bb $(dirname $0)/rhel/ndctl.spec