Date: Fri, 10 Mar 2000 12:13:47 -0700 (MST) From: "John E. Hein" <jhein@timing.com> To: FreeBSD-gnats-submit@freebsd.org Subject: kern/17304: patch for bsd.kmod.mk to support more flexible compilation of KLDs via $KERN Message-ID: <200003101913.MAA32389@Brain.timing.com>
next in thread | raw e-mail | index | archive | help
>Number: 17304 >Category: kern >Synopsis: building a KLD can fail on platforms that are not the desired target FreeBSD version >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Mar 10 11:20:01 PST 2000 >Closed-Date: >Last-Modified: >Originator: John E. Hein >Release: FreeBSD 4.0 (osreldate: 400016) >Organization: Timing Solutions Corp. >Environment: Desired target OS: FreeBSD demo.ts 4.0-TSC-20000301 FreeBSD 4.0-TSC-20000301 #0: Fri Mar 3 18:24:00 MST 2000 imp@marvin.timing.com:/net/daffy/u7/homes/imp/tsc/FreeBSD-tsc-4/sys/compile/MINNIE.TS i386 System on which building of KLD is done: Building from any FreeBSD version != desired target OS: >Description: bsd.kmod.mk does not support having a FreeBSD source tree in a location other than the default /usr/src very well. There are 2 problems with this: - the machine you compile on is not exactly the same version of FreeBSD as the desired target machine. - you can't keep your own KLD sources outside the FreeBSD source tree easily. Thus people tend to pollute their FreeBSD source tree with their own KLD sources. The included patch supports more flexible compilation on non-target machines & compilation of KLD sources located outside the FreeBSD source tree. >How-To-Repeat: The following example will not compile on a recent 4.0 machine (such as osreldate 400016). It DOES compile on a November snapshot of 4.0 (osreldate 400011). With my patch (below), you can point $KERN to the FreeBSD source tree of your choice (which may or may not be located where your KLD is) and you can compile successfully. In addition, this example will not compile if it is NOT in the proper place actually within the FreeBSD source tree. The patch below allows the user to put his KLD anywhere and simply tell the makefile where to find the desired FreeBSD sources. Thus he can compile his KLD for any desired FreeBSD version from any machine he wishes. Here's the Makefile: /* Makefile */ SRCS = test.c .include <bsd.kmod.mk> Here's the test.c source code: /* test.c */ #include <sys/cdefs.h> #include <sys/types.h> #ifdef _KERNEL #warning "_KERNEL defined... we are using a recent bsd.kmod.mk" #else #warning "_KERNEL NOT defined... we're not using the latest OS stuff" #endif #include <i386/isa/isa_device.h> void testfunc (void); void testfunc (void) { /* * example of trying to use stuff that is gone in newer versions of the * 4.x source tree * * This DID compile on an old November snapshot of 4.0 (400011) * * This does NOT compile on a recent November snapshot of 4.0 (400016) * since the id_alive field no longer exists * * * This is just an example to demonstrate why one might * want to compile for a version of FreeBSD other than * the installed version of the current machine. Let's say * we have a compile system based on a certain version of * FreeBSD and we want to upgrade it, but not before we can be * sure that we can make our KLDs compile. */ struct isa_device isa_dev; #warning "This should not compile for newer versions of 4.x" isa_dev.id_alive = 1; } >Fix: Following is the proposed patch to bsd.kmod.mk : It allows the KLD developer to specify $KERN which points to the sys/kern directory of his desired target FreeBSD version. So he would compile his KLD with 'make KERN=/the/location/of/my/desired/target/FreeBSD/version/sys/kern' Note that this does not break buildworld. In fact, it does not change the default behavior at all unless KERN is specified (and it's not in any of the default buildworld makefiles). In addition, this allows that your KLD source need not be in the FreeBSD tree to compile. It can be anywhere (such as the location of your company's driver repository). @@ -175,15 +175,24 @@ # found in the search are likely to cause problems. If nothing is found, # then the links default to /usr/include and /usr/include/machine. ${_ILINKS}: - @set +x; for up in ../.. ../../.. ; do \ + @set +x; for up in ${ILINK_SEARCH_DIRS}; do \ case ${.TARGET} in \ machine) \ - testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ - path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ + if [ "${ILINK_SEARCH_DEFAULT}" = "1" ]; then \ + testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ + else \ + testpath=$$up/${MACHINE_ARCH}/include ; \ + fi ; \ + path=$$testpath ; \ defaultpath=/usr/include/machine ;; \ @) \ - testpath=${.CURDIR}/$$up/sys ; \ - path=${.CURDIR}/$$up ; \ + if [ "${ILINK_SEARCH_DEFAULT}" = "1" ]; then \ + testpath=${.CURDIR}/$$up/sys ; \ + path=${.CURDIR}/$$up ; \ + else \ + testpath=$$up ; \ + path=$$up ; \ + fi ; \ defaultpath=/usr/include ;; \ esac ; \ if [ -d $$testpath ] ; then break ; fi ; \ @@ -261,10 +270,17 @@ ${KMODUNLOAD} ${KMOD} .endif +.if !defined(KERN) .if exists(${.CURDIR}/../../kern) KERN= ${.CURDIR}/../../kern .else KERN= ${.CURDIR}/../../sys/kern +.endif +ILINK_SEARCH_DEFAULT=1 +ILINK_SEARCH_DIRS= ../.. ../../.. +.else +ILINK_SEARCH_DEFAULT=0 +ILINK_SEARCH_DIRS= ${KERN}/.. .endif .for _src in ${SRCS:Mopt_*.h} >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003101913.MAA32389>