Bug 233265 - 'make -V MAKEOBJDIRPREFIX' at the top of base source tree doesn't work if value of MAKEOBJDIRPREFIX is customized
Summary: 'make -V MAKEOBJDIRPREFIX' at the top of base source tree doesn't work if val...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-17 00:39 UTC by Yasuhiro Kimura
Modified: 2022-06-09 22:06 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yasuhiro Kimura freebsd_committer freebsd_triage 2018-11-17 00:39:02 UTC
I'm writing shell script to build and install base system from source and -V option of make(1) is used in it to get value of MAKEOBJDIRPREFIX.

By default it works fine with all of head, releng/11.2, releng/12.0, stable/11 and stable/12.

----------------------------------------------------------------------
yasu@eastasia[2389]% svn info /usr0/freebsd/base/head
Path: /usr0/freebsd/base/head
Working Copy Root Path: /usr0/freebsd/base/head
URL: https://svn.freebsd.org/base/head
Relative URL: ^/head
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 340474
Node Kind: directory
Schedule: normal
Last Changed Author: karels
Last Changed Rev: 340474
Last Changed Date: 2018-11-16 12:42:29 +0900 (Fri, 16 Nov 2018)

yasu@eastasia[2390]% make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/head
/usr/obj
yasu@eastasia[2391]% svn info /usr0/freebsd/base/releng/11.2
Path: /usr0/freebsd/base/releng/11.2
Working Copy Root Path: /usr0/freebsd/base/releng/11.2
URL: https://svn.freebsd.org/base/releng/11.2
Relative URL: ^/releng/11.2
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 338990
Node Kind: directory
Schedule: normal
Last Changed Author: gordon
Last Changed Rev: 338981
Last Changed Date: 2018-09-28 03:36:30 +0900 (Fri, 28 Sep 2018)

yasu@eastasia[2392]% make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/releng/11.2
/usr/obj
yasu@eastasia[2393]% svn info /usr0/freebsd/base/releng/12.0
Path: /usr0/freebsd/base/releng/12.0
Working Copy Root Path: /usr0/freebsd/base/releng/12.0
URL: https://svn.freebsd.org/base/releng/12.0
Relative URL: ^/releng/12.0
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 340471
Node Kind: directory
Schedule: normal
Last Changed Author: gjb
Last Changed Rev: 340470
Last Changed Date: 2018-11-16 09:00:59 +0900 (Fri, 16 Nov 2018)

yasu@eastasia[2394]% make -C /usr0/freebsd/base/releng/12.0 -V MAKEOBJDIRPREFIX
/usr/obj
yasu@eastasia[2395]% svn info /usr0/freebsd/base/stable/11
Path: /usr0/freebsd/base/stable/11
Working Copy Root Path: /usr0/freebsd/base/stable/11
URL: https://svn.freebsd.org/base/stable/11
Relative URL: ^/stable/11
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 340473
Node Kind: directory
Schedule: normal
Last Changed Author: ygy
Last Changed Rev: 340449
Last Changed Date: 2018-11-15 17:43:17 +0900 (Thu, 15 Nov 2018)

yasu@eastasia[2396]% make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/stable/11
/usr/obj
yasu@eastasia[2397]% svn info /usr0/freebsd/base/stable/12
Path: /usr0/freebsd/base/stable/12
Working Copy Root Path: /usr0/freebsd/base/stable/12
URL: https://svn.freebsd.org/base/stable/12
Relative URL: ^/stable/12
Repository Root: https://svn.freebsd.org/base
Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Revision: 340474
Node Kind: directory
Schedule: normal
Last Changed Author: gjb
Last Changed Rev: 340471
Last Changed Date: 2018-11-16 09:03:31 +0900 (Fri, 16 Nov 2018)

yasu@eastasia[2398]% make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/stable/12
/usr/obj
----------------------------------------------------------------------

But if I customize value of MAKEOBJDIRPREFIX then it still works with releng/11.2 and stable/11 but doesn't with head, releng/12.0 and stable/12.

----------------------------------------------------------------------
yasu@eastasia[2399]% env MAKEOBJDIRPREFIX=/usr0/freebsd/base/ogj make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/head

yasu@eastasia[2400]% env MAKEOBJDIRPREFIX=/usr0/freebsd/base/ogj make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/releng/11.2
/usr0/freebsd/base/ogj
yasu@eastasia[2401]% env MAKEOBJDIRPREFIX=/usr0/freebsd/base/ogj make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/releng/12.0

yasu@eastasia[2402]% env MAKEOBJDIRPREFIX=/usr0/freebsd/base/ogj make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/stable/11
/usr0/freebsd/base/ogj
yasu@eastasia[2403]% env MAKEOBJDIRPREFIX=/usr0/freebsd/base/ogj make -V MAKEOBJDIRPREFIX -C /usr0/freebsd/base/stable/12

yasu@eastasia[2404]%
----------------------------------------------------------------------

I used env(1) to customize but I got same results when I use src-env.conf.

To find when behavior changed I bisected head from base r302408 (revision that stable/11 is cleated) to base r340439 and got following result.

Order	Revision	Does 'make -V MAKEOBJDIRPREFIX` work?
----------------------------------------------------------------------
1	302408		Yes		
2	340439		No
3	323176		Yes
4	332305		No
5	327441		No
6	325415		No
7	324362		Yes
8	324940		Yes
9	325181		Yes
10	325295		No
11	325248		Yes
12	325271		Yes
13	325285		Yes
14	325290		No
15	325288		No
16	325287		Yes

That is, behavior changed at base r325288. And commit message says as following.

----------------------------------------------------------------------
Add option UNIFIED_OBJDIR, on by default, which moves the default build OBJDIR.

This changes the build OBJDIR from the older style of /usr/obj/<srcdir> for
native builds, and /usr/obj/<target>.<target_arch>/<srcdir> for cross builds to
a new simpler format of /usr/obj/<srcdir>/<target>.<target_arch>.  This
new format is used regardless of cross or native build.  It allows
easier management of multiple source tree object directories.

The UNIFIED_OBJDIR option will be removed and its feature made permanent
for the 12.0 release.
----------------------------------------------------------------------

As far as I read this, behavior change of 'make -V MAKEOBJDIRPREFIX` doesn't seem intentional. So I decided to submit this bug report.

Add committer of base r325288 to CC list.
Comment 1 Bryan Drewery freebsd_committer freebsd_triage 2022-06-08 17:40:10 UTC
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)
Comment 2 Simon J. Gerraty freebsd_committer freebsd_triage 2022-06-09 22:06:48 UTC
Should the clobbering of MAKEOBJDIRPREFIX be dependent on MK_DIRDEPS_BUILD=yes ?
Since it originally make from local.meta.sys.mk?

I note too that there are two blocks in src.sys.obj.mk guarded by

.if !empty(MAKEOBJDIRPREFIX)

but since the first one clobbers MAKEOBJDIRPREFIX, the 2nd one should never be entered.

I know the traditional freebsd build plays games with MAKEOBJDIRPREFIX,
but wondering what the motive was for clobbering it outside the context of
DIRDEPS_BUILD - where use of MAKEOBJDIR is relied upon to ensure that the same RELDIR is valid in src and object trees.