First thing, all my examples are based on SuSE. Red Hat and others use different default locations. I created this little how to because there was very little "clear" documentation on how to create RPMs within. And what documentation did exist, was not specific to SuSE or focused on different utilities. RPMBUILD is the DEFAULT utility tat comes with every RPM linux distribution. (i.e. I have no idea if Debian uses it since it is not a RPM distribution)
The reason I needed to create RPMs was that I needed a way to publish programs and small utilities that were not available in RPM format. In fact many of the RPMs I have created were nothing but a zip file that extracts to a specific location in the filesystem. But since it is now a RPM, it can be managed via YaST and distributed via custom repositories.
Now that you know my motivation, you might want to know what exactly a RPM is? Originally RPM stood for Redhat Package Manager, but as it became used by other distributions it became the recursive acronym, RPM Package Manager. Either is correct!
If you want to get into great detail about an RPM you can look up the website rpm.org, however for the most part you can think of RPM files as the Linux equivalent to the Windows MSI file. It contains the a tar.gz archive holding the source code and the SPEC file explaining what to do with it.
The way you create a RPM file is to use the command RPMBUILD. The RPMBUILD command uses a default location to compile, assemble and store the RPMs. Everything starts in the /usr/src/packages directory. Underneath you will file the following directories:
These locations can be changes, but unless you have a great need to do so, don't
How I work the process (a very abridged version!!) is:
For an example I will illustrate how I created a RPM for a Java based LDAP Browser.
mkdir -p /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2
cd /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2 mkdir -p opt/ldapbrowser mkdir -p usr/bin mkdir -p usr/share/applications
# LDAPBrowser.desktop [Desktop Entry] Version=1.0 Encoding=UTF-8 Name=LDAP Browser Type=Application Exec=ldapbrowser Icon=/opt/gnome/share/pixmaps/gataxx.png Terminal=false Categories=Application;Network;Utility
cd /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2 ln -s opt/ldapbrowser/lbe.sh usr/bin/ldapbrowser
cd /usr/src/packages/SOURCES tar -cf LDAPBrowser-2.8.2.b2.tar LDAPBrowser-2.8.2.b2/ gzip -9fv LDAPBrowser-2.8.2.b2.tar
Summary: LDAP Browser 2.8.2 Beta 2 for SuSE Linux
Name: LDAPBrowser
Version: 2.8.2.b2
Release: 3
URL: http://www.brandt.ie/
Source0: %{name}-%{version}.tar.gz
License: GPL
Group: Applications/Utilities
BuildRoot: %{_tmppath}/%{name}-root
%description
This is a RPM build of LDAP Browser 2.8.2 Beta 2 for Linux. The original source is available at http://www-unix.mcs.anl.gov/~gawor/ldap/
%prep
%setup -q
%build
%install
rm -rf $RPM_BUILD_ROOT
cp -a ${RPM_BUILD_DIR}/%{name}-%{version} $RPM_BUILD_ROOT
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
/opt/ldapbrowser/
/usr/share/applications/LDAPBrowser.desktop
/usr/bin/ldapbrowser
%changelog
* Thu Jun 21 2007 Bob Brandt <projects@brandt.ie>
Initial build.
rpmbuild -bp only runs the %prep section. You should see
:/usr/src/packages> rpmbuild -bp SPECS/LDAPBrowser-2.8.2.b2.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.12934 + umask 022 + cd /usr/src/packages/BUILD + cd /usr/src/packages/BUILD + rm -rf LDAPBrowser-2.8.2.b2 + /usr/bin/gzip -dc /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2.tar.gz + tar -xf - + STATUS=0 + '[' 0 -ne 0 ']' + cd LDAPBrowser-2.8.2.b2 ++ /usr/bin/id -u + '[' 664 = 0 ']' ++ /usr/bin/id -u + '[' 664 = 0 ']' + /bin/chmod -Rf a+rX,u+w,g-w,o-w . + exit 0 :/usr/src/packages>
rpmbuild -bc runs the %prep and %build sections. But since our build section is blank the output should be the same as above.
rpmbuild -bi runs the %prep, %build and %install sections. You should see the above output plus what the %install section outputs
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.16884 + umask 022 + cd /usr/src/packages/BUILD + /bin/rm -rf /var/tmp/LDAPBrowser-root ++ dirname /var/tmp/LDAPBrowser-root + /bin/mkdir -p /var/tmp + /bin/mkdir /var/tmp/LDAPBrowser-root + cd LDAPBrowser-2.8.2.b2 + exit 0 Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.16884 + umask 022 + cd /usr/src/packages/BUILD + cd LDAPBrowser-2.8.2.b2 + rm -rf /var/tmp/LDAPBrowser-root + cp -a /usr/src/packages/BUILD/LDAPBrowser-2.8.2.b2 /var/tmp/LDAPBrowser-root + RPM_BUILD_ROOT=/var/tmp/LDAPBrowser-root + export RPM_BUILD_ROOT + test -x /usr/sbin/Check -a 0 = 0 -o -x /usr/sbin/Check -a '!' -z /var/tmp/LDAPBrowser-root + echo 'I call /usr/sbin/Check...' I call /usr/sbin/Check... + /usr/sbin/Check + /usr/lib/rpm/brp-compress + /usr/lib/rpm/brp-symlink Processing files: LDAPBrowser-2.8.2.b2-3 Finding Provides: /usr/lib/rpm/find-provides LDAPBrowser Finding Requires: /usr/lib/rpm/find-requires LDAPBrowser Finding Supplements: /usr/lib/rpm/find-supplements LDAPBrowser Requires(rpmlib): rpmlib(PartialHardlinkSets) <= 4.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 Requires: /bin/sh Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/LDAPBrowser-root :/usr/src/packages #
rpmbuild -ba runs all the sections and then creates the source and binary RPMs.
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/LDAPBrowser-root Wrote: /usr/src/packages/SRPMS/LDAPBrowser-2.8.2.b2-3.src.rpm Wrote: /usr/src/packages/RPMS/i586/LDAPBrowser-2.8.2.b2-3.i586.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.47823 + umask 022 + cd /usr/src/packages/BUILD + cd LDAPBrowser-2.8.2.b2 + rm -rf /var/tmp/LDAPBrowser-root + exit 0 :/usr/src/packages #
References: