[PATCH] Set SYSDIR for modules built with kernel

John Baldwin jhb at freebsd.org
Thu Mar 5 08:32:29 PST 2009


One of the things each kernel module build has to do is figure out where the 
source tree it belongs to lives.  /usr/share/mk/bsd.kmod.mk uses a heuristic 
where it walks up N levels of the tree looking for a kernel source directory.  
If that fails it falls back to /sys or /usr/src/sys.  One side effect of this 
(besides lots of directory lookups during a build as each kernel module build 
stage has to do this) is that if CURRENT adds an even deeper level of nesting 
(such as with the recent ata chipset modules) then you can't build a kernel 
with those modules until /usr/share/mk/bsd.kmod.mk on your build machine has 
been updated.  This means you can't build an 8.0 kernel on 7.0 simply because 
ata chipset modules don't find the right headers.

However, the SYSDIR is already known during a kernel build (we depend on this 
to make modules built in ports DTRT when they are rebuilt via buildkernel).  
I just changed the kernel build Makefile to always set SYSDIR.  With this 
change, I was able to build an 8.0 kernel + modules on a 7.1-ish machine with 
an unpatched /usr/share/mk/bsd.kmod.mk.  This should also have the side 
effect of reducing the number of pathname lookup operations done during a 
kernel build with modules.

Thoughts?

--- //depot/projects/smpng/sys/conf/kern.post.mk	2009/01/15 22:41:24
+++ //depot/user/jhb/lock/conf/kern.post.mk	2009/03/04 21:25:21
@@ -12,7 +12,8 @@
 .if defined(DESTDIR)
 MKMODULESENV+=	DESTDIR="${DESTDIR}"
 .endif
-MKMODULESENV+=	KERNBUILDDIR="${.CURDIR}"
+SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;}
+MKMODULESENV+=	KERNBUILDDIR="${.CURDIR}" SYSDIR="${SYSDIR}"
 
 .MAIN: all
 
@@ -29,7 +30,6 @@
 
 # Handle out of tree ports 
 .if !defined(NO_MODULES) && defined(PORTS_MODULES)
-SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;}
 PORTSMODULESENV=SYSDIR=${SYSDIR}
 .for __target in all install reinstall clean
 ${__target}: ports-${__target}

-- 
John Baldwin


More information about the freebsd-arch mailing list