diff --git a/Makefile.inc1 b/Makefile.inc1 index 2bf120c5312e..c5c176099973 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -2776,7 +2776,8 @@ BW_CANONICALOBJDIR:=${OBJROOT} .endif .endif cleanworld cleanuniverse: .PHONY -.if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) +.if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) && \ + ${.CURDIR:tA} != ${BW_CANONICALOBJDIR:tA} -rm -rf ${BW_CANONICALOBJDIR}* -chflags -R 0 ${BW_CANONICALOBJDIR} rm -rf ${BW_CANONICALOBJDIR}* diff --git a/share/mk/bsd.init.mk b/share/mk/bsd.init.mk index f3851745a44d..ca2bfb6ebed1 100644 --- a/share/mk/bsd.init.mk +++ b/share/mk/bsd.init.mk @@ -13,7 +13,7 @@ ____: .if ${MK_AUTO_OBJ} == "yes" # This is also done in bsd.obj.mk -.if defined(NO_OBJ) +.if defined(NO_OBJ) && ${.OBJDIR} != ${.CURDIR} .OBJDIR: ${.CURDIR} .endif .endif diff --git a/share/mk/bsd.obj.mk b/share/mk/bsd.obj.mk index c73daa1e29f3..f86314ac255d 100644 --- a/share/mk/bsd.obj.mk +++ b/share/mk/bsd.obj.mk @@ -48,7 +48,7 @@ objwarn: .PHONY obj: .PHONY CANONICALOBJDIR= ${.OBJDIR} # This is also done in bsd.init.mk -.if defined(NO_OBJ) +.if defined(NO_OBJ) && ${.OBJDIR} != ${.CURDIR} # but this makefile does not want it! .OBJDIR: ${.CURDIR} .endif diff --git a/share/mk/src.sys.obj.mk b/share/mk/src.sys.obj.mk index 6936f980bcbb..fc545a0e4a76 100644 --- a/share/mk/src.sys.obj.mk +++ b/share/mk/src.sys.obj.mk @@ -70,7 +70,10 @@ OBJROOT:= ${OBJROOT:H:tA}/${OBJROOT:T} .export OBJROOT SRCTOP .endif -.if ${MK_UNIFIED_OBJDIR} == "yes" +# SRCTOP == OBJROOT only happens with clever MAKEOBJDIRPREFIX=/. Don't +# append TARGET.TARGET_ARCH for that case since the user wants to build +# in the source tree. +.if ${MK_UNIFIED_OBJDIR} == "yes" && ${SRCTOP} != ${OBJROOT:tA} OBJTOP:= ${OBJROOT}${TARGET:D${TARGET}.${TARGET_ARCH}:U${MACHINE}.${MACHINE_ARCH}} .else # TARGET.TARGET_ARCH handled in OBJROOT already. @@ -103,13 +106,12 @@ __objdir:= ${MAKEOBJDIR} .endif # Try to enable MK_AUTO_OBJ by default if we can write to the __objdir. Only -# do this if AUTO_OBJ is not disabled by the user, not cleaning, and this is -# the first make ran. +# do this if AUTO_OBJ is not disabled by the user, and this is the first make +# ran. .if ${.MAKE.LEVEL} == 0 && \ ${MK_AUTO_OBJ} == "no" && empty(.MAKEOVERRIDES:MMK_AUTO_OBJ) && \ !defined(WITHOUT_AUTO_OBJ) && !make(showconfig) && !make(print-dir) && \ - !defined(NO_OBJ) && \ - (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "") + !defined(NO_OBJ) # Find the last existing directory component and check if we can write to it. # If the last component is a symlink then recurse on the new path. CheckAutoObj= \ @@ -147,9 +149,13 @@ CheckAutoObj() { \ fi; \ } .if !empty(__objdir) +.if ${.CURDIR} == ${__objdir} +__objdir_writable?= yes +.else __objdir_writable!= \ ${CheckAutoObj}; CheckAutoObj "${__objdir}" || echo no .endif +.endif __objdir_writable?= no # Export the decision to sub-makes. MK_AUTO_OBJ:= ${__objdir_writable} @@ -179,3 +185,14 @@ MK_AUTO_OBJ:= ${__objdir_writable} # auto.obj.mk or bsd.obj.mk will create the directory and fix .OBJDIR later. .OBJDIR: ${.CURDIR} .endif + +# Ensure .OBJDIR=.CURDIR cases have a proper OBJTOP and .OBJDIR +.if defined(NO_OBJ) || ${__objdir_writable:Uunknown} == "no" || \ + ${__objdir} == ${.CURDIR} +OBJTOP= ${SRCTOP} +OBJROOT= ${SRCTOP}/ +# Compare only to avoid an unneeded chdir(2), :tA purposely left out. +.if ${.OBJDIR} != ${.CURDIR} +.OBJDIR: ${.CURDIR} +.endif +.endif # defined(NO_OBJ)