Subject: toolchain/26329: MKOBJDIRS and build.sh
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <prlw1@cam.ac.uk>
List: netbsd-bugs
Date: 07/14/2004 20:43:10
>Number:         26329
>Category:       toolchain
>Synopsis:       MKOBJDIRS=no impossible with build.sh
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 14 19:44:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Patrick Welche
>Release:        NetBSD 2.0G
>Organization:
>Environment:
>Description:
Revisiting MKOBJDIRS and build.sh, there is something wrong with
the ordering.  It is impossible to set MKOBJDIRS in mk.conf, and
only possible to have it set (to "no") by passing the -o flag to
build.sh.  This may not have been the original intention given the
following comment in build.sh:

        # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
        # These may be set as build.sh options or in "mk.conf".
        # Don't export them as they're only used for tests in build.sh.
        #
        MKOBJDIRS=$(getmakevar MKOBJDIRS)      
        MKUNPRIVED=$(getmakevar MKUNPRIVED)
        MKUPDATE=$(getmakevar MKUPDATE)

The comment suggests they may be set in build.sh. Unfortunately,
by the time this code (in validatemakeparams()) is called, MAKEFLAGS
already contains MKOBJDIRS=yes, as set in parseoptions(), so
getmakevar, which calls make, which honours the environment variable
MAKEFLAGS, will return the value of MKOBJDIRS overriden by MAKEFLAGS
rather than the value it read from /etc/mk.conf (via
bsd.prog.mk->bsd.init.mk->bsd.own.mk)

One may take the opposite view, and suggest MKOBJDIRS should not be
settable, but then maybe that comment should be changed.

I would suggest delaying the application of the default "yes" until
after the getmakevar as per the attached patch.

(There probably is a neater syntax for the patch, but it shows what
I mean.)  
>How-To-Repeat:
echo "MKOBJDIRS=no">>/etc/mk.conf
/usr/src/build.sh build
>Fix:
Index: build.sh
===================================================================
RCS file: /cvsroot/src/build.sh,v
retrieving revision 1.130
diff -u -r1.130 build.sh
--- build.sh	2 Jul 2004 04:25:24 -0000	1.130
+++ build.sh	12 Jul 2004 18:07:39 -0000
@@ -657,7 +657,7 @@
 	setmakeenv LC_ALL C
 	makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
 	[ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
-	MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
+	MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
 	export MAKEFLAGS MACHINE MACHINE_ARCH
 }
 
@@ -730,6 +730,7 @@
 	# Don't export them as they're only used for tests in build.sh.
 	#
 	MKOBJDIRS=$(getmakevar MKOBJDIRS)
+	MKOBJDIRS=${MKOBJDIRS-yes}
 	MKUNPRIVED=$(getmakevar MKUNPRIVED)
 	MKUPDATE=$(getmakevar MKUPDATE)
 
>Release-Note:
>Audit-Trail:
>Unformatted: