Index: share/mk/bsd.obj.mk =================================================================== --- share/mk/bsd.obj.mk +++ share/mk/bsd.obj.mk @@ -51,6 +51,8 @@ .if defined(NO_OBJ) # but this makefile does not want it! .OBJDIR: ${.CURDIR} +.elif ${.OBJDIR} == ${.CURDIR} +.error .OBJDIR not properly set by auto.obj.mk. .endif # Handle special case where SRCS is full-pathed and requires # nested objdirs. This duplicates some auto.obj.mk logic. @@ -85,6 +87,10 @@ CANONICALOBJDIR:=/usr/obj${.CURDIR} .endif +.if ${CANONICALOBJDIR} == /${RELDIR} || ${.OBJDIR} == /${RELDIR} +.error .OBJDIR incorrectly set to /${RELDIR} +.endif + OBJTOP?= ${.OBJDIR:S,${.CURDIR},,}${SRCTOP} # Index: share/mk/src.sys.obj.mk =================================================================== --- share/mk/src.sys.obj.mk +++ share/mk/src.sys.obj.mk @@ -157,9 +157,8 @@ .export MK_AUTO_OBJ .endif # ${MK_AUTO_OBJ} == "no" && ... -# Assign this directory as .OBJDIR if possible after determining if AUTO_OBJ -# can be enabled by default. -.if ${MK_AUTO_OBJ} == "no" +# Assign this directory as .OBJDIR if possible. +# # The expected OBJDIR already exists, set it as .OBJDIR. .if !empty(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${.CURDIR}) .OBJDIR: ${MAKEOBJDIRPREFIX}${.CURDIR} @@ -172,5 +171,11 @@ .elif ${MAKE_VERSION} <= 20170720 && \ ${.CURDIR} == ${SRCTOP} && ${.OBJDIR} == ${SRCTOP}/ .OBJDIR: ${.CURDIR} +.else +# The OBJDIR we wanted does not yet exist, ensure we default to safe .CURDIR +# in case make started with a bogus MAKEOBJDIR, that expanded before OBJTOP +# was set, that happened to match some unexpected directory. +# Either auto.obj.mk or bsd.obj.mk will create the directory and fix .OBJDIR +# later. +.OBJDIR: ${.CURDIR} .endif -.endif # ${MK_AUTO_OBJ} == "no" Index: share/mk/sys.mk =================================================================== --- share/mk/sys.mk +++ share/mk/sys.mk @@ -125,6 +125,9 @@ .if defined(__objdir) && ${.OBJDIR} != ${__objdir} .MAKEOVERRIDES+= MK_AUTO_OBJ MK_AUTO_OBJ= no +# Fallback to safe .CURDIR rather than whatever make happened +# to start with. bsd.obj.mk will fix it later. +.OBJDIR: ${.CURDIR} .endif .endif .endif # ${MK_AUTO_OBJ} == "yes"