diff --git a/share/mk/bsd.obj.mk b/share/mk/bsd.obj.mk index 235d6eb12953..c9377db63c55 100644 --- a/share/mk/bsd.obj.mk +++ b/share/mk/bsd.obj.mk @@ -51,6 +51,30 @@ CANONICALOBJDIR= ${.OBJDIR} # but this makefile does not want it! .OBJDIR: ${.CURDIR} .endif +# Handle special case where SRCS is full-pathed and requires +# nested objdirs. This duplicates some auto.obj.mk logic. +.if (!empty(SRCS:M*/*) || !empty(DPSRCS:M*/*)) && \ + (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "") +_wantdirs= ${SRCS:M*/*:H} ${DPSRCS:M*/*:H} +.if !empty(_wantdirs) +_wantdirs:= ${_wantdirs:O:u} +_needdirs= +.for _dir in ${_wantdirs} +.if !exists(${.OBJDIR}/${_dir}/) +_needdirs+= ${_dir} +.endif +.endfor +.endif +.if !empty(_needdirs) +#_mkneededdirs!= umask ${OBJDIR_UMASK:U002}; ${Mkdirs} ${_needdirs} +__objdir_made != umask ${OBJDIR_UMASK:U002}; ${Mkdirs}; \ + for dir in ${_needdirs}; do \ + dir=${.OBJDIR}/$${dir}; \ + ${ECHO_TRACE} "[Creating nested objdir $${dir}...]" >&2; \ + Mkdirs $${dir}; \ + done +.endif +.endif # !empty(SRCS:M*/*) || !empty(DPSRCS:M*/*) .elif defined(MAKEOBJDIRPREFIX) CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} .elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""