From 1039d32b8c066fb2f7e657a38055df0ee16c1e6a Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 27 Dec 2011 22:38:52 -0600 Subject: [PATCH] Reworked nmh.spec to support rpmbuild from source RPM. --- Makefile.in | 19 ++++++------- nmh.spec | 90 ++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 31 deletions(-) diff --git a/Makefile.in b/Makefile.in index 598173f..39e027b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -200,18 +200,15 @@ nmhrelease: cd $(ftpdir) && ln -s $(tarfile) nmh.tar.gz cd $(ftpdir) && md5sum *.gz > MD5SUM -# Create binary and source RPMs. Assumes that configure had already -# been run. Otherwise, there wouldn't be a Makefile. +# Create binary and source RPMs. # _topdir is the specified RPM build root. # _tmppath is TMP below _topdir. -# srcdir is the top level nmh source directory. -# tarfile and version are as specified in this file. rpmbuild does -# not allow Version to contain any dashes. -rpm: all nmhdist +rpm: nmhdist + @test -d $(rpmdir)/SOURCES || mkdir -p $(rpmdir)/SOURCES + @test -d $(rpmdir)/SPECS || mkdir -p $(rpmdir)/SPECS + @mv -f $(tarfile) $(rpmdir)/SOURCES + @cp -p VERSION $(rpmdir)/SOURCES + @cp -p nmh.spec $(rpmdir)/SPECS @rpmbuild --define '_topdir $(rpmdir)' \ --define '_tmppath %{_topdir}/TMP' \ - --define 'srcdir $(abs_srcdir)' \ - --define 'tarfile $(tarfile)' \ - --define 'version '`echo $(VERSION) | sed "s/-/_/g"` \ - -ba nmh.spec - @$(RM) $(tarfile) + -ba $(rpmdir)/SPECS/nmh.spec diff --git a/nmh.spec b/nmh.spec index 35de0c8..e5fdb12 100644 --- a/nmh.spec +++ b/nmh.spec @@ -1,26 +1,50 @@ -# Assumes that rpmbuild was invoked in main nmh directory using "make -# rpm". Therefore, configure must already have been run. +# This spec supports two methods of RPM creation: # -# This file is intended to be zero maintenance, that's why it relies -# on the Makefile (and specifically on the nmhdist target). If you -# really want to start with rpmbuild from a clean distribution, you'll -# need to first run configure, make, and make nmhdist. +# 1) Start from an nmh workspace, run configure as desired and then "make rpm". +# For example: +# $ git clone git://git.savannah.nongnu.org/nmh.git +# $ cd nmh +# $ ./autogen.sh +# $ ./configure --with-cyrus-sasl --with-locking=fcntl && make rpm +# +# 2) Start with a source RPM and use rpmbuild. Configure options are hard +# coded below, but they can be overridden on the rpmbuild command line +# with --define 'configure_opts --opt=value [...]'. +# For example: +# $ rpm -i nmh-1.4-0.fc16.src.rpm +# $ rpmbuild --rmsource --rmspec \ +# --define 'configure_opts --with-cyrus-sasl --with-locking=fcntl' \ +# --bb ~/lib/rpmbuild/SPECS/nmh.spec +# +# If configure has previously been run successfully in the workspace, +# it will not be invoked again, even if configure_opts is defined. +# +# With kernel (fcntl, flock, or lockf) locking, or with dot locking +# and a lockdir that's writable by the user, bin/inc does not need to +# be setgid. This spec assumes that. But if needed, add something +# like this to the %files section to make bin/inc setgid: +# %attr(2755,-,mail) /usr/local/nmh/bin/inc # # Note that Version cannot contain any dashes. # # The description, summary, and a few other tags were taken from the # nmh.spec used to build the Fedora 15 nmh rpm. -Name: nmh -Version: %version -Release: 0%{?dist} -Summary: A capable mail handling system with a command line interface. -Group: Applications/Internet -License: BSD -URL: http://savannah.nongnu.org/projects/nmh -Source: %tarfile +Name: nmh +Version: %(sed "s/-/_/g" $RPM_SOURCE_DIR/VERSION) +%define rawversion %(cat $RPM_SOURCE_DIR/VERSION) +Release: 0%{?dist} +Summary: A capable mail handling system with a command line interface. +Group: Applications/Internet +License: BSD +URL: http://savannah.nongnu.org/projects/nmh +BuildRequires: gdbm-devel ncurses-devel +%define tarfile nmh-%rawversion.tar.gz +Source0: %tarfile +Source1: VERSION +%define srcdir %(pwd) # This should already be defined in /usr/lib/rpm/macros: -# BuildRoot: %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch} +# BuildRoot: %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch} %description Nmh is an email system based on the MH email system and is intended to @@ -35,24 +59,50 @@ interface for it--nmh only has a command line interface. %prep -#### The tarfile is only needed for the source rpm. -cp -p %srcdir/%tarfile $RPM_SOURCE_DIR +if [ ! -f $RPM_SOURCE_DIR/%tarfile ]; then + #### The tarfile wasn't already installed and we started with a + #### workspace (using make rpm), so get it from there. + [ -f %srcdir/%tarfile ] || (cd %srcdir && make nmhdist) + cp -p %srcdir/%tarfile $RPM_SOURCE_DIR/%tarfile +fi +[ -f $RPM_SOURCE_DIR/VERSION ] || cp -p %srcdir/VERSION $RPM_SOURCE_DIR +%setup -q -n %name-%rawversion %build +if [ -f %srcdir/config.status ]; then + echo reusing existing configuration + cp -pf %srcdir/config.status . + ./config.status +else + %if %{undefined configure_opts} + %define configure_opts --enable-pop --with-cyrus-sasl --with-locking=fcntl + %endif + %configure %configure_opts +fi +make all nmhdist %install rm -rf $RPM_BUILD_ROOT doc -(cd %srcdir && make install DESTDIR=$RPM_BUILD_ROOT SETGID_MAIL=) +make install DESTDIR=$RPM_BUILD_ROOT SETGID_MAIL= #### Exclude docs from nmh_files because its files are added with the #### %doc directive in the %files section below. mv `find $RPM_BUILD_ROOT -type d -name doc` . -find $RPM_BUILD_ROOT ! -type d -print | sed "s#^$RPM_BUILD_ROOT##" > nmh_files + +gz_manpages='-e ' + +if find $RPM_BUILD_ROOT -name 'inc.1*' | \ + egrep -q '/usr(/lib|/share)?/man/([^/]+/)?man'; then + #### brp-compress will gzip the man pages, so account for that. + gz_manpages='-e s#\(/man/man./.*\)#\1.gz#' +fi +find $RPM_BUILD_ROOT ! -type d -print | \ + sed -e "s#^$RPM_BUILD_ROOT##" "$gz_manpages" > nmh_files %clean -rm -rf $RPM_BUILD_ROOT doc $RPM_SOURCE_DIR/%tarfile nmh_files +rm -rf $RPM_BUILD_ROOT doc $RPM_BUILD_DIR/%name-%rawversion %files -f nmh_files -- 1.7.10.4