Building my first RPM package

Have you ever built any rpm package before? Nope? Try reading this blog entry, and we’ll see if you are capable of building one afterward :D .. Oh c’mon, don’t be so pesimistic :p



So, to make things simple, I’ve tried using KDevelop built in (suppose-to-be) rpm builder. You know what, it throws error that Source is empty. Take a peek into the .kdevelop.spec file, you’ll found that indeed “Source:” is empty.



Google to the rescue. Let’s query a RPM howto. Yay, I found one, dated somewhere around 1999 on rpm.org. It looked like a reference file instead of a real howto :( . After crawling several pages thru google. I ended up with a page on fedoranews.org. It’s a “HOWTO: Building Metisse RPM package for Fedora Core”. Could this be my saviour?. Well, I downloaded the spec file. Take a good look into it and removed thing I don’t feel good on (yeah, it’s a hunch stuff :p). Well, with a lil bit of luck I made it to make a working spec file. it’s not difficult as I thought (lucky me). it’s pretty trivial. What to care about is filenaming as it’s the core foundation. Here, lemme give you the spec first:

[geek@toni ~]$ cat /tmp/kbfxvista-0.4.8.1.spec
Name            : kbfxvista
Version         : 0.4.8.1
Release         : 1.FC4

License         : GPL
Summary         : Kbfx for fedora core 4
Group           : Accessories

URL             : http://blog.neofreko.com
Vendor          : kbfx.org
Packager        : Akhmad Fathonih <akhmadf@gmail.com>

BuildRoot       : %{_tmppath}/%{name}-%{version}-buildroot
Source          : %{name}-%{version}.tar.gz

%description
kbfx is a customizable kmenu-like button

%prep
rm -rf $RPM_BUILD_ROOT

%setup -q

%build
./configure --prefix=/usr --mandir=/usr/share/man
%{__make}

%install
%{__make} DESTDIR=$RPM_BUILD_ROOT prefix=/usr install
rm -rf $RPM_BUILD_ROOT/var/tmp

%clean
rm -rf $RPM_BUILD_ROOT

%files
#####################################################
# defattr sets the default attributes for all files
#####################################################
%defattr(-, root, root)

%changelog
* Thu Jan 24 2006 Akhmad Fathonih <akhmadf@gmail.com> 0.4.8.1-1.FC4
I'm trying to build the rpm




Okay, what you need to care about a lot here is filenaming rite. You see these lines:

Name            : kbfxvista
Version         : 0.4.8.1
Release         : 1.FC4

That’s important and has to be synchronized with the Source line:

Source          : %{name}-%{version}.tar.gz

Yep, with this line above, you need not to adjust Source line for each build.


Okay, now that our spec file is ready, we have to compress our actual source code. First thing first, make sure it’s under <package>-version folder (as the Source format has said). Then compressed as the source format pattern as well.


Now, copy that compressed file to /usr/src/redhat/BUILD as rpmbuild will always refer that folder. And finally invoke:

sudo rpmbuild -ba kbfxvista-0.4.8.1.spec

Note that I use sudo to raise my privilege. You need to do the same with your own recipe, you may not use sudo rite? Done? Not yet. I got this error:

Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kbfxvista-0.4.8.1-buildroot
error: Installed (but unpackaged) file(s) found:
   /usr/lib/kde3/kcm_kcmkbfx.la
   /usr/lib/kde3/kcm_kcmkbfx.so
   /usr/lib/libkbfxvista.la
   /usr/lib/libkbfxvista.so
   /usr/share/applications/kde/kcmkbfx.desktop
   /usr/share/apps/kicker/applets/kbfxvista.desktop
   /usr/share/config.kcfg/kbfx.kcfg

RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/lib/kde3/kcm_kcmkbfx.la
   /usr/lib/kde3/kcm_kcmkbfx.so
   /usr/lib/libkbfxvista.la
   /usr/lib/libkbfxvista.so
   /usr/share/applications/kde/kcmkbfx.desktop
   /usr/share/apps/kicker/applets/kbfxvista.desktop
   /usr/share/config.kcfg/kbfx.kcfg

Someone said it’s rpm 4.1 feature :D . Other said it can be resolved by adjusting two macros flags in usr/lib/rpm/macros. After adjusting the flag, we can rebuild our rpm.



Darn, it’s still doesn’t work. Let’s follow second advice, add this in the end of .spec file:

%{prefix}/lib/kde3/kcm_kcmkbfx.*  %{prefix}/usr/lib/libkbfxvista.*   %{prefix}/share/applications/kde/kcmkbfx.desktop   %{prefix}/share/apps/kicker/applets/kbfxvista.desktop   %{prefix}/share/config.kcfg/kbfx.kcfg



Doesn’t work either eh? yup. It’s shitty indeed. Let’s googling some more. Dammit.



Okay, these flags thing seems referring to our local rpmmacros (~/.rpmmacros). Thus we have to edit ~/.rpmmacros (i don’t have any so I make a new file), add this line:

%_unpackaged_files_terminate_build    0




Now, rebuild:

[geek@toni tmp]$ sudo rpmbuild -ba kbfxvista-0.4.8.1.spec --nobuild
Password:
Processing files: kbfxvista-0.4.8.1-1.FC4
Processing files: kbfxvista-debuginfo-0.4.8.1-1.FC4
Provides: kcm_kcmkbfx.so.debug libkbfxvista.so.debug
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kbfxvista-0.4.8.1-buildroot
warning: Installed (but unpackaged) file(s) found:
   /usr/lib/kde3/kcm_kcmkbfx.la
   /usr/lib/kde3/kcm_kcmkbfx.so
   /usr/lib/libkbfxvista.la
   /usr/lib/libkbfxvista.so
   /usr/share/applications/kde/kcmkbfx.desktop
   /usr/share/apps/kicker/applets/kbfxvista.desktop
   /usr/share/config.kcfg/kbfx.kcfg
[geek@toni tmp]$



I use --nobuild since my source already built with no error, and I hate to wait for a time consuming rebuild. Now, where's my freaking *.rpm?! Dammit, I need to do a full build over it (remove --nobuild option). And this is what I got:

Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kbfxvista-0.4.8.1-buildroot
warning: Installed (but unpackaged) file(s) found:
   /usr/lib/kde3/kcm_kcmkbfx.la
   /usr/lib/kde3/kcm_kcmkbfx.so
   /usr/lib/libkbfxvista.la
   /usr/lib/libkbfxvista.so
   /usr/share/applications/kde/kcmkbfx.desktop
   /usr/share/apps/kicker/applets/kbfxvista.desktop
   /usr/share/config.kcfg/kbfx.kcfg
Wrote: /usr/src/redhat/SRPMS/kbfxvista-0.4.8.1-1.FC4.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/kbfxvista-0.4.8.1-1.FC4.i386.rpm
Wrote: /usr/src/redhat/RPMS/i386/kbfxvista-debuginfo-0.4.8.1-1.FC4.i386.rpm




Whooohooooo!! Now, let's check it wether it's empty or not. unpackaged warning means it's not placed into the package, so I'm afraid it's not inside the rpm file. Voila!

[geek@toni ~]$ rpm -qpl /usr/src/redhat/RPMS/i386/kbfxvista-0.4.8.1-1.FC4.i386.rpm
(contains no files)



Aarrggghh!!!


Okay, now I really need to include those files within the package (delete my previous ~/.rpmmacros). And how am I suppose to do that? Back to google, everyone! Full speed ahead!

Okay, let's do this .. it seems that rpmbuild will look for the files to package relative to {BUILD_ROOT} .. I have /usr in my {BUILD_ROOT}. Damn, a dreadfull job. I just can take this no more so, let's do brute force. No more Mr. Niceguy:

%defattr(-, root, root)
/usr/*



That will glob everything unser {BUILD_ROOT}/usr. NOw we need to "rebuild" the package. remember, --nobuild means simulation, it's a good practise to test a spec file. Now that I've compiled the whole thing I can do:

rpmbuild -bi kbfxvista-0.4.8.1.spec --short-circuit



Short circuit will skip any other stage and go to the stage we specified after -b, in this case I want an install stage (make isntall). This should do it. I hope. Damn, I've lost quite a lot of hair today. And that's for a single rpm file. Ggrrrhhhhh!!!!


Okay, that didn't work. It run but the package weren't build! damn, I geuss I'll give up and use -bb (build binary)

Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kbfxvista-0.4.8.1-buildroot
Wrote: /usr/src/redhat/RPMS/i386/kbfxvista-0.4.8.1-1.FC4.i386.rpm
Wrote: /usr/src/redhat/RPMS/i386/kbfxvista-debuginfo-0.4.8.1-1.FC4.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.15339
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd kbfxvista-0.4.8.1
+ rm -rf /var/tmp/kbfxvista-0.4.8.1-buildroot
+ exit 0



And let's cek our new generated rpm, shall we ..

[geek@toni ~]$ rpm -qpl /usr/src/redhat/RPMS/i386/kbfxvista-0.4.8.1-1.FC4.i386.rpm
/usr/lib
/usr/lib/debug
/usr/lib/debug/usr
/usr/lib/debug/usr/lib
/usr/lib/debug/usr/lib/kde3
/usr/lib/debug/usr/lib/kde3/kcm_kcmkbfx.so.debug
/usr/lib/debug/usr/lib/libkbfxvista.so.debug
/usr/lib/kde3
/usr/lib/kde3/kcm_kcmkbfx.la
/usr/lib/kde3/kcm_kcmkbfx.so
/usr/lib/libkbfxvista.la
/usr/lib/libkbfxvista.so
/usr/share
/usr/share/applications
/usr/share/applications/kde
/usr/share/applications/kde/kcmkbfx.desktop
/usr/share/apps
/usr/share/apps/kicker
/usr/share/apps/kicker/applets
/usr/share/apps/kicker/applets/kbfxvista.desktop
/usr/share/config.kcfg
/usr/share/config.kcfg/kbfx.kcfg
/usr/src
/usr/src/debug
[geek@toni ~]$



WHOAAAAAAAAAA!!!!!!! . Now, let's find a guinea pig ... :D

11 Responses to “Building my first RPM package”

  1. stwn says:

    jadi inget jaman dulu, pengen lagi..
    para rpm-builder biasanya pake referensi ini: Maximum RPM, walau udah agak lama tapi lumangyan.

  2. toni says:

    Wah, kok aku kelewatan url ini ya :( .. sepertinya isinya lengkap banget ..

  3. aRdho says:

    wow.. anda pintar sekali…

    *gag ngerti sama sekali*

  4. toni says:

    halo aRdho :) … pakabar di luar sana?

  5. bLub says:

    waw!!
    saya ga ngerti dong *bangga*

  6. Bojes says:

    Blog-mu iki nggawene nganggo opo Mas? Wordpress opo dudu?

  7. Giuliano says:

    Where you put your rpm ? please send me ?

  8. toni says:

    Check you inbox ;)

  9. toni says:

    @Bojes
    Iyo, wordpress

  10. Fernando says:

    Where can I download this RPM ?

  11. toni says:

    I’ll try to upload it somewhere, hopefully soon. But notice, this is a non official package. The code itself differs a lot from the official release :D .

Leave a Reply