[Bug 233265] 'make -V MAKEOBJDIRPREFIX' at the top of base source tree doesn't work if value of MAKEOBJDIRPREFIX is customized

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 08 Jun 2022 17:40:10 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233265

Bryan Drewery <bdrewery@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sjg@FreeBSD.org

--- Comment #1 from Bryan Drewery <bdrewery@FreeBSD.org> ---
This is quite old but yes that change did remove MAKEOBJDIRPREFIX there. The
code was activated / moved from another file and originated from here (for a
different build mode involving MK_DIRDEPS_BUILD):

commit 916c1cd0abd348b515a8ac1e6dc4326eb52bbbed
Author: Simon J. Gerraty <sjg@FreeBSD.org>
Date:   Sat Jun 20 21:48:07 2015 +0000

    Deal with MAKEOBJDIRPREFIX

    MAKEOBJDIRPREFIX does not really fit our model.
    Use it to set OBJROOT to about where user expects
    and set MAKEOBJDIR to do what we want.

Notes:
    svn path=/head/; revision=284650

diff --git share/mk/local.meta.sys.mk share/mk/local.meta.sys.mk
index 2b7f81d49b82..b3cb2575d457 100644
--- share/mk/local.meta.sys.mk
+++ share/mk/local.meta.sys.mk
@@ -8,6 +8,18 @@
 MK_INSTALL_AS_USER= yes

 .if empty(OBJROOT) || ${.MAKE.LEVEL} == 0
+.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX})
+.warning MAKEOBJDIRPREFIX not supported; setting MAKEOBJDIR...
+# put things approximately where they want
+OBJROOT:=${MAKEOBJDIRPREFIX}${SRCTOP:S,/src,,}/
+# OBJTOP set below
+MAKEOBJDIR=$${.CURDIR:S,$${SRCTOP},$${OBJTOP},}
+MAKEOBJDIRPREFIX=
+# export but do not track
+.export-env MAKEOBJDIRPREFIX MAKEOBJDIR
+# now for our own use
+MAKEOBJDIR= ${.CURDIR:S,${SRCTOP},${OBJTOP},}
+.endif
 .if !empty(SB)
 SB_OBJROOT ?= ${SB}/obj/
 # this is what we use below




I think the following patch will fix it but it is not fully tested. There are a
lot of complex cases that need testing before committing.

diff --git share/mk/src.sys.obj.mk share/mk/src.sys.obj.mk
index 3b48fc3c5514..236548b5e94b 100644
--- share/mk/src.sys.obj.mk
+++ share/mk/src.sys.obj.mk
@@ -48,9 +48,12 @@ MAKEOBJDIRPREFIX:=  
${MAKEOBJDIRPREFIX}${TARGET:D/${TARGET}.${TARGET_ARCH}}
 .if !empty(MAKEOBJDIRPREFIX)
 # put things approximately where they want
 OBJROOT:=      ${MAKEOBJDIRPREFIX}${SRCTOP}/
+_saveMAKEOBJDIRPREFIX:= ${MAKEOBJDIRPREFIX}
 MAKEOBJDIRPREFIX=
 # export but do not track
 .export-env MAKEOBJDIRPREFIX
+MAKEOBJDIRPREFIX:= ${_saveMAKEOBJDIRPREFIX}
+.undef _saveMAKEOBJDIRPREFIX
 .endif
 .if empty(MAKEOBJDIR)
 # OBJTOP set below


(I expected '.export-env MAKEOBJDIRPREFIX=' to work but it did not. I had to do
the dance above to export a blank value but keep the current value available)

-- 
You are receiving this mail because:
You are the assignee for the bug.