[OpenAFS-devel] (Re-)building the Linux kernel module

Russ Allbery rra@stanford.edu
Fri, 24 Sep 2010 21:32:05 -0700


The current Debian kernel source packages build the kernel module three
times in the process of building the package, once for make and then twice
more for make install, which obviously makes it much slower than it needs
to be, so I dug into why that is.  I'm now very confused because it seems
to be intentional?

First, the double builds for make install seem to be due to these two
targets in MakefileProto.LINUX.in:

${INSTDIRS} ${DESTDIRS}: ${COMPDIRS}
        if [ "${LINUX_KERNEL_PACKAGING}" ] ; then \
            TARGPREFIX="pack_"; \
        fi ; \
        for m in ${MPS} ; do \
                KDIR=${KOBJ}-${LINUX_VERSION}${LINUX_MODULE_NAME}-$$m ; \
                echo Building in directory: $${KDIR} ; \
                if [ "$$m" = "MP" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.mp" ; \
                elif [ "$$m" = "EP" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.ep" ; \
                elif [ "$$m" = "BM" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.bm" ; \
                else  \
                        SMP_DEF="@RHCONFIG_SP@ ${LOCAL_SMP_DEF}" ; \
                        TARG=libafs ; \
                fi ; \
                cd $${KDIR} ; \
                $(MAKE) -f Makefile.afs SMP_DEF="$${SMP_DEF}" $@_$${TARGPREFIX}$${TARG} CLIENT=${LINUX_VERSION}${LINUX_MODULE_NAME} KDIR=$${KDIR} || exit $$?; \
                cd ../ ; \
        done

${COMPDIRS}: setup
        $(RM) -f h 
        $(RM) -f sys
        $(RM) -f netinet 
# ...
        if [ "${LINUX_KERNEL_PACKAGING}" ] ; then \
            TARGPREFIX="pack_"; \
        fi ; \
        for m in ${MPS} ; do \
                KDIR=${KOBJ}-${LINUX_VERSION}${LINUX_MODULE_NAME}-$$m ; \
                echo Building in directory: $${KDIR} ; \
                if [ "$$m" = "MP" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.mp" ; \
                elif [ "$$m" = "EP" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.ep" ; \
                elif [ "$$m" = "BM" ] ; then \
                        SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
                        TARG="libafs.bm" ; \
                else  \
                        SMP_DEF="@RHCONFIG_SP@ ${LOCAL_SMP_DEF}" ; \
                        TARG=libafs ; \
                fi ; \
                cd $${KDIR} ; \
                $(MAKE) -f Makefile.afs SMP_DEF="$${SMP_DEF}" $@_$${TARGPREFIX}$${TARG} CLIENT=${LINUX_VERSION}${LINUX_MODULE_NAME} KDIR=$${KDIR} || exit $$?; \
                cd ../ ; \
<all>
        done

Notice how ${INSTDIRS} depends on ${COMPDIRS}, which sets a bunch of stuff
up and then builds the kernel module, but then ${INSTDIRS} contains a
second copy of exactly the same code and builds the kernel module again.
What's going on here?  Why would we do this?

Then, the fact that we build the kernel module on build and then again on
install (and always rebuild the kernel module each time one runs make),
appears to be because we're explicitly forcing doing so:

.FORCE:
${LINUX_LIBAFS_NAME}.ko afspag.ko: .FORCE
        env EXTRA_CFLAGS="${EXTRA_CFLAGS}" @TOP_SRCDIR@/libafs/make_kbuild_makefile.pl ${KDIR} $@ @TOP_OBJDIR@/src/config/Makefile.config Makefile.afs Makefile.common
        env EXTRA_CFLAGS="${EXTRA_CFLAGS}" $(MAKE) -C ${LINUX_KERNEL_BUILD} M=@TOP_OBJDIR@/src/libafs/${KDIR} modules

Why are we forcing this?  Just because no one's come up with the correct
dependencies to know when to rebuild the kernel module properly?

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>