Re: use of "build.sh -B BUILDID".... with patch and more questions
"Greg A. Woods" <[email protected]> Sun, 30 Nov 2025 17:46:45 -0800
| Newsgroups | gmane.os.netbsd.current,gmane.os.netbsd.devel.toolchain |
|---|---|
| Organization | Planix, Inc. |
| Message-ID | <[email protected]> |
--pgp-sign-Multipart_Sun_Nov_30_17:46:28_2025-1 Content-Type: text/plain; charset=US-ASCII At Mon, 24 Nov 2025 13:27:48 -0800, "Greg A. Woods" <[email protected]> wrote: Subject: use of "build.sh -B BUILDID".... > > So, mk.conf(5) used to give some interesting ideas about what a > $(BUILDID), i.e. as set by "build.sh -B BUILDID" could be used for: > > ... can be consulted in the make(1) configuration file in order > to set additional build parameters, such as compiler flags. > > This made me think it would be useful for creating variant releases, > such as one with (or without) INET6 enabled, for example. > > However as implemented it doesn't go nearly far enough -- it only > affects $(OBJDIR) but to be useful for variant releases it would have to > also be appended to $(DESTDIR) and either to $(RELEASEDIR), or to some > other similar place where resulting release sets could be identified by > variant. So I'm betting the silence here is because nobody has really used BUILDID ever since it was added in 2002 because it didn't really help enough. The BUILDID setting never made it into the environment early enough to be useful in changing anything like the OBJDIR or DESTDIR, etc. -- it was only set in the nbmake environment by the new uniquely named makewrapper. So it could only ever be useful for complete rebuilds; and even then required yet another wrapper around build.sh (or very careful use) to set an unique OBJDIR, DESTDIR; and even then it couldn't create a shared releasedir with several different build variants in parallel. So, below is what I've come up with so far. This puts the BUILDID in various places it is useful, but tries to share the TOOLDIR with other related builds. Unfortunately this points out something that has bugged me for some time as the tools sub-directory doesn't have its own separate object directory. I realize that objects there have a ".lo" suffix, but that's not sufficient to truly share the TOOLDIR with builds that have a different BUILDID as the objects for those tools will end up in each BUILDID object directory. This doesn't matter for when object directories are kept within the source tree, but hopefully almost nobody does this any more, at least not if they're using build.sh. However when -M or -O are used, or either MAKEOBJDIRPREFIX or MAKEOBJDIR is set in the environment, then .OBJDIR has to have the BUILDID appended or inserted somewhere in order for this BUILDID thing to actually work. If anyone has any suggestions of how one might trick make into using a different MAKEOBJDIRPREFIX, or MAKEOBJDIR, depending on which was set, whenever it is working in ${TOP}/tools, I'd really love to learn about it! I can now make "normal" (my "normal") builds without some feature enabled, then build a variant with "-B variant" all by using conditionals in mk.conf, e.g.: .if !defined(BUILDID) || (${BUILDID:M*inet6*} != "inet6") MKINET6 = no # by default USE_INET6 is forced to "no" when MKINET6="no", but Justin Case # says... USE_INET6 = no .endif Still to-do is to make sure the image files are uniquely named if a BUILDID is set. -- Greg A. Woods <[email protected]> Kelowna, BC +1 250 762-7675 RoboHack <[email protected]> Planix, Inc. <[email protected]> Avoncote Farms <[email protected]> diff --git a/BUILDING b/BUILDING index 51c078f43cfb..7806164365fe 100644 --- a/BUILDING +++ b/BUILDING @@ -650,7 +650,9 @@ BUILDING Set the value of BUILDID to buildid. This will also append the build identifier to the name of the nbmake-MACHINE wrapper script so that the resulting name is of the form - "nbmake-MACHINE-BUILDID". + "nbmake-MACHINE-BUILDID". The build ID will also be appended + to the internal RELEASEMACHINEDIR subdirectory name, as well as + to the object directory name(s) (done by <bsd.obj.mk>). -C cdextras Append cdextras to the CDEXTRA variable, which is a space- @@ -706,6 +708,12 @@ BUILDING /usr/obj/usr/src/bin, /usr/obj/usr/src/lib, /usr/obj/usr/src/usr.bin, and so forth. + This might be useful if you want one shared main "obj" + directory but you build from multiple different source + trees, however since it also, by default, places + RELEASEDIR and TOOLDIR under /usr/obj/usr/src it can be + cumbersome, so see "-O" instead! + If a relative path is specified, it will be converted to an absolute path before being used. build.sh imposes the restriction that the argument to the -M option must not begin diff --git a/build.sh b/build.sh index c6ef6291fdb1..c7737c95cd07 100755 --- a/build.sh +++ b/build.sh @@ -1072,6 +1072,9 @@ resolvepath() local var="$1" local val eval val=\"\${${var}}\" + # remove any leading (and trailing) whitespace + val=${val##*[[:blank:]]} + val=${val%%*[[:blank:]]} case "${val}" in /) ;; @@ -1175,7 +1178,7 @@ help() -h Show this help message, and exit. -j NJOB Run up to NJOB jobs in parallel; see make(1) -j. -M MOBJ Set obj root directory to MOBJ; sets MAKEOBJDIRPREFIX=MOBJ, - unsets MAKEOBJDIR. + unsets MAKEOBJDIR. "/BUILDID", if given, is appended. -m MACH Set MACHINE=MACH. Some MACH values are actually aliases that set MACHINE/MACHINE_ARCH pairs. [Default: deduced from the host system if the host @@ -1274,7 +1277,7 @@ parseoptions() -B) eval ${optargcmd} - BUILDID=${OPTARG} + setmakeenv BUILDID "${OPTARG}" ;; -C) @@ -1363,7 +1366,7 @@ parseoptions() ;; esac unsetmakeenv MAKEOBJDIRPREFIX - setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}" + setmakeenv MAKEOBJDIR "\${.CURDIR:C,^${TOP},${OPTARG}${BUILDID:+/${BUILDID}},}" ;; -o) @@ -1600,8 +1603,16 @@ parseoptions() # Set up default make(1) environment. # + if [ -n "${BUILDID}" ]; then + if [ -n "${MAKEOBJDIRPREFIX}" -a -n "${TOP_objdir}" ]; then + # xxx this will dup MAKEOBJDIRPREFIX in $makeenv but + # unsetmakeenv doesn't remove var from $makeenv so it + # can't help here + setmakeenv MAKEOBJDIRPREFIX "${MAKEOBJDIRPREFIX}/${BUILDID}" + TOP_objdir="${MAKEOBJDIRPREFIX}/${TOP}" + fi + fi makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS" - [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID" [ -z "${BUILDINFO}" ] || makeenv="${makeenv} BUILDINFO" MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}" MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}" @@ -2012,7 +2023,7 @@ validatemakeparams() # could be handled either way, but we choose to handle # it similarly to MAKEOBJDIRPREFIX. # - if [ -n "${TOP_obj}" ] + if [ -n "${TOP_objdir}" ] then # It must have been set by the "-M" or "-O" # command line options, so there's no need to @@ -2020,16 +2031,16 @@ validatemakeparams() : elif [ -n "$MAKEOBJDIRPREFIX" ] then - TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}" + TOP_objdir="$(getmakevar MAKEOBJDIRPREFIX)${TOP}" elif [ -n "$MAKEOBJDIR" ] then - TOP_obj="$(getmakevar MAKEOBJDIR)" + TOP_objdir="$(getmakevar MAKEOBJDIR)" fi - if [ -n "$TOP_obj" ] + if [ -n "$TOP_objdir" ] then - ${runcmd} mkdir -p "${TOP_obj}" || + ${runcmd} mkdir -p "${TOP_objdir}" || bomb "Can't create top level object directory" \ - "${TOP_obj}" + "${TOP_objdir}" else ${runcmd} "${make}" -m "${TOP}/share/mk" obj NOSUBDIR= || bomb "Can't create top level object directory" \ @@ -2057,16 +2068,20 @@ validatemakeparams() newval="$(getmakevar $var)" if ! $do_expertmode then + # xxx this should be outside the for loop!?!?!?! : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)} case "$var" in DESTDIR) : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}} - makeenv="${makeenv} DESTDIR" ;; RELEASEDIR) - : ${newval:=${_SRC_TOP_OBJ_}/releasedir} - makeenv="${makeenv} RELEASEDIR" + if [ -n "${BUILDID}" ]; then + : ${newval:=$(echo ${_SRC_TOP_OBJ_} | sed "s|/${BUILDID}||")/releasedir} + else + : ${newval:=${_SRC_TOP_OBJ_}/releasedir} + fi ;; + # n.b.: TOOLDIR will have the correct value from getmakevar esac fi if [ -n "$oldval" ] && [ "$oldval" != "$newval" ] @@ -2076,10 +2091,15 @@ validatemakeparams() fi eval ${var}=\"\${newval}\" eval export ${var} + makeenv="${makeenv} ${var}" statusmsg2 "${var} path:" "${newval}" + + # XXX could/should make these directories now too??? done - # RELEASEMACHINEDIR is just a subdir name, e.g. "i386". + # RELEASEMACHINEDIR is just a subdir name, e.g. "i386", with ".$BUILDID" + # appended if BUILDID is set (see <bsd.own.mk>) + # RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR) # Check validity of TOOLDIR and DESTDIR. @@ -2169,7 +2189,7 @@ createmakewrapper() done fi - # Recreate $TOOLDIR. + # (Re)create $TOOLDIR. # ${runcmd} mkdir -p "${TOOLDIR}/bin" || bomb "mkdir of '${TOOLDIR}/bin' failed" @@ -2825,6 +2845,8 @@ setup_mkrepro() bomb "Failed to get timestamp for vcs=$vcs in '$d'" fi + # XXX this assumes all of ${dirs} were updated at nearly the same time!!! + #echo "latest $d $vcs $t" if [ "$t" -gt "$MKREPRO_TIMESTAMP" ] then @@ -2838,6 +2860,7 @@ setup_mkrepro() statusmsg2 "MKREPRO_TIMESTAMP" \ "$(repro_date "${MKREPRO_TIMESTAMP}")" fi + # XXX why are these not in $makeenv??? export MKREPRO MKREPRO_TIMESTAMP NETBSD_REVISIONID } diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index 405fb9054220..1bb91d4a40d2 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -48,9 +48,9 @@ LDELFSO_MACHINE_ARCH=m68k ${MACHINE:Mevbmips} || \ ${MACHINE:Mevbsh3} || \ ${MACHINE:Mriscv} -RELEASEMACHINEDIR?= ${MACHINE}-${MACHINE_ARCH} +RELEASEMACHINEDIR?= ${MACHINE}-${MACHINE_ARCH}${BUILDID:D.${BUILDID}} .else -RELEASEMACHINEDIR?= ${MACHINE} +RELEASEMACHINEDIR?= ${MACHINE}${BUILDID:D.${BUILDID}} .endif # @@ -290,7 +290,7 @@ EXTERNAL_JEMALLOC_SUBDIR = /does/not/exist .if empty(.MAKEFLAGS:tW:M*-V .OBJDIR*) .if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR) -PRINTOBJDIR= ${MAKE} -B -r -V .OBJDIR -f /dev/null xxx +PRINTOBJDIR= ${MAKE} -B -r -V .OBJDIR -f /dev/null .else PRINTOBJDIR= ${MAKE} -B -V .OBJDIR .endif @@ -335,6 +335,9 @@ NETBSDSRCDIR?= ${_SRC_TOP_} .if !defined(_SRC_TOP_OBJ_) _SRC_TOP_OBJ_!= cd "${_SRC_TOP_}" && ${PRINTOBJDIR} +. if !empty(BUILDID) && empty(_SRC_TOP_OBJ_:M*/${BUILDID}*) +_SRC_TOP_OBJ_:= ${_SRC_TOP_OBJ_}/${BUILDID} +. endif .MAKEOVERRIDES+= _SRC_TOP_OBJ_ .endif @@ -378,7 +381,11 @@ USETOOLS?= no # Provide a default for TOOLDIR. # .if !defined(TOOLDIR) +. if !empty(BUILDID) +TOOLDIR:= ${_SRC_TOP_OBJ_:S|/${BUILDID}||}/tooldir.${HOST_OSTYPE} +. else TOOLDIR:= ${_SRC_TOP_OBJ_}/tooldir.${HOST_OSTYPE} +. endif .MAKEOVERRIDES+= TOOLDIR .endif @@ -1310,6 +1317,7 @@ _MKVARS.yes= \ MKMDNS \ MKNLS \ MKNPF \ + MKNSD \ MKOBJ \ MKPAM \ MKPF \ @@ -1448,7 +1456,7 @@ EXTERNAL_MESALIB_DIR?= MesaLib.old EXTERNAL_MESALIB_DIR?= MesaLib .endif -# Default to LLVM run-time if x86 or aarch64 and X11 and Mesa 18 or newer +# Default to LLVM run-time if x86 or aarch64 and X11 and Mesa 19 or newer # XXX This knows that MKX11=no is default below, but would # require splitting the below loop in two parts. .if ${MKX11:Uno} != "no" && ${HAVE_MESA_VER} >= 19 @@ -1504,7 +1512,6 @@ _MKVARS.no= \ MKLLVMRT \ MKMANZ \ MKNOUVEAUFIRMWARE \ - MKNSD \ MKOBJDIRS \ MKPCC \ MKPICINSTALL \ --pgp-sign-Multipart_Sun_Nov_30_17:46:28_2025-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit Content-Description: OpenPGP Digital Signature -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRuK6dmwVAucmRxuh9mfXG3eL/0fwUCaSzzdwAKCRBmfXG3eL/0 f0aKAKCiEcPC39g5aE51aQZlak7haiL9uACcCZj9V0LX81+ZH1skPNNTPWaka5g= =4Qir -----END PGP SIGNATURE----- --pgp-sign-Multipart_Sun_Nov_30_17:46:28_2025-1--