[PATCH V1] Add rpm spec file and build script to help build rpm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The script will build source rpm and binary rpm.
Added rpm target into makefile.

Signed-off-by: Roi Dayan <roid@xxxxxxxxxxxx>
---

Hi,

renamed to build-rpm.sh.

Thanks,
Roi

 Makefile             |   10 +++++-
 scripts/build-rpm.sh |   67 ++++++++++++++++++++++++++++++++++++++
 scripts/tgtd.spec    |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+), 1 deletions(-)
 create mode 100755 scripts/build-rpm.sh
 create mode 100644 scripts/tgtd.spec

diff --git a/Makefile b/Makefile
index 4ae5850..4ec004f 100644
--- a/Makefile
+++ b/Makefile
@@ -64,8 +64,16 @@ clean-conf:
 .PHONY: install
 install: install-programs install-doc install-conf install-scripts
 
+.PHONY: rpm
+rpm:
+	@./scripts/build-rpm.sh
+
+.PHONY: clean-rpm
+clean-rpm:
+	rm -fr rpmtop
+
 .PHONY: clean
-clean: clean-programs clean-doc clean-conf clean-scripts
+clean: clean-programs clean-doc clean-conf clean-scripts clean-rpm
 
 .PHONY:check
 check: ARCH=$(shell sh script/checkarch.sh)
diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh
new file mode 100755
index 0000000..fbfbee8
--- /dev/null
+++ b/scripts/build-rpm.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 Roi Dayan <roid@xxxxxxxxxxxx>
+#
+
+
+DIR=$(cd `dirname $0`; pwd)
+BASE=`cd $DIR/.. ; pwd`
+RPMTOP="$BASE/rpmtop"
+SPEC="tgtd.spec"
+LOG=/tmp/`basename $0`-$$.log
+
+# get branch name
+branch=`git branch | grep '^*' | sed 's/^..\(.*\)/\1/'`
+# get version tag
+version=`git describe --tags --abbrev=0`
+# release is number of commits since the version tag
+release=`git describe --tags | cut -d- -f2 | tr - _`
+
+if [ "$branch" != "master" ]; then
+    # if not under master branch include hash tag
+    hash=`git rev-parse HEAD | cut -c 1-6`
+    release+=".$hash"
+fi
+
+echo "Building version: $version-$release"
+
+name=scsi-target-utils-$version-$release
+TARBALL=$name.tgz
+SRPM=$RPMTOP/SRPMS/$name.src.rpm
+
+echo "Creating rpm build dirs under $RPMTOP"
+mkdir -p $RPMTOP/{RPMS,SRPMS,SOURCES,BUILD,SPECS,tmp}
+mkdir -p $RPMTOP/tmp/$name
+
+echo "Creating tgz $TARBALL"
+cd $BASE
+cp -a conf $RPMTOP/tmp/$name
+cp -a doc $RPMTOP/tmp/$name
+cp -a scripts $RPMTOP/tmp/$name
+cp -a usr $RPMTOP/tmp/$name
+cp -a README $RPMTOP/tmp/$name
+cp -a Makefile $RPMTOP/tmp/$name
+
+tar -czf $RPMTOP/SOURCES/$TARBALL -C $RPMTOP/tmp $name
+
+check() {
+    local rc=$?
+    local msg="$1"
+    if (( rc )); then
+        echo $msg
+        exit 1
+    fi
+}
+
+echo "Creating rpm"
+sed -r "s/^Version:(\s*).*/Version:\1$version/;s/^Release:(\s*).*/Release:\1$release/" scripts/$SPEC > $RPMTOP/SPECS/$SPEC
+rpmbuild -bs --define="_topdir $RPMTOP" $RPMTOP/SPECS/$SPEC
+check "Failed to create source rpm."
+
+rpmbuild -bb --define="_topdir $RPMTOP" $RPMTOP/SPECS/$SPEC > $LOG 2>&1
+check "Failed to build rpm. LOG: $LOG"
+# display created rpm files
+grep ^Wrote $LOG
+
+rm -fr $LOG
+echo "Done."
diff --git a/scripts/tgtd.spec b/scripts/tgtd.spec
new file mode 100644
index 0000000..acbb712
--- /dev/null
+++ b/scripts/tgtd.spec
@@ -0,0 +1,87 @@
+Name:           scsi-target-utils
+Version:        1.0.24
+Release:        2%{?dist}
+Summary:        The SCSI target daemon and utility programs
+Packager:       Roi Dayan <roid@xxxxxxxxxxxx>
+Group:          System Environment/Daemons
+License:        GPLv2
+URL:            http://stgt.sourceforge.net/
+Source0:        %{name}-%{version}-%{release}.tgz
+BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+BuildRequires:  pkgconfig libibverbs-devel librdmacm-devel libxslt docbook-style-xsl libaio-devel
+%if %{defined suse_version}
+Requires: aaa_base
+%else
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
+%endif
+Requires: lsof sg3_utils
+ExcludeArch:    s390 s390x
+
+%description
+The SCSI target package contains the daemon and tools to setup a SCSI targets.
+Currently, software iSCSI targets are supported.
+
+
+%prep
+%setup -q -n %{name}-%{version}-%{release}
+
+
+%build
+%{__make} %{?_smp_mflags} ISCSI_RDMA=1
+
+
+%install
+%{__rm} -rf %{buildroot}
+%{__install} -d %{buildroot}%{_sbindir}
+%{__install} -d %{buildroot}%{_mandir}/man5
+%{__install} -d %{buildroot}%{_mandir}/man8
+%{__install} -d %{buildroot}%{_initrddir}
+%{__install} -d %{buildroot}/etc/tgt
+
+%{__install} -p -m 0755 scripts/tgt-setup-lun %{buildroot}%{_sbindir}
+%{__install} -p -m 0755 scripts/initd.sample %{buildroot}%{_initrddir}/tgtd
+%{__install} -p -m 0755 scripts/tgt-admin %{buildroot}/%{_sbindir}/tgt-admin
+%{__install} -p -m 0644 doc/manpages/targets.conf.5 %{buildroot}/%{_mandir}/man5
+%{__install} -p -m 0644 doc/manpages/tgtadm.8 %{buildroot}/%{_mandir}/man8
+%{__install} -p -m 0644 doc/manpages/tgt-admin.8 %{buildroot}/%{_mandir}/man8
+%{__install} -p -m 0644 doc/manpages/tgt-setup-lun.8 %{buildroot}/%{_mandir}/man8
+%{__install} -p -m 0644 doc/manpages/tgtimg.8 %{buildroot}/%{_mandir}/man8
+%{__install} -p -m 0600 conf/targets.conf %{buildroot}/etc/tgt
+
+pushd usr
+%{__make} install DESTDIR=%{buildroot} sbindir=%{_sbindir}
+
+
+%post
+/sbin/chkconfig --add tgtd
+
+%postun
+if [ "$1" = "1" ] ; then
+     /sbin/service tgtd condrestart > /dev/null 2>&1 || :
+fi
+
+%preun
+if [ "$1" = "0" ] ; then
+     /sbin/chkconfig tgtd stop > /dev/null 2>&1
+     /sbin/chkconfig --del tgtd
+fi
+
+
+%clean
+%{__rm} -rf %{buildroot}
+
+
+%files
+%defattr(-, root, root, -)
+%doc README doc/README.iscsi doc/README.iser doc/README.lu_configuration doc/README.mmc
+%{_sbindir}/tgtd
+%{_sbindir}/tgtadm
+%{_sbindir}/tgt-setup-lun
+%{_sbindir}/tgt-admin
+%{_sbindir}/tgtimg
+%{_mandir}/man5/*
+%{_mandir}/man8/*
+%{_initrddir}/tgtd
+%attr(0600,root,root) %config(noreplace) /etc/tgt/targets.conf
-- 
1.7.8.2

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux