|
Linux /
How to create an RPM using the RPMBUILD commandLinux.RPMBuild HistoryShow minor edits - Show changes to markup February 27, 2009, at 10:18 AM
by -
Changed line 20 from:
to:
November 04, 2007, at 09:30 PM
by -
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 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
(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.
(: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:)
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
(: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 %{name}-%{version}-%{release}.i586.rpm
The %prep section is the first section to be run. %setup -q is not a section but rather a macro that extracts the .tar.gz file to the BUILD directory.
The %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 %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 %clean section cleans up after we are done. (i.e. make clean)
The %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. %defattr(-,root,root) is another macro that sets file permissions.
:/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>
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 #
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: The 'Official' site for RPM: http://www.rpm.org
Software Packaging with RPM: http://www.linux-mag.com/2004-02/compile_01.html
Building RPM Packages: http://www-uxsup.csx.cam.ac.uk/talks/rpmbuild/rpmbuild.pdf
RPM 101: http://linuxvm.org/present/SHARE99/S9372NFa.pdf
Creating the Spec File http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html
Maximum RPM http://www.rpm.org/max-rpm/
|