Index: share/mk/src.sys.obj.mk =================================================================== --- share/mk/src.sys.obj.mk +++ share/mk/src.sys.obj.mk @@ -86,6 +86,63 @@ OBJROOT:= ${OBJTOP}/ .endif +# Check how to handle default MK_AUTO_OBJ by creating/testing write to all +# directories needed, and then cleaning up anything we did on exit. +.if ${MK_AUTO_OBJ} == "no" && empty(.MAKEOVERRIDES:MMK_AUTO_OBJ) && \ + !defined(WITHOUT_AUTO_OBJ) && !make(showconfig) && !make(print-dir) +.if !defined(OBJDIR_WRITE_${OBJROOT:hash}) +CheckAutoObj= \ +CheckAutoObj() { \ + if [ -w "$${1}" ]; then \ + echo yes; \ + exit 0; \ + fi; \ + trap 'CleanupAutoObj' EXIT HUP INT TERM QUIT; \ + IFS=/; \ + d="$${1}"; \ + set -- $${d}; \ + for d in "$${@}"; do \ + dir="$${dir}$${d}/"; \ + [ -d "$${dir}" ] && continue; \ + if ! mkdir "$${dir}"; then \ + echo no; \ + exit 0; \ + fi; \ + created="$${dir} $${created}"; \ + done; \ + if [ -w "$${dir}" ]; then \ + echo yes; \ + exit 0; \ + fi; \ + echo no; \ + exit 0; \ +}; \ +CleanupAutoObj() { \ + IFS=" "; \ + for dir in $${created}; do \ + rmdir $${dir}; \ + done; \ +} + +OBJDIR_WRITE_${OBJROOT:hash}!= \ + ${CheckAutoObj}; CheckAutoObj "${OBJROOT}" 2>/dev/null || : +.export OBJDIR_WRITE_${OBJROOT:hash} +.endif +.if ${OBJDIR_WRITE_${OBJROOT:hash}} == "yes" +# Make AUTO_OBJ default and reevaluate it +__DEFAULT_YES_OPTIONS+= AUTO_OBJ +.undef MK_AUTO_OBJ +.include +.if ${MK_AUTO_OBJ} == "yes" +.export MK_AUTO_OBJ +.endif +.endif +.elif make(showconfig) +# Lie to showconfig so it gets a proper default displayed. auto.obj.mk won't +# be loaded with make(showconifg). +MK_AUTO_OBJ= yes +.endif # !defined(WITHOUT_AUTO_OBJ) + # Assign this directory as .OBJDIR if possible .if ${MK_AUTO_OBJ} == "no" # The expected OBJDIR already exists, set it as .OBJDIR. Index: tools/build/options/WITHOUT_AUTO_OBJ =================================================================== --- /dev/null +++ tools/build/options/WITHOUT_AUTO_OBJ @@ -0,0 +1,3 @@ +.\" $FreeBSD$ +Disable automatic creation of objdirs. +This is enabled by default if the wanted OBJDIR is writable by the current user.