Aaron S. Hawley (aaronhawley) wrote,

rpmbuild -tb tarball

The usual manner to build a package with the Redhat package manager (RPM) is running rpmbuild on the RPM spec file.

$ rpmbuild -bb package.spec

This presumes that all the source files for the RPM are already copied to the SOURCES directory accessible by RPM (%_topdir/SOURCES).

Its possible to build a source RPM (SRPM) from a spec file.

$ rpmbuild -bs package.spec

The benefit of an SRPM, is it contains all the source files necessary to rebuild the RPM.

$ rpmbuild --rebuild package-1.0-1.src.rpm

Using RPM to build an SRPM guarantees those files are included, and will put files in your SOURCES directory for you.

RPM has an additional feature where it can build an RPM from a tarball. Only a spec file needs to exist in the archive for it to work.

$ rpmbuild -tb package-1.0.tar.gz

This isn't a popular feature, nor is it very well documented. It is likely a relic of another time, when RPMs were not maintained by a distribution, but software maintainers would try and have their source packages install using RPM. This feature of RPM is made more and more obsolete with the success of large RPM-based distributions with a large and vibrant posse of packagers.

The rpmbuild in its tarball mode will find a spec file, even if its not in the top-directory of the package. For example, its not uncommon to put a spec file inside pkg/fedora.

The tarball mode of rpmbuild presumes you're in the SOURCES directory (More proof that RPM's tarball mode is probably a legacy feature). So copy the tarball to the SOURCES directory and run rpmbuild on it from there.

Most software packages simply need to be built from their source archive and don't need any additional files. However, it's not uncommon for packages to need to be specially configured by RPM on some systems by including particular files. On this chance, the included RPM spec file will name other source files or patch files besides the tarball (Source1, Source2, Patch0, Patch1 and so on). These files will need to be copied to the SOURCES directory as well. (Did I mention you need to run rpmbuild -tb in your SOURCES directory?)

I presumed there was some way to tell RPM where to find these SOURCE files in the tarball. For example, if you put these extra source files in the same place as the spec file, pkg/fedora then RPM would find them. Unfortunately, RPM's tarball mode doesn't know to copy anything to the SOURCES directory for you. However, it should be easy to modify the spec file to have it copy the source files in pkg/fedora to the SOURCES directory.

Adding the following tar command to the %prep section of the RPM spec file to copy the source files to the SOURCES directory.

tar -C %{name}-%{version}/pkg/fedora -cf - . | tar -C %{_sourcedir} -xf -

Alternatively, a single tar command on the actual tarball could extract the files into the SOURCES directory.

tar --strip=3 -C %{_sourcedir} -zxf %{SOURCE0} %{name}-%{version}/pkg/fedora/\*

The latter would only use a single execution of the tar command. The former may be more reliable should GNU tar not be available.

With that line inserted, a tar archive with such a SPEC file can bootstrap its own RPM.. The rpmbuild -ta will build both the binary and source RPMS.

Unfortunately, the rpmbuild -ts command will not work in this scenario, until the SOURCE files are present. You can copy the files yourself for it to work. Or run the the %prep stage of rpmbuild to get the task done.

$ rpmbuild -tp
$ rpmbuild -ts

And one other final word of warning, don't make changes to the tarball's source files in the SOURCES directory. Since the source files are extracted every time on each build, any changes to these files will be overwritten, unless you "short-circuit" the rpmbuild. Although short circuiting in RPM will not allow you to actually build the package.

Being able to build an RPM from the tarball source package is something for software maintainers to advertise to their users, but isn't a reliable way to develop RPM packages.
Tags: free software, howto, programming, unix
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded  

  • 0 comments