Recent Changes - Search:

Bob Brandt

Linux Projects


Server Projects

Desktop Projects

Novell Projects


VMware Projects


N900 (Maemo) Projects


Python Projects


OpenOffice.org Projects


Other Projects


PmWiki

edit SideBar

How to create an RPM using the RPMBUILD command

Linux.RPMBuild History

Hide minor edits - Show changes to output

February 27, 2009, at 10:18 AM by 82.141.254.184 -
Changed line 20 from:
# To create a new directory underneath the SOURCES directory for each project I am working on. For all the fiels that I create, I use the format {NAME}-{VERSION}.
to:
# To create a new directory underneath the SOURCES directory for each project I am working on. For all the files that I create, I use the format {NAME}-{VERSION}.
November 04, 2007, at 09:30 PM by 217.75.11.25 -
Added lines 1-204:
(:title How to create an RPM using the RPMBUILD command :)

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 %newwin% [[ http://www.rpm.org/ | 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:
* BUILD (this is where the RPMBUILD command builds the program)
* RPMS (this is where the final RPMs are stored)
* SOURCES (this is where you store the source files)
* SPECS (this is where you store the SPEC files)
* SRPMS (this is where the final source RPMs are stored)
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:
# To create a new directory underneath the SOURCES directory for each project I am working on. For all the fiels that I create, I use the format {NAME}-{VERSION}.
# Replicate the root file system underneath the newly created directory.
# Create the .tar.gz file using the same format as above {NAME}-{VERSION}.tar.gz
# Create the SPEC file using the same format {NAME}-{VERSION}.spec
# Test the spec file using various switches of the RPMBUILD command
## The .tar.gz file is extracted to the BUILD directory
## Commands in the SPEC file explain how to build the source files
## More commands in the SPEC file explain how to install the source files
## A list of files within the SPEC file specify the exact files that will be installed
# Build the RPM using the RPMBUILD with the -ba switch. (this creates both the normal and source RPMs)

For an example I will illustrate how I created a RPM for a Java based LDAP Browser.
*I created a directory under the SOURCES using the following command:
->[@
mkdir -p /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2
@]
*I created the part of the root filesystem I would need for this project.
->[@
cd /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2
mkdir -p opt/ldapbrowser
mkdir -p usr/bin
mkdir -p usr/share/applications
@]
*Copied all the application files into opt/ldapbrowser directory. Available from %newwin% [[ http://www-unix.mcs.anl.gov/~gawor/ldap/dwld/bin-dwld.cgi?fileid=282b2tar | here ]]
->[-(Be aware that I had to edit the lbe.sh script file so that it would work. I needed to add a path to the lbe.jar file reference to get it to work.-]
*I created a desktop file that I placed in the usr/share/applications directories (The .desktop file is GUI icon) there is one gotcha when creating the .desktop file. You need to make sure that the Categories line is present, without it the icon will not appear in the Gnome Application Browser. Below is an example:
(:div style="border-style:ridge; border-width:2px; background-color:#ffffcc; margin-left:50px; overflow:auto; width:650px; height:250px;":)
[@
# 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
@]
(:divend:)
*I create a symbolic link in the usr/bin directory to the executable
->[@
cd /usr/src/packages/SOURCES/LDAPBrowser-2.8.2.b2
ln -s opt/ldapbrowser/lbe.sh usr/bin/ldapbrowser
@]
*Now that the directory structure is created we need to create the .tar.gz file
->[@
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
@]
*Next we need to create the SPEC file. Below is the LDAPBrowser-2.8.2.b2.spec file I used
(:div style="border-style:ridge; border-width:2px; background-color:#ffffcc; margin-left:50px; overflow:auto; width:650px; height:250px;":)
[@
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.
@]
(:divend:)
->Most of the sections are easy enough to figure out. However there are a few things that should be pointed out:
->The final RPM will be labeled &#37;{name}-&#37;{version}-&#37;{release}.i586.rpm
->The &#37;prep section is the first section to be run. &#37;setup -q is not a section but rather a macro that extracts the .tar.gz file to the BUILD directory.
->The &#37;build section is where you would normally place the configure and make commands, but since we don't need to install anything, I left this section blank.
->The &#37;install section is where you would normally place the make install command, however since this is project is a little different, I copy the contents of the BUILD directory to a temporary location created by the RPMBUILD command. The variable $RPM_BUILD_ROOT expands to the temporary location, normally in the /tmp directory. The variable $RPM_BUILD_DIR expands to the BUILD directory.
->The &#37;clean section cleans up after we are done. (i.e. make clean)
->The &#37;files section lists all the files you want to copy from the temporary directory to the system. This is needed since there could be temporary files created during the install process that you don't actually want on the final system. &#37;defattr(-,root,root) is another macro that sets file permissions.

*Once you have the .tar.gz file and SPEC file created you can start testing it.
*[@rpmbuild -bp@] only runs the &#37;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 &#37;prep and &#37;build sections. But since our build section is blank the output should be the same as above.
*[@rpmbuild -bi@] runs the &#37;prep, &#37;build and &#37;install sections. You should see the above output plus what the &#37;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 #
@]
*The only thing left is to install the RPM on a clean "vanilla" system and make sure everything works.







[+References:+]

->The 'Official' site for RPM: %newwin% [[ http://www.rpm.org ]]
->Software Packaging with RPM: %newwin% [[ http://www.linux-mag.com/2004-02/compile_01.html ]]
->Building RPM Packages: %newwin% [[ http://www-uxsup.csx.cam.ac.uk/talks/rpmbuild/rpmbuild.pdf ]]
->RPM 101: %newwin% [[ http://linuxvm.org/present/SHARE99/S9372NFa.pdf ]]
->Creating the Spec File %newwin% [[ http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html ]]
->Maximum RPM %newwin% [[ http://www.rpm.org/max-rpm/ ]]
Edit - History - Print - Recent Changes - Search
Page last modified on February 27, 2009, at 10:18 AM