[openfabrics-ewg] RHEL5 and OFED ...

Doug Ledford dledford at redhat.com
Tue Oct 17 14:34:13 PDT 2006


On Tue, 2006-10-17 at 22:28 +0200, Michael S. Tsirkin wrote:
> On a tangent, is there a way to set up a cross-build environment that will
> build kernel modules for e.g. RHEL amd64 kernel on a 32 bit machine?
> I'm doing this now with gcc and kernel.org kernel I built myself from source.
> I guess I mostly need to get gcc and binutils SRPMs to generate
> cross-compiling tools - has anyone done that?

At least for Red Hat, rpm already mostly supports this with only a few
examples of breakage (apps needing gfortran like openmpi are an example
that might break depending on usage).  This is one of the reason I
totally ignore the install.sh script in the OFED releases.  For any arch
that supports multiple run time variants, the default installation
installs compilers for all supported run time variants, but not
necessarily for other variants (aka, on x86_64 gcc will support x86_64
or ia32, but ia32 won't necessarily support x86_64, and neither will
necessarily support building ppc or ppc64 or ia64 or s390(x)).  You can
call rpmbuild with the --target option to specify the mode you want the
package built as, and in the process that automatically changes all of
the configure options present as part of the %configure macro of rpm to
the right paths (hence why I also strip out all of the %_libdir and
friends settings from the spec file, rpm gets this right itself) and
changes the CFLAGS and CPPFLAGS environment variables to force compiling
in the right mode.

Now, that being said, kernel modules in particular are a different
beast.  I originally had a module build kit for the 2.4 kernels that
would cross build kernel modules.  That's long since deprecated though.
Now a days, the rule is to build a proper kernel looking source tree,
install the kernel-devel package, then the build command is basically
something like:

cd /lib/modules/`uname -r`/build
make SUBDIRS=<src-directory-path>

In order to cross compile, you would likely need to pass ARCH= to the
make command line.  In addition, for a cross compile you very well may
need to install the kernel-devel from that arch instead of the native
one.  However, given the limitations I listed above about cross
compiling, it's likely that you can only cross compile from certain
arches to certain other arches.

All that being said, a kernel-ib spec file could include something like
this:

BuildConflicts: kernel-devel (I'm not sure build conflicts is a proper
tag, if not, you might have to script a little more carefully in %setup)

%prep
%setup -q
rpm -i /usr/src/redhat/RPMS/%{arch}/kernel-devel-`uname -r`.%{arch}.rpm

%build
cd /lib/modules/`uname -r`/build
make ARCH=%{arch} SUBDIRS=${RPM_BUILD_DIR}/%{name}-%{version} modules

%install
cd /lib/modules/`uname -r`/build
make ARCH=%{arch} SUBDIRS=${RPM_BUILD_DIR}/%{name}-%{version}
INSTALL_MOD_PATH=${RPM_BUILD_ROOT} modules_install

%clean
rm -fr ${RPM_BUILD_ROOT}
rpm -e kernel-devel

Then, to cross compile, you would simply run rpmbuild multiple times:

for i in i686 x86_64; do
  rpmbuild --ba --target=$i kernel-ib.spec
done

BTW, all the rpms are live on my site now.

-- 
Doug Ledford <dledford at redhat.com>
              GPG KeyID: CFBFF194
              http://people.redhat.com/dledford

Infiniband specific RPMs available at
              http://people.redhat.com/dledford/Infiniband
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.openfabrics.org/pipermail/ewg/attachments/20061017/b3c5de8e/attachment.sig>


More information about the ewg mailing list