Tuesday, 27 March 2007

GPIB packaging

I've been re-packaging the latest Linux GPIB Package into an RPM for our SUSE 10.0 machines. This was prompted by the desire to upgrade from kernel 2.6.13-15.11 to 2.6.13-15.15 for security reasons. And because the GPIB drivers and hence the RPM depend on a specific kernel release, upgrading the kernel means a new RPM is required. So far so good, I've done this before, I just need to rebuild the RPM. But maybe there's a new release of the GPIB package too, I thought, so I looked at that this morning, and sure enough, the latest version of linux-gpib is 3.2.09 whereas what we had previously was 3.2.07. So I downloaded 3.2.09 and tried to re-build the RPM with the new linux-gpib version.
Turns out, two important things have changed.
  1. A directory previously called driver is now called drivers
  2. The Makefile newly (and correctly) delegates the installation of the modules to the kernel build system, KBUILD
Having to change the .spec file for the first change is mildly irritating but approximately no work (more or less just s/driver/drivers/, being a little bit careful where that's done), but the second change was a bit more tricky to deal with. The RPM spec file's %install section runs make install to install the drivers which then invokes KBUILD as follows:

$(MAKE) -C $(LINUX_SRCDIR) V=1 modules_install CC="$(LINUX_CC) \
-I/usr/src/packages/BUILD/linux-gpib-3.2.09/drivers/.. \
-I/usr/src/packages/BUILD/linux-gpib-3.2.09/drivers/../driver/include \
-I/usr/src/packages/BUILD/linux-gpib-3.2.09/drivers/../include" \

but this means that the RPM fails to build because KBUILD tries (as a non-root user) to install the kernel modules under the absolute path /lib/modules/2.6.13-15.15-default/gpib. What we need is to get the modules installed under the RPM build root, but there seems to be no way to tell KBUILD to install modules somewhere else other than under /lib/modules/. KBUILD's output path variable O has no effect on this, it seems. Finally, in the %prep section of the spec file I introduce a module_prefix variable in front of the INSTALL_MOD_DIR path thus:

sed -i '/INSTALL_MOD_DIR="gpib"/s/gpib/$(module_prefix)gpib/'

and then override this during %install thus:

make module_prefix=../../../$RPM_BUILD_ROOT/lib/modules/%{kernel}/ install

so that the final directory to which the module is copied is, in full


And that works. Phew!