How-To create a RPM -- page 4 -- building the package
2.4. building the package
Finally, we are ready do get our first package built!!!.
At this point, in ~/packages we can see the directories:
$ ls ~/packages/
BUILD RPMS SOURCES SPECS SRPMS
SPECS contains subtitleeditor spec file, SOURCES contains our source tarball and eventually, patches.
Let's go do our SPECS directory and start building our package.
$ cd ~/packages/SPECS
In order to build a package, we are going to use the rpmbuild command.
rpmbuild syntax is: rpmbuild -b<build stage> <spec file>. So, depending on which build stage you choose, you are going to build either th binary RPM, source RPM, none of them or both of them. Here is the list of the different switches that can be used:
- -ba : build all, both a binary and source RPM
- -bb : build only the binary RPM
- -bc : only compile the program. Does not make the full RPM, stopping just after the %build section
- -bp : prepare for building a binary RPM, and stop just after the %prep section
- -bi : create a binary RPM and stop just after the %install section
- -bl : check the listing of files for the RPM and generate errors if the buildroot is missing any of the files to be installed
- -bs : build aonly the source RPM
Therefore, if you want to build everything (source RPM, binary RPM), you will type:
$ rpmbuild -ba subtitleeditor.spec
if you only want to build the binary RPM:
$ rpmbuild -bb subtitleeditor.spec
will do.
Unfortunately, this is not going to work on the first shot because we are not building the package into the default location: /usr/src/redhat. In order to tell rpmbuild to use another top directory, we are going to use a rpm macro. rpm macros can be set in ~/.rpmmacros. Open and edit ~/.rpmmacros with the following line:
%_topdir /home/<your user here>/packages
Now, when you will use rpmbuild, /home/user/packages will be used as the top directory.
What to expect from now? Running:
$ rpmbuild -ba subtitleeditor.spec
Should unpack the archive, configure, compile and install the software into an rpm package. The source RPM will be in ~/packages/SRPMS while the binary RPM will be in ~/packges/RPMS/
Well, that's it, if everything when without error, you have your RPM package ready in ~/packages/RPMS/
2.5. Signing your packages
Signing a RPM with rpmbuild is pretty easy. First, you need to have a GPG key. I suppose that you already have a GPG key. Now, go and edit ~/.rpmmacros and add:
%_signature gpg
%_gpg_path /path/to/.gnupg
%_gpg_name name lastname (comment) <email>
%_gpgbin /usr/bin/gpg
You might want to use the output of gpg --list-keys to find out we value to enter for %_gpg_name .
Next time you want to sign your RPM, use the following command:
$ rpmbuild -ba --sign subtitleeditor.spec
3. Conclusion
By using a template .spec, it is pretty easy to create your own package. Once packaged, the software will be easier to distribute, install, uninstall and manage.
There is a lot more you can do with the .spec file, but this is out of the scope of this article.
Let's start packaging ;)
Reference:
Fedora's RPM Guide
- Login or register to post comments
- Download PDF












