openSUSE – Build a rpm package

Update @ 2013-12-30: If you are working on fedora core4, please refer to the comment by Gurce. Thx Gurce. =D

Recently, i need to study building a rpm package. after searching on google, i found a very useful document about how to build and rpm.

Reference: RPMS for fun and Profit or, How I Learned to Love the Package

So first of all, i setup an openSUSE 11.2 vm for my building purpose. This is the first time i use openSUSE and i found that the graphics look good and the YaST manager is really useful for package management and system configuration.

so make sure u have the require softwares for building rpm like gcc, make and build etc…

here comes to the steps. =)
*The .spec file i used in this post is different from the one in the above reference link. If i used that .spec file, the build will fail due to file not found or undeclared file in the %file stage.

1. Create the following folders as your rpm home folder

  • */rpm
  • */rpm/BUILD
  • */rpm/RPMS
  • */rpm/SOURCES
  • */rpm/SPECS
  • */rpm/SRPMS

2. Create the .rpmmacros at your home folder for your own rpm build configuration

%packager       ykyuen <yingkityuen@gmail.com>

%_topdir        /home/ykyuen/rpm
%_tmppath       /var/tmp

%_rpmtopdir     %{_topdir}
%_builddir      %{_rpmtopdir}/BUILD
%_rpmdir        %{_rpmtopdir}/RPMS
%_sourcedir     %{_rpmtopdir}/SOURCES
%_specdir       %{_rpmtopdir}/SPECS
%_srcrpmdir     %{_rpmtopdir}/SRPMS

3. Download the hello-2.1.1.tar.gz to */rpm/SOURCES folder

4. Create the hello-2.1.1.spec in the */rpm/SPECS folder

Summary: GNU Hello
Name: hello
Version: 2.1.1
Release: 1
Source: http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz
URL: http://www.gnu.org/software/hello/hello.html
License: GPL
Group: System Environment/Libraries
%description
This project is an example that demonstrates GNU coding standards.
%prep
%setup
%build
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{_prefix}
make
%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc AUTHORS BUGS ChangeLog COPYING INSTALL NEWS README THANKS TODO
%{_prefix}/bin/hello
%{_prefix}/info/dir
%{_prefix}/info/hello.info.gz
%{_prefix}/man/man1/*
%{_prefix}/share/locale/*/LC_MESSAGES/hello.mo
%changelog
* Wed Dec 23 2009 ykyuen <yingkityuen@gmail.com>
- First draft of the spec file

5. Run the rpm build command

  • rpmbuild -ba hello-2.1.1.spec

6. If everything works fine u should be able to find the following 2 rpm files.

  • */rpm/RPMS/i586/hello-2.1.1-1.i586.rpm
  • */rpm/SRPMS/hello-2.1.1-1.src.rpm

7. Then you can try to install the rpm u just created and test it

  • rpm -ivh hello-2.1.1-1.i586.rpm

Done =)

About these ads

7 thoughts on “openSUSE – Build a rpm package

  1. Nick

    One of the few linux post out there that really provide useful information in an accessible manner – simple and straight to the point. Good Job!

    The only problem I had in following this guide was that when issuing the “rpmbuild -ba hello-2.1.1.spec” command was that it was searching for the file a directory called “rpmbuild” and not “rpm”. I renamed it and it was OK.

    Reply
    1. ykyuen Post author

      I guess the reason it searches for a directory called “rpmbuild” is becoz of the setting in .rpmmacros.

      Anyway, good to know that this post could help. =D

      Reply
  2. Pingback: Rename kernel external build packages

  3. Gurce

    Thanks for your walkthrough, it had helped me on several occasions when I needed to figure out rpm’s in opensuse.

    Recently, I found myself on an old fedora (core 4, very old, circa 2005’ish), and bumped into one issue with these steps (which work just fine in opensuse).

    During the install stage, it complained that it didn’t have permission to write to the /usr/ folder. It seemed to be ignoring the spec telling it to install to DESTDIR=$RPM_BUILD_ROOT.

    But on closer examination, it turned out this version of rpmbuild on fc4 had left $RPM_BUILD_ROOT as empty (so when the make install tried installing to $(DESTDIR)/usr”, it was trying to install to “/usr”).

    I had a look at another spec-file from the fc4 era. I noticed they made use of an extra parameter early-on in the spec file to enforce what $RPM_BUILD_ROOT should be set to, for example:

    BuildRoot: %{_tmppath}/%{name}-%{version}-build

    Once I added a line like this, $RPM_BUILD_ROOT had a valid value, hence DESTDIR also had it, and the install stage worked fine.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s