From SpectLog
Jump to: navigation, search

: rpmbuild, yumdownloader

The following steps show how to get absolutely any source code for currently running software on the system using bash package example. The source code may potentially have distribution-specific changes which is probably what you want more often. It provides the choice to manipulate the most detailed aspects of the system (which is open source all about).

Select the package required

Get absolute path to the file in the package:

which bash
/bin/bash

List candidate packages for selection:

yum whatprovides /bin/bash
Loaded plugins: refresh-packagekit
bash-4.1.2-3.el6.x86_64 : The GNU Bourne Again shell
Repo        : sl
Matched from:
Filename    : /bin/bash



bash-4.1.2-3.el6.x86_64 : The GNU Bourne Again shell
Repo        : installed
Matched from:
Other       : Provides-match: /bin/bash

Alternative way is to use repoquery command:

repoquery -qf /bin/bash
bash-0:4.0-9.fc11.x86_64
bash-0:4.0-6.fc11.x86_64

Downlodad related SRPM and install source code

Download SRPM (source RPM):

yumdownloader --source bash
bash-4.0-9.fc11.src.rpm

Install source files under ~/rpmbuild/SOURCES directory (which is default based on RPM settings which are provided by ~/.rpmmacros file).

rpm -i bash-4.0-9.fc11.src.rpm

Apply any patches used by RPM package

This will generate sources ready for compilation (with all patches applied) inside ~/rpmbuild/BUILD/bash-*.

rpmbuild -bc ~/rpmbuild/SPECS/bash.spec

If there is any unresolved dependencies to build bash RPM, install those (regular) RPM packages using yum.

The initial source code used by RPM is "vanilla" archive from related open source project. This source code is patched during RPM building before compilation to include distribution-specific changes.

Review or modify and build source code

Note that any changes made in ~/rpmbuild/BUILD/bash-* directory will be overwritten next time rpmbuild command is run. However, you may use normal direct compilation command (avoiding rpmbuild) inside the directory (for example, make bash in this case).

Alternatively, there is "the right" method for any serious long-term changes. This requires creating customized source code under ~/rpmbuild/SOURCES directory and modifying RPM spec file.