32bit Packages
From openSUSE
There will be instances where a package build produces 32-bit binaries along with 64-bit and architecture neutral files. This page is to help you develop a RPM specfile that will create packages containing the correct files for the correct architectures.
Contents |
Package Hierarchy
To understand the process, it is important to understand the overall package organization.
Image:32bit-package-relationship.svg - This is a great image, if only I could upload .svg files :P
The main package will contain architecture neutral files, such as manpages and scripts. Two main subpackages will be created, one for 32-bit binaries, one for 64-bit binaries. This will all be done it one specfile.
Defining Architectures
You should start with the fundamentals - what are the architectures that binaries will be created for. In our case, the build creates 32-bit and 64-bit binaries. It also installs architecture neutral files, but those will be put into the package that both architectures will use. The basic architecture definitions look like this:
%define packagename_32bit_arch %ix86 ppc %arm s390 %define packagename_64bit_arch x86_64 ppc64 s390x
Of course, s390 and s390x is not completely necessary on the open build service, but has it's use in building packages for IBM mainframes.
Specifying Package and Subpackage Details
Now is a good time to specify the individual packages you will create. It should look something like this, now:
%define packagename_32bit_arch %ix86 ppc %arm s390
%define packagename_64bit_arch x86_64 ppc64 s390x
Name: packagename
BuildRequires: gcc
Summary: A package of amazing software
Version: 1.0.0
Release: 0
License: GPLv2
Group: Miscellaneous
Source: %{name}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-build
ExclusiveArch: %packagename_32bit_arch %packagename_64bit_arch
%description
This package has software that will increase your productivity 1000%!
%ifarch %packagename_32bit_arch
%package 32bit
PreReq: packagename
ExclusiveArch: %packagename_32bit_arch
%description 32bit
This package has software that will increase your productivity 1000%!
%endif
%ifarch %packagename_64bit_arch
%package 64bit
PreReq: packagename
ExclusiveArch: %packagename_64bit_arch
%description 64bit
This package has software that will increase your productivity 1000%!
%endif
Some details to note are the two %package definitions. Each is followed with a suffix that will be added to the end of each subpackage. For instance, the %package 32bit definition will create a package named packagename-32bit.
Also note that there is a %description followed with a suffix for each package.
Finally, in this example I have isolated each package definition with a %ifarch/%endif, so that the specific package is only created on the correct platforms. If your build process is creating both 64bit and 32bit binaries, you will want to remove these conditional statements and allow both packages to be created.
The Prep/Build/Install Sections
These sections do not change in most cases. They appear as such:
%prep
%setup
%build
./configure --prefix=/usr --libdir=%{_libdir}
make
%install
make install DESTDIR=$RPM_BUILD_ROOT
The one thing to verify would be the --libdir=%{_libdir} on the ./configure line. This is necessary for OpenSUSE builds, simply because 64bit libraries are installed in the /usr/lib64 directory, as opposed to /usr/lib for 32bit libraries.
The Pre/Post Sections
These sections are allowed to have suffix values as well, for specific subpackages. Please remember to surround any specific subpackage definitions in %ifarch/%endif conditions if you have done the same in the package definition area.
The Files Section
This will also have suffix values when necessary, surround by conditions. Here is an example:
%files
%defattr(-,root,root)
/etc/init.d/*
/usr/sbin/*
%{_mandir}/man*/*
%ifarch %packagename_32bit_arch
%files 32bit
%defattr(-,root,root)
%{_libdir}/*.so
%endif
%ifarch %packagename_64bit_arch
%files 64bit
%defattr(-,root,root)
%{_libdir}/*.so
%endif
Summary
Creating separate 32bit and 64bit packages is fairly simple, if you remember a couple of basic rules:
- Use %define to specify which architectures build which packages
- Use the 32bit and 64bit suffixes on %package, %description, %pre, %post, %preun, %postun, and %files sections to perform architecture-specific actions
- Surround architecture-specific actions with %ifarch/%endif where necessary.
Good luck with your newfound skill, and have fun!

