[BACK]Return to bsd.obj.mk CVS log [TXT][DIR] Up to [local] / src / share / mk

File: [local] / src / share / mk / bsd.obj.mk (download)

Revision 1.17, Sat Jan 21 06:55:52 2017 UTC (7 years, 4 months ago) by tb
Branch: MAIN
Changes since 1.16: +2 -2 lines

Only do chown :wobj when this command will succeed. Allows using
bsd.prog.mk outside /usr/src by users not belonging to group wobj.

Requested by many after a report by Sebastien Marie.
ok deraadt

#	$OpenBSD: bsd.obj.mk,v 1.17 2017/01/21 06:55:52 tb Exp $
#	$NetBSD: bsd.obj.mk,v 1.9 1996/04/10 21:08:05 thorpej Exp $

.if !target(obj)
.  if defined(NOOBJ)
obj:
.  else

.  if defined(MAKEOBJDIR)
__objdir=	${MAKEOBJDIR}
.  else
__objdir=	obj
.  endif

_SUBDIRUSE:

obj! _SUBDIRUSE
	@cd ${.CURDIR}; \
	umask ${WOBJUMASK}; \
	here=`/bin/pwd`; bsdsrcdir=`cd ${BSDSRCDIR}; /bin/pwd`; \
	subdir=$${here#$${bsdsrcdir}/}; \
	if [[ `id -u` -eq 0 && ${BUILDUSER} != root ]]; then \
		SETOWNER="chown -h ${BUILDUSER}:${WOBJGROUP}"; \
		if [[ $$here != $$subdir ]]; then \
			_mkdirs() { \
				su ${BUILDUSER} -c "mkdir -p $$1"; \
			}; \
			MKDIRS=_mkdirs; \
		fi; \
	elif [[ `id` == *'('${WOBJGROUP}')'* && $$here == $$subdir ]]; then \
		SETOWNER="chown :${WOBJGROUP}"; \
	else \
		SETOWNER=:; \
	fi; \
	[[ -z $$MKDIRS ]] && MKDIRS="mkdir -p"; \
	if test $$here != $$subdir ; then \
		dest=${BSDOBJDIR}/$$subdir ; \
		echo "$$here/${__objdir} -> $$dest"; \
		if test ! -L ${__objdir} -o \
		    X`readlink ${__objdir}` != X$$dest; \
		    then \
			if test -e ${__objdir}; then rm -rf ${__objdir}; fi; \
			ln -sf $$dest ${__objdir}; \
			$$SETOWNER ${__objdir}; \
		fi; \
		if test -d ${BSDOBJDIR}; then \
			test -d $$dest || $$MKDIRS $$dest; \
		else \
			if test -e ${BSDOBJDIR}; then \
				echo "${BSDOBJDIR} is not a directory"; \
			else \
				echo "${BSDOBJDIR} does not exist"; \
			fi; \
		fi; \
	else \
		true ; \
		dest=$$here/${__objdir} ; \
		if test ! -d ${__objdir} ; then \
			echo "making $$dest" ; \
			$$MKDIRS $$dest; \
			$$SETOWNER $$dest; \
		fi ; \
	fi;
.  endif
.endif

.include <bsd.own.mk>