The purpose of doing this lab is to create an RPM package. So here we go.
Preparation
First, we need to install the building
packages.
| yum groupinstall "Fedora Packager"
| yum install rpmlint yum-utils
Then I created ~/rpmbuild directories and ~/.rpmmacros by using this command.
Steps
First, we need to install the building packages.
* run this command as a regular user
This prepared the package environment for the next steps.
Create RPM package
To create an RPM package, I need to have a ".spec" file that contains infomation about the software being packaged. To generate a default spec file, issue the command rpmdev-newspec "package" under the SPEC directory. Edit the spec file until it compiles without an error. After that, check the spec file, SRPM, and RPM file by rpmlint for any error and warning. These are basic steps for creating an RPM package. For more detailed infomation related to the spec file, building process, and examples, please check the following wiki page.
=>
How to create an RPM package
which
I copied the tarball into ~/rpmbuild/SOURCES. The file should be located in the SOURCES directory since the spec file will look for source file in this directory when you build the rpm package.
| cp which-2.20.tar.gz ~/rpmbuild/SOURCES
Create an empty skeleton spec file:
| rpmdev-newspec ~/rpmbuild/SPEC/which.spec
Edit the spec file to include necessary information for building "which" package. Below is my first spec file.
Time to build the package!
| rpmbuild -ba which.spec
The build was successful! Then I got RPMs and source RPM built in the following directories.
rpmbuild
├── BUILD
│ └── which-2.20
├── BUILDROOT
├── RPMS
│ └── x86_64
│ ├── which-2.20-1.fc17.x86_64.rpm
│ └── which-debuginfo-2.20-1.fc17.x86_64.rpm
├── SOURCES
│ └── which-2.20.tar.gz
├── SPECS
│ └── which.spec
└── SRPMS
└── which-2.20-1.fc17.src.rpm
The next step was to check if all of my package files can pass the rpmlint test. rpmlint is a tool to check common problems in rpm packages.
I ran rpmlint for the spec file, SRPM file, and two RPMs.
| rpmlint ~/rpmbuild/SPEC/which.spec
| rpmlint ~/rpmbuild/RPMS/x86_64/which-2.20-1.fc.17.x86_64.rpm
| rpmlint ~/rpmbuild/RPMS/x86_64/which-debuginfo-2.20-1.fc.17.x86_64.rpm
| rpmlint ~/rpmbuild/SRPMS/which-2.20-1.fc.17.src.rpm
I got some errors for RPMs.
And I did a lot of research on the Internet as well as the
Common Rpmlint issues. I added "post" and "preun" sections in my spec file.This time the build went though without an error. Also the rpmlint which.spec and RPM
, SRPM tests passed with 0 error and warning.
I still had 5 errors for debuginfo RPM package. I found this fix regarding to "incorrect-fsf-address" error on the wiki site.
"In all cases, upstream should be informed about this. This is the only requirement with respect to this error.
The license file, usually COPYING, must not be patched for
legal reasons. Other files can be patched if deemed suitable. The
updated GPL 2.0 license (the usual case) with correct address is at GPL-2.0.txt"
So I removed COPYING file in the %doc section of spec file and I still got the same error. The which package uses GPLv3 license and I think the reason for this error is because the COPYING file was not 100% equal to the original license file. So this error wouldn't affect the actual package building process.
hello
Follow the same steps as creating which package. I created "hello.spec" template and edited the spec file. When I tried to build the spec file, I got the following errors. And the build was unsucessful.
error: Installed (but unpackaged) file(s) found:
/usr/share/locale/bg/LC_MESSAGES/hello.mo
/usr/share/locale/ca/LC_MESSAGES/hello.mo
/usr/share/locale/da/LC_MESSAGES/hello.mo
/usr/share/locale/de/LC_MESSAGES/hello.mo
/usr/share/locale/el/LC_MESSAGES/hello.mo
/usr/share/locale/eo/LC_MESSAGES/hello.mo
/usr/share/locale/es/LC_MESSAGES/hello.mo
/usr/share/locale/et/LC_MESSAGES/hello.mo
/usr/share/locale/eu/LC_MESSAGES/hello.mo
/usr/share/locale/fa/LC_MESSAGES/hello.mo
...........................
...........................
/usr/share/locale/uk/LC_MESSAGES/hello.mo
/usr/share/locale/vi/LC_MESSAGES/hello.mo
/usr/share/locale/zh_CN/LC_MESSAGES/hello.mo
/usr/share/locale/zh_TW/LC_MESSAGES/hello.mo
Since the unpackaged files seemed like all language files, I added the following lines in the spec file.
%find_lang hello
%files -f hello.lang
Then the build was successful with "exit 0".
Also rpmlint for all four files were passed without errors and warnings.
Done!
Here's the link to all the files I've created in this lab.
=>
which package (spec file, RPMs, SRPM)
=>
hello package files
Until here my first RPMs have been created. Thanks for reading. :)