Thursday, August 14, 2008

Changing Compile Options for a Source RPM

Continuing from May 21, 2008...

While most precompiled RPMs will serve your needs, at times you will want to modify the source code or compile options in the corresponding SRPMs. You can do so in the spec file that you get when you installed the source RPM. Let's looking at the directories and their purpose.

/usr/src/redhat/SOURCES - Contains the original program source code.

/usr/src/redhat/SPECS - Contains spec files, which control the RPM build process

/usr/src/redhat/BUILD - Source code is unpacked and built here

/usr/src/redhat/RPMS - Contains the output binary RPM

/usr/src/redhat/SRPMS - Contains the SRPM created by the build process

To change the compile options in an SRPM, you must understand spec files. The spec file is stored in /usr/src/redhat/SPECS/packagename.spec. The spec file controls the way a package is built and what actions are performed when it is installed or removed from a system. A spec file has 10 different sections (see the list below). Several of the sections include commands that can be run as individual shell scripts. You won't see all of these sections every spec file. For more information, see the RPM HOWTO at www.rpm.org.

%preamble - Includes informaton shown with an rpm -qi command. This normally includes a summary, version, and group. It also includes a list of dependent packages.

%description - A basic package description.

%pre - Adds a macro for preinstallation scripts.

%prep - Includes any preparatory commands required before building the source code, such as unpacking.

%build - Commands to compile the spec file and build sources.

%install - Commands to install the software on a system.

Install and uninstall scripts - Spec files usually contains cripts that will be run on the end user's system to insall or remove the software. RPM can execute a script before the package is installed, after the package is installed, before the package is removed, and after the package is removed.

%verify - Although RPM takes care of most verifictaion tasks, a script can be inserted here for any desired extra checks.

%clean - A script can be specified here to perform any necessary cleanup tasks.

%post - Adds a macro that cleans up after installation.

%preun - Scripts that prepare for uninstallation.

%postrun - Adds a macro that cleans up after installation.

%files - A list of files in the package.

%changelog - A list of revisions.

You can change the compile-time options for a package in the build section of the spec file. Here's a sample %clean section from a different spec file (this is not from the vsftpd RPM):

%build
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/etc
./configure --prefix=/usr/ --exec-prefix=/
make CFLAGS="$RPM_OPT_FLAGS" LDFLAGS=-s

This section, a shell script, begins with some housekeeping, removing any files that may be left over from a previous build. A directory structure is created for the source files. Then the package is configured and compiled with the make command.

For a different package, you might modify the make command line to compile other components after LDFLAGS. The compile options from $RPM_OPT_FLAGS are defaults, set by RPM. Alternatively, you could use this variable to set other compile-time options such as a different CPU.

Note: Perhaps the essential reference guide to the RPM system is Red Hat's book Maximum RPM. An older version is available online from Red Hat at www.redhat.com/docs/books/max-rpm.

0 comments: