By thomas, Tue, 09/22/2009 - 10:39
It's a good idea to build a source rpm for your spec file. You'll keep the source rpm so that when you need to make a change to the package, you have everything you need readily available. To build a source rpm you use the unfortunate argument of bs.
[build@client11 SPECS]$ rpmbuild -bs tar.spec
Wrote: /home/build/rpmbuild/SRPMS/tar-1.22-1.src.rpm
If you are only building the source rpm, you don't need to bother with dependencies, so a good option here is to say nodeps.
[build@client11 SPECS]$ rpmbuild --nodeps -bs tar.spec
Wrote: /home/build/rpmbuild/SRPMS/tar-1.22-1.src.rpm
The build options for rpmbuild are as follows
  • -ba build everything
  • -bb build binary
  • -bp continue only to the %prep stage
  • -bc continue only to the %build stage
  • -bi continue only to the %install stage
  • -bl just verify the %files section
  • -bs build only the source package
One nice thing you can do when you are building your rpms and having trouble is to skip the prep sections and just go straight into building, you would do that like this
[build@client11 SPECS]$ rpmbuild --short-circuit -bc tar.spec
Or if you have just built a package and it fails because you missed a file, you can just verify the files section again after making your change.
[build@client11 SPECS]$ rpmbuild --short-circuit -bl tar.spec
Processing files: tar-1.22-1
Requires(rpmlib): rpmlib(CompressedFileNames) = 3.0.4-1 rpmlib(PayloadFilesHavePrefix) = 4.0-1
Requires: libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.4)(64bit) librt.so.1()(64bit) librt.so.1(GLIBC_2.2.5)(64bit) rtld(GNU_HASH)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/rpm-buildroot-tar-1.22
I don't think I'll have time to cover some advanced topics, but something we use a lot is --target. --target allows you to specify the architecture for which you are building. We typically build on x86_64 and then specify --target to build the i386 rpm. You need to use the program setarch in front of rpmbuild to achieve a true i386 package.
[build@client11 SPECS]$ setarch i386 rpmbuild --target i386 -bb tar.spec 
Building target platforms: i386
Building for target i386
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.85806
...
configure: error: C compiler cannot create executables
See `config.log' for more details.
error: Bad exit status from /var/tmp/rpm-tmp.85806 (%prep)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.85806 (%prep)
There's a lot more to that problem though...you need a full i386 system installed so that you can compile i386 binaries on an x86_64 system. That means compilers, libraries, etc. The solution to that problem is beyond scope but I can summarize it with one word, mock.

It's doubtful you'll need any other options to rpmbuild, read the man page, but the rest are all margin case options.