From owner-freebsd-bugs Fri Mar 10 11:20:10 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4631D37BF47 for ; Fri, 10 Mar 2000 11:20:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id LAA98195; Fri, 10 Mar 2000 11:20:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from timingpdc.timing.com (timingpdc.timing.com [206.168.13.194]) by hub.freebsd.org (Postfix) with ESMTP id C89B837BD47 for ; Fri, 10 Mar 2000 11:14:00 -0800 (PST) (envelope-from jhein@timing.com) Received: from Brain.timing.com ([206.168.13.195]) by timingpdc.timing.com (Post.Office MTA v3.1.2 release (PO205-101c) ID# 103-49575U100L2S100) with ESMTP id AAA617; Fri, 10 Mar 2000 12:14:34 -0700 Received: (from jhein@localhost) by Brain.timing.com (8.9.3/8.9.3) id MAA32389; Fri, 10 Mar 2000 12:13:47 -0700 (MST) (envelope-from jhein) Message-Id: <200003101913.MAA32389@Brain.timing.com> Date: Fri, 10 Mar 2000 12:13:47 -0700 (MST) From: "John E. Hein" Reply-To: jhein@timing.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: kern/17304: patch for bsd.kmod.mk to support more flexible compilation of KLDs via $KERN Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 Here's the test.c source code: /* test.c */ #include #include #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 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