initCommon(); $template->displayHeader(); ?>

19.4. Creating Non-Linux RPMS

Once you have RPM set up on a system, you should be able to create RPMs using the rpmbuild command on that system.

Warning

Do not build RPM packages logged in as a root or Administrator user. If something goes wrong, rpmbuild could destroy files in your system. Remember that spec files can define a number of commands and shell scripts. Any of these could have an error that could cause major damage when run as a root user.

Before building RPMs with the rpmbuild command, though, you may want to customize the build environment to better reflect your system. You may also find it is too difficult to build most RPMs on the non-Linux system and instead focus on cross-building packages, should the rpmbuild command not work on the target systems.

This section covers topics related to building RPMs on or for non-Linux systems.

19.4.1. Setting up a build environment

In RPM terms, your build environment consists of the directories where you build RPMs, as well as the rc and macro settings that define all of the variables in an RPM-based system. To set up your build environment, you need to ensure that all the rc and macro settings reflect the true environment on your non-Linux system.

The rpm --showrc command, discussed previously in the "Creating the RPM Environment" section, lists the settings for your system. You can use this command to verify all the settings.

You may want to change some settings, such as the top directory where RPMs are built. By default, this setting is something like the following:

_topdir %{_usrsrc}/redhat

Cross Reference

See Chapter 21 for more on how to customize the rc and macro settings.

In most cases the _topdir setting on Red Hat Linux systems map to the /usr/src/redhat directory. Your system may not even have a /usr/src directory. Also you may not want to build RPMs in a redhat directory, which may cause confusion if you are building on a non-Red Hat Linux system.

Cross Reference

See Chapter 19 for more information on setting up a build environment for RPMs. Chapter 19 focuses on other Linux systems, but many of the same techniques apply.

With a build environment set up, you should be able to create RPMs with the rpmbuild command. If this doesn’t work, or is too difficult, then you can try cross-building packages.

19.4.2. Cross-building packages

You may find that it is too difficult to create RPMs on a given platform. It may be easier to build the RPMs on another platform, such as a Linux system, as if it were on the target platform. This is called cross-building packages, since you are building a package on one system specifically designed for another.

In most cases, the target platform is quite different from the system where you cross-build packages. Otherwise, you would likely just build the RPMs on the target platform.

The key issues with cross-building are the following:

*You must compile any executables with a cross compiler for the proper target platform.

*You must set the target platform in the RPMs you build.

*You must manage dependencies, and likely need to turn off the automatic generation of dependencies.

Note

Setting up a cross-building environment is oftentimes more work than it is worth. If you can compile applications and build packages on the target system, do that. The cross-building option should be used only if you really cannot build packages on the target system. For example, many handheld or small-format computers lack the processor performance or memory to compile applications. These are good candidates for cross-building.

To compile executables for another platform, especially a platform with a different processor architecture, you need a cross compiler. A cross compiler runs on one system and produces executables for another.

Note

Cross compilers are heavily used when working with embedded and small device systems. The embedded system may not have the processor power to compile applications, or it may simply be inconvenient to compile applications on the embedded system.

The Linux gcc compiler can act as a cross compiler if you install the right gcc add-on packages. See the GNU site for more on the gcc compiler.

Cross Reference

You can download GCC and other GNU software from www.gnu.org.

In addition to compiling for the target platform, you need to ensure that the RPM is marked as being for the target architecture. If not, the rpm command will fail when trying to install the RPM on the target system.

You can set the target architecture with the --target option to the rpmbuild command. For example:

rpmbuild –bi --target arm-sharp-linux

This specifies a target CPU architecture of ARM, the vendor Sharp (which just happens to make an ARM-based Linux device) and the operating system of Linux. The basic format is:

cpu-vendor-os

Cross Reference

See Chapter 12 for more on using the --target option to the rpmbuild command.

You must also turn off or correct any automatically generated dependencies in RPMs you build for other platforms. That is, any dependencies based on the operating system or architecture of the system you are cross-building on will likely not be found, or be found in a different location or format, on the target platform.

This is where the handy RPM feature of automatically building the dependencies does not work to your advantage. You can turn off this feature, however.

Cross Reference

See Chapter 19 for information on how to turn off the automatic generation of dependencies.

You should turn off the automatically building of dependencies for any packages you cross build.

Using these techniques, you can build packages on one system for use on another, very different system. Due to the difficulties, you should only go this route if it becomes too difficult to use the rpmbuild command on the target systems.

displayFooter('$Date: 2005/11/02 19:30:07 $'); ?>